@jsb188/mday-web 1.1.10 → 1.1.12

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.
Files changed (38) hide show
  1. package/package.json +36 -24
  2. package/src/libs/route-metadata.server.ts +67 -0
  3. package/src/modules/Grids.filters.ts +36 -0
  4. package/src/modules/Grids.tsx +610 -0
  5. package/src/modules/RouteShell.tsx +76 -0
  6. package/src/schemas/organization.ts +128 -0
  7. package/src/utils/email.ts +117 -0
  8. package/src/utils/list-web.ts +17 -0
  9. package/src/utils/log-web.helpers.ts +99 -0
  10. package/src/utils/log-web.icons.ts +184 -0
  11. package/src/utils/log-web.ts +74 -364
  12. package/src/utils/operation-pages.ts +154 -0
  13. package/src/utils/org-web.ts +35 -8
  14. package/src/utils/route-helpers.ts +837 -596
  15. package/src/utils/workflow-web.ts +72 -0
  16. package/tests/log-web.test.ts +134 -0
  17. package/tests/route-helpers.test.ts +17 -0
  18. package/tsconfig.json +11 -11
  19. package/src/modules/DataTable-ContextMenu.tsx +0 -169
  20. package/src/modules/DataTable-InboundContact.tsx +0 -523
  21. package/src/modules/DataTable.tsx +0 -5060
  22. package/src/modules/Sheet-ContextMenu.tsx +0 -161
  23. package/src/modules/Sheet.tsx +0 -28
  24. package/src/modules/cell-save-beacon.ts +0 -67
  25. package/src/modules/dataTable-interaction-state.ts +0 -276
  26. package/src/modules/dataTable-shortcuts.ts +0 -192
  27. package/src/modules/dataTable-viewport.ts +0 -89
  28. package/src/modules/grid-cell-render.ts +0 -72
  29. package/src/modules/grid-context-menu.ts +0 -112
  30. package/src/modules/grid-keyboard.ts +0 -267
  31. package/src/modules/grid-render-store.ts +0 -103
  32. package/src/modules/grid-runtime.ts +0 -178
  33. package/src/modules/grid-selection.ts +0 -336
  34. package/src/modules/grid-viewport.ts +0 -57
  35. package/src/modules/use-dataTable-states.ts +0 -529
  36. package/src/modules/use-debounced-cell-save-batch.ts +0 -160
  37. package/tests/DataTable.test.tsx +0 -4466
  38. package/tests/dataTable-interaction-state.test.ts +0 -127
@@ -1,523 +0,0 @@
1
- import i18n from '@jsb188/app/i18n/index.ts';
2
- import { cn } from '@jsb188/app/utils/string.ts';
3
- import { useEditInboundContact } from '@jsb188/graphql/hooks/use-inboundContact-mtn';
4
- import { useInboundContact } from '@jsb188/graphql/hooks/use-inboundContact-qry';
5
- import { useChildOrganizations } from '@jsb188/graphql/hooks/use-organization-qry';
6
- import { makeEditInboundContactSchema } from '@jsb188/mday/schemas/inboundContact.ts';
7
- import type { InboundContactGQL, InboundContactOrgGQL } from '@jsb188/mday/types/inboundContact.d.ts';
8
- import type { OrganizationChildGQL } from '@jsb188/mday/types/organization.d.ts';
9
- import { MoreBelowScrollArea } from '@jsb188/react-web/modules/Scroll';
10
- import { COMMON_ICON_NAMES, Icon } from '@jsb188/react-web/svgs/Icon';
11
- import { TextWithLinks } from '@jsb188/react-web/ui/Markdown';
12
- import { SheetEditorNav, SheetSaveButton } from '@jsb188/react-web/ui/SheetEditor';
13
- import type { SheetUIEditorClickSource } from '@jsb188/react-web/ui/SheetUI';
14
- import type { OpenModalPopUpFn } from '@jsb188/react/states';
15
- import { type ReactNode, useEffect, useState } from 'react';
16
-
17
- type InboundContactDraftValues = {
18
- email: string;
19
- memory: string;
20
- personName: string;
21
- phone: string;
22
- };
23
-
24
- type DataTableInboundContactEditorTab = 'CONTACT' | 'ORGANIZATION';
25
-
26
- type DataTableInboundContactEditorProps = {
27
- clickSource?: SheetUIEditorClickSource;
28
- displayValue: string;
29
- inboundContactId: string;
30
- openModalPopUp: OpenModalPopUpFn;
31
- organizationId: string;
32
- onClose: () => void;
33
- };
34
-
35
- type DataTableInboundContactSchemaItem = ReturnType<typeof makeEditInboundContactSchema>['listData'][number];
36
-
37
- type DataTableInboundContactContactTabProps = {
38
- disabled: boolean;
39
- renderSchemaField: (schemaItem: DataTableInboundContactSchemaItem) => ReactNode;
40
- saving: boolean;
41
- schema: ReturnType<typeof makeEditInboundContactSchema>;
42
- };
43
-
44
- type DataTableInboundContactOrganizationTabProps = {
45
- associatedOrganizationNameById: Map<string, string>;
46
- disabled: boolean;
47
- onChildOrganizationClick: (childOrganization: OrganizationChildGQL) => void;
48
- organizationId: string;
49
- saving: boolean;
50
- selectedOrganizationIds?: string[];
51
- };
52
-
53
- type DataTableInboundContactEditorContentProps = DataTableInboundContactContactTabProps & DataTableInboundContactOrganizationTabProps & {
54
- activeTab: DataTableInboundContactEditorTab;
55
- };
56
-
57
- const MAX_SELECTED_ASSOCIATED_ORGANIZATIONS = 5;
58
-
59
- /*
60
- * Build one inbound contact editor draft from cached or queried contact data.
61
- */
62
-
63
- function getInboundContactDraftValues(contact: InboundContactGQL | null | undefined, displayValue: string): InboundContactDraftValues {
64
- return {
65
- email: contact?.email || '',
66
- memory: contact?.memory || '',
67
- personName: contact?.personName || displayValue,
68
- phone: contact?.phone || '',
69
- };
70
- }
71
-
72
- /*
73
- * Check whether one schema field name is supported by the inbound contact draft.
74
- */
75
-
76
- function isInboundContactDraftField(field: string): field is keyof InboundContactDraftValues {
77
- return field === 'email' || field === 'memory' || field === 'personName' || field === 'phone';
78
- }
79
-
80
- /*
81
- * Check whether a contact field should be read-only in the dataTable editor.
82
- */
83
-
84
- function isReadOnlyInboundContactDraftField(field: keyof InboundContactDraftValues) {
85
- return field === 'email' || field === 'phone';
86
- }
87
-
88
- /*
89
- * Return associated organization IDs from one inbound contact.
90
- */
91
-
92
- function getInboundContactAssociatedOrganizationIds(contact: InboundContactGQL | null | undefined) {
93
- return (contact?.associated || [])
94
- .map((orgRel: InboundContactOrgGQL) => orgRel.organizationId)
95
- .filter(Boolean);
96
- }
97
-
98
- /*
99
- * Return associated organization names from one inbound contact.
100
- */
101
-
102
- function getInboundContactAssociatedOrganizationNameById(contact: InboundContactGQL | null | undefined) {
103
- return new Map((contact?.associated || [])
104
- .filter((orgRel: InboundContactOrgGQL) => orgRel.organizationId && orgRel.name)
105
- .map((orgRel: InboundContactOrgGQL) => [orgRel.organizationId, orgRel.name || '']));
106
- }
107
-
108
- /*
109
- * Toggle one child organization ID in a selected IDs list.
110
- */
111
-
112
- function toggleSelectedOrganizationId(selectedOrganizationIds: string[], organizationId: string) {
113
- if (selectedOrganizationIds.includes(organizationId)) {
114
- return selectedOrganizationIds.filter((id) => id !== organizationId);
115
- }
116
-
117
- if (selectedOrganizationIds.length >= MAX_SELECTED_ASSOCIATED_ORGANIZATIONS) {
118
- return selectedOrganizationIds;
119
- }
120
-
121
- return [...selectedOrganizationIds, organizationId];
122
- }
123
-
124
- /*
125
- * Return organization names for the currently selected organization IDs.
126
- */
127
-
128
- function getSelectedOrganizationNames(
129
- selectedOrganizationIds: string[],
130
- organizationNameById: Map<string, string>,
131
- ) {
132
- return selectedOrganizationIds
133
- .map((organizationId) => organizationNameById.get(organizationId) || '')
134
- .filter(Boolean);
135
- }
136
-
137
- /*
138
- * Escape text before placing it inside HTML markup rendered by TextWithLinks.
139
- */
140
-
141
- function escapeInlineHTML(text: string) {
142
- return text
143
- .replace(/&/g, '&amp;')
144
- .replace(/</g, '&lt;')
145
- .replace(/>/g, '&gt;')
146
- .replace(/"/g, '&quot;')
147
- .replace(/'/g, '&#39;');
148
- }
149
-
150
- /*
151
- * Render the contact tab fields and its pinned save action.
152
- */
153
-
154
- function DataTableInboundContactContactTab(p: DataTableInboundContactContactTabProps) {
155
- return <>
156
- <div className='pt_12 px_6 v_stretch gap_5'>
157
- {p.schema.listData.map(p.renderSchemaField)}
158
- </div>
159
- <div className='bd_t_1 bd_lt h_right p_6'>
160
- <SheetSaveButton
161
- disabled={p.disabled || p.saving}
162
- saving={p.saving}
163
- />
164
- </div>
165
- </>;
166
- }
167
-
168
- /*
169
- * Render one selectable child organization row for the organization tab.
170
- */
171
-
172
- function DataTableInboundContactOrganizationItem(p: {
173
- childOrganization: OrganizationChildGQL;
174
- onClick: (childOrganization: OrganizationChildGQL) => void;
175
- selected: boolean;
176
- }) {
177
- const org = p.childOrganization.organization;
178
- const name = org?.name || i18n.t('form.unknown');
179
-
180
- return <button
181
- aria-pressed={p.selected}
182
- className={cn('h_spread px_5 h_24 bd_1 bd_lt no_shrink', p.selected ? 'bg_primary_fd' : 'bg_alt_hv')}
183
- data-sheet-inbound-contact-child-organization={org?.id || p.childOrganization.id}
184
- onClick={() => {
185
- p.onClick(p.childOrganization);
186
- }}
187
- type='button'
188
- >
189
- <span className='ellip'>{name}</span>
190
- {p.selected ? <Icon name='check' /> : null}
191
- </button>;
192
- }
193
-
194
- /*
195
- * Render the organization tab child organization list and its pinned save action.
196
- */
197
-
198
- function DataTableInboundContactOrganizationTab(p: DataTableInboundContactOrganizationTabProps) {
199
- const { childOrganizations } = useChildOrganizations({
200
- organizationId: p.organizationId,
201
- limit: 250,
202
- });
203
-
204
- const isEmpty = !!childOrganizations && !childOrganizations.length;
205
- const mockChildOrganizations = Array.from({ length: 3 });
206
- const organizationNameById = new Map(p.associatedOrganizationNameById);
207
- const selectedOrganizationIds = p.selectedOrganizationIds || [];
208
-
209
- (childOrganizations || []).forEach((childOrganization: OrganizationChildGQL) => {
210
- const childOrganizationId = childOrganization.organization?.id;
211
- const childOrganizationName = childOrganization.organization?.name;
212
-
213
- if (childOrganizationId && childOrganizationName) {
214
- organizationNameById.set(childOrganizationId, childOrganizationName);
215
- }
216
- });
217
-
218
- const selectedOrganizationNames = getSelectedOrganizationNames(
219
- selectedOrganizationIds,
220
- organizationNameById,
221
- );
222
- const selectedOrganizationNamesText = selectedOrganizationNames
223
- .map((organizationName) => `<u class="cl_bd">${escapeInlineHTML(organizationName)}</u>`)
224
- .join(', ');
225
- const associatedOrganizationText = selectedOrganizationNames.length
226
- ? i18n.t('org.contact_associated_with', {
227
- organizationNames: selectedOrganizationNamesText,
228
- })
229
- : i18n.t('org.contact_choose_associated_orgs');
230
-
231
- return <>
232
- <TextWithLinks
233
- as='div'
234
- className='px_12 pt_8 pb_4 ft_xs cl_md lh_2'
235
- >
236
- {associatedOrganizationText}
237
- </TextWithLinks>
238
- <MoreBelowScrollArea
239
- className={cn('px_6 grid gap_4 max_h_300', isEmpty ? 'pt_4' : 'pt_12')}
240
- scrollClassName='y_scr flat'
241
- >
242
- {childOrganizations == null ? mockChildOrganizations.map((_, index) => (
243
- // {childOrganizations ? mockChildOrganizations.map((_, index) => (
244
- <div className='h_spread px_5 h_24 bd_1 bd_lt no_shrink' key={index}>
245
- <span className='mock alt'>
246
- {'... ... '.repeat([7, 6, 5][index % 3]).trim()}
247
- </span>
248
- </div>
249
- )) : childOrganizations.map((childOrganization: OrganizationChildGQL) => (
250
- <DataTableInboundContactOrganizationItem
251
- childOrganization={childOrganization}
252
- key={childOrganization.id}
253
- onClick={p.onChildOrganizationClick}
254
- selected={selectedOrganizationIds.includes(childOrganization.organization?.id || '')}
255
- />
256
- ))}
257
-
258
- <p className={cn('mx_6 pb_6 cl_lt', isEmpty ? 'bd_t_1 bd_lt pt_14' : '')}>
259
- {i18n.t('agent.inbound_contact_associated_orgs_auto_create_msg')}
260
- </p>
261
-
262
- </MoreBelowScrollArea>
263
- <div className='bd_t_1 bd_lt h_spread p_6 gap_8'>
264
- <span className='ft_xs cl_md'>
265
- {selectedOrganizationIds.length ? `${selectedOrganizationIds.length}/${MAX_SELECTED_ASSOCIATED_ORGANIZATIONS}` : null}
266
- </span>
267
- <SheetSaveButton
268
- disabled={p.disabled || p.saving}
269
- saving={p.saving}
270
- />
271
- </div>
272
- </>;
273
- }
274
-
275
- /*
276
- * Render the active inbound contact editor tab content.
277
- */
278
-
279
- function DataTableInboundContactEditorContent(p: DataTableInboundContactEditorContentProps) {
280
- switch (p.activeTab) {
281
- case 'CONTACT':
282
- return <DataTableInboundContactContactTab
283
- disabled={p.disabled}
284
- renderSchemaField={p.renderSchemaField}
285
- saving={p.saving}
286
- schema={p.schema}
287
- />;
288
- case 'ORGANIZATION':
289
- return <DataTableInboundContactOrganizationTab
290
- associatedOrganizationNameById={p.associatedOrganizationNameById}
291
- disabled={p.disabled}
292
- onChildOrganizationClick={p.onChildOrganizationClick}
293
- organizationId={p.organizationId}
294
- saving={p.saving}
295
- selectedOrganizationIds={p.selectedOrganizationIds}
296
- />;
297
- default:
298
- return null;
299
- }
300
- }
301
-
302
- /*
303
- * Render the dataTable-local form for editing one inbound contact.
304
- */
305
-
306
- export function DataTableInboundContactEditor(p: DataTableInboundContactEditorProps) {
307
- const { inboundContact, initialLoading } = useInboundContact({
308
- organizationId: p.organizationId,
309
- inboundContactId: p.inboundContactId,
310
- }) as { inboundContact: InboundContactGQL | null; initialLoading?: boolean };
311
- const { editInboundContact, saving } = useEditInboundContact({}, p.openModalPopUp);
312
- const [draftValues, setDraftValues] = useState(() => getInboundContactDraftValues(inboundContact, p.displayValue));
313
- const [selectedOrganizationIds, setSelectedOrganizationIds] = useState(() => getInboundContactAssociatedOrganizationIds(inboundContact));
314
- const [activeTab, setActiveTab] = useState<DataTableInboundContactEditorTab>('CONTACT');
315
- const schema = makeEditInboundContactSchema('sheet_inbound_contact', '', draftValues);
316
- const disabled = !!initialLoading;
317
- const saveDisabled = disabled || saving;
318
- const associatedOrganizationNameById = getInboundContactAssociatedOrganizationNameById(inboundContact);
319
-
320
- useEffect(() => {
321
- setDraftValues(getInboundContactDraftValues(inboundContact, p.displayValue));
322
- setSelectedOrganizationIds(getInboundContactAssociatedOrganizationIds(inboundContact));
323
- }, [inboundContact, p.displayValue]);
324
-
325
- /*
326
- * Update one inbound contact draft field inside the dataTable-local editor.
327
- */
328
-
329
- function setDraftField(field: keyof InboundContactDraftValues, value: string) {
330
- setDraftValues((currentValues) => ({
331
- ...currentValues,
332
- [field]: value,
333
- }));
334
- }
335
-
336
- /*
337
- * Save the inbound contact draft values through the existing GraphQL mutation.
338
- */
339
-
340
- async function saveInboundContact() {
341
- if (saveDisabled) {
342
- return;
343
- }
344
-
345
- const result = await editInboundContact({
346
- variables: {
347
- organizationId: p.organizationId,
348
- inboundContactId: p.inboundContactId,
349
- personName: draftValues.personName,
350
- memory: draftValues.memory,
351
- },
352
- });
353
-
354
- if (result?.editInboundContact && !result?.error) {
355
- p.onClose();
356
- }
357
- }
358
-
359
- /*
360
- * Save the selected child organization associations through the existing GraphQL mutation.
361
- */
362
-
363
- async function saveInboundContactOrganization() {
364
- if (saveDisabled) {
365
- return;
366
- }
367
-
368
- const result = await editInboundContact({
369
- variables: {
370
- organizationId: p.organizationId,
371
- inboundContactId: p.inboundContactId,
372
- associatedOrganizationIds: selectedOrganizationIds,
373
- },
374
- });
375
-
376
- if (result?.editInboundContact && !result?.error) {
377
- p.onClose();
378
- }
379
- }
380
-
381
- /*
382
- * Toggle one child organization selection inside the organization tab.
383
- */
384
-
385
- function handleChildOrganizationClick(childOrganization: OrganizationChildGQL) {
386
- const childOrganizationId = childOrganization.organization?.id;
387
-
388
- if (!childOrganizationId) {
389
- return;
390
- }
391
-
392
- setSelectedOrganizationIds((currentIds) => toggleSelectedOrganizationId(currentIds, childOrganizationId));
393
- }
394
-
395
- /*
396
- * Render a schema-backed inbound contact field inside the dataTable overlay editor.
397
- */
398
-
399
- function renderSchemaField(schemaItem: DataTableInboundContactSchemaItem) {
400
- const { __type, item } = schemaItem;
401
- const { name, label, description, maxLength, placeholder, autoComplete, type } = item;
402
-
403
- if (!isInboundContactDraftField(name)) {
404
- return null;
405
- }
406
-
407
- if (__type === 'input') {
408
- const isReadOnly = isReadOnlyInboundContactDraftField(name);
409
- const notEditable = disabled || isReadOnly;
410
-
411
- return <label
412
- className='h_item gap_8'
413
- key={name}
414
- >
415
- <span className='cl_md w_70 min_w_70 px_4 ellip'>
416
- {label}
417
- </span>
418
- <span className={cn('rel f bg_alt', notEditable ? 'pattern_stripes medium_bf' : '')}>
419
- <input
420
- autoComplete={autoComplete}
421
- className={cn('f min_w_0 w_f stock r_2 ft_xs px_4 py_2 rel', notEditable ? 'cl_md pr_24' : 'bg_alt')}
422
- disabled={notEditable}
423
- maxLength={maxLength}
424
- name={name}
425
- onChange={isReadOnly ? undefined : (event) => {
426
- setDraftField(name, event.currentTarget.value);
427
- }}
428
- placeholder={placeholder}
429
- readOnly={isReadOnly}
430
- type={type}
431
- value={draftValues[name]}
432
- />
433
- {notEditable && <span className='abs_r_center mr_5 ic_sm cl_md noclick'>
434
- <Icon name={COMMON_ICON_NAMES.lock} />
435
- </span>}
436
- </span>
437
- </label>;
438
- }
439
-
440
- if (__type === 'textarea') {
441
- return <label
442
- className='ft_xs bd_t_1 bd_lt pt_8 mt_6'
443
- key={name}
444
- >
445
- <div className='cl_md bl ft_tn mb_6 px_4'>
446
- <div className='mb_4'>
447
- {label}
448
- </div>
449
-
450
- {description && <div className='cl_lt ft_tn lh_2'>
451
- {description}
452
- </div>}
453
- </div>
454
-
455
- <textarea
456
- autoComplete={autoComplete}
457
- className='min_h_105 max_h_240 bg_alt r_2 resize_v ft_xs mt_5 p_4 w_f stock lh_2'
458
- disabled={disabled}
459
- maxLength={maxLength}
460
- name={name}
461
- onChange={(event) => {
462
- setDraftField(name, event.currentTarget.value);
463
- }}
464
- placeholder={placeholder}
465
- value={draftValues[name]}
466
- />
467
- </label>;
468
- }
469
-
470
- return null;
471
- }
472
-
473
- /*
474
- * Save the currently active inbound contact editor tab.
475
- */
476
-
477
- function saveActiveTab() {
478
- if (activeTab === 'ORGANIZATION') {
479
- saveInboundContactOrganization();
480
- return;
481
- }
482
-
483
- void saveInboundContact();
484
- }
485
-
486
- return <form
487
- aria-busy={disabled}
488
- className='bg bd_2 bd_lt r_2 v_stretch gap_5 sheet_overlay_editor lh_2'
489
- data-sheet-click-source={p.clickSource}
490
- data-sheet-inbound-contact-editor='true'
491
- onSubmit={(e) => {
492
- e.preventDefault();
493
- saveActiveTab();
494
- }}
495
- >
496
- <SheetEditorNav
497
- activeValue={activeTab}
498
- onChange={setActiveTab}
499
- items={[
500
- {
501
- label: i18n.t('form.contact'),
502
- value: 'CONTACT',
503
- },
504
- {
505
- label: i18n.t('org.organizations'),
506
- value: 'ORGANIZATION',
507
- },
508
- ]}
509
- />
510
-
511
- <DataTableInboundContactEditorContent
512
- activeTab={activeTab}
513
- associatedOrganizationNameById={associatedOrganizationNameById}
514
- disabled={disabled}
515
- onChildOrganizationClick={handleChildOrganizationClick}
516
- organizationId={p.organizationId}
517
- renderSchemaField={renderSchemaField}
518
- saving={saving}
519
- schema={schema}
520
- selectedOrganizationIds={selectedOrganizationIds}
521
- />
522
- </form>;
523
- }