@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.
- package/package.json +36 -24
- package/src/libs/route-metadata.server.ts +67 -0
- package/src/modules/Grids.filters.ts +36 -0
- package/src/modules/Grids.tsx +610 -0
- package/src/modules/RouteShell.tsx +76 -0
- package/src/schemas/organization.ts +128 -0
- package/src/utils/email.ts +117 -0
- package/src/utils/list-web.ts +17 -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 +74 -364
- package/src/utils/operation-pages.ts +154 -0
- package/src/utils/org-web.ts +35 -8
- package/src/utils/route-helpers.ts +837 -596
- package/src/utils/workflow-web.ts +72 -0
- package/tests/log-web.test.ts +134 -0
- package/tests/route-helpers.test.ts +17 -0
- package/tsconfig.json +11 -11
- package/src/modules/DataTable-ContextMenu.tsx +0 -169
- package/src/modules/DataTable-InboundContact.tsx +0 -523
- package/src/modules/DataTable.tsx +0 -5060
- package/src/modules/Sheet-ContextMenu.tsx +0 -161
- package/src/modules/Sheet.tsx +0 -28
- package/src/modules/cell-save-beacon.ts +0 -67
- package/src/modules/dataTable-interaction-state.ts +0 -276
- package/src/modules/dataTable-shortcuts.ts +0 -192
- package/src/modules/dataTable-viewport.ts +0 -89
- package/src/modules/grid-cell-render.ts +0 -72
- package/src/modules/grid-context-menu.ts +0 -112
- package/src/modules/grid-keyboard.ts +0 -267
- package/src/modules/grid-render-store.ts +0 -103
- package/src/modules/grid-runtime.ts +0 -178
- package/src/modules/grid-selection.ts +0 -336
- package/src/modules/grid-viewport.ts +0 -57
- package/src/modules/use-dataTable-states.ts +0 -529
- package/src/modules/use-debounced-cell-save-batch.ts +0 -160
- package/tests/DataTable.test.tsx +0 -4466
- package/tests/dataTable-interaction-state.test.ts +0 -127
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import { COMMON_CLASSNAMES } from '@jsb188/app/constants/app.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
4
|
+
import { useDataTables } from '@jsb188/graphql/hooks/use-dataTable-qry';
|
|
5
|
+
import { useSheets } from '@jsb188/graphql/hooks/use-sheet-qry';
|
|
6
|
+
import type { DataTableGQL } from '@jsb188/mday/types/dataTable.d.ts';
|
|
7
|
+
import type { GridItemSortEnum, SheetGQL } from '@jsb188/mday/types/sheet.d.ts';
|
|
8
|
+
import { useOpenModalPopUp, usePopOverActions, usePopOverDefinition, usePopOverEvent } from '@jsb188/react/states';
|
|
9
|
+
import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
|
|
10
|
+
import { ContentGate } from '@jsb188/react-web/modules/layout/MainLayout';
|
|
11
|
+
import { ModalTileGrid } from '@jsb188/react-web/modules/layout/TabbedModalLayout';
|
|
12
|
+
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
13
|
+
import { SimpleLabel } from '@jsb188/react-web/ui/Button';
|
|
14
|
+
import { TileItem } from '@jsb188/react-web/ui/TileUI';
|
|
15
|
+
import { type MouseEvent, memo, useCallback, useEffect, useId, useMemo, useRef } from 'react';
|
|
16
|
+
import { mapRenderableItems } from '../utils/list-web.ts';
|
|
17
|
+
|
|
18
|
+
const FILE_CONSTANTS = {
|
|
19
|
+
contentPaddingClassName: COMMON_CLASSNAMES.contentXPadding,
|
|
20
|
+
dataTableIconName: COMMON_ICON_NAMES.data_table,
|
|
21
|
+
gridCreateIconName: COMMON_ICON_NAMES.plus,
|
|
22
|
+
sectionDataTables: 'dataTables',
|
|
23
|
+
sectionSheets: 'sheets',
|
|
24
|
+
sheetIconName: COMMON_ICON_NAMES.sheet,
|
|
25
|
+
tileContextMenuIdPrefix: 'grids_tile_context_menu:',
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
export type GridsSectionMode = 'all' | 'sheets' | 'dataTables';
|
|
29
|
+
export { GRIDS_FILTER_SCHEMA, useGridsToolbarState } from './Grids.filters.ts';
|
|
30
|
+
|
|
31
|
+
type GridItem = {
|
|
32
|
+
id: string;
|
|
33
|
+
__typename: 'Sheet' | 'DataTable';
|
|
34
|
+
__deleted?: boolean;
|
|
35
|
+
title: string;
|
|
36
|
+
description: string;
|
|
37
|
+
iconName: string;
|
|
38
|
+
// Ownership is independent of the nullable headline; owned tables have no delete action of their own
|
|
39
|
+
ownerNoteId?: string | null;
|
|
40
|
+
ownerNoteHeadline?: string | null;
|
|
41
|
+
to: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type GridsTileContextMenuValue = {
|
|
45
|
+
action: 'DELETE_GRID_ITEM' | 'OPEN_GRID_ITEM_NEW_TAB';
|
|
46
|
+
item: GridItem;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
type GridsReadyData = {
|
|
50
|
+
dataTables: DataTableGQL[] | null;
|
|
51
|
+
sheets: SheetGQL[] | null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type GridsSectionVisibility = {
|
|
55
|
+
showDataTables: boolean;
|
|
56
|
+
showSheets: boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type GridsTileSectionProps = {
|
|
60
|
+
contextMenuOwnerId: string;
|
|
61
|
+
createDescription?: string;
|
|
62
|
+
createTitle?: string;
|
|
63
|
+
items: GridItem[];
|
|
64
|
+
mocked: boolean;
|
|
65
|
+
sectionId: string;
|
|
66
|
+
showCreateTile: boolean;
|
|
67
|
+
title: string;
|
|
68
|
+
onCreate?: () => void;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
interface GridsModuleProps {
|
|
72
|
+
contentClassName?: string;
|
|
73
|
+
notReadyClassName?: string;
|
|
74
|
+
organizationId: string;
|
|
75
|
+
sections?: GridsSectionMode;
|
|
76
|
+
showCreateTiles?: boolean;
|
|
77
|
+
sort: GridItemSortEnum;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
* Return which grids sections should be visible for one module mode.
|
|
82
|
+
*/
|
|
83
|
+
function getGridsSectionVisibility(sections: GridsSectionMode): GridsSectionVisibility {
|
|
84
|
+
return {
|
|
85
|
+
showDataTables: sections !== FILE_CONSTANTS.sectionSheets,
|
|
86
|
+
showSheets: sections !== FILE_CONSTANTS.sectionDataTables,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* Keep the last fully loaded grids data available during replacement fetches.
|
|
92
|
+
*/
|
|
93
|
+
function useLastGridsReadyData(p: {
|
|
94
|
+
dataTables?: DataTableGQL[] | null;
|
|
95
|
+
sheets?: SheetGQL[] | null;
|
|
96
|
+
showDataTables: boolean;
|
|
97
|
+
showSheets: boolean;
|
|
98
|
+
}) {
|
|
99
|
+
const { dataTables, sheets, showDataTables, showSheets } = p;
|
|
100
|
+
const readyDataRef = useRef<GridsReadyData | null>(null);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if ((showSheets && !sheets) || (showDataTables && !dataTables)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
readyDataRef.current = {
|
|
108
|
+
dataTables: showDataTables ? dataTables || null : null,
|
|
109
|
+
sheets: showSheets ? sheets || null : null,
|
|
110
|
+
};
|
|
111
|
+
}, [dataTables, sheets, showDataTables, showSheets]);
|
|
112
|
+
|
|
113
|
+
return readyDataRef.current;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
* Return query variables for one grids data source when its section is visible.
|
|
118
|
+
*/
|
|
119
|
+
function getGridsQueryVariables(visible: boolean, organizationId: string, sort: GridItemSortEnum) {
|
|
120
|
+
return visible
|
|
121
|
+
? {
|
|
122
|
+
organizationId,
|
|
123
|
+
sort,
|
|
124
|
+
}
|
|
125
|
+
: null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* Convert one sheet record into a grids tile item.
|
|
130
|
+
*/
|
|
131
|
+
function mapSheetToGridItem(sheet: SheetGQL): GridItem | null {
|
|
132
|
+
if (!sheet.id) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
id: sheet.id,
|
|
138
|
+
__typename: 'Sheet',
|
|
139
|
+
title: sheet.title || i18n.t('app.untitled_sheet'),
|
|
140
|
+
description: sheet.description || sheet.name || '',
|
|
141
|
+
iconName: FILE_CONSTANTS.sheetIconName,
|
|
142
|
+
to: `/app/s/${sheet.id}`,
|
|
143
|
+
__deleted: Boolean(sheet.__deleted || sheet.deletedAt),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
* Convert one dataTable record into a grids tile item.
|
|
149
|
+
*/
|
|
150
|
+
function mapDataTableToGridItem(dataTable: DataTableGQL): GridItem | null {
|
|
151
|
+
if (!dataTable.id) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
id: dataTable.id,
|
|
157
|
+
__typename: 'DataTable',
|
|
158
|
+
title: dataTable.title || i18n.t('sheet.untitled_data_table'),
|
|
159
|
+
description: dataTable.description || '',
|
|
160
|
+
iconName: FILE_CONSTANTS.dataTableIconName,
|
|
161
|
+
ownerNoteId: dataTable.ownerNote?.id,
|
|
162
|
+
ownerNoteHeadline: dataTable.ownerNote?.headline,
|
|
163
|
+
to: `/app/d/${dataTable.id}`,
|
|
164
|
+
__deleted: Boolean(dataTable.__deleted || dataTable.archivedAt),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/*
|
|
169
|
+
* Convert a right-click event into a popover anchor rectangle.
|
|
170
|
+
*/
|
|
171
|
+
function getGridsTileContextMenuRect(e: MouseEvent<Element>) {
|
|
172
|
+
const { clientX, clientY } = e;
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
width: 0,
|
|
176
|
+
height: 0,
|
|
177
|
+
left: clientX,
|
|
178
|
+
right: clientX,
|
|
179
|
+
top: clientY,
|
|
180
|
+
bottom: clientY,
|
|
181
|
+
x: clientX,
|
|
182
|
+
y: clientY,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/*
|
|
187
|
+
* Build an absolute URL for a grids tile route action.
|
|
188
|
+
*/
|
|
189
|
+
function getGridsTileRouteUrl(to: string) {
|
|
190
|
+
return new URL(to, globalThis.location?.origin || 'http://localhost').toString();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/*
|
|
194
|
+
* Return the modal preset name used to delete one grids tile.
|
|
195
|
+
*/
|
|
196
|
+
function getGridsTileDeleteModalName(item: GridItem) {
|
|
197
|
+
return item.__typename === 'Sheet' ? 'DELETE_SHEET' : 'DELETE_DATA_TABLE';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/*
|
|
201
|
+
* Return the modal props used to delete one grids tile.
|
|
202
|
+
*/
|
|
203
|
+
function getGridsTileDeleteModalProps(item: GridItem, organizationId: string) {
|
|
204
|
+
return {
|
|
205
|
+
itemTitle: item.title,
|
|
206
|
+
organizationId,
|
|
207
|
+
...(item.__typename === 'Sheet' ? { sheetId: item.id } : { dataTableId: item.id }),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/*
|
|
212
|
+
* Return the popover menu options for one grids tile. A data table an AI note owns has no
|
|
213
|
+
* delete option: the server refuses it (20243) while the note owns it.
|
|
214
|
+
*/
|
|
215
|
+
function getGridsTileContextOptions(item: GridItem): POListIfaceItem[] {
|
|
216
|
+
const options: POListIfaceItem[] = [
|
|
217
|
+
{
|
|
218
|
+
__type: 'LIST_ITEM',
|
|
219
|
+
iconName: COMMON_ICON_NAMES.open_external_link,
|
|
220
|
+
text: i18n.t('app.open_in_new_tab'),
|
|
221
|
+
value: {
|
|
222
|
+
action: 'OPEN_GRID_ITEM_NEW_TAB',
|
|
223
|
+
item,
|
|
224
|
+
} satisfies GridsTileContextMenuValue,
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
|
|
228
|
+
if (!item.ownerNoteId) {
|
|
229
|
+
options.push({
|
|
230
|
+
__type: 'LIST_ITEM',
|
|
231
|
+
iconName: COMMON_ICON_NAMES.delete,
|
|
232
|
+
text: i18n.t(item.__typename === 'Sheet' ? 'sheet.delete_sheet' : 'sheet.delete_data_table'),
|
|
233
|
+
className: 'cl_err_hv',
|
|
234
|
+
value: {
|
|
235
|
+
action: 'DELETE_GRID_ITEM',
|
|
236
|
+
item,
|
|
237
|
+
} satisfies GridsTileContextMenuValue,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return options;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/*
|
|
245
|
+
* Return a tile description; a data table an AI note owns shows an owner badge before the note headline.
|
|
246
|
+
*/
|
|
247
|
+
function getGridsTileDescription(item: GridItem) {
|
|
248
|
+
if (!item.ownerNoteId) {
|
|
249
|
+
return item.description;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return (
|
|
253
|
+
<span className="h_item gap_6 min_w_0">
|
|
254
|
+
<SimpleLabel
|
|
255
|
+
preset="outline"
|
|
256
|
+
color="alt"
|
|
257
|
+
text={i18n.t('sheet.data_table_owner_badge')}
|
|
258
|
+
/>
|
|
259
|
+
<span className="ellip">{item.ownerNoteHeadline?.trim() || i18n.t('agent_note.agent_note')}</span>
|
|
260
|
+
</span>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/*
|
|
265
|
+
* Return the popover id for one grids tile context menu.
|
|
266
|
+
*/
|
|
267
|
+
function getGridsTileContextMenuId(contextMenuOwnerId: string, sectionId: string, item: GridItem) {
|
|
268
|
+
return `${FILE_CONSTANTS.tileContextMenuIdPrefix}${contextMenuOwnerId}:${sectionId}:${item.__typename}:${item.id}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/*
|
|
272
|
+
* Render one mapped grids tile item with a right-click menu.
|
|
273
|
+
*/
|
|
274
|
+
const GridsTileItem = memo((p: { contextMenuOwnerId: string; item: GridItem; sectionId: string }) => {
|
|
275
|
+
const { contextMenuOwnerId, item, sectionId } = p;
|
|
276
|
+
const popOver = usePopOverDefinition();
|
|
277
|
+
const { openPopOver } = usePopOverActions();
|
|
278
|
+
const popOverId = getGridsTileContextMenuId(contextMenuOwnerId, sectionId, item);
|
|
279
|
+
const active = popOver?.id === popOverId;
|
|
280
|
+
// Sheet and data table routes have no server loader, so their intent prefetch stays route-JS only.
|
|
281
|
+
const prefetch = !active ? 'intent' : 'none';
|
|
282
|
+
|
|
283
|
+
/*
|
|
284
|
+
* Open the grid item context menu at the pointer location.
|
|
285
|
+
*/
|
|
286
|
+
const onContextMenu = useCallback(
|
|
287
|
+
(e: MouseEvent<Element>) => {
|
|
288
|
+
if (item.__deleted) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
e.stopPropagation();
|
|
294
|
+
|
|
295
|
+
openPopOver({
|
|
296
|
+
name: 'PO_LIST',
|
|
297
|
+
id: popOverId,
|
|
298
|
+
animationClassName: 'anim_dropdown_top on_mount',
|
|
299
|
+
position: 'bottom_left',
|
|
300
|
+
offsetX: 0,
|
|
301
|
+
offsetY: 0,
|
|
302
|
+
rect: getGridsTileContextMenuRect(e),
|
|
303
|
+
variables: {
|
|
304
|
+
options: getGridsTileContextOptions(item),
|
|
305
|
+
shadowClassName: 'shadow_md',
|
|
306
|
+
},
|
|
307
|
+
zClassName: 'z8',
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
[item, openPopOver, popOverId],
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
<TileItem
|
|
315
|
+
__deleted={item.__deleted}
|
|
316
|
+
active={active}
|
|
317
|
+
iconName={item.iconName}
|
|
318
|
+
title={item.title}
|
|
319
|
+
description={getGridsTileDescription(item)}
|
|
320
|
+
prefetch={prefetch}
|
|
321
|
+
to={item.to}
|
|
322
|
+
onContextMenu={onContextMenu}
|
|
323
|
+
/>
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
GridsTileItem.displayName = 'GridsTileItem';
|
|
328
|
+
|
|
329
|
+
/*
|
|
330
|
+
* Render one presentational grids tile section.
|
|
331
|
+
*/
|
|
332
|
+
const GridsTileSection = memo((p: GridsTileSectionProps) => {
|
|
333
|
+
return (
|
|
334
|
+
<ModalTileGrid
|
|
335
|
+
className="mb_md"
|
|
336
|
+
loading={p.mocked}
|
|
337
|
+
title={p.title}
|
|
338
|
+
items={p.items}
|
|
339
|
+
ItemComponent={GridsTileItem}
|
|
340
|
+
itemProps={{ contextMenuOwnerId: p.contextMenuOwnerId, sectionId: p.sectionId }}
|
|
341
|
+
>
|
|
342
|
+
{!p.showCreateTile || !p.onCreate ? null : (
|
|
343
|
+
<TileItem
|
|
344
|
+
iconName={FILE_CONSTANTS.gridCreateIconName}
|
|
345
|
+
title={p.createTitle}
|
|
346
|
+
description={p.createDescription}
|
|
347
|
+
onClick={p.onCreate}
|
|
348
|
+
/>
|
|
349
|
+
)}
|
|
350
|
+
</ModalTileGrid>
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
GridsTileSection.displayName = 'GridsTileSection';
|
|
355
|
+
|
|
356
|
+
/*
|
|
357
|
+
* Render the grids sheets section.
|
|
358
|
+
*/
|
|
359
|
+
function GridsSheetsSection(p: {
|
|
360
|
+
contextMenuOwnerId: string;
|
|
361
|
+
organizationId: string;
|
|
362
|
+
sheets?: SheetGQL[] | null;
|
|
363
|
+
showCreateTile: boolean;
|
|
364
|
+
}) {
|
|
365
|
+
const { contextMenuOwnerId, organizationId, sheets, showCreateTile } = p;
|
|
366
|
+
const openModalPopUp = useOpenModalPopUp();
|
|
367
|
+
const sheetItems = useMemo(() => mapRenderableItems(sheets, mapSheetToGridItem), [sheets]);
|
|
368
|
+
|
|
369
|
+
/*
|
|
370
|
+
* Open the sheet creation flow.
|
|
371
|
+
*/
|
|
372
|
+
const openCreateSheet = useCallback(() => {
|
|
373
|
+
openModalPopUp({
|
|
374
|
+
name: 'CREATE_SHEET',
|
|
375
|
+
preset: 'CREATE_SHEET',
|
|
376
|
+
props: {
|
|
377
|
+
organizationId,
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
}, [openModalPopUp, organizationId]);
|
|
381
|
+
|
|
382
|
+
return (
|
|
383
|
+
<GridsTileSection
|
|
384
|
+
contextMenuOwnerId={contextMenuOwnerId}
|
|
385
|
+
createDescription={i18n.t('sheet.create_sheet_description')}
|
|
386
|
+
createTitle={i18n.t('sheet.create_sheet')}
|
|
387
|
+
items={sheetItems}
|
|
388
|
+
mocked={!sheets}
|
|
389
|
+
sectionId={FILE_CONSTANTS.sectionSheets}
|
|
390
|
+
showCreateTile={showCreateTile}
|
|
391
|
+
title={i18n.t('sheet.sheets')}
|
|
392
|
+
onCreate={openCreateSheet}
|
|
393
|
+
/>
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/*
|
|
398
|
+
* Render the grids data tables section. Tables are created by agents (and workflows), so this
|
|
399
|
+
* section has no create tile.
|
|
400
|
+
*/
|
|
401
|
+
function GridsDataTablesSection(p: { contextMenuOwnerId: string; dataTables?: DataTableGQL[] | null }) {
|
|
402
|
+
const { contextMenuOwnerId, dataTables } = p;
|
|
403
|
+
const dataTableItems = useMemo(() => mapRenderableItems(dataTables, mapDataTableToGridItem), [dataTables]);
|
|
404
|
+
|
|
405
|
+
return (
|
|
406
|
+
<GridsTileSection
|
|
407
|
+
contextMenuOwnerId={contextMenuOwnerId}
|
|
408
|
+
items={dataTableItems}
|
|
409
|
+
mocked={!dataTables}
|
|
410
|
+
sectionId={FILE_CONSTANTS.sectionDataTables}
|
|
411
|
+
showCreateTile={false}
|
|
412
|
+
title={i18n.t('sheet.data_tables')}
|
|
413
|
+
/>
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/*
|
|
418
|
+
* Return whether visible grids data is missing during a fetch.
|
|
419
|
+
*/
|
|
420
|
+
function getGridsVisibleDataMissing(p: {
|
|
421
|
+
dataTables?: DataTableGQL[] | null;
|
|
422
|
+
sheets?: SheetGQL[] | null;
|
|
423
|
+
showDataTables: boolean;
|
|
424
|
+
showSheets: boolean;
|
|
425
|
+
}) {
|
|
426
|
+
const { dataTables, sheets, showDataTables, showSheets } = p;
|
|
427
|
+
|
|
428
|
+
return (showSheets && !sheets) || (showDataTables && !dataTables);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/*
|
|
432
|
+
* Return the data lists that should render while preserving last-ready data during fetches.
|
|
433
|
+
*/
|
|
434
|
+
function getGridsDisplayData(p: {
|
|
435
|
+
dataTables?: DataTableGQL[] | null;
|
|
436
|
+
lastGridsReadyData: GridsReadyData | null;
|
|
437
|
+
sheets?: SheetGQL[] | null;
|
|
438
|
+
showDataTables: boolean;
|
|
439
|
+
showingLastGridsReadyData: boolean;
|
|
440
|
+
showSheets: boolean;
|
|
441
|
+
}) {
|
|
442
|
+
const { dataTables, lastGridsReadyData, sheets, showDataTables, showingLastGridsReadyData, showSheets } = p;
|
|
443
|
+
|
|
444
|
+
return {
|
|
445
|
+
displayDataTables: showDataTables ? (showingLastGridsReadyData ? lastGridsReadyData?.dataTables : dataTables) : null,
|
|
446
|
+
displaySheets: showSheets ? (showingLastGridsReadyData ? lastGridsReadyData?.sheets : sheets) : null,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/*
|
|
451
|
+
* Fetch grids data and render each visible grids section.
|
|
452
|
+
*/
|
|
453
|
+
export function GridsModule(p: GridsModuleProps) {
|
|
454
|
+
const { contentClassName, notReadyClassName, organizationId, sections = 'all', showCreateTiles = true, sort } = p;
|
|
455
|
+
const contextMenuOwnerId = useId().replaceAll(':', '_');
|
|
456
|
+
const contextMenuIdPrefix = `${FILE_CONSTANTS.tileContextMenuIdPrefix}${contextMenuOwnerId}:`;
|
|
457
|
+
const popOver = usePopOverDefinition();
|
|
458
|
+
const { acknowledgePopOverEvent, closePopOver } = usePopOverActions();
|
|
459
|
+
const activeGridsPopOverId = popOver?.id?.startsWith(contextMenuIdPrefix) ? popOver.id : null;
|
|
460
|
+
const popOverEvent = usePopOverEvent({ popOverId: activeGridsPopOverId });
|
|
461
|
+
const openModalPopUp = useOpenModalPopUp();
|
|
462
|
+
const { showDataTables, showSheets } = getGridsSectionVisibility(sections);
|
|
463
|
+
const popOverHandlersRef = useRef({
|
|
464
|
+
closePopOver,
|
|
465
|
+
openModalPopUp,
|
|
466
|
+
});
|
|
467
|
+
const sheetsQueryVariables = useMemo(
|
|
468
|
+
() => getGridsQueryVariables(showSheets, organizationId, sort),
|
|
469
|
+
[organizationId, showSheets, sort],
|
|
470
|
+
);
|
|
471
|
+
const dataTablesQueryVariables = useMemo(
|
|
472
|
+
() => getGridsQueryVariables(showDataTables, organizationId, sort),
|
|
473
|
+
[organizationId, showDataTables, sort],
|
|
474
|
+
);
|
|
475
|
+
const {
|
|
476
|
+
dataTables,
|
|
477
|
+
error: dataTablesError,
|
|
478
|
+
loading: dataTablesLoading,
|
|
479
|
+
refetch: refetchDataTables,
|
|
480
|
+
} = useDataTables(dataTablesQueryVariables);
|
|
481
|
+
const { sheets, error: sheetsError, loading: sheetsLoading, refetch: refetchSheets } = useSheets(sheetsQueryVariables);
|
|
482
|
+
const error = (showSheets && sheetsError) || (showDataTables && dataTablesError);
|
|
483
|
+
const gridsLoading = Boolean((showSheets && sheetsLoading) || (showDataTables && dataTablesLoading));
|
|
484
|
+
const lastGridsReadyData = useLastGridsReadyData({
|
|
485
|
+
dataTables,
|
|
486
|
+
sheets,
|
|
487
|
+
showDataTables,
|
|
488
|
+
showSheets,
|
|
489
|
+
});
|
|
490
|
+
const visibleDataMissing = getGridsVisibleDataMissing({
|
|
491
|
+
dataTables,
|
|
492
|
+
sheets,
|
|
493
|
+
showDataTables,
|
|
494
|
+
showSheets,
|
|
495
|
+
});
|
|
496
|
+
const showingLastGridsReadyData = gridsLoading && visibleDataMissing && !!lastGridsReadyData;
|
|
497
|
+
const { displayDataTables, displaySheets } = getGridsDisplayData({
|
|
498
|
+
dataTables,
|
|
499
|
+
lastGridsReadyData,
|
|
500
|
+
sheets,
|
|
501
|
+
showDataTables,
|
|
502
|
+
showingLastGridsReadyData,
|
|
503
|
+
showSheets,
|
|
504
|
+
});
|
|
505
|
+
const notReady = getGridsVisibleDataMissing({
|
|
506
|
+
dataTables: displayDataTables,
|
|
507
|
+
sheets: displaySheets,
|
|
508
|
+
showDataTables,
|
|
509
|
+
showSheets,
|
|
510
|
+
});
|
|
511
|
+
popOverHandlersRef.current = {
|
|
512
|
+
closePopOver,
|
|
513
|
+
openModalPopUp,
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
/*
|
|
517
|
+
* Close the grids popover when the module unmounts.
|
|
518
|
+
*/
|
|
519
|
+
useEffect(() => {
|
|
520
|
+
return () => {
|
|
521
|
+
popOverHandlersRef.current.closePopOver();
|
|
522
|
+
};
|
|
523
|
+
}, []);
|
|
524
|
+
|
|
525
|
+
/*
|
|
526
|
+
* Handle item events scoped to the currently open grids context menu.
|
|
527
|
+
*/
|
|
528
|
+
useEffect(() => {
|
|
529
|
+
if (!popOverEvent) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const { action, id, value } = popOverEvent;
|
|
534
|
+
const contextValue = value as GridsTileContextMenuValue | null;
|
|
535
|
+
|
|
536
|
+
if (action !== 'ITEM' || typeof id !== 'string' || !id.startsWith(contextMenuIdPrefix) || !contextValue) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
acknowledgePopOverEvent(popOverEvent.eventId);
|
|
541
|
+
const { item } = contextValue;
|
|
542
|
+
popOverHandlersRef.current.closePopOver();
|
|
543
|
+
|
|
544
|
+
switch (contextValue.action) {
|
|
545
|
+
case 'OPEN_GRID_ITEM_NEW_TAB':
|
|
546
|
+
globalThis.window?.open(getGridsTileRouteUrl(item.to), '_blank', 'noopener,noreferrer');
|
|
547
|
+
return;
|
|
548
|
+
case 'DELETE_GRID_ITEM':
|
|
549
|
+
break;
|
|
550
|
+
default:
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const deleteModalName = getGridsTileDeleteModalName(item);
|
|
555
|
+
|
|
556
|
+
popOverHandlersRef.current.openModalPopUp({
|
|
557
|
+
name: deleteModalName,
|
|
558
|
+
preset: deleteModalName,
|
|
559
|
+
props: getGridsTileDeleteModalProps(item, organizationId),
|
|
560
|
+
});
|
|
561
|
+
}, [acknowledgePopOverEvent, contextMenuIdPrefix, organizationId, popOverEvent]);
|
|
562
|
+
|
|
563
|
+
/*
|
|
564
|
+
* Refetch every visible data source used by the grids.
|
|
565
|
+
*/
|
|
566
|
+
const refetchGridItems = useCallback(() => {
|
|
567
|
+
if (showSheets) {
|
|
568
|
+
refetchSheets();
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (showDataTables) {
|
|
572
|
+
refetchDataTables();
|
|
573
|
+
}
|
|
574
|
+
}, [refetchDataTables, refetchSheets, showDataTables, showSheets]);
|
|
575
|
+
|
|
576
|
+
return (
|
|
577
|
+
<ContentGate
|
|
578
|
+
showLoadingIfNotReady
|
|
579
|
+
notReady={notReady}
|
|
580
|
+
loading={gridsLoading}
|
|
581
|
+
error={error || null}
|
|
582
|
+
notReadyClassName={notReadyClassName ?? 'fs v_center'}
|
|
583
|
+
onRefetch={refetchGridItems}
|
|
584
|
+
>
|
|
585
|
+
<div
|
|
586
|
+
className={cn(
|
|
587
|
+
'rel pt_md pb_md',
|
|
588
|
+
FILE_CONSTANTS.contentPaddingClassName,
|
|
589
|
+
showingLastGridsReadyData && 'anim_data_loading',
|
|
590
|
+
contentClassName,
|
|
591
|
+
)}
|
|
592
|
+
>
|
|
593
|
+
{!showSheets ? null : (
|
|
594
|
+
<GridsSheetsSection
|
|
595
|
+
contextMenuOwnerId={contextMenuOwnerId}
|
|
596
|
+
organizationId={organizationId}
|
|
597
|
+
sheets={displaySheets}
|
|
598
|
+
showCreateTile={showCreateTiles}
|
|
599
|
+
/>
|
|
600
|
+
)}
|
|
601
|
+
{!showDataTables ? null : (
|
|
602
|
+
<GridsDataTablesSection
|
|
603
|
+
contextMenuOwnerId={contextMenuOwnerId}
|
|
604
|
+
dataTables={displayDataTables}
|
|
605
|
+
/>
|
|
606
|
+
)}
|
|
607
|
+
</div>
|
|
608
|
+
</ContentGate>
|
|
609
|
+
);
|
|
610
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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';
|
|
7
|
+
import { memo, type Dispatch, type SetStateAction } from 'react';
|
|
8
|
+
|
|
9
|
+
interface AppRouteShellProps {
|
|
10
|
+
layoutOpen: boolean;
|
|
11
|
+
setLayoutOpen: Dispatch<SetStateAction<boolean>>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface AppRouteErrorMessageProps extends AppRouteShellProps {
|
|
15
|
+
buttonColorClassName?: string;
|
|
16
|
+
buttonHref?: string;
|
|
17
|
+
buttonText?: string;
|
|
18
|
+
error?: ServerErrorObj | null;
|
|
19
|
+
iconName: string;
|
|
20
|
+
message: string;
|
|
21
|
+
title: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Render a reusable route error inside the app shell layout.
|
|
26
|
+
*/
|
|
27
|
+
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;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ErrorMessageContainer
|
|
42
|
+
layoutOpen={layoutOpen}
|
|
43
|
+
setLayoutOpen={setLayoutOpen}
|
|
44
|
+
>
|
|
45
|
+
<ErrorMessage
|
|
46
|
+
buttonColorClassName={buttonColorClassName}
|
|
47
|
+
buttonHref={buttonHref}
|
|
48
|
+
buttonText={buttonText}
|
|
49
|
+
iconName={iconName}
|
|
50
|
+
title={title}
|
|
51
|
+
message={message}
|
|
52
|
+
{...error}
|
|
53
|
+
/>
|
|
54
|
+
</ErrorMessageContainer>
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
AppRouteErrorMessage.displayName = 'AppRouteErrorMessage';
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* Render a reusable app-shell loading state while route data is being fetched.
|
|
62
|
+
*/
|
|
63
|
+
export const AppRouteLoading = memo((p: AppRouteShellProps) => {
|
|
64
|
+
const { layoutOpen, setLayoutOpen } = p;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<ErrorMessageContainer
|
|
68
|
+
layoutOpen={layoutOpen}
|
|
69
|
+
setLayoutOpen={setLayoutOpen}
|
|
70
|
+
>
|
|
71
|
+
<ContentGate loading notReady showLoadingIfNotReady />
|
|
72
|
+
</ErrorMessageContainer>
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
AppRouteLoading.displayName = 'AppRouteLoading';
|