@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,800 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
COMMON_CLASSNAMES,
|
|
3
|
-
END_BUTTON_WIDTH,
|
|
4
|
-
} from '@jsb188/app/constants/app.ts';
|
|
5
|
-
import i18n from '@jsb188/app/i18n/index.ts';
|
|
6
|
-
import { getReadableCalDate } from '@jsb188/app/utils/datetime.ts';
|
|
7
|
-
import { cn } from '@jsb188/app/utils/string.ts';
|
|
8
|
-
import {
|
|
9
|
-
useCreateAgentDoc,
|
|
10
|
-
useUpdateAgentDoc,
|
|
11
|
-
} from '@jsb188/graphql/hooks/use-agentDoc-mtn';
|
|
12
|
-
import {
|
|
13
|
-
useAgentDocFolders,
|
|
14
|
-
useAgentDocs,
|
|
15
|
-
} from '@jsb188/graphql/hooks/use-agentDoc-qry';
|
|
16
|
-
import { useOrgRelFromMyOrganizations } from '@jsb188/graphql/hooks/use-organization-qry';
|
|
17
|
-
import type {
|
|
18
|
-
AgentDocFolderGQL,
|
|
19
|
-
AgentDocGQL,
|
|
20
|
-
AgentDocSettingsObj,
|
|
21
|
-
} from '@jsb188/mday/types/agentDoc.d.ts';
|
|
22
|
-
import type { GridItemSortEnum } from '@jsb188/mday/types/sheet.d.ts';
|
|
23
|
-
import { isAgentDocStale } from '@jsb188/mday/utils/agentDoc.ts';
|
|
24
|
-
import { checkACL } from '@jsb188/mday/utils/organization.ts';
|
|
25
|
-
import {
|
|
26
|
-
ContentGate,
|
|
27
|
-
type SetFloatingMessage,
|
|
28
|
-
} from '@jsb188/react-web/modules/layout/MainLayout';
|
|
29
|
-
import {
|
|
30
|
-
EditableTable,
|
|
31
|
-
type EditableTableColumn,
|
|
32
|
-
getEditableTableActionColumn,
|
|
33
|
-
getEditableTablePopOverName,
|
|
34
|
-
getEditableTableRowKeyFromPopOverName,
|
|
35
|
-
useEditableTableState,
|
|
36
|
-
} from '@jsb188/react-web/modules/TableList';
|
|
37
|
-
import type { ToolbarItemObj } from '@jsb188/react-web/modules/Toolbar';
|
|
38
|
-
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
39
|
-
import { PillButton } from '@jsb188/react-web/ui/Button';
|
|
40
|
-
import {
|
|
41
|
-
useOpenModalPopUp,
|
|
42
|
-
useOpenModalScreen,
|
|
43
|
-
usePopOver,
|
|
44
|
-
} from '@jsb188/react/states';
|
|
45
|
-
import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
|
|
46
|
-
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
47
|
-
import { useNavigate } from 'react-router';
|
|
48
|
-
import { getGridsToolbarState } from './Grids.tsx';
|
|
49
|
-
|
|
50
|
-
const FILE_CONSTANTS = {
|
|
51
|
-
contentPaddingClassName: COMMON_CLASSNAMES.contentXPadding,
|
|
52
|
-
folderParamName: 'f',
|
|
53
|
-
gridLayoutStyle: `minmax(240px, 1.6fr) 170px 150px minmax(200px, 1fr) ${END_BUTTON_WIDTH}`,
|
|
54
|
-
rowPopOverNamePrefix: 'agent_docs_row:',
|
|
55
|
-
} as const;
|
|
56
|
-
|
|
57
|
-
const AGENT_DOCS_TABLE_HEADERS = [
|
|
58
|
-
{ text: i18n.t('form.title') },
|
|
59
|
-
{ text: i18n.t('agentDoc.folder') },
|
|
60
|
-
{ text: i18n.t('agentDoc.last_edited') },
|
|
61
|
-
{ text: i18n.t('agentDoc.ai_status') },
|
|
62
|
-
{ text: '' },
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Types
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
type AgentDocBadgeObj = {
|
|
70
|
-
className?: string;
|
|
71
|
-
text: string;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
type AgentDocsTableItem = {
|
|
75
|
-
badges: AgentDocBadgeObj[];
|
|
76
|
-
folderId: string;
|
|
77
|
-
folderName: string;
|
|
78
|
-
lastEditedText: string;
|
|
79
|
-
title: string;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// The agent docs table has no inline editors; only the actions column is used
|
|
83
|
-
type AgentDocsDraftValues = Record<string, never>;
|
|
84
|
-
|
|
85
|
-
interface AgentDocsModuleProps {
|
|
86
|
-
contentClassName?: string;
|
|
87
|
-
// Raw folder filter value from the URL; validated against loaded folders
|
|
88
|
-
folderId?: string | null;
|
|
89
|
-
// Path that clears the folder filter (used after deleting the active folder)
|
|
90
|
-
folderClearTo?: string | null;
|
|
91
|
-
notReadyClassName?: string;
|
|
92
|
-
organizationId: string;
|
|
93
|
-
setFloatingMessage?: SetFloatingMessage;
|
|
94
|
-
sort: GridItemSortEnum;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/*
|
|
98
|
-
* Return the current agent docs folder filter value from search params.
|
|
99
|
-
*/
|
|
100
|
-
export function getAgentDocsFolderFilterValue(searchParams: URLSearchParams) {
|
|
101
|
-
return searchParams.get(FILE_CONSTANTS.folderParamName) || '';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/*
|
|
105
|
-
* Build an agent docs path with the selected folder filter search param.
|
|
106
|
-
*/
|
|
107
|
-
function createAgentDocsFolderPath(
|
|
108
|
-
pathname: string,
|
|
109
|
-
searchParams: URLSearchParams,
|
|
110
|
-
folderId: string,
|
|
111
|
-
) {
|
|
112
|
-
const nextSearchParams = new URLSearchParams(searchParams);
|
|
113
|
-
|
|
114
|
-
if (folderId) {
|
|
115
|
-
nextSearchParams.set(FILE_CONSTANTS.folderParamName, folderId);
|
|
116
|
-
} else {
|
|
117
|
-
nextSearchParams.delete(FILE_CONSTANTS.folderParamName);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const searchText = nextSearchParams.toString();
|
|
121
|
-
|
|
122
|
-
return searchText ? `${pathname}?${searchText}` : pathname;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/*
|
|
126
|
-
* Build the toolbar filter item that scopes the agent docs list to one folder.
|
|
127
|
-
*/
|
|
128
|
-
function getAgentDocsFolderToolbarItem(p: {
|
|
129
|
-
folders: AgentDocFolderGQL[] | null;
|
|
130
|
-
pathname: string;
|
|
131
|
-
searchParams: URLSearchParams;
|
|
132
|
-
}): ToolbarItemObj {
|
|
133
|
-
const { folders, pathname, searchParams } = p;
|
|
134
|
-
const folderId = getAgentDocsFolderFilterValue(searchParams);
|
|
135
|
-
const activeFolder =
|
|
136
|
-
folders?.find((folder) => String(folder.id) === folderId) || null;
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
id: 'agent_docs_folder',
|
|
140
|
-
text: activeFolder?.name || i18n.t('agentDoc.all_docs'),
|
|
141
|
-
hasValue: !!activeFolder,
|
|
142
|
-
popOverClassName: 'min_w_200',
|
|
143
|
-
initialState: activeFolder ? folderId : '',
|
|
144
|
-
disablePopOverButton: true,
|
|
145
|
-
clearTo: activeFolder
|
|
146
|
-
? createAgentDocsFolderPath(pathname, searchParams, '')
|
|
147
|
-
: null,
|
|
148
|
-
options: [
|
|
149
|
-
{
|
|
150
|
-
__type: 'LIST_SUBTITLE',
|
|
151
|
-
text: i18n.t('agentDoc.folders'),
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
__type: 'SINGLE_OPTION_LIST_ITEM',
|
|
155
|
-
value: '',
|
|
156
|
-
text: i18n.t('agentDoc.all_docs'),
|
|
157
|
-
},
|
|
158
|
-
...(folders || []).map((folder) => ({
|
|
159
|
-
__type: 'SINGLE_OPTION_LIST_ITEM' as const,
|
|
160
|
-
value: String(folder.id),
|
|
161
|
-
text: folder.name || '',
|
|
162
|
-
})),
|
|
163
|
-
],
|
|
164
|
-
getItemTo: (nextFolderId) =>
|
|
165
|
-
createAgentDocsFolderPath(
|
|
166
|
-
pathname,
|
|
167
|
-
searchParams,
|
|
168
|
-
String(nextFolderId || ''),
|
|
169
|
-
),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/*
|
|
174
|
-
* Return sort/folder state and toolbar items for the agent docs surface.
|
|
175
|
-
* Reuses the grids sort toolbar so both list surfaces share the same URL
|
|
176
|
-
* sort contract.
|
|
177
|
-
*/
|
|
178
|
-
export function getAgentDocsToolbarState(p: {
|
|
179
|
-
folders: AgentDocFolderGQL[] | null;
|
|
180
|
-
pathname: string;
|
|
181
|
-
searchParams: URLSearchParams;
|
|
182
|
-
}) {
|
|
183
|
-
const { folders, pathname, searchParams } = p;
|
|
184
|
-
const { sortQueryValue, toolbarOptions } = getGridsToolbarState({
|
|
185
|
-
pathname,
|
|
186
|
-
searchParams,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
folderClearTo: createAgentDocsFolderPath(pathname, searchParams, ''),
|
|
191
|
-
folderId: getAgentDocsFolderFilterValue(searchParams),
|
|
192
|
-
sortQueryValue,
|
|
193
|
-
toolbarOptions: [
|
|
194
|
-
getAgentDocsFolderToolbarItem({ folders, pathname, searchParams }),
|
|
195
|
-
...toolbarOptions,
|
|
196
|
-
],
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/*
|
|
201
|
-
* Return the row key encoded in an agent docs row popover option name.
|
|
202
|
-
*/
|
|
203
|
-
function getAgentDocRowKeyFromPopOverName(name?: string | null) {
|
|
204
|
-
return getEditableTableRowKeyFromPopOverName(
|
|
205
|
-
FILE_CONSTANTS.rowPopOverNamePrefix,
|
|
206
|
-
name,
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/*
|
|
211
|
-
* Return the AI badges shown for one agent doc row.
|
|
212
|
-
*/
|
|
213
|
-
function getAgentDocBadges(
|
|
214
|
-
settings?: AgentDocSettingsObj | null,
|
|
215
|
-
): AgentDocBadgeObj[] {
|
|
216
|
-
const badges: AgentDocBadgeObj[] = [];
|
|
217
|
-
|
|
218
|
-
if (settings?.aiCannotRead) {
|
|
219
|
-
badges.push({ text: i18n.t('agentDoc.badge_ai_hidden') });
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (settings?.aiCannotEdit && !settings?.aiCannotRead) {
|
|
223
|
-
badges.push({ text: i18n.t('agentDoc.badge_ai_locked') });
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (settings?.pinned) {
|
|
227
|
-
badges.push({ text: i18n.t('agentDoc.badge_pinned') });
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (isAgentDocStale(settings)) {
|
|
231
|
-
badges.push({
|
|
232
|
-
text: i18n.t('agentDoc.badge_stale'),
|
|
233
|
-
className: 'cl_err',
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return badges;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/*
|
|
241
|
-
* Build the popover menu options for one agent docs table row.
|
|
242
|
-
*/
|
|
243
|
-
function getAgentDocRowEditOptions(p: {
|
|
244
|
-
canEdit: boolean;
|
|
245
|
-
currentFolderId: string;
|
|
246
|
-
folders: AgentDocFolderGQL[];
|
|
247
|
-
rowKey: string;
|
|
248
|
-
}): POListIfaceItem[] {
|
|
249
|
-
const { canEdit, currentFolderId, folders, rowKey } = p;
|
|
250
|
-
const optionName = getEditableTablePopOverName(
|
|
251
|
-
FILE_CONSTANTS.rowPopOverNamePrefix,
|
|
252
|
-
rowKey,
|
|
253
|
-
);
|
|
254
|
-
const options: POListIfaceItem[] = [
|
|
255
|
-
{
|
|
256
|
-
__type: 'LIST_ITEM',
|
|
257
|
-
name: optionName,
|
|
258
|
-
iconName: COMMON_ICON_NAMES.open_external_link,
|
|
259
|
-
text: i18n.t('app.open_in_new_tab'),
|
|
260
|
-
value: 'open_new_tab',
|
|
261
|
-
},
|
|
262
|
-
];
|
|
263
|
-
|
|
264
|
-
if (!canEdit) {
|
|
265
|
-
return options;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
options.push(
|
|
269
|
-
{
|
|
270
|
-
__type: 'LIST_ITEM',
|
|
271
|
-
name: optionName,
|
|
272
|
-
iconName: COMMON_ICON_NAMES.ai_avatar,
|
|
273
|
-
text: i18n.t('agentDoc.ai_settings'),
|
|
274
|
-
value: 'ai_settings',
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
__type: 'LIST_ITEM',
|
|
278
|
-
name: optionName,
|
|
279
|
-
iconName: COMMON_ICON_NAMES.lock,
|
|
280
|
-
text: i18n.t('agentDoc.access_settings'),
|
|
281
|
-
value: 'access_settings',
|
|
282
|
-
},
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
// Folder targets exclude the row's current folder; a doc already inside a
|
|
286
|
-
// folder can always be moved back out
|
|
287
|
-
const folderTargets = [
|
|
288
|
-
...(currentFolderId
|
|
289
|
-
? [{ id: '', name: i18n.t('agentDoc.no_folder') }]
|
|
290
|
-
: []),
|
|
291
|
-
...folders.filter((folder) => String(folder.id) !== currentFolderId),
|
|
292
|
-
];
|
|
293
|
-
|
|
294
|
-
if (folderTargets.length) {
|
|
295
|
-
options.push({
|
|
296
|
-
__type: 'LIST_SUBTITLE',
|
|
297
|
-
text: i18n.t('agentDoc.move_to_folder'),
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
for (const folder of folderTargets) {
|
|
301
|
-
options.push({
|
|
302
|
-
__type: 'LIST_ITEM',
|
|
303
|
-
name: optionName,
|
|
304
|
-
iconName: 'folder-empty',
|
|
305
|
-
text: folder.name || '',
|
|
306
|
-
value: `move_folder:${folder.id || ''}`,
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
options.push({
|
|
312
|
-
__type: 'LIST_ITEM',
|
|
313
|
-
name: optionName,
|
|
314
|
-
iconName: COMMON_ICON_NAMES.delete,
|
|
315
|
-
text: i18n.t('agentDoc.delete_doc'),
|
|
316
|
-
value: 'delete',
|
|
317
|
-
className: 'cl_err_hv',
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
return options;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/*
|
|
324
|
-
* Build an absolute URL for one agent doc route path.
|
|
325
|
-
*/
|
|
326
|
-
function getAgentDocRouteUrl(agentDocId: string) {
|
|
327
|
-
return new URL(
|
|
328
|
-
`/app/a/${agentDocId}`,
|
|
329
|
-
globalThis.location?.origin || 'http://localhost',
|
|
330
|
-
).toString();
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/*
|
|
334
|
-
* Keep the last fully loaded agent docs list available while a replacement
|
|
335
|
-
* fetch (sort/folder change) is in flight.
|
|
336
|
-
*/
|
|
337
|
-
function useLastReadyAgentDocs(agentDocs?: AgentDocGQL[] | null) {
|
|
338
|
-
const readyDocsRef = useRef<AgentDocGQL[] | null>(null);
|
|
339
|
-
|
|
340
|
-
useEffect(() => {
|
|
341
|
-
if (agentDocs) {
|
|
342
|
-
readyDocsRef.current = agentDocs;
|
|
343
|
-
}
|
|
344
|
-
}, [agentDocs]);
|
|
345
|
-
|
|
346
|
-
return readyDocsRef.current;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/*
|
|
350
|
-
* Show the app refresh prompt when the agent docs list queries receive a
|
|
351
|
-
* RESET_ONLY emit from another session.
|
|
352
|
-
*/
|
|
353
|
-
function useAgentDocsResetOnlyFloatingMessage(
|
|
354
|
-
resetOnlyTime: string,
|
|
355
|
-
setFloatingMessage?: SetFloatingMessage,
|
|
356
|
-
) {
|
|
357
|
-
const lastUpdateTime = useRef(resetOnlyTime);
|
|
358
|
-
|
|
359
|
-
useEffect(() => {
|
|
360
|
-
if (!resetOnlyTime || !setFloatingMessage) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (resetOnlyTime !== lastUpdateTime.current) {
|
|
365
|
-
setFloatingMessage({
|
|
366
|
-
type: 'REFRESH',
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
lastUpdateTime.current = resetOnlyTime;
|
|
371
|
-
}, [resetOnlyTime, setFloatingMessage]);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/*
|
|
375
|
-
* Fetch agent docs + folders and render the agent docs list surface: the
|
|
376
|
-
* folder/create action row, the docs table with per-row action popovers, and
|
|
377
|
-
* the folder management pop-ups.
|
|
378
|
-
*/
|
|
379
|
-
export function AgentDocsModule(p: AgentDocsModuleProps) {
|
|
380
|
-
const {
|
|
381
|
-
contentClassName,
|
|
382
|
-
folderId,
|
|
383
|
-
folderClearTo,
|
|
384
|
-
notReadyClassName,
|
|
385
|
-
organizationId,
|
|
386
|
-
setFloatingMessage,
|
|
387
|
-
sort,
|
|
388
|
-
} = p;
|
|
389
|
-
const navigate = useNavigate();
|
|
390
|
-
const openModalPopUp = useOpenModalPopUp();
|
|
391
|
-
const openModalScreen = useOpenModalScreen();
|
|
392
|
-
const { closePopOver } = usePopOver();
|
|
393
|
-
const { organizationRelationship } =
|
|
394
|
-
useOrgRelFromMyOrganizations(organizationId);
|
|
395
|
-
const canEdit = !!checkACL(organizationRelationship, 'agent_docs_edit');
|
|
396
|
-
const timeZone =
|
|
397
|
-
organizationRelationship?.organization?.settings?.timeZone || null;
|
|
398
|
-
const {
|
|
399
|
-
agentDocFolders,
|
|
400
|
-
refetch: refetchAgentDocFolders,
|
|
401
|
-
resetOnlyTime: foldersResetOnlyTime,
|
|
402
|
-
} = useAgentDocFolders(organizationId);
|
|
403
|
-
// The URL folder value only filters once it matches a loaded folder, so a
|
|
404
|
-
// stale link (deleted folder) degrades to the unfiltered list instead of a
|
|
405
|
-
// persistent server error
|
|
406
|
-
const activeFolder = useMemo(
|
|
407
|
-
() =>
|
|
408
|
-
(agentDocFolders as AgentDocFolderGQL[] | null)?.find(
|
|
409
|
-
(folder) => String(folder.id) === folderId,
|
|
410
|
-
) || null,
|
|
411
|
-
[agentDocFolders, folderId],
|
|
412
|
-
);
|
|
413
|
-
const activeFolderId = activeFolder ? String(activeFolder.id) : null;
|
|
414
|
-
const docsVariables = useMemo(
|
|
415
|
-
() => ({
|
|
416
|
-
organizationId,
|
|
417
|
-
folderId: activeFolderId,
|
|
418
|
-
sort,
|
|
419
|
-
}),
|
|
420
|
-
[activeFolderId, organizationId, sort],
|
|
421
|
-
);
|
|
422
|
-
const {
|
|
423
|
-
agentDocs,
|
|
424
|
-
error,
|
|
425
|
-
loading,
|
|
426
|
-
refetch: refetchAgentDocs,
|
|
427
|
-
resetOnlyTime: docsResetOnlyTime,
|
|
428
|
-
} = useAgentDocs(docsVariables);
|
|
429
|
-
const lastReadyAgentDocs = useLastReadyAgentDocs(agentDocs);
|
|
430
|
-
const showingLastReadyDocs = !agentDocs && !!lastReadyAgentDocs && loading;
|
|
431
|
-
const displayAgentDocs: AgentDocGQL[] | null =
|
|
432
|
-
agentDocs || lastReadyAgentDocs;
|
|
433
|
-
const resetOnlyTime = [docsResetOnlyTime, foldersResetOnlyTime]
|
|
434
|
-
.filter(Boolean)
|
|
435
|
-
.join('|');
|
|
436
|
-
const { createAgentDoc, saving: creatingAgentDoc } = useCreateAgentDoc(
|
|
437
|
-
{
|
|
438
|
-
onCompleted: (data: any) => {
|
|
439
|
-
const agentDocId = String(data?.createAgentDoc || '');
|
|
440
|
-
if (agentDocId) {
|
|
441
|
-
navigate(`/app/a/${agentDocId}`);
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
},
|
|
445
|
-
openModalPopUp,
|
|
446
|
-
);
|
|
447
|
-
const { updateAgentDoc } = useUpdateAgentDoc({}, openModalPopUp);
|
|
448
|
-
const agentDocById = useMemo(() => {
|
|
449
|
-
const docById = new Map<string, AgentDocGQL>();
|
|
450
|
-
for (const agentDoc of displayAgentDocs || []) {
|
|
451
|
-
if (agentDoc?.id) {
|
|
452
|
-
docById.set(String(agentDoc.id), agentDoc);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return docById;
|
|
456
|
-
}, [displayAgentDocs]);
|
|
457
|
-
const closePopOverRef = useRef(closePopOver);
|
|
458
|
-
closePopOverRef.current = closePopOver;
|
|
459
|
-
|
|
460
|
-
useAgentDocsResetOnlyFloatingMessage(resetOnlyTime, setFloatingMessage);
|
|
461
|
-
|
|
462
|
-
/*
|
|
463
|
-
* Close the row popover when this page unmounts.
|
|
464
|
-
*/
|
|
465
|
-
useEffect(() => {
|
|
466
|
-
return () => {
|
|
467
|
-
closePopOverRef.current();
|
|
468
|
-
};
|
|
469
|
-
}, []);
|
|
470
|
-
|
|
471
|
-
useEditableTableState<AgentDocsDraftValues>({
|
|
472
|
-
getRowKeyFromPopOverName: getAgentDocRowKeyFromPopOverName,
|
|
473
|
-
onPopOverAction: ({ rowKey, value }) => {
|
|
474
|
-
const agentDoc = agentDocById.get(rowKey);
|
|
475
|
-
const valueText = String(value || '');
|
|
476
|
-
|
|
477
|
-
if (!agentDoc) {
|
|
478
|
-
return false;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
if (valueText === 'open_new_tab') {
|
|
482
|
-
globalThis.window?.open(
|
|
483
|
-
getAgentDocRouteUrl(rowKey),
|
|
484
|
-
'_blank',
|
|
485
|
-
'noopener,noreferrer',
|
|
486
|
-
);
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (valueText === 'ai_settings') {
|
|
491
|
-
openModalScreen({
|
|
492
|
-
name: 'AGENT_DOC_AI_SETTINGS',
|
|
493
|
-
props: {
|
|
494
|
-
organizationId,
|
|
495
|
-
agentDocId: rowKey,
|
|
496
|
-
settings: agentDoc.settings || null,
|
|
497
|
-
},
|
|
498
|
-
});
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
if (valueText === 'access_settings') {
|
|
503
|
-
// No access/canEditAccess props: the list selection is content-free,
|
|
504
|
-
// so the modal fetches the full agent doc itself
|
|
505
|
-
openModalScreen({
|
|
506
|
-
name: 'AGENT_DOC_ACCESS_SETTINGS',
|
|
507
|
-
props: {
|
|
508
|
-
organizationId,
|
|
509
|
-
agentDocId: rowKey,
|
|
510
|
-
},
|
|
511
|
-
});
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
if (valueText === 'delete') {
|
|
516
|
-
openModalPopUp({
|
|
517
|
-
name: 'DELETE_AGENT_DOC',
|
|
518
|
-
preset: 'DELETE_AGENT_DOC',
|
|
519
|
-
props: {
|
|
520
|
-
organizationId,
|
|
521
|
-
agentDocId: rowKey,
|
|
522
|
-
itemTitle: agentDoc.title || '',
|
|
523
|
-
},
|
|
524
|
-
});
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
if (valueText.startsWith('move_folder:')) {
|
|
529
|
-
const targetFolderId = valueText.slice('move_folder:'.length) || null;
|
|
530
|
-
void updateAgentDoc({
|
|
531
|
-
variables: {
|
|
532
|
-
organizationId,
|
|
533
|
-
agentDocId: rowKey,
|
|
534
|
-
folderId: targetFolderId,
|
|
535
|
-
},
|
|
536
|
-
}).then((result: any) => {
|
|
537
|
-
// A fragment update cannot remove the row from a folder-filtered
|
|
538
|
-
// page, so refetch the filtered list once the move confirmed
|
|
539
|
-
if (activeFolderId && result?.data?.updateAgentDoc?.id) {
|
|
540
|
-
void refetchAgentDocs();
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
return false;
|
|
547
|
-
},
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
const folderNameById = useMemo(() => {
|
|
551
|
-
const nameById = new Map<string, string>();
|
|
552
|
-
for (const folder of (agentDocFolders as AgentDocFolderGQL[] | null) ||
|
|
553
|
-
[]) {
|
|
554
|
-
if (folder?.id) {
|
|
555
|
-
nameById.set(String(folder.id), folder.name || '');
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
return nameById;
|
|
559
|
-
}, [agentDocFolders]);
|
|
560
|
-
|
|
561
|
-
const columns = useMemo<
|
|
562
|
-
EditableTableColumn<AgentDocsTableItem, AgentDocsDraftValues>[]
|
|
563
|
-
>(
|
|
564
|
-
() => [
|
|
565
|
-
{
|
|
566
|
-
display: ({ item }) => <span className="ft_medium">{item.title}</span>,
|
|
567
|
-
},
|
|
568
|
-
{
|
|
569
|
-
display: ({ item }) =>
|
|
570
|
-
item.folderName || (
|
|
571
|
-
<span className="cl_lt">{i18n.t('agentDoc.no_folder')}</span>
|
|
572
|
-
),
|
|
573
|
-
},
|
|
574
|
-
{
|
|
575
|
-
display: ({ item }) => item.lastEditedText,
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
display: ({ item }) =>
|
|
579
|
-
!item.badges.length ? null : (
|
|
580
|
-
<div className="h_item gap_4 wrap">
|
|
581
|
-
{item.badges.map((badge) => (
|
|
582
|
-
<span
|
|
583
|
-
key={badge.text}
|
|
584
|
-
className={cn(
|
|
585
|
-
'r_sm bd_1 bd_lt px_6 pt_2 pb_1 ft_xs nowrap',
|
|
586
|
-
badge.className || 'cl_md',
|
|
587
|
-
)}
|
|
588
|
-
>
|
|
589
|
-
{badge.text}
|
|
590
|
-
</span>
|
|
591
|
-
))}
|
|
592
|
-
</div>
|
|
593
|
-
),
|
|
594
|
-
},
|
|
595
|
-
getEditableTableActionColumn(({ item, rowKey }) => ({
|
|
596
|
-
allowEdit: true,
|
|
597
|
-
editOptions: getAgentDocRowEditOptions({
|
|
598
|
-
canEdit,
|
|
599
|
-
currentFolderId: item.folderId,
|
|
600
|
-
folders: (agentDocFolders as AgentDocFolderGQL[] | null) || [],
|
|
601
|
-
rowKey,
|
|
602
|
-
}),
|
|
603
|
-
})),
|
|
604
|
-
],
|
|
605
|
-
[agentDocFolders, canEdit],
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
const rows = useMemo(() => {
|
|
609
|
-
return (displayAgentDocs || []).flatMap((agentDoc) => {
|
|
610
|
-
if (!agentDoc?.id) {
|
|
611
|
-
return [];
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
const rowKey = String(agentDoc.id);
|
|
615
|
-
|
|
616
|
-
return [
|
|
617
|
-
{
|
|
618
|
-
__deleted: agentDoc.__deleted,
|
|
619
|
-
className: 'pointer',
|
|
620
|
-
draftValues: {} as AgentDocsDraftValues,
|
|
621
|
-
item: {
|
|
622
|
-
badges: getAgentDocBadges(agentDoc.settings),
|
|
623
|
-
folderId: agentDoc.folderId ? String(agentDoc.folderId) : '',
|
|
624
|
-
folderName: agentDoc.folderId
|
|
625
|
-
? folderNameById.get(String(agentDoc.folderId)) || ''
|
|
626
|
-
: '',
|
|
627
|
-
lastEditedText: agentDoc.updatedAt
|
|
628
|
-
? getReadableCalDate(new Date(agentDoc.updatedAt), timeZone) || ''
|
|
629
|
-
: '',
|
|
630
|
-
title: agentDoc.title || i18n.t('agentDoc.untitled'),
|
|
631
|
-
},
|
|
632
|
-
onClick: () => navigate(`/app/a/${rowKey}`),
|
|
633
|
-
rowKey,
|
|
634
|
-
},
|
|
635
|
-
];
|
|
636
|
-
});
|
|
637
|
-
}, [displayAgentDocs, folderNameById, navigate, timeZone]);
|
|
638
|
-
|
|
639
|
-
/*
|
|
640
|
-
* Create one agent doc (inside the active folder when filtered) and open it.
|
|
641
|
-
*/
|
|
642
|
-
const createNewAgentDoc = useCallback(() => {
|
|
643
|
-
if (creatingAgentDoc) {
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
void createAgentDoc({
|
|
648
|
-
variables: {
|
|
649
|
-
organizationId,
|
|
650
|
-
...(activeFolderId ? { folderId: activeFolderId } : {}),
|
|
651
|
-
},
|
|
652
|
-
});
|
|
653
|
-
}, [activeFolderId, createAgentDoc, creatingAgentDoc, organizationId]);
|
|
654
|
-
|
|
655
|
-
/*
|
|
656
|
-
* Open the create-folder pop-up; the issuer refetches folders on save.
|
|
657
|
-
*/
|
|
658
|
-
const openCreateFolder = useCallback(() => {
|
|
659
|
-
openModalPopUp({
|
|
660
|
-
name: 'CREATE_AGENT_DOC_FOLDER',
|
|
661
|
-
preset: 'CREATE_AGENT_DOC_FOLDER',
|
|
662
|
-
props: {
|
|
663
|
-
organizationId,
|
|
664
|
-
onSaved: () => refetchAgentDocFolders(),
|
|
665
|
-
},
|
|
666
|
-
});
|
|
667
|
-
}, [openModalPopUp, organizationId, refetchAgentDocFolders]);
|
|
668
|
-
|
|
669
|
-
/*
|
|
670
|
-
* Open the rename pop-up for the folder the list is filtered to.
|
|
671
|
-
*/
|
|
672
|
-
const openRenameFolder = useCallback(() => {
|
|
673
|
-
if (!activeFolder) {
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
openModalPopUp({
|
|
678
|
-
name: 'RENAME_AGENT_DOC_FOLDER',
|
|
679
|
-
preset: 'RENAME_AGENT_DOC_FOLDER',
|
|
680
|
-
props: {
|
|
681
|
-
organizationId,
|
|
682
|
-
folderId: String(activeFolder.id),
|
|
683
|
-
folderName: activeFolder.name || '',
|
|
684
|
-
onSaved: () => refetchAgentDocFolders(),
|
|
685
|
-
},
|
|
686
|
-
});
|
|
687
|
-
}, [activeFolder, openModalPopUp, organizationId, refetchAgentDocFolders]);
|
|
688
|
-
|
|
689
|
-
/*
|
|
690
|
-
* Open the delete pop-up for the folder the list is filtered to. Deleting
|
|
691
|
-
* clears the filter and refetches: the server moved the docs out of the
|
|
692
|
-
* folder, so both lists changed.
|
|
693
|
-
*/
|
|
694
|
-
const openDeleteFolder = useCallback(() => {
|
|
695
|
-
if (!activeFolder) {
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
openModalPopUp({
|
|
700
|
-
name: 'DELETE_AGENT_DOC_FOLDER',
|
|
701
|
-
preset: 'DELETE_AGENT_DOC_FOLDER',
|
|
702
|
-
props: {
|
|
703
|
-
organizationId,
|
|
704
|
-
folderId: String(activeFolder.id),
|
|
705
|
-
onDeleted: () => {
|
|
706
|
-
refetchAgentDocFolders();
|
|
707
|
-
refetchAgentDocs();
|
|
708
|
-
|
|
709
|
-
if (folderClearTo) {
|
|
710
|
-
navigate(folderClearTo);
|
|
711
|
-
}
|
|
712
|
-
},
|
|
713
|
-
},
|
|
714
|
-
});
|
|
715
|
-
}, [
|
|
716
|
-
activeFolder,
|
|
717
|
-
folderClearTo,
|
|
718
|
-
navigate,
|
|
719
|
-
openModalPopUp,
|
|
720
|
-
organizationId,
|
|
721
|
-
refetchAgentDocFolders,
|
|
722
|
-
refetchAgentDocs,
|
|
723
|
-
]);
|
|
724
|
-
|
|
725
|
-
return (
|
|
726
|
-
<ContentGate
|
|
727
|
-
showLoadingIfNotReady
|
|
728
|
-
notReady={!displayAgentDocs}
|
|
729
|
-
loading={loading}
|
|
730
|
-
error={error || null}
|
|
731
|
-
notReadyClassName={notReadyClassName ?? 'fs v_center'}
|
|
732
|
-
onRefetch={refetchAgentDocs}
|
|
733
|
-
>
|
|
734
|
-
<div
|
|
735
|
-
className={cn(
|
|
736
|
-
'rel pt_md pb_md',
|
|
737
|
-
FILE_CONSTANTS.contentPaddingClassName,
|
|
738
|
-
showingLastReadyDocs && 'anim_data_loading',
|
|
739
|
-
contentClassName,
|
|
740
|
-
)}
|
|
741
|
-
>
|
|
742
|
-
<div className="h_spread gap_sm mb_md">
|
|
743
|
-
<p className="ft_sm cl_md">{i18n.t('agentDoc.agent_docs_desc')}</p>
|
|
744
|
-
|
|
745
|
-
{canEdit && (
|
|
746
|
-
<div className="h_item gap_5 no_shrink">
|
|
747
|
-
{!!activeFolder && (
|
|
748
|
-
<>
|
|
749
|
-
<PillButton
|
|
750
|
-
preset="sm"
|
|
751
|
-
designClassName="bg bd_1 h_32 gap_1"
|
|
752
|
-
leftIconName="folder-empty"
|
|
753
|
-
leftIconClassName="ic_sm"
|
|
754
|
-
text={i18n.t('agentDoc.rename_folder')}
|
|
755
|
-
onClick={openRenameFolder}
|
|
756
|
-
/>
|
|
757
|
-
|
|
758
|
-
<PillButton
|
|
759
|
-
preset="sm"
|
|
760
|
-
designClassName="bg bd_1 h_32 gap_1"
|
|
761
|
-
leftIconName={COMMON_ICON_NAMES.delete}
|
|
762
|
-
leftIconClassName="ic_sm"
|
|
763
|
-
text={i18n.t('agentDoc.delete_folder')}
|
|
764
|
-
onClick={openDeleteFolder}
|
|
765
|
-
/>
|
|
766
|
-
</>
|
|
767
|
-
)}
|
|
768
|
-
|
|
769
|
-
<PillButton
|
|
770
|
-
preset="sm"
|
|
771
|
-
designClassName="bg bd_1 h_32 gap_1"
|
|
772
|
-
leftIconName="folder-empty"
|
|
773
|
-
leftIconClassName="ic_sm"
|
|
774
|
-
text={i18n.t('agentDoc.new_folder')}
|
|
775
|
-
onClick={openCreateFolder}
|
|
776
|
-
/>
|
|
777
|
-
|
|
778
|
-
<PillButton
|
|
779
|
-
preset="sm"
|
|
780
|
-
designClassName="bg_primary_md h_32 gap_1"
|
|
781
|
-
leftIconName={COMMON_ICON_NAMES.plus}
|
|
782
|
-
leftIconClassName="ic_sm"
|
|
783
|
-
text={i18n.t('agentDoc.new_doc')}
|
|
784
|
-
onClick={createNewAgentDoc}
|
|
785
|
-
/>
|
|
786
|
-
</div>
|
|
787
|
-
)}
|
|
788
|
-
</div>
|
|
789
|
-
|
|
790
|
-
<EditableTable
|
|
791
|
-
columns={columns}
|
|
792
|
-
emptyStateMessage={i18n.t('agentDoc.agent_docs_empty_msg')}
|
|
793
|
-
gridLayoutStyle={FILE_CONSTANTS.gridLayoutStyle}
|
|
794
|
-
headers={AGENT_DOCS_TABLE_HEADERS}
|
|
795
|
-
rows={rows}
|
|
796
|
-
/>
|
|
797
|
-
</div>
|
|
798
|
-
</ContentGate>
|
|
799
|
-
);
|
|
800
|
-
}
|