@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
package/src/modules/Grids.tsx
CHANGED
|
@@ -1,57 +1,28 @@
|
|
|
1
1
|
import { COMMON_CLASSNAMES } from '@jsb188/app/constants/app.ts';
|
|
2
2
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
3
|
import { cn } from '@jsb188/app/utils/string.ts';
|
|
4
|
-
import { useDataTables } from '@jsb188/graphql/hooks/use-dataTable-qry';
|
|
5
4
|
import { useSheets } from '@jsb188/graphql/hooks/use-sheet-qry';
|
|
6
|
-
import type { DataTableGQL } from '@jsb188/mday/types/dataTable.d.ts';
|
|
7
5
|
import type { GridItemSortEnum, SheetGQL } from '@jsb188/mday/types/sheet.d.ts';
|
|
8
|
-
import {
|
|
9
|
-
ContentGate,
|
|
10
|
-
type SetFloatingMessage,
|
|
11
|
-
} from '@jsb188/react-web/modules/layout/MainLayout';
|
|
12
|
-
import type { ToolbarItemObj } from '@jsb188/react-web/modules/Toolbar';
|
|
13
|
-
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
14
|
-
import { TileItem, TileSection } from '@jsb188/react-web/ui/TileUI';
|
|
15
|
-
import { useOpenModalPopUp, usePopOver } from '@jsb188/react/states';
|
|
6
|
+
import { useOpenModalPopUp, usePopOverActions, usePopOverDefinition, usePopOverEvent } from '@jsb188/react/states';
|
|
16
7
|
import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
useRef,
|
|
23
|
-
type MouseEvent,
|
|
24
|
-
} from 'react';
|
|
8
|
+
import { ContentGate } from '@jsb188/react-web/modules/layout/MainLayout';
|
|
9
|
+
import { ModalTileGrid } from '@jsb188/react-web/modules/layout/TabbedModalLayout';
|
|
10
|
+
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
11
|
+
import { TileItem } from '@jsb188/react-web/ui/TileUI';
|
|
12
|
+
import { type MouseEvent, memo, useCallback, useEffect, useId, useMemo, useRef } from 'react';
|
|
25
13
|
import { mapRenderableItems } from '../utils/list-web.ts';
|
|
26
14
|
|
|
27
15
|
const FILE_CONSTANTS = {
|
|
28
|
-
contentPaddingClassName: COMMON_CLASSNAMES.contentXPadding,
|
|
29
|
-
dataTableIconName: COMMON_ICON_NAMES.data_table,
|
|
30
|
-
gridCreateIconName: COMMON_ICON_NAMES.plus,
|
|
31
|
-
sectionDataTables: 'dataTables',
|
|
32
|
-
sectionSheets: 'sheets',
|
|
33
|
-
sheetIconName: COMMON_ICON_NAMES.sheet,
|
|
34
|
-
sortParamName: 's',
|
|
35
|
-
sortTitle: '2',
|
|
36
|
-
sortUpdatedDate: '1',
|
|
37
16
|
tileContextMenuIdPrefix: 'grids_tile_context_menu:',
|
|
38
17
|
} as const;
|
|
39
18
|
|
|
40
|
-
|
|
41
|
-
FILE_CONSTANTS.sortUpdatedDate,
|
|
42
|
-
FILE_CONSTANTS.sortTitle,
|
|
43
|
-
] as const;
|
|
44
|
-
|
|
45
|
-
export type GridsSectionMode = 'all' | 'sheets' | 'dataTables';
|
|
46
|
-
export type GridsSortValue = (typeof GRIDS_SORT_OPTIONS)[number];
|
|
19
|
+
export { GRIDS_FILTER_SCHEMA } from './Grids.filters.ts';
|
|
47
20
|
|
|
48
21
|
type GridItem = {
|
|
49
22
|
id: string;
|
|
50
|
-
__typename: 'Sheet' | 'DataTable';
|
|
51
23
|
__deleted?: boolean;
|
|
52
24
|
title: string;
|
|
53
25
|
description: string;
|
|
54
|
-
iconName: string;
|
|
55
26
|
to: string;
|
|
56
27
|
};
|
|
57
28
|
|
|
@@ -60,141 +31,6 @@ type GridsTileContextMenuValue = {
|
|
|
60
31
|
item: GridItem;
|
|
61
32
|
};
|
|
62
33
|
|
|
63
|
-
type GridsReadyData = {
|
|
64
|
-
dataTables: DataTableGQL[] | null;
|
|
65
|
-
sheets: SheetGQL[] | null;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
type GridsSectionVisibility = {
|
|
69
|
-
showDataTables: boolean;
|
|
70
|
-
showSheets: boolean;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
type GridsTileSectionProps = {
|
|
74
|
-
createDescription: string;
|
|
75
|
-
createTitle: string;
|
|
76
|
-
items: GridItem[];
|
|
77
|
-
mocked: boolean;
|
|
78
|
-
sectionId: string;
|
|
79
|
-
showCreateTile: boolean;
|
|
80
|
-
title: string;
|
|
81
|
-
onCreate: () => void;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
interface GridsModuleProps {
|
|
85
|
-
contentClassName?: string;
|
|
86
|
-
notReadyClassName?: string;
|
|
87
|
-
organizationId: string;
|
|
88
|
-
sections?: GridsSectionMode;
|
|
89
|
-
setFloatingMessage?: SetFloatingMessage;
|
|
90
|
-
showCreateTiles?: boolean;
|
|
91
|
-
sort: GridItemSortEnum;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/*
|
|
95
|
-
* Return which grids sections should be visible for one module mode.
|
|
96
|
-
*/
|
|
97
|
-
function getGridsSectionVisibility(
|
|
98
|
-
sections: GridsSectionMode,
|
|
99
|
-
): GridsSectionVisibility {
|
|
100
|
-
return {
|
|
101
|
-
showDataTables: sections !== FILE_CONSTANTS.sectionSheets,
|
|
102
|
-
showSheets: sections !== FILE_CONSTANTS.sectionDataTables,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/*
|
|
107
|
-
* Return one stable reset-only signal value for all visible grids list queries.
|
|
108
|
-
*/
|
|
109
|
-
function getGridsResetOnlyTime(
|
|
110
|
-
sheetsResetOnlyTime: string,
|
|
111
|
-
dataTablesResetOnlyTime: string,
|
|
112
|
-
) {
|
|
113
|
-
return [sheetsResetOnlyTime, dataTablesResetOnlyTime]
|
|
114
|
-
.filter(Boolean)
|
|
115
|
-
.join('|');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/*
|
|
119
|
-
* Show the app refresh prompt when grids queries receive a RESET_ONLY emit.
|
|
120
|
-
*/
|
|
121
|
-
function useGridsResetOnlyFloatingMessage(
|
|
122
|
-
resetOnlyTime: string,
|
|
123
|
-
setFloatingMessage?: SetFloatingMessage,
|
|
124
|
-
) {
|
|
125
|
-
const lastUpdateTime = useRef(resetOnlyTime);
|
|
126
|
-
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
if (!resetOnlyTime || !setFloatingMessage) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (resetOnlyTime !== lastUpdateTime.current) {
|
|
133
|
-
setFloatingMessage({
|
|
134
|
-
type: 'REFRESH',
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
lastUpdateTime.current = resetOnlyTime;
|
|
139
|
-
}, [resetOnlyTime, setFloatingMessage]);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/*
|
|
143
|
-
* Keep the last fully loaded grids data available during replacement fetches.
|
|
144
|
-
*/
|
|
145
|
-
function useLastGridsReadyData(p: {
|
|
146
|
-
dataTables?: DataTableGQL[] | null;
|
|
147
|
-
sheets?: SheetGQL[] | null;
|
|
148
|
-
showDataTables: boolean;
|
|
149
|
-
showSheets: boolean;
|
|
150
|
-
}) {
|
|
151
|
-
const { dataTables, sheets, showDataTables, showSheets } = p;
|
|
152
|
-
const readyDataRef = useRef<GridsReadyData | null>(null);
|
|
153
|
-
|
|
154
|
-
useEffect(() => {
|
|
155
|
-
if ((showSheets && !sheets) || (showDataTables && !dataTables)) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
readyDataRef.current = {
|
|
160
|
-
dataTables: showDataTables ? dataTables || null : null,
|
|
161
|
-
sheets: showSheets ? sheets || null : null,
|
|
162
|
-
};
|
|
163
|
-
}, [dataTables, sheets, showDataTables, showSheets]);
|
|
164
|
-
|
|
165
|
-
return readyDataRef.current;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/*
|
|
169
|
-
* Return query variables for one grids data source when its section is visible.
|
|
170
|
-
*/
|
|
171
|
-
function getGridsQueryVariables(
|
|
172
|
-
visible: boolean,
|
|
173
|
-
organizationId: string,
|
|
174
|
-
sort: GridItemSortEnum,
|
|
175
|
-
) {
|
|
176
|
-
return visible
|
|
177
|
-
? {
|
|
178
|
-
organizationId,
|
|
179
|
-
sort,
|
|
180
|
-
}
|
|
181
|
-
: null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/*
|
|
185
|
-
* Return the best display title for one sheet.
|
|
186
|
-
*/
|
|
187
|
-
function getSheetTitle(sheet: SheetGQL) {
|
|
188
|
-
return sheet.title || i18n.t('app.untitled_sheet');
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/*
|
|
192
|
-
* Return the best display title for one dataTable.
|
|
193
|
-
*/
|
|
194
|
-
function getDataTableTitle(dataTable: DataTableGQL) {
|
|
195
|
-
return dataTable.title || i18n.t('sheet.untitled_data_table');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
34
|
/*
|
|
199
35
|
* Convert one sheet record into a grids tile item.
|
|
200
36
|
*/
|
|
@@ -205,155 +41,13 @@ function mapSheetToGridItem(sheet: SheetGQL): GridItem | null {
|
|
|
205
41
|
|
|
206
42
|
return {
|
|
207
43
|
id: sheet.id,
|
|
208
|
-
|
|
209
|
-
title: getSheetTitle(sheet),
|
|
44
|
+
title: sheet.title || i18n.t('app.untitled_sheet'),
|
|
210
45
|
description: sheet.description || sheet.name || '',
|
|
211
|
-
iconName: FILE_CONSTANTS.sheetIconName,
|
|
212
46
|
to: `/app/s/${sheet.id}`,
|
|
213
47
|
__deleted: Boolean(sheet.__deleted || sheet.deletedAt),
|
|
214
48
|
};
|
|
215
49
|
}
|
|
216
50
|
|
|
217
|
-
/*
|
|
218
|
-
* Convert one dataTable record into a grids tile item.
|
|
219
|
-
*/
|
|
220
|
-
function mapDataTableToGridItem(dataTable: DataTableGQL): GridItem | null {
|
|
221
|
-
if (!dataTable.id) {
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return {
|
|
226
|
-
id: dataTable.id,
|
|
227
|
-
__typename: 'DataTable',
|
|
228
|
-
title: getDataTableTitle(dataTable),
|
|
229
|
-
description: dataTable.description || dataTable.name || '',
|
|
230
|
-
iconName: FILE_CONSTANTS.dataTableIconName,
|
|
231
|
-
to: `/app/d/${dataTable.id}`,
|
|
232
|
-
__deleted: Boolean(dataTable.__deleted || dataTable.active === false),
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/*
|
|
237
|
-
* Return the current grids sort value from search params.
|
|
238
|
-
*/
|
|
239
|
-
export function getGridsSortValue(
|
|
240
|
-
searchParams: URLSearchParams,
|
|
241
|
-
sortParamName: string = FILE_CONSTANTS.sortParamName,
|
|
242
|
-
): GridsSortValue {
|
|
243
|
-
const sortValue = searchParams.get(sortParamName);
|
|
244
|
-
|
|
245
|
-
return GRIDS_SORT_OPTIONS.includes(sortValue as GridsSortValue)
|
|
246
|
-
? (sortValue as GridsSortValue)
|
|
247
|
-
: FILE_CONSTANTS.sortUpdatedDate;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/*
|
|
251
|
-
* Return the toolbar label for the selected grids sort option.
|
|
252
|
-
*/
|
|
253
|
-
function getGridsSortText(sortValue: GridsSortValue) {
|
|
254
|
-
return i18n.t(
|
|
255
|
-
sortValue === FILE_CONSTANTS.sortTitle
|
|
256
|
-
? 'app.grids_sort_title'
|
|
257
|
-
: 'app.grids_sort_updated_date',
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/*
|
|
262
|
-
* Return the GraphQL sort value for the current grids URL sort value.
|
|
263
|
-
*/
|
|
264
|
-
export function getGridsSortQueryValue(
|
|
265
|
-
sortValue: GridsSortValue,
|
|
266
|
-
): GridItemSortEnum {
|
|
267
|
-
return sortValue === FILE_CONSTANTS.sortTitle
|
|
268
|
-
? 'TITLE_ASC'
|
|
269
|
-
: 'UPDATED_AT_DESC';
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/*
|
|
273
|
-
* Build a grids path with the selected sort search param.
|
|
274
|
-
*/
|
|
275
|
-
function createGridsSortPath(
|
|
276
|
-
pathname: string,
|
|
277
|
-
searchParams: URLSearchParams,
|
|
278
|
-
sortValue: GridsSortValue,
|
|
279
|
-
sortParamName: string,
|
|
280
|
-
) {
|
|
281
|
-
const nextSearchParams = new URLSearchParams(searchParams);
|
|
282
|
-
nextSearchParams.set(sortParamName, sortValue);
|
|
283
|
-
|
|
284
|
-
return `${pathname}?${nextSearchParams.toString()}`;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/*
|
|
288
|
-
* Return the app toolbar options for a grids surface.
|
|
289
|
-
*/
|
|
290
|
-
export function getGridsToolbarOptions(
|
|
291
|
-
pathname: string,
|
|
292
|
-
searchParams: URLSearchParams,
|
|
293
|
-
sortValue: GridsSortValue,
|
|
294
|
-
sortParamName: string = FILE_CONSTANTS.sortParamName,
|
|
295
|
-
): ToolbarItemObj[] {
|
|
296
|
-
return [
|
|
297
|
-
{
|
|
298
|
-
id: 'grids_sort',
|
|
299
|
-
text: getGridsSortText(sortValue),
|
|
300
|
-
hasValue: true,
|
|
301
|
-
hideClearIcon: true,
|
|
302
|
-
popOverClassName: 'min_w_200',
|
|
303
|
-
initialState: sortValue,
|
|
304
|
-
disablePopOverButton: true,
|
|
305
|
-
options: [
|
|
306
|
-
{
|
|
307
|
-
__type: 'LIST_SUBTITLE',
|
|
308
|
-
text: i18n.t('form.sort_by'),
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
__type: 'SINGLE_OPTION_LIST_ITEM',
|
|
312
|
-
value: FILE_CONSTANTS.sortUpdatedDate,
|
|
313
|
-
text: i18n.t('app.grids_sort_updated_date'),
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
__type: 'SINGLE_OPTION_LIST_ITEM',
|
|
317
|
-
value: FILE_CONSTANTS.sortTitle,
|
|
318
|
-
text: i18n.t('app.grids_sort_title'),
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
getItemTo: (nextSortValue) =>
|
|
322
|
-
createGridsSortPath(
|
|
323
|
-
pathname,
|
|
324
|
-
searchParams,
|
|
325
|
-
nextSortValue === FILE_CONSTANTS.sortTitle
|
|
326
|
-
? FILE_CONSTANTS.sortTitle
|
|
327
|
-
: FILE_CONSTANTS.sortUpdatedDate,
|
|
328
|
-
sortParamName,
|
|
329
|
-
),
|
|
330
|
-
},
|
|
331
|
-
];
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/*
|
|
335
|
-
* Return sort state and toolbar items for a grids surface.
|
|
336
|
-
*/
|
|
337
|
-
export function getGridsToolbarState(p: {
|
|
338
|
-
pathname: string;
|
|
339
|
-
searchParams: URLSearchParams;
|
|
340
|
-
sortParamName?: string;
|
|
341
|
-
}) {
|
|
342
|
-
const { pathname, searchParams, sortParamName } = p;
|
|
343
|
-
const sortValue = getGridsSortValue(searchParams, sortParamName);
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
sortQueryValue: getGridsSortQueryValue(sortValue),
|
|
347
|
-
sortValue,
|
|
348
|
-
toolbarOptions: getGridsToolbarOptions(
|
|
349
|
-
pathname,
|
|
350
|
-
searchParams,
|
|
351
|
-
sortValue,
|
|
352
|
-
sortParamName,
|
|
353
|
-
),
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
51
|
/*
|
|
358
52
|
* Convert a right-click event into a popover anchor rectangle.
|
|
359
53
|
*/
|
|
@@ -376,34 +70,11 @@ function getGridsTileContextMenuRect(e: MouseEvent<Element>) {
|
|
|
376
70
|
* Build an absolute URL for a grids tile route action.
|
|
377
71
|
*/
|
|
378
72
|
function getGridsTileRouteUrl(to: string) {
|
|
379
|
-
return new URL(
|
|
380
|
-
to,
|
|
381
|
-
globalThis.location?.origin || 'http://localhost',
|
|
382
|
-
).toString();
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/*
|
|
386
|
-
* Return the modal preset name used to delete one grids tile.
|
|
387
|
-
*/
|
|
388
|
-
function getGridsTileDeleteModalName(item: GridItem) {
|
|
389
|
-
return item.__typename === 'Sheet' ? 'DELETE_SHEET' : 'DELETE_DATA_TABLE';
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/*
|
|
393
|
-
* Return the modal props used to delete one grids tile.
|
|
394
|
-
*/
|
|
395
|
-
function getGridsTileDeleteModalProps(item: GridItem, organizationId: string) {
|
|
396
|
-
return {
|
|
397
|
-
itemTitle: item.title,
|
|
398
|
-
organizationId,
|
|
399
|
-
...(item.__typename === 'Sheet'
|
|
400
|
-
? { sheetId: item.id }
|
|
401
|
-
: { dataTableId: item.id }),
|
|
402
|
-
};
|
|
73
|
+
return new URL(to, globalThis.location?.origin || 'http://localhost').toString();
|
|
403
74
|
}
|
|
404
75
|
|
|
405
76
|
/*
|
|
406
|
-
*
|
|
77
|
+
* Build the spreadsheet tile context menu.
|
|
407
78
|
*/
|
|
408
79
|
function getGridsTileContextOptions(item: GridItem): POListIfaceItem[] {
|
|
409
80
|
return [
|
|
@@ -419,11 +90,7 @@ function getGridsTileContextOptions(item: GridItem): POListIfaceItem[] {
|
|
|
419
90
|
{
|
|
420
91
|
__type: 'LIST_ITEM',
|
|
421
92
|
iconName: COMMON_ICON_NAMES.delete,
|
|
422
|
-
text: i18n.t(
|
|
423
|
-
item.__typename === 'Sheet'
|
|
424
|
-
? 'sheet.delete_sheet'
|
|
425
|
-
: 'sheet.delete_data_table',
|
|
426
|
-
),
|
|
93
|
+
text: i18n.t('sheet.delete_sheet'),
|
|
427
94
|
className: 'cl_err_hv',
|
|
428
95
|
value: {
|
|
429
96
|
action: 'DELETE_GRID_ITEM',
|
|
@@ -433,21 +100,17 @@ function getGridsTileContextOptions(item: GridItem): POListIfaceItem[] {
|
|
|
433
100
|
];
|
|
434
101
|
}
|
|
435
102
|
|
|
436
|
-
/*
|
|
437
|
-
* Return the popover id for one grids tile context menu.
|
|
438
|
-
*/
|
|
439
|
-
function getGridsTileContextMenuId(sectionId: string, item: GridItem) {
|
|
440
|
-
return `${FILE_CONSTANTS.tileContextMenuIdPrefix}${sectionId}:${item.__typename}:${item.id}`;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
103
|
/*
|
|
444
104
|
* Render one mapped grids tile item with a right-click menu.
|
|
445
105
|
*/
|
|
446
|
-
const GridsTileItem = memo((p: {
|
|
447
|
-
const {
|
|
448
|
-
const
|
|
449
|
-
const
|
|
106
|
+
const GridsTileItem = memo((p: { contextMenuIdPrefix: string; item: GridItem }) => {
|
|
107
|
+
const { contextMenuIdPrefix, item } = p;
|
|
108
|
+
const popOver = usePopOverDefinition();
|
|
109
|
+
const { openPopOver } = usePopOverActions();
|
|
110
|
+
const popOverId = contextMenuIdPrefix + item.id;
|
|
450
111
|
const active = popOver?.id === popOverId;
|
|
112
|
+
// Sheet routes have no server loader, so their intent prefetch stays route-JS only.
|
|
113
|
+
const prefetch = !active ? 'intent' : 'none';
|
|
451
114
|
|
|
452
115
|
/*
|
|
453
116
|
* Open the grid item context menu at the pointer location.
|
|
@@ -483,9 +146,10 @@ const GridsTileItem = memo((p: { item: GridItem; sectionId: string }) => {
|
|
|
483
146
|
<TileItem
|
|
484
147
|
__deleted={item.__deleted}
|
|
485
148
|
active={active}
|
|
486
|
-
iconName={
|
|
149
|
+
iconName={COMMON_ICON_NAMES.sheet}
|
|
487
150
|
title={item.title}
|
|
488
151
|
description={item.description}
|
|
152
|
+
prefetch={prefetch}
|
|
489
153
|
to={item.to}
|
|
490
154
|
onContextMenu={onContextMenu}
|
|
491
155
|
/>
|
|
@@ -495,252 +159,32 @@ const GridsTileItem = memo((p: { item: GridItem; sectionId: string }) => {
|
|
|
495
159
|
GridsTileItem.displayName = 'GridsTileItem';
|
|
496
160
|
|
|
497
161
|
/*
|
|
498
|
-
*
|
|
499
|
-
*/
|
|
500
|
-
const GridsTileSection = memo((p: GridsTileSectionProps) => {
|
|
501
|
-
return (
|
|
502
|
-
<TileSection className="mb_md" mocked={p.mocked} title={p.title}>
|
|
503
|
-
{p.items.map((item) => (
|
|
504
|
-
<GridsTileItem
|
|
505
|
-
key={`${item.__typename}:${item.id}`}
|
|
506
|
-
item={item}
|
|
507
|
-
sectionId={p.sectionId}
|
|
508
|
-
/>
|
|
509
|
-
))}
|
|
510
|
-
|
|
511
|
-
{!p.showCreateTile ? null : (
|
|
512
|
-
<TileItem
|
|
513
|
-
iconName={FILE_CONSTANTS.gridCreateIconName}
|
|
514
|
-
title={p.createTitle}
|
|
515
|
-
description={p.createDescription}
|
|
516
|
-
onClick={p.onCreate}
|
|
517
|
-
/>
|
|
518
|
-
)}
|
|
519
|
-
</TileSection>
|
|
520
|
-
);
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
GridsTileSection.displayName = 'GridsTileSection';
|
|
524
|
-
|
|
525
|
-
/*
|
|
526
|
-
* Render the grids sheets section.
|
|
527
|
-
*/
|
|
528
|
-
function GridsSheetsSection(p: {
|
|
529
|
-
organizationId: string;
|
|
530
|
-
sheets?: SheetGQL[] | null;
|
|
531
|
-
showCreateTile: boolean;
|
|
532
|
-
}) {
|
|
533
|
-
const { organizationId, sheets, showCreateTile } = p;
|
|
534
|
-
const openModalPopUp = useOpenModalPopUp();
|
|
535
|
-
const sheetItems = useMemo(
|
|
536
|
-
() => mapRenderableItems(sheets, mapSheetToGridItem),
|
|
537
|
-
[sheets],
|
|
538
|
-
);
|
|
539
|
-
|
|
540
|
-
/*
|
|
541
|
-
* Open the sheet creation flow.
|
|
542
|
-
*/
|
|
543
|
-
const openCreateSheet = useCallback(() => {
|
|
544
|
-
openModalPopUp({
|
|
545
|
-
name: 'CREATE_SHEET',
|
|
546
|
-
preset: 'CREATE_SHEET',
|
|
547
|
-
props: {
|
|
548
|
-
organizationId,
|
|
549
|
-
},
|
|
550
|
-
});
|
|
551
|
-
}, [openModalPopUp, organizationId]);
|
|
552
|
-
|
|
553
|
-
return (
|
|
554
|
-
<GridsTileSection
|
|
555
|
-
createDescription={i18n.t('sheet.create_sheet_description')}
|
|
556
|
-
createTitle={i18n.t('sheet.create_sheet')}
|
|
557
|
-
items={sheetItems}
|
|
558
|
-
mocked={!sheets}
|
|
559
|
-
sectionId={FILE_CONSTANTS.sectionSheets}
|
|
560
|
-
showCreateTile={showCreateTile}
|
|
561
|
-
title={i18n.t('sheet.sheets')}
|
|
562
|
-
onCreate={openCreateSheet}
|
|
563
|
-
/>
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/*
|
|
568
|
-
* Render the grids data tables section.
|
|
162
|
+
* Show spreadsheets in the picker and handle actions on their tiles.
|
|
569
163
|
*/
|
|
570
|
-
function
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
})
|
|
575
|
-
const
|
|
164
|
+
export function GridsModule({ organizationId, sort }: { organizationId: string; sort: GridItemSortEnum }) {
|
|
165
|
+
const contextMenuOwnerId = useId().replaceAll(':', '_');
|
|
166
|
+
const contextMenuIdPrefix = `${FILE_CONSTANTS.tileContextMenuIdPrefix}${contextMenuOwnerId}:`;
|
|
167
|
+
const popOver = usePopOverDefinition();
|
|
168
|
+
const { acknowledgePopOverEvent, closePopOver } = usePopOverActions();
|
|
169
|
+
const activeGridsPopOverId = popOver?.id?.startsWith(contextMenuIdPrefix) ? popOver.id : null;
|
|
170
|
+
const popOverEvent = usePopOverEvent({ popOverId: activeGridsPopOverId });
|
|
576
171
|
const openModalPopUp = useOpenModalPopUp();
|
|
577
|
-
const dataTableItems = useMemo(
|
|
578
|
-
() => mapRenderableItems(dataTables, mapDataTableToGridItem),
|
|
579
|
-
[dataTables],
|
|
580
|
-
);
|
|
581
|
-
|
|
582
|
-
/*
|
|
583
|
-
* Open the data table creation flow.
|
|
584
|
-
*/
|
|
585
|
-
const openCreateDataTable = useCallback(() => {
|
|
586
|
-
openModalPopUp({
|
|
587
|
-
name: 'CREATE_DATASET',
|
|
588
|
-
preset: 'CREATE_DATASET',
|
|
589
|
-
props: {
|
|
590
|
-
organizationId,
|
|
591
|
-
},
|
|
592
|
-
});
|
|
593
|
-
}, [openModalPopUp, organizationId]);
|
|
594
|
-
|
|
595
|
-
return (
|
|
596
|
-
<GridsTileSection
|
|
597
|
-
createDescription={i18n.t('sheet.create_data_table_description')}
|
|
598
|
-
createTitle={i18n.t('sheet.create_data_table')}
|
|
599
|
-
items={dataTableItems}
|
|
600
|
-
mocked={!dataTables}
|
|
601
|
-
sectionId={FILE_CONSTANTS.sectionDataTables}
|
|
602
|
-
showCreateTile={showCreateTile}
|
|
603
|
-
title={i18n.t('sheet.data_tables')}
|
|
604
|
-
onCreate={openCreateDataTable}
|
|
605
|
-
/>
|
|
606
|
-
);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/*
|
|
610
|
-
* Return whether visible grids data is missing during a fetch.
|
|
611
|
-
*/
|
|
612
|
-
function getGridsVisibleDataMissing(p: {
|
|
613
|
-
dataTables?: DataTableGQL[] | null;
|
|
614
|
-
sheets?: SheetGQL[] | null;
|
|
615
|
-
showDataTables: boolean;
|
|
616
|
-
showSheets: boolean;
|
|
617
|
-
}) {
|
|
618
|
-
const { dataTables, sheets, showDataTables, showSheets } = p;
|
|
619
|
-
|
|
620
|
-
return (showSheets && !sheets) || (showDataTables && !dataTables);
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
/*
|
|
624
|
-
* Return the data lists that should render while preserving last-ready data during fetches.
|
|
625
|
-
*/
|
|
626
|
-
function getGridsDisplayData(p: {
|
|
627
|
-
dataTables?: DataTableGQL[] | null;
|
|
628
|
-
lastGridsReadyData: GridsReadyData | null;
|
|
629
|
-
sheets?: SheetGQL[] | null;
|
|
630
|
-
showDataTables: boolean;
|
|
631
|
-
showingLastGridsReadyData: boolean;
|
|
632
|
-
showSheets: boolean;
|
|
633
|
-
}) {
|
|
634
|
-
const {
|
|
635
|
-
dataTables,
|
|
636
|
-
lastGridsReadyData,
|
|
637
|
-
sheets,
|
|
638
|
-
showDataTables,
|
|
639
|
-
showingLastGridsReadyData,
|
|
640
|
-
showSheets,
|
|
641
|
-
} = p;
|
|
642
|
-
|
|
643
|
-
return {
|
|
644
|
-
displayDataTables: showDataTables
|
|
645
|
-
? showingLastGridsReadyData
|
|
646
|
-
? lastGridsReadyData?.dataTables
|
|
647
|
-
: dataTables
|
|
648
|
-
: null,
|
|
649
|
-
displaySheets: showSheets
|
|
650
|
-
? showingLastGridsReadyData
|
|
651
|
-
? lastGridsReadyData?.sheets
|
|
652
|
-
: sheets
|
|
653
|
-
: null,
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/*
|
|
658
|
-
* Fetch grids data and render each visible grids section.
|
|
659
|
-
*/
|
|
660
|
-
export function GridsModule(p: GridsModuleProps) {
|
|
661
|
-
const {
|
|
662
|
-
contentClassName,
|
|
663
|
-
notReadyClassName,
|
|
664
|
-
organizationId,
|
|
665
|
-
sections = 'all',
|
|
666
|
-
setFloatingMessage,
|
|
667
|
-
showCreateTiles = true,
|
|
668
|
-
sort,
|
|
669
|
-
} = p;
|
|
670
|
-
const { popOver, closePopOver } = usePopOver();
|
|
671
|
-
const openModalPopUp = useOpenModalPopUp();
|
|
672
|
-
const { showDataTables, showSheets } = getGridsSectionVisibility(sections);
|
|
673
172
|
const popOverHandlersRef = useRef({
|
|
674
173
|
closePopOver,
|
|
675
174
|
openModalPopUp,
|
|
676
175
|
});
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
);
|
|
685
|
-
const {
|
|
686
|
-
dataTables,
|
|
687
|
-
error: dataTablesError,
|
|
688
|
-
loading: dataTablesLoading,
|
|
689
|
-
refetch: refetchDataTables,
|
|
690
|
-
resetOnlyTime: dataTablesResetOnlyTime,
|
|
691
|
-
} = useDataTables(dataTablesQueryVariables);
|
|
692
|
-
const {
|
|
693
|
-
sheets,
|
|
694
|
-
error: sheetsError,
|
|
695
|
-
loading: sheetsLoading,
|
|
696
|
-
refetch: refetchSheets,
|
|
697
|
-
resetOnlyTime: sheetsResetOnlyTime,
|
|
698
|
-
} = useSheets(sheetsQueryVariables);
|
|
699
|
-
const error =
|
|
700
|
-
(showSheets && sheetsError) || (showDataTables && dataTablesError);
|
|
701
|
-
const gridsLoading = Boolean(
|
|
702
|
-
(showSheets && sheetsLoading) || (showDataTables && dataTablesLoading),
|
|
703
|
-
);
|
|
704
|
-
const lastGridsReadyData = useLastGridsReadyData({
|
|
705
|
-
dataTables,
|
|
706
|
-
sheets,
|
|
707
|
-
showDataTables,
|
|
708
|
-
showSheets,
|
|
709
|
-
});
|
|
710
|
-
const visibleDataMissing = getGridsVisibleDataMissing({
|
|
711
|
-
dataTables,
|
|
712
|
-
sheets,
|
|
713
|
-
showDataTables,
|
|
714
|
-
showSheets,
|
|
715
|
-
});
|
|
716
|
-
const showingLastGridsReadyData =
|
|
717
|
-
gridsLoading && visibleDataMissing && !!lastGridsReadyData;
|
|
718
|
-
const { displayDataTables, displaySheets } = getGridsDisplayData({
|
|
719
|
-
dataTables,
|
|
720
|
-
lastGridsReadyData,
|
|
721
|
-
sheets,
|
|
722
|
-
showDataTables,
|
|
723
|
-
showingLastGridsReadyData,
|
|
724
|
-
showSheets,
|
|
725
|
-
});
|
|
726
|
-
const notReady = getGridsVisibleDataMissing({
|
|
727
|
-
dataTables: displayDataTables,
|
|
728
|
-
sheets: displaySheets,
|
|
729
|
-
showDataTables,
|
|
730
|
-
showSheets,
|
|
731
|
-
});
|
|
732
|
-
const gridsResetOnlyTime = getGridsResetOnlyTime(
|
|
733
|
-
showSheets ? sheetsResetOnlyTime : '',
|
|
734
|
-
showDataTables ? dataTablesResetOnlyTime : '',
|
|
735
|
-
);
|
|
736
|
-
|
|
176
|
+
const { sheets, loading, error, refetch } = useSheets({ organizationId, sort });
|
|
177
|
+
const lastSheets = useRef<typeof sheets>(null);
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (sheets) lastSheets.current = sheets;
|
|
180
|
+
}, [sheets]);
|
|
181
|
+
const visibleSheets = sheets ?? (loading ? lastSheets.current : null);
|
|
182
|
+
const items = useMemo(() => mapRenderableItems(visibleSheets, mapSheetToGridItem), [visibleSheets]);
|
|
737
183
|
popOverHandlersRef.current = {
|
|
738
184
|
closePopOver,
|
|
739
185
|
openModalPopUp,
|
|
740
186
|
};
|
|
741
187
|
|
|
742
|
-
useGridsResetOnlyFloatingMessage(gridsResetOnlyTime, setFloatingMessage);
|
|
743
|
-
|
|
744
188
|
/*
|
|
745
189
|
* Close the grids popover when the module unmounts.
|
|
746
190
|
*/
|
|
@@ -751,31 +195,27 @@ export function GridsModule(p: GridsModuleProps) {
|
|
|
751
195
|
}, []);
|
|
752
196
|
|
|
753
197
|
/*
|
|
754
|
-
* Handle
|
|
198
|
+
* Handle item events scoped to the currently open grids context menu.
|
|
755
199
|
*/
|
|
756
200
|
useEffect(() => {
|
|
757
|
-
|
|
201
|
+
if (!popOverEvent) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const { action, id, value } = popOverEvent;
|
|
758
206
|
const contextValue = value as GridsTileContextMenuValue | null;
|
|
759
207
|
|
|
760
|
-
if (
|
|
761
|
-
action !== 'ITEM' ||
|
|
762
|
-
typeof id !== 'string' ||
|
|
763
|
-
!id.startsWith(FILE_CONSTANTS.tileContextMenuIdPrefix) ||
|
|
764
|
-
!contextValue
|
|
765
|
-
) {
|
|
208
|
+
if (action !== 'ITEM' || typeof id !== 'string' || !id.startsWith(contextMenuIdPrefix) || !contextValue) {
|
|
766
209
|
return;
|
|
767
210
|
}
|
|
768
211
|
|
|
212
|
+
acknowledgePopOverEvent(popOverEvent.eventId);
|
|
769
213
|
const { item } = contextValue;
|
|
770
214
|
popOverHandlersRef.current.closePopOver();
|
|
771
215
|
|
|
772
216
|
switch (contextValue.action) {
|
|
773
217
|
case 'OPEN_GRID_ITEM_NEW_TAB':
|
|
774
|
-
globalThis.window?.open(
|
|
775
|
-
getGridsTileRouteUrl(item.to),
|
|
776
|
-
'_blank',
|
|
777
|
-
'noopener,noreferrer',
|
|
778
|
-
);
|
|
218
|
+
globalThis.window?.open(getGridsTileRouteUrl(item.to), '_blank', 'noopener,noreferrer');
|
|
779
219
|
return;
|
|
780
220
|
case 'DELETE_GRID_ITEM':
|
|
781
221
|
break;
|
|
@@ -783,59 +223,31 @@ export function GridsModule(p: GridsModuleProps) {
|
|
|
783
223
|
return;
|
|
784
224
|
}
|
|
785
225
|
|
|
786
|
-
const deleteModalName = getGridsTileDeleteModalName(item);
|
|
787
|
-
|
|
788
226
|
popOverHandlersRef.current.openModalPopUp({
|
|
789
|
-
name:
|
|
790
|
-
preset:
|
|
791
|
-
props:
|
|
227
|
+
name: 'DELETE_SHEET',
|
|
228
|
+
preset: 'DELETE_SHEET',
|
|
229
|
+
props: { sheetId: item.id, itemTitle: item.title, organizationId },
|
|
792
230
|
});
|
|
793
|
-
}, [organizationId,
|
|
794
|
-
|
|
795
|
-
/*
|
|
796
|
-
* Refetch every visible data source used by the grids.
|
|
797
|
-
*/
|
|
798
|
-
const refetchGridItems = useCallback(() => {
|
|
799
|
-
if (showSheets) {
|
|
800
|
-
refetchSheets();
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
if (showDataTables) {
|
|
804
|
-
refetchDataTables();
|
|
805
|
-
}
|
|
806
|
-
}, [refetchDataTables, refetchSheets, showDataTables, showSheets]);
|
|
231
|
+
}, [acknowledgePopOverEvent, contextMenuIdPrefix, organizationId, popOverEvent]);
|
|
807
232
|
|
|
808
233
|
return (
|
|
809
234
|
<ContentGate
|
|
810
235
|
showLoadingIfNotReady
|
|
811
|
-
notReady={
|
|
812
|
-
loading={
|
|
813
|
-
error={error
|
|
814
|
-
notReadyClassName=
|
|
815
|
-
onRefetch={
|
|
236
|
+
notReady={!visibleSheets}
|
|
237
|
+
loading={!!loading}
|
|
238
|
+
error={error}
|
|
239
|
+
notReadyClassName="h_500 v_center"
|
|
240
|
+
onRefetch={() => refetch()}
|
|
816
241
|
>
|
|
817
|
-
<div
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
<GridsSheetsSection
|
|
827
|
-
organizationId={organizationId}
|
|
828
|
-
sheets={displaySheets}
|
|
829
|
-
showCreateTile={showCreateTiles}
|
|
830
|
-
/>
|
|
831
|
-
)}
|
|
832
|
-
{!showDataTables ? null : (
|
|
833
|
-
<GridsDataTablesSection
|
|
834
|
-
dataTables={displayDataTables}
|
|
835
|
-
organizationId={organizationId}
|
|
836
|
-
showCreateTile={showCreateTiles}
|
|
837
|
-
/>
|
|
838
|
-
)}
|
|
242
|
+
<div className={cn('rel pt_md pb_md', COMMON_CLASSNAMES.contentXPadding, !sheets && !!visibleSheets && 'anim_data_loading')}>
|
|
243
|
+
<ModalTileGrid
|
|
244
|
+
className="mb_md"
|
|
245
|
+
loading={!visibleSheets}
|
|
246
|
+
title={i18n.t('sheet.sheets')}
|
|
247
|
+
items={items}
|
|
248
|
+
ItemComponent={GridsTileItem}
|
|
249
|
+
itemProps={{ contextMenuIdPrefix }}
|
|
250
|
+
/>
|
|
839
251
|
</div>
|
|
840
252
|
</ContentGate>
|
|
841
253
|
);
|