@jsb188/mday-web 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +25 -17
- package/src/modules/Grids.filters.ts +9 -0
- package/src/modules/Grids.tsx +62 -650
- package/src/modules/RouteShell.tsx +9 -19
- package/src/schemas/organization.ts +154 -0
- package/src/utils/email.ts +122 -0
- package/src/utils/linkedEntity.ts +110 -0
- package/src/utils/log-web.helpers.ts +99 -0
- package/src/utils/log-web.icons.ts +184 -0
- package/src/utils/log-web.ts +58 -458
- package/src/utils/route-helpers.ts +207 -296
- package/src/utils/workflow-web.ts +11 -62
- package/src/modules/AgentDocs.tsx +0 -800
- package/src/modules/DocAccessSettings.tsx +0 -963
- package/src/utils/account-web.ts +0 -64
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -11
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { ServerErrorObj } from '@jsb188/app/types/app.d.ts';
|
|
2
|
-
import {
|
|
3
|
-
ContentGate,
|
|
4
|
-
ErrorMessage,
|
|
5
|
-
ErrorMessageContainer,
|
|
6
|
-
} from '@jsb188/react-web/modules/layout/MainLayout';
|
|
2
|
+
import { ContentGate, ErrorMessage, ErrorMessageContainer } from '@jsb188/react-web/modules/layout/MainLayout';
|
|
7
3
|
import { memo, type Dispatch, type SetStateAction } from 'react';
|
|
8
4
|
|
|
9
5
|
interface AppRouteShellProps {
|
|
10
|
-
layoutOpen
|
|
11
|
-
setLayoutOpen
|
|
6
|
+
layoutOpen?: boolean;
|
|
7
|
+
setLayoutOpen?: Dispatch<SetStateAction<boolean>>;
|
|
12
8
|
}
|
|
13
9
|
|
|
14
10
|
interface AppRouteErrorMessageProps extends AppRouteShellProps {
|
|
@@ -25,17 +21,7 @@ interface AppRouteErrorMessageProps extends AppRouteShellProps {
|
|
|
25
21
|
* Render a reusable route error inside the app shell layout.
|
|
26
22
|
*/
|
|
27
23
|
export const AppRouteErrorMessage = memo((p: AppRouteErrorMessageProps) => {
|
|
28
|
-
const {
|
|
29
|
-
buttonColorClassName,
|
|
30
|
-
buttonHref,
|
|
31
|
-
buttonText,
|
|
32
|
-
error,
|
|
33
|
-
iconName,
|
|
34
|
-
layoutOpen,
|
|
35
|
-
message,
|
|
36
|
-
setLayoutOpen,
|
|
37
|
-
title,
|
|
38
|
-
} = p;
|
|
24
|
+
const { buttonColorClassName, buttonHref, buttonText, error, iconName, layoutOpen, message, setLayoutOpen, title } = p;
|
|
39
25
|
|
|
40
26
|
return (
|
|
41
27
|
<ErrorMessageContainer
|
|
@@ -68,7 +54,11 @@ export const AppRouteLoading = memo((p: AppRouteShellProps) => {
|
|
|
68
54
|
layoutOpen={layoutOpen}
|
|
69
55
|
setLayoutOpen={setLayoutOpen}
|
|
70
56
|
>
|
|
71
|
-
<ContentGate
|
|
57
|
+
<ContentGate
|
|
58
|
+
loading
|
|
59
|
+
notReady
|
|
60
|
+
showLoadingIfNotReady
|
|
61
|
+
/>
|
|
72
62
|
</ErrorMessageContainer>
|
|
73
63
|
);
|
|
74
64
|
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { SUPPORTED_LOG_LANGUAGES } from '@jsb188/app/constants/app.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import { makeAddressSchema } from '@jsb188/auth-web/schemas/address';
|
|
4
|
+
import { defineForm } from '@jsb188/form/libs/defineForm';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { OrganizationGQL, OrganizationSettingsObj } from '@jsb188/mday/types/organization.d.ts';
|
|
7
|
+
import {
|
|
8
|
+
getOrganizationAllowMcpConnectionsSetting,
|
|
9
|
+
getOrganizationDisplayTranslatedLogsSetting,
|
|
10
|
+
getOrganizationLogLanguageSetting,
|
|
11
|
+
} from '@jsb188/mday/utils/organization.ts';
|
|
12
|
+
|
|
13
|
+
/* Keep the existing organization settings popovers consistent across selectors. */
|
|
14
|
+
function settingsPopover(name: string, options: object[], designClassName?: string, className?: string) {
|
|
15
|
+
return {
|
|
16
|
+
id: `edit_org_${name}`,
|
|
17
|
+
zClassName: 'z9',
|
|
18
|
+
position: 'bottom_left' as const,
|
|
19
|
+
offsetX: 0,
|
|
20
|
+
offsetY: 7,
|
|
21
|
+
iface: {
|
|
22
|
+
name: 'PO_LIST',
|
|
23
|
+
variables: { designClassName, className, options },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Define organization information, language preferences, AI app connections, and address in display order. */
|
|
29
|
+
export function makeEditOrganizationSchema(
|
|
30
|
+
organization: OrganizationGQL,
|
|
31
|
+
settings: Pick<OrganizationSettingsObj, 'displayTranslatedLogs' | 'translateLanguage' | 'allowMcpConnections'>,
|
|
32
|
+
) {
|
|
33
|
+
const address = makeAddressSchema(organization.address);
|
|
34
|
+
const disabledLanguageText = i18n.t('org.translate_language_disabled');
|
|
35
|
+
|
|
36
|
+
return defineForm({
|
|
37
|
+
schema: address.schema.extend({
|
|
38
|
+
name: z.string(),
|
|
39
|
+
operation: z.string(),
|
|
40
|
+
translateLanguage: z.string().nullable(),
|
|
41
|
+
displayTranslatedLogs: z.boolean(),
|
|
42
|
+
allowMcpConnections: z.boolean(),
|
|
43
|
+
}),
|
|
44
|
+
defaults: {
|
|
45
|
+
...address.defaults,
|
|
46
|
+
name: organization.name || '',
|
|
47
|
+
operation: organization.operation,
|
|
48
|
+
translateLanguage: getOrganizationLogLanguageSetting(settings, 'translateLanguage'),
|
|
49
|
+
displayTranslatedLogs: getOrganizationDisplayTranslatedLogsSetting(settings),
|
|
50
|
+
allowMcpConnections: getOrganizationAllowMcpConnectionsSetting(settings),
|
|
51
|
+
},
|
|
52
|
+
fields: {
|
|
53
|
+
name: {
|
|
54
|
+
kind: 'input',
|
|
55
|
+
maxLength: 40,
|
|
56
|
+
label: i18n.t('org.name_of'),
|
|
57
|
+
placeholder: organization.name,
|
|
58
|
+
autoComplete: 'off',
|
|
59
|
+
},
|
|
60
|
+
operation: {
|
|
61
|
+
kind: 'input',
|
|
62
|
+
locked: true,
|
|
63
|
+
label: i18n.t('org.type_of'),
|
|
64
|
+
placeholder: i18n.t(`org.type.${organization.operation}`),
|
|
65
|
+
getter: (value: string) => i18n.t(`org.type.${value}`),
|
|
66
|
+
autoComplete: 'off',
|
|
67
|
+
info: i18n.t('org.contact_to_change'),
|
|
68
|
+
},
|
|
69
|
+
translateLanguage: {
|
|
70
|
+
kind: 'click',
|
|
71
|
+
label: i18n.t('org.translate_language'),
|
|
72
|
+
info: i18n.t('org.translate_language_description'),
|
|
73
|
+
placeholder: disabledLanguageText,
|
|
74
|
+
getter: (value: string | null) => (value === null ? disabledLanguageText : i18n.t(`c.lang.${value || 'en'}`)),
|
|
75
|
+
resolve: ({ values }) => ({
|
|
76
|
+
inputClassName: values.translateLanguage === null ? 'cl_md' : undefined,
|
|
77
|
+
popOverProps: settingsPopover(
|
|
78
|
+
'translateLanguage',
|
|
79
|
+
[
|
|
80
|
+
{
|
|
81
|
+
__type: 'LIST_ITEM',
|
|
82
|
+
text: disabledLanguageText,
|
|
83
|
+
textClassName: 'cl_md',
|
|
84
|
+
name: 'translateLanguage',
|
|
85
|
+
value: null,
|
|
86
|
+
selected: values.translateLanguage === null,
|
|
87
|
+
},
|
|
88
|
+
...SUPPORTED_LOG_LANGUAGES.map((language) => ({
|
|
89
|
+
__type: 'LIST_ITEM',
|
|
90
|
+
text: i18n.t(`c.lang.${language}`),
|
|
91
|
+
name: 'translateLanguage',
|
|
92
|
+
value: language,
|
|
93
|
+
selected: values.translateLanguage === language,
|
|
94
|
+
})).sort((a, b) => a.text.localeCompare(b.text)),
|
|
95
|
+
],
|
|
96
|
+
'w_400',
|
|
97
|
+
'max_h_40vh',
|
|
98
|
+
),
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
displayTranslatedLogs: {
|
|
102
|
+
kind: 'click',
|
|
103
|
+
label: i18n.t('org.log_language_preference'),
|
|
104
|
+
info: i18n.t('org.log_language_preference_description'),
|
|
105
|
+
getter: (value: boolean) =>
|
|
106
|
+
i18n.t(value === false ? 'org.always_show_original_log_texts' : 'org.display_translated_logs_if_available'),
|
|
107
|
+
resolve: ({ values }) => ({
|
|
108
|
+
popOverProps: settingsPopover(
|
|
109
|
+
'displayTranslatedLogs',
|
|
110
|
+
[true, false].map((value) => ({
|
|
111
|
+
__type: 'LIST_ITEM',
|
|
112
|
+
text: i18n.t(value ? 'org.display_translated_logs_if_available' : 'org.always_show_original_log_texts'),
|
|
113
|
+
name: 'displayTranslatedLogs',
|
|
114
|
+
value,
|
|
115
|
+
selected: values.displayTranslatedLogs === value,
|
|
116
|
+
})),
|
|
117
|
+
'w_400',
|
|
118
|
+
),
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
allowMcpConnections: {
|
|
122
|
+
kind: 'click',
|
|
123
|
+
label: i18n.t('org.allow_mcp_connections'),
|
|
124
|
+
info: i18n.t('org.allow_mcp_connections_description'),
|
|
125
|
+
getter: (value: boolean) => i18n.t(value === false ? 'c.no' : 'c.yes'),
|
|
126
|
+
resolve: ({ values }) => ({
|
|
127
|
+
popOverProps: settingsPopover(
|
|
128
|
+
'allowMcpConnections',
|
|
129
|
+
[true, false].map((value) => ({
|
|
130
|
+
__type: 'LIST_ITEM',
|
|
131
|
+
text: i18n.t(value ? 'c.yes' : 'c.no'),
|
|
132
|
+
name: 'allowMcpConnections',
|
|
133
|
+
value,
|
|
134
|
+
selected: values.allowMcpConnections === value,
|
|
135
|
+
})),
|
|
136
|
+
),
|
|
137
|
+
}),
|
|
138
|
+
},
|
|
139
|
+
...address.fields,
|
|
140
|
+
},
|
|
141
|
+
layout: [
|
|
142
|
+
{ kind: 'section', id: 'information', title: i18n.t('c.information') },
|
|
143
|
+
'name',
|
|
144
|
+
'operation',
|
|
145
|
+
{ kind: 'section', id: 'language', title: i18n.t('account.language') },
|
|
146
|
+
'translateLanguage',
|
|
147
|
+
'displayTranslatedLogs',
|
|
148
|
+
{ kind: 'section', id: 'integrations', title: i18n.t('app.integrations') },
|
|
149
|
+
'allowMcpConnections',
|
|
150
|
+
{ kind: 'section', id: 'address', title: i18n.t('c.address'), description: i18n.t('org.address_notice_msg') },
|
|
151
|
+
...(address.layout || []),
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import { getFullDate, getFullDateTime } from '@jsb188/app/utils/datetime.ts';
|
|
3
|
+
import { ucFirst } from '@jsb188/app/utils/string.ts';
|
|
4
|
+
import type { EmailMessageHeadingFields, EmailMessageStatusEnum } from '@jsb188/mday/types/email.d.ts';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Describe one email event with its recorded local time and a capitalized sentence.
|
|
8
|
+
*/
|
|
9
|
+
function getEmailEventHeading(event: string, name: string, timeZone: string | null, timestamp?: string | null): string {
|
|
10
|
+
const dateTime =
|
|
11
|
+
timestamp && Number.isFinite(Date.parse(timestamp))
|
|
12
|
+
? `${getFullDate(timestamp, 'DATE_TEXT', timeZone)}, ${getFullDateTime(timestamp, { timeZone, hideDate: true })}`
|
|
13
|
+
: null;
|
|
14
|
+
return ucFirst(i18n.t(`agent.email_message_heading.${event}${dateTime ? '_at' : ''}`, { name, dateTime }));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Share outbound delivery headings between campaign recipients and email message details.
|
|
19
|
+
*/
|
|
20
|
+
export function getOutboundEmailHeading(
|
|
21
|
+
email: {
|
|
22
|
+
name: string;
|
|
23
|
+
status?: EmailMessageStatusEnum | null;
|
|
24
|
+
sentAt?: string | null;
|
|
25
|
+
deliveredAt?: string | null;
|
|
26
|
+
openedAt?: string | null;
|
|
27
|
+
respondedAt?: string | null;
|
|
28
|
+
bouncedAt?: string | null;
|
|
29
|
+
spamComplaintAt?: string | null;
|
|
30
|
+
},
|
|
31
|
+
timeZone: string | null,
|
|
32
|
+
): string {
|
|
33
|
+
const { name } = email;
|
|
34
|
+
switch (email.status) {
|
|
35
|
+
case 'SENT':
|
|
36
|
+
if (email.spamComplaintAt) return getEmailEventHeading('spam', name, timeZone, email.spamComplaintAt);
|
|
37
|
+
if (email.respondedAt) return getEmailEventHeading('responded', name, timeZone, email.respondedAt);
|
|
38
|
+
if (email.openedAt) return getEmailEventHeading('opened', name, timeZone, email.openedAt);
|
|
39
|
+
if (email.deliveredAt) return getEmailEventHeading('delivered', name, timeZone, email.deliveredAt);
|
|
40
|
+
return getEmailEventHeading('sent', name, timeZone, email.sentAt);
|
|
41
|
+
case 'BOUNCED':
|
|
42
|
+
return getEmailEventHeading('bounced', name, timeZone, email.bouncedAt);
|
|
43
|
+
case 'QUEUED':
|
|
44
|
+
return getEmailEventHeading('queued', name, timeZone);
|
|
45
|
+
case 'PROCESSING':
|
|
46
|
+
return getEmailEventHeading('sending', name, timeZone);
|
|
47
|
+
case 'DELIVERY_UNKNOWN':
|
|
48
|
+
return getEmailEventHeading('unknown_delivery', name, timeZone);
|
|
49
|
+
case 'ERRORED':
|
|
50
|
+
return getEmailEventHeading('failed', name, timeZone);
|
|
51
|
+
case 'SUPPRESSED':
|
|
52
|
+
return getEmailEventHeading('skipped', name, timeZone);
|
|
53
|
+
default:
|
|
54
|
+
return getEmailEventHeading('unavailable', name, timeZone);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* Show the inbound status summary when available, with an event heading as the fallback.
|
|
60
|
+
*/
|
|
61
|
+
export function getEmailMessageHeading(email: EmailMessageHeadingFields, timeZone: string | null): string {
|
|
62
|
+
if (email.direction === 'OUTBOUND') {
|
|
63
|
+
return getOutboundEmailHeading(
|
|
64
|
+
{
|
|
65
|
+
name: email.toName?.trim() || email.toEmail || i18n.t('c.unknown'),
|
|
66
|
+
status: email.status,
|
|
67
|
+
sentAt: email.sentAt,
|
|
68
|
+
deliveredAt: email.deliveredAt,
|
|
69
|
+
openedAt: email.firstOpenedAt,
|
|
70
|
+
bouncedAt: email.bouncedAt,
|
|
71
|
+
spamComplaintAt: email.spamComplaintAt,
|
|
72
|
+
},
|
|
73
|
+
timeZone,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const summary = email.statusSummary?.trim();
|
|
77
|
+
if (summary) return summary;
|
|
78
|
+
|
|
79
|
+
const name = email.fromName?.trim() || email.fromEmail || i18n.t('c.unknown');
|
|
80
|
+
switch (email.status) {
|
|
81
|
+
case 'RECEIVED':
|
|
82
|
+
return getEmailEventHeading('received', name, timeZone, email.occurredAt);
|
|
83
|
+
case 'QUEUED':
|
|
84
|
+
return getEmailEventHeading('inbound_queued', name, timeZone);
|
|
85
|
+
case 'PROCESSING':
|
|
86
|
+
return getEmailEventHeading('inbound_processing', name, timeZone, email.processingStartedAt);
|
|
87
|
+
case 'COMPLETED':
|
|
88
|
+
return getEmailEventHeading('inbound_completed', name, timeZone, email.occurredAt);
|
|
89
|
+
case 'ERRORED':
|
|
90
|
+
return getEmailEventHeading('inbound_failed', name, timeZone, email.processingCompletedAt);
|
|
91
|
+
case 'IGNORED':
|
|
92
|
+
return getEmailEventHeading('inbound_ignored', name, timeZone);
|
|
93
|
+
case 'SUPERSEDED':
|
|
94
|
+
return getEmailEventHeading('inbound_superseded', name, timeZone);
|
|
95
|
+
default:
|
|
96
|
+
return getEmailEventHeading('inbound_unavailable', name, timeZone);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Explain one campaign delivery suppression without exposing internal codes.
|
|
102
|
+
*/
|
|
103
|
+
export function getOutboundEmailSuppressionReasonText(reason: string | null | undefined): string {
|
|
104
|
+
switch (reason) {
|
|
105
|
+
case 'ORGANIZATION_OPT_OUT':
|
|
106
|
+
return i18n.t('campaign.email_suppression_organization_opt_out');
|
|
107
|
+
case 'CLEANED':
|
|
108
|
+
return i18n.t('campaign.email_suppression_cleaned');
|
|
109
|
+
case 'SPAM_COMPLAINT':
|
|
110
|
+
return i18n.t('campaign.email_suppression_spam_complaint');
|
|
111
|
+
case 'MANUAL_SUPPRESSION':
|
|
112
|
+
return i18n.t('campaign.email_suppression_manual');
|
|
113
|
+
case 'AUDIENCE_INELIGIBLE':
|
|
114
|
+
return i18n.t('campaign.email_suppression_audience_ineligible');
|
|
115
|
+
case 'ALREADY_REPLIED':
|
|
116
|
+
return i18n.t('campaign.email_suppression_already_replied');
|
|
117
|
+
case 'EMAIL_OUTREACH_UNAVAILABLE':
|
|
118
|
+
return i18n.t('campaign.email_suppression_campaign_unavailable');
|
|
119
|
+
default:
|
|
120
|
+
return i18n.t('campaign.email_suppression_unknown');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { LinkedEntityType } from '@jsb188/mday/constants/linkedEntity.ts';
|
|
2
|
+
import type { LinkedEntityRef, LinkedEntitySummary } from '@jsb188/mday/types/linkedEntity.d.ts';
|
|
3
|
+
import type { LogTaxonomyGQL } from '@jsb188/mday/types/log.d.ts';
|
|
4
|
+
import { serializePageFilters } from '@jsb188/react/libs/page-filters';
|
|
5
|
+
import { COMMON_ICON_NAMES, getFileTypeIconName } from '@jsb188/react-web/svgs/Icon';
|
|
6
|
+
import { makeFieldDocFormPath } from './route-helpers';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Describe a linked entity's ordinary destination without loading its viewer. A workflow (workflowKind WORKFLOW) opens
|
|
10
|
+
* only its modal; a scheduled task, or a WORKFLOW link whose kind is not known yet, keeps its runs page.
|
|
11
|
+
*/
|
|
12
|
+
export function getLinkedEntityDestination(
|
|
13
|
+
ref: LinkedEntityRef & Pick<LinkedEntitySummary, 'fieldDocProgramId' | 'workflowKind' | 'fileName' | 'fileContentType'>,
|
|
14
|
+
): {
|
|
15
|
+
to?: string;
|
|
16
|
+
iconName: string;
|
|
17
|
+
modalName?: string;
|
|
18
|
+
} {
|
|
19
|
+
const id = encodeURIComponent(ref.entityId);
|
|
20
|
+
switch (ref.entityType) {
|
|
21
|
+
case 'SHEET':
|
|
22
|
+
return {
|
|
23
|
+
to: `/app/s/${id}${ref.sheetTabId ? `?tab=${encodeURIComponent(ref.sheetTabId)}` : ''}`,
|
|
24
|
+
iconName: COMMON_ICON_NAMES.sheet,
|
|
25
|
+
};
|
|
26
|
+
case 'DATA_TABLE':
|
|
27
|
+
return { to: `/app/d/${id}`, iconName: COMMON_ICON_NAMES.data_table };
|
|
28
|
+
case 'EMAIL_OUTREACH':
|
|
29
|
+
return { to: `/app/oe/${id}`, iconName: COMMON_ICON_NAMES.email_outreach };
|
|
30
|
+
case 'AGENT_NOTE':
|
|
31
|
+
return { iconName: COMMON_ICON_NAMES.description, modalName: 'AGENT_NOTE' };
|
|
32
|
+
case 'WORKFLOW':
|
|
33
|
+
return ref.workflowKind === 'WORKFLOW'
|
|
34
|
+
? { iconName: COMMON_ICON_NAMES.ai_workflow, modalName: 'WORKFLOW' }
|
|
35
|
+
: { to: `/app/runs/${id}`, iconName: COMMON_ICON_NAMES.ai_workflow, modalName: 'WORKFLOW' };
|
|
36
|
+
case 'WORKFLOW_RUN':
|
|
37
|
+
return { iconName: COMMON_ICON_NAMES.ai_workflow, modalName: 'WORKFLOW_RUN' };
|
|
38
|
+
case 'FIELD_DOC':
|
|
39
|
+
return {
|
|
40
|
+
to: ref.fieldDocProgramId ? makeFieldDocFormPath(ref.fieldDocProgramId, ref.entityId) : undefined,
|
|
41
|
+
iconName: COMMON_ICON_NAMES.field_document,
|
|
42
|
+
};
|
|
43
|
+
case 'FIELD_DOC_SUBMISSION':
|
|
44
|
+
return { to: `/app/p/${id}`, iconName: COMMON_ICON_NAMES.field_document };
|
|
45
|
+
case 'GENERATED_FILE':
|
|
46
|
+
return { to: `/app/downloads?file=${id}`, iconName: 'download', modalName: 'DOWNLOAD_GENERATED_FILE' };
|
|
47
|
+
case 'LIBRARY_FILE':
|
|
48
|
+
return {
|
|
49
|
+
to: `/app/y/${id}`,
|
|
50
|
+
iconName:
|
|
51
|
+
ref.fileName || ref.fileContentType
|
|
52
|
+
? getFileTypeIconName(ref.fileContentType ?? '', ref.fileName)
|
|
53
|
+
: COMMON_ICON_NAMES.description,
|
|
54
|
+
};
|
|
55
|
+
case 'LOG_ACTIVITY':
|
|
56
|
+
return {
|
|
57
|
+
to: ref.logActivityKey ? makeLinkedLogPath('activities', ref.logActivityKey) : undefined,
|
|
58
|
+
iconName: COMMON_ICON_NAMES.logs,
|
|
59
|
+
};
|
|
60
|
+
case 'LOG_ACTIVITY_GROUP':
|
|
61
|
+
return {
|
|
62
|
+
to: ref.logActivityGroupKey ? makeLinkedLogPath('types', ref.logActivityGroupKey) : undefined,
|
|
63
|
+
iconName: COMMON_ICON_NAMES.logs,
|
|
64
|
+
};
|
|
65
|
+
case 'CHILD_ORG':
|
|
66
|
+
return { iconName: COMMON_ICON_NAMES.team, modalName: 'ORG_PROFILE' };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Resolve same-origin document links into identities that can open in the chat pane. */
|
|
71
|
+
export function parseLinkedEntityPath(
|
|
72
|
+
href: string,
|
|
73
|
+
origin = typeof window === 'undefined' ? 'https://marketday.local' : window.location.origin,
|
|
74
|
+
): LinkedEntityRef | null {
|
|
75
|
+
try {
|
|
76
|
+
const url = new URL(href, origin);
|
|
77
|
+
if (url.origin !== origin) return null;
|
|
78
|
+
const match = /^\/app\/(s|d|p|outreach|runs)\/([^/]+)\/?$/.exec(url.pathname);
|
|
79
|
+
if (!match) return null;
|
|
80
|
+
const types: Record<string, LinkedEntityType> = {
|
|
81
|
+
s: 'SHEET',
|
|
82
|
+
d: 'DATA_TABLE',
|
|
83
|
+
p: 'FIELD_DOC_SUBMISSION',
|
|
84
|
+
outreach: 'EMAIL_OUTREACH',
|
|
85
|
+
runs: 'WORKFLOW',
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
entityType: types[match[1]],
|
|
89
|
+
entityId: decodeURIComponent(match[2]),
|
|
90
|
+
...(match[1] === 's' && url.searchParams.get('tab') ? { sheetTabId: url.searchParams.get('tab') } : {}),
|
|
91
|
+
};
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* Match existing taxonomy-key links without guessing registry ids or display labels. */
|
|
98
|
+
export function resolveLinkedLogRef(ref: LinkedEntityRef, taxonomy?: LogTaxonomyGQL | null): LinkedEntityRef {
|
|
99
|
+
if (ref.entityType === 'LOG_ACTIVITY' && taxonomy?.activities.some((activity) => activity.key === ref.entityId))
|
|
100
|
+
return { ...ref, logActivityKey: ref.entityId };
|
|
101
|
+
if (ref.entityType === 'LOG_ACTIVITY_GROUP' && taxonomy?.groups.some((group) => group.key === ref.entityId))
|
|
102
|
+
return { ...ref, logActivityGroupKey: ref.entityId };
|
|
103
|
+
return ref;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* Encode one log scope using the same canonical filter grammar as the logs page. */
|
|
107
|
+
function makeLinkedLogPath(field: 'activities' | 'types', key: string): string {
|
|
108
|
+
const filter = serializePageFilters({ filter: { [field]: { type: 'array', items: { type: 'string' } } } }, { [field]: [key] });
|
|
109
|
+
return `/app/logs?${new URLSearchParams({ filter })}`;
|
|
110
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type IconMatchRule = {
|
|
2
|
+
icon: string;
|
|
3
|
+
tier: 'specific' | 'activity' | 'fallback';
|
|
4
|
+
words?: readonly string[];
|
|
5
|
+
phrases?: readonly string[];
|
|
6
|
+
prefixes?: readonly string[];
|
|
7
|
+
patterns?: readonly string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type CompiledIconMatcher = {
|
|
11
|
+
icon: string;
|
|
12
|
+
priority: number;
|
|
13
|
+
regex: RegExp;
|
|
14
|
+
key: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const FILE_CONSTANTS = {
|
|
18
|
+
tierPriority: { specific: 3, activity: 2, fallback: 1 },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Normalize case, Unicode compatibility forms, separators, and whitespace once per input.
|
|
23
|
+
*/
|
|
24
|
+
function normalizeIconText(text: string): string {
|
|
25
|
+
return text
|
|
26
|
+
.normalize('NFKC')
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.replace(/[\p{Dash_Punctuation}_\s]+/gu, ' ')
|
|
29
|
+
.trim();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Escape literal aliases so punctuation cannot accidentally introduce regex syntax.
|
|
34
|
+
*/
|
|
35
|
+
function escapeIconAlias(text: string): string {
|
|
36
|
+
return normalizeIconText(text).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* Precompile each rule once, sorting literal alternatives longest-first to retain overlapping phrases.
|
|
41
|
+
* Only patterns contain regex syntax; words and phrases match complete tokens, while prefixes consume word endings.
|
|
42
|
+
*/
|
|
43
|
+
export function compileIconMatchRules(rules: readonly IconMatchRule[]): readonly CompiledIconMatcher[] {
|
|
44
|
+
return rules
|
|
45
|
+
.flatMap((rule) => {
|
|
46
|
+
const literals = [...(rule.words || []), ...(rule.phrases || [])].map(escapeIconAlias);
|
|
47
|
+
// Literal alternatives can be safely ordered by length; variable-length regexes must compete independently.
|
|
48
|
+
literals.sort((a, b) => b.length - a.length || (a < b ? -1 : a > b ? 1 : 0));
|
|
49
|
+
const patterns = [
|
|
50
|
+
...(literals.length ? [literals.join('|')] : []),
|
|
51
|
+
...(rule.prefixes || []).map((prefix) => `${escapeIconAlias(prefix)}[\\p{L}\\p{M}]*`),
|
|
52
|
+
...(rule.patterns || []),
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
return patterns.map((source) => ({
|
|
56
|
+
icon: rule.icon,
|
|
57
|
+
priority: FILE_CONSTANTS.tierPriority[rule.tier],
|
|
58
|
+
regex: new RegExp(`(^|[^\\p{L}\\p{M}\\p{N}])(${source})(?![\\p{L}\\p{M}\\p{N}])`, 'u'),
|
|
59
|
+
key: `${rule.icon}:${rule.tier}:${source}`,
|
|
60
|
+
}));
|
|
61
|
+
})
|
|
62
|
+
.sort((a, b) => b.priority - a.priority);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* Choose the strongest tier, then the first mention. At the same start, prefer the longer matching phrase.
|
|
67
|
+
* Containing phrases start before their inner words; stable keys resolve identical spans without list-order priority.
|
|
68
|
+
* Regexes are non-global, so repeated calls and repeated words cannot retain mutable lastIndex state.
|
|
69
|
+
*/
|
|
70
|
+
export function matchIconName(matchers: readonly CompiledIconMatcher[], text?: string | null): string | null {
|
|
71
|
+
if (!text?.trim()) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const normalizedText = normalizeIconText(text);
|
|
76
|
+
let best: { matcher: CompiledIconMatcher; index: number; length: number } | null = null;
|
|
77
|
+
|
|
78
|
+
for (const matcher of matchers) {
|
|
79
|
+
// Compiled rules are sorted by tier, so lower tiers cannot displace an existing match.
|
|
80
|
+
if (best && matcher.priority < best.matcher.priority) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
const match = matcher.regex.exec(normalizedText);
|
|
84
|
+
if (!match) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const index = match.index + match[1].length;
|
|
88
|
+
const length = match[2].length;
|
|
89
|
+
if (
|
|
90
|
+
!best ||
|
|
91
|
+
index < best.index ||
|
|
92
|
+
(index === best.index && (length > best.length || (length === best.length && matcher.key < best.matcher.key)))
|
|
93
|
+
) {
|
|
94
|
+
best = { matcher, index, length };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return best?.matcher.icon || null;
|
|
99
|
+
}
|