@jsb188/graphql 1.1.12 → 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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/audience.d.ts +14 -152
  3. package/cache/config.ts +35 -32
  4. package/cache/index.helpers.ts +1 -1
  5. package/cache/index.ts +73 -44
  6. package/cache/mounted-queries.ts +33 -0
  7. package/cache/persist.ts +10 -4
  8. package/cache/realtime-fence.ts +47 -0
  9. package/cache/realtime-live.ts +17 -0
  10. package/client/draft-persistence.ts +10 -39
  11. package/client/index.ts +2 -1
  12. package/client/request.ts +9 -34
  13. package/client/storage-asset.ts +58 -0
  14. package/gql/fragments/accountAuthFragments.ts +0 -4
  15. package/gql/fragments/agentNoteFragments.ts +8 -2
  16. package/gql/fragments/aiChatFragments.ts +0 -2
  17. package/gql/fragments/aiChatLinkFragments.ts +8 -0
  18. package/gql/fragments/audienceFragments.ts +1 -66
  19. package/gql/fragments/emailFragments.ts +27 -4
  20. package/gql/fragments/emailOutreachFragments.ts +281 -0
  21. package/gql/fragments/inboundContactFragments.ts +1 -1
  22. package/gql/fragments/libraryFragments.ts +120 -0
  23. package/gql/fragments/organizationFragments.ts +4 -2
  24. package/gql/fragments/scheduleFragments.ts +241 -324
  25. package/gql/fragments/sheetFragments.ts +4 -53
  26. package/gql/fragments/workWaitFragments.ts +13 -0
  27. package/gql/fragments/workflowFragments.ts +20 -4
  28. package/gql/mutations/agentNoteMutations.ts +2 -0
  29. package/gql/mutations/aiChatLinkMutations.ts +13 -0
  30. package/gql/mutations/aiChatMutations.ts +4 -6
  31. package/gql/mutations/audienceMutations.ts +0 -13
  32. package/gql/mutations/authMutations.ts +12 -60
  33. package/gql/mutations/emailMutations.ts +22 -0
  34. package/gql/mutations/emailOutreachMutations.ts +139 -0
  35. package/gql/mutations/index.ts +3 -1
  36. package/gql/mutations/organizationMutations.ts +2 -2
  37. package/gql/mutations/scheduleMutations.ts +61 -787
  38. package/gql/mutations/storageMutations.ts +1 -0
  39. package/gql/mutations/workflowMutations.ts +76 -0
  40. package/gql/queries/agentMemoryQueries.ts +6 -2
  41. package/gql/queries/agentNoteQueries.ts +26 -29
  42. package/gql/queries/aiChatQueries.ts +39 -40
  43. package/gql/queries/audienceQueries.ts +31 -55
  44. package/gql/queries/authQueries.ts +16 -6
  45. package/gql/queries/billingQueries.ts +26 -10
  46. package/gql/queries/dataTableQueries.ts +24 -15
  47. package/gql/queries/emailOutreachQueries.ts +282 -0
  48. package/gql/queries/emailQueries.ts +39 -12
  49. package/gql/queries/emailReplyReportQueries.ts +60 -9
  50. package/gql/queries/fieldDocQueries.ts +36 -14
  51. package/gql/queries/inboundContactQueries.ts +11 -4
  52. package/gql/queries/index.ts +2 -2
  53. package/gql/queries/libraryQueries.ts +112 -0
  54. package/gql/queries/logQueries.ts +31 -12
  55. package/gql/queries/organizationQueries.ts +31 -12
  56. package/gql/queries/qrCodeQueries.ts +11 -4
  57. package/gql/queries/scheduleQueries.ts +252 -505
  58. package/gql/queries/sheetQueries.ts +36 -14
  59. package/gql/queries/storageQueries.ts +11 -4
  60. package/gql/queries/workflowQueries.ts +53 -10
  61. package/gql/reactivity.ts +98 -0
  62. package/gql/recordReads.ts +171 -0
  63. package/hooks/index.ts +79 -52
  64. package/hooks/use-agentNote-mtn.ts +7 -0
  65. package/hooks/use-agentNote-qry.ts +30 -58
  66. package/hooks/use-agentNote-recovery.ts +6 -21
  67. package/hooks/use-aiChat-mtn.ts +9 -4
  68. package/hooks/use-aiChat-qry.ts +28 -7
  69. package/hooks/use-audience-mtn.ts +0 -24
  70. package/hooks/use-audience-qry.helpers.ts +0 -24
  71. package/hooks/use-audience-qry.ts +1 -86
  72. package/hooks/use-dataTable-mtn.ts +3 -3
  73. package/hooks/use-dataTable-qry.ts +7 -2
  74. package/hooks/use-email-mtn.ts +26 -0
  75. package/hooks/use-email-qry.helpers.ts +1 -1
  76. package/hooks/use-email-qry.ts +18 -3
  77. package/hooks/use-emailOutreach-mtn.ts +211 -0
  78. package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
  79. package/hooks/use-emailOutreach-qry.ts +367 -0
  80. package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
  81. package/hooks/use-fieldDoc-qry.ts +1 -1
  82. package/hooks/use-library-qry.ts +233 -0
  83. package/hooks/use-qrCode-qry.ts +1 -1
  84. package/hooks/use-schedule-mtn.ts +10 -300
  85. package/hooks/use-schedule-qry.ts +168 -680
  86. package/hooks/use-schedule-reactive.ts +71 -339
  87. package/hooks/use-sheet-qry.ts +6 -1
  88. package/hooks/use-workflow-mtn.ts +45 -1
  89. package/hooks/use-workflow-qry.ts +22 -2
  90. package/libs/ai-chat-link-events.ts +78 -0
  91. package/libs/data-changes.helpers.ts +161 -0
  92. package/libs/data-changes.ts +382 -0
  93. package/libs/fragment-realtime-sequence.ts +3 -3
  94. package/libs/record-read.ts +327 -0
  95. package/libs/sheet-command-batch.ts +3 -2
  96. package/libs/sheet-realtime-packet.ts +53 -0
  97. package/loaders/emailPreference.ts +18 -24
  98. package/package.json +44 -17
  99. package/schedule.d.ts +267 -874
  100. package/types.d.ts +3 -1
  101. package/cache/index.chat-activity.test.ts +0 -119
  102. package/cache/index.chat.test.ts +0 -92
  103. package/cache/index.regression.test.ts +0 -149
  104. package/cache/index.test.ts +0 -1209
  105. package/deno.lock +0 -187
  106. package/deno.test.json +0 -12
  107. package/gql/fragments/campaignFragments.ts +0 -566
  108. package/gql/mutations/campaignMutations.ts +0 -258
  109. package/gql/queries/appQueries.ts +0 -14
  110. package/gql/queries/campaignQueries.ts +0 -236
  111. package/hooks/index.helpers.test.ts +0 -50
  112. package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
  113. package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
  114. package/hooks/use-app-qry.ts +0 -22
  115. package/hooks/use-audience-qry.helpers.test.ts +0 -80
  116. package/hooks/use-campaign-generation-recovery.ts +0 -53
  117. package/hooks/use-campaign-mtn.ts +0 -436
  118. package/hooks/use-campaign-qry.helpers.ts +0 -40
  119. package/hooks/use-campaign-qry.ts +0 -834
  120. package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
  121. package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
  122. package/hooks/use-publicFormEmail-mtn.ts +0 -27
  123. package/libs/fragment-recovery.test.ts +0 -326
  124. package/libs/fragment-recovery.ts +0 -325
  125. package/libs/orchestrator-realtime.helpers.test.ts +0 -229
  126. package/libs/orchestrator-realtime.helpers.ts +0 -317
  127. package/libs/orchestrator-realtime.ts +0 -433
  128. package/libs/request-cache-regression.test.ts +0 -122
  129. package/libs/request-managed-session.test.ts +0 -574
  130. package/libs/request-no-store.test.ts +0 -419
  131. package/libs/sheet-view-realtime-router.test.ts +0 -214
  132. package/libs/sse-ticket.test.ts +0 -26
  133. package/loaders/campaign.test.ts +0 -186
  134. package/loaders/campaign.ts +0 -110
  135. package/tests/agent-note-detail-cache.test.ts +0 -120
  136. package/tests/agent-note-search.test.ts +0 -444
  137. package/tsconfig.json +0 -13
@@ -1,50 +1,45 @@
1
1
  import { useEffect, useMemo, useRef } from 'react';
2
- import { gql } from 'graphql-tag';
3
- import { FRAGMENT_NAMES, QUERY_NAMES, makeFragmentKey, getFragmentBaseName } from '@jsb188/mday/constants/graphqlReactivity.ts';
2
+ import {
3
+ FRAGMENT_NAMES,
4
+ QUERY_NAMES,
5
+ makeFragmentKey,
6
+ getFragmentBaseName,
7
+ type WSFragmentName,
8
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
4
9
  import { useRealtimeConnectionGenerationValue } from '@jsb188/react/states';
5
10
  import { graphqlRequestNoStore } from '../client/request.ts';
6
11
  import { resetQueryByTarget } from '../cache/index.ts';
12
+ import { scheduleCalendarRevisionQry, scheduleProjectRevisionQry } from '../gql/queries/scheduleQueries.ts';
7
13
  import { useReactiveFragment, useReactiveFragmentMap, useUpdateObservers } from './index.ts';
8
14
  import type * as Schedule from '../schedule.d.ts';
9
15
 
10
- /* Observe one project row using the server's canonical fragment key. */
11
- export function useReactiveScheduleProject(
16
+ // A row the server deleted: a realtime tombstone or a soft-deleted row
17
+ type ScheduleReactiveRow = { __deleted?: boolean; deletedAt?: string | null };
18
+
19
+ /* Observe one row by its canonical fragment key; a deleted row reads as null. */
20
+ function useReactiveScheduleRow<T>(
21
+ fragmentName: WSFragmentName,
12
22
  id: string | null | undefined,
13
- data: Schedule.ScheduleProjectGQL | null,
23
+ data: T | null,
14
24
  queryCount?: number | boolean,
15
- ): Schedule.ScheduleProjectGQL | null {
16
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleProject, id)] : [], queryCount);
25
+ ): T | null {
26
+ const row = useReactiveFragment(data, id ? [makeFragmentKey(fragmentName, id)] : [], queryCount);
17
27
  return row?.__deleted || row?.deletedAt ? null : row;
18
28
  }
19
29
 
20
- /* Observe project rows and remove authoritative deletion tombstones. */
21
- export function useReactiveScheduleProjectMap(
22
- rows: Schedule.ScheduleProjectGQL[] | null,
23
- queryCount?: number | boolean,
24
- ): Schedule.ScheduleProjectGQL[] | null {
25
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleProject), queryCount);
26
- return useMemo(
27
- () =>
28
- live?.filter(
29
- (
30
- row: Schedule.ScheduleProjectGQL & {
31
- __deleted?: boolean;
32
- deletedAt?: string | null;
33
- },
34
- ) => !row.__deleted && !row.deletedAt,
35
- ) ?? null,
36
- [live],
37
- );
30
+ /* Observe rows of one fragment and drop the rows the server deleted. */
31
+ function useReactiveScheduleRows<T>(fragmentName: WSFragmentName, rows: T[] | null, queryCount?: number | boolean): T[] | null {
32
+ const live = useReactiveFragmentMap(rows, getFragmentBaseName(fragmentName), queryCount);
33
+ return useMemo(() => live?.filter((row: T & ScheduleReactiveRow) => !row.__deleted && !row.deletedAt) ?? null, [live]);
38
34
  }
39
35
 
40
- /* Observe one activity row using the server's canonical fragment key. */
41
- export function useReactiveScheduleActivity(
36
+ /* Observe one project row using the server's canonical fragment key. */
37
+ export function useReactiveScheduleProject(
42
38
  id: string | null | undefined,
43
- data: Schedule.ScheduleActivityGQL | null,
39
+ data: Schedule.ScheduleProjectGQL | null,
44
40
  queryCount?: number | boolean,
45
- ): Schedule.ScheduleActivityGQL | null {
46
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleActivity, id)] : [], queryCount);
47
- return row?.__deleted || row?.deletedAt ? null : row;
41
+ ): Schedule.ScheduleProjectGQL | null {
42
+ return useReactiveScheduleRow(FRAGMENT_NAMES.scheduleProject, id, data, queryCount);
48
43
  }
49
44
 
50
45
  /* Observe activity rows and remove authoritative deletion tombstones. */
@@ -52,29 +47,7 @@ export function useReactiveScheduleActivityMap(
52
47
  rows: Schedule.ScheduleActivityGQL[] | null,
53
48
  queryCount?: number | boolean,
54
49
  ): Schedule.ScheduleActivityGQL[] | null {
55
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleActivity), queryCount);
56
- return useMemo(
57
- () =>
58
- live?.filter(
59
- (
60
- row: Schedule.ScheduleActivityGQL & {
61
- __deleted?: boolean;
62
- deletedAt?: string | null;
63
- },
64
- ) => !row.__deleted && !row.deletedAt,
65
- ) ?? null,
66
- [live],
67
- );
68
- }
69
-
70
- /* Observe one relationship row using the server's canonical fragment key. */
71
- export function useReactiveScheduleRelationship(
72
- id: string | null | undefined,
73
- data: Schedule.ScheduleRelationshipGQL | null,
74
- queryCount?: number | boolean,
75
- ): Schedule.ScheduleRelationshipGQL | null {
76
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleRelationship, id)] : [], queryCount);
77
- return row?.__deleted || row?.deletedAt ? null : row;
50
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleActivity, rows, queryCount);
78
51
  }
79
52
 
80
53
  /* Observe relationship rows and remove authoritative deletion tombstones. */
@@ -82,149 +55,48 @@ export function useReactiveScheduleRelationshipMap(
82
55
  rows: Schedule.ScheduleRelationshipGQL[] | null,
83
56
  queryCount?: number | boolean,
84
57
  ): Schedule.ScheduleRelationshipGQL[] | null {
85
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleRelationship), queryCount);
86
- return useMemo(
87
- () =>
88
- live?.filter(
89
- (
90
- row: Schedule.ScheduleRelationshipGQL & {
91
- __deleted?: boolean;
92
- deletedAt?: string | null;
93
- },
94
- ) => !row.__deleted && !row.deletedAt,
95
- ) ?? null,
96
- [live],
97
- );
58
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleRelationship, rows, queryCount);
98
59
  }
99
60
 
100
- /* Observe one projectrun row using the server's canonical fragment key. */
61
+ /* Observe one project run row using the server's canonical fragment key. */
101
62
  export function useReactiveScheduleProjectRun(
102
63
  id: string | null | undefined,
103
64
  data: Schedule.ScheduleProjectRunGQL | null,
104
65
  queryCount?: number | boolean,
105
66
  ): Schedule.ScheduleProjectRunGQL | null {
106
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleRun, id)] : [], queryCount);
107
- return row?.__deleted || row?.deletedAt ? null : row;
67
+ return useReactiveScheduleRow(FRAGMENT_NAMES.scheduleRun, id, data, queryCount);
108
68
  }
109
69
 
110
- /* Observe projectrun rows and remove authoritative deletion tombstones. */
70
+ /* Observe project run rows and remove authoritative deletion tombstones. */
111
71
  export function useReactiveScheduleProjectRunMap(
112
72
  rows: Schedule.ScheduleProjectRunGQL[] | null,
113
73
  queryCount?: number | boolean,
114
74
  ): Schedule.ScheduleProjectRunGQL[] | null {
115
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleRun), queryCount);
116
- return useMemo(
117
- () =>
118
- live?.filter(
119
- (
120
- row: Schedule.ScheduleProjectRunGQL & {
121
- __deleted?: boolean;
122
- deletedAt?: string | null;
123
- },
124
- ) => !row.__deleted && !row.deletedAt,
125
- ) ?? null,
126
- [live],
127
- );
75
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleRun, rows, queryCount);
128
76
  }
129
77
 
130
- /* Observe one occurrence row using the server's canonical fragment key. */
131
- export function useReactiveScheduleOccurrence(
132
- id: string | null | undefined,
133
- data: Schedule.ScheduleOccurrenceGQL | null,
134
- queryCount?: number | boolean,
135
- ): Schedule.ScheduleOccurrenceGQL | null {
136
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleOccurrence, id)] : [], queryCount);
137
- return row?.__deleted || row?.deletedAt ? null : row;
138
- }
139
-
140
- /* Observe occurrence rows and remove authoritative deletion tombstones. */
141
- export function useReactiveScheduleOccurrenceMap(
142
- rows: Schedule.ScheduleOccurrenceGQL[] | null,
143
- queryCount?: number | boolean,
144
- ): Schedule.ScheduleOccurrenceGQL[] | null {
145
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleOccurrence), queryCount);
146
- return useMemo(
147
- () =>
148
- live?.filter(
149
- (
150
- row: Schedule.ScheduleOccurrenceGQL & {
151
- __deleted?: boolean;
152
- deletedAt?: string | null;
153
- },
154
- ) => !row.__deleted && !row.deletedAt,
155
- ) ?? null,
156
- [live],
157
- );
158
- }
159
-
160
- /* Observe one calendar row using the server's canonical fragment key. */
161
- export function useReactiveScheduleCalendar(
162
- id: string | null | undefined,
163
- data: Schedule.ScheduleCalendarGQL | null,
164
- queryCount?: number | boolean,
165
- ): Schedule.ScheduleCalendarGQL | null {
166
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleCalendar, id)] : [], queryCount);
167
- return row?.__deleted || row?.deletedAt ? null : row;
168
- }
169
-
170
- /* Observe calendar rows and remove authoritative deletion tombstones. */
78
+ /* Observe calendar rows and remove deleted calendars. */
171
79
  export function useReactiveScheduleCalendarMap(
172
80
  rows: Schedule.ScheduleCalendarGQL[] | null,
173
81
  queryCount?: number | boolean,
174
82
  ): Schedule.ScheduleCalendarGQL[] | null {
175
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleCalendar), queryCount);
176
- return useMemo(
177
- () =>
178
- live?.filter(
179
- (
180
- row: Schedule.ScheduleCalendarGQL & {
181
- __deleted?: boolean;
182
- deletedAt?: string | null;
183
- },
184
- ) => !row.__deleted && !row.deletedAt,
185
- ) ?? null,
186
- [live],
187
- );
188
- }
189
-
190
- /* Observe one series row using the server's canonical fragment key. */
191
- export function useReactiveScheduleSeries(
192
- id: string | null | undefined,
193
- data: Schedule.ScheduleSeriesGQL | null,
194
- queryCount?: number | boolean,
195
- ): Schedule.ScheduleSeriesGQL | null {
196
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleSeries, id)] : [], queryCount);
197
- return row?.__deleted || row?.deletedAt ? null : row;
83
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleCalendar, rows, queryCount);
198
84
  }
199
85
 
200
- /* Observe series rows and remove authoritative deletion tombstones. */
201
- export function useReactiveScheduleSeriesMap(
202
- rows: Schedule.ScheduleSeriesGQL[] | null,
86
+ /* Observe seat rows and remove deleted drafts; canceled seats stay. */
87
+ export function useReactiveScheduleShiftMap(
88
+ rows: Schedule.ScheduleShiftGQL[] | null,
203
89
  queryCount?: number | boolean,
204
- ): Schedule.ScheduleSeriesGQL[] | null {
205
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleSeries), queryCount);
206
- return useMemo(
207
- () =>
208
- live?.filter(
209
- (
210
- row: Schedule.ScheduleSeriesGQL & {
211
- __deleted?: boolean;
212
- deletedAt?: string | null;
213
- },
214
- ) => !row.__deleted && !row.deletedAt,
215
- ) ?? null,
216
- [live],
217
- );
90
+ ): Schedule.ScheduleShiftGQL[] | null {
91
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleShift, rows, queryCount);
218
92
  }
219
93
 
220
- /* Observe one resource row using the server's canonical fragment key. */
221
- export function useReactiveScheduleResource(
222
- id: string | null | undefined,
223
- data: Schedule.ScheduleResourceGQL | null,
94
+ /* Observe role rows and remove deleted roles; archived roles stay. */
95
+ export function useReactiveScheduleRoleMap(
96
+ rows: Schedule.ScheduleRoleGQL[] | null,
224
97
  queryCount?: number | boolean,
225
- ): Schedule.ScheduleResourceGQL | null {
226
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleResource, id)] : [], queryCount);
227
- return row?.__deleted || row?.deletedAt ? null : row;
98
+ ): Schedule.ScheduleRoleGQL[] | null {
99
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleRole, rows, queryCount);
228
100
  }
229
101
 
230
102
  /* Observe resource rows and remove authoritative deletion tombstones. */
@@ -232,176 +104,45 @@ export function useReactiveScheduleResourceMap(
232
104
  rows: Schedule.ScheduleResourceGQL[] | null,
233
105
  queryCount?: number | boolean,
234
106
  ): Schedule.ScheduleResourceGQL[] | null {
235
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleResource), queryCount);
236
- return useMemo(
237
- () =>
238
- live?.filter(
239
- (
240
- row: Schedule.ScheduleResourceGQL & {
241
- __deleted?: boolean;
242
- deletedAt?: string | null;
243
- },
244
- ) => !row.__deleted && !row.deletedAt,
245
- ) ?? null,
246
- [live],
247
- );
107
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleResource, rows, queryCount);
248
108
  }
249
109
 
250
- /* Observe one workcalendar row using the server's canonical fragment key. */
251
- export function useReactiveScheduleWorkCalendar(
252
- id: string | null | undefined,
253
- data: Schedule.ScheduleWorkCalendarGQL | null,
254
- queryCount?: number | boolean,
255
- ): Schedule.ScheduleWorkCalendarGQL | null {
256
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleWorkCalendar, id)] : [], queryCount);
257
- return row?.__deleted || row?.deletedAt ? null : row;
258
- }
259
-
260
- /* Observe workcalendar rows and remove authoritative deletion tombstones. */
110
+ /* Observe work calendar rows and remove deleted work calendars. */
261
111
  export function useReactiveScheduleWorkCalendarMap(
262
112
  rows: Schedule.ScheduleWorkCalendarGQL[] | null,
263
113
  queryCount?: number | boolean,
264
114
  ): Schedule.ScheduleWorkCalendarGQL[] | null {
265
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleWorkCalendar), queryCount);
266
- return useMemo(
267
- () =>
268
- live?.filter(
269
- (
270
- row: Schedule.ScheduleWorkCalendarGQL & {
271
- __deleted?: boolean;
272
- deletedAt?: string | null;
273
- },
274
- ) => !row.__deleted && !row.deletedAt,
275
- ) ?? null,
276
- [live],
277
- );
278
- }
279
-
280
- /* Observe one request row using the server's canonical fragment key. */
281
- export function useReactiveScheduleRequest(
282
- id: string | null | undefined,
283
- data: Schedule.ScheduleRequestGQL | null,
284
- queryCount?: number | boolean,
285
- ): Schedule.ScheduleRequestGQL | null {
286
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleRequest, id)] : [], queryCount);
287
- return row?.__deleted || row?.deletedAt ? null : row;
115
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleWorkCalendar, rows, queryCount);
288
116
  }
289
117
 
290
- /* Observe request rows and remove authoritative deletion tombstones. */
291
- export function useReactiveScheduleRequestMap(
292
- rows: Schedule.ScheduleRequestGQL[] | null,
293
- queryCount?: number | boolean,
294
- ): Schedule.ScheduleRequestGQL[] | null {
295
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleRequest), queryCount);
296
- return useMemo(
297
- () =>
298
- live?.filter(
299
- (
300
- row: Schedule.ScheduleRequestGQL & {
301
- __deleted?: boolean;
302
- deletedAt?: string | null;
303
- },
304
- ) => !row.__deleted && !row.deletedAt,
305
- ) ?? null,
306
- [live],
307
- );
308
- }
309
-
310
- /* Observe one timeoff row using the server's canonical fragment key. */
311
- export function useReactiveScheduleTimeOff(
312
- id: string | null | undefined,
313
- data: Schedule.ScheduleTimeOffGQL | null,
314
- queryCount?: number | boolean,
315
- ): Schedule.ScheduleTimeOffGQL | null {
316
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleTimeOff, id)] : [], queryCount);
317
- return row?.__deleted || row?.deletedAt ? null : row;
318
- }
319
-
320
- /* Observe timeoff rows and remove authoritative deletion tombstones. */
118
+ /* Observe time-off rows and remove authoritative deletion tombstones. */
321
119
  export function useReactiveScheduleTimeOffMap(
322
120
  rows: Schedule.ScheduleTimeOffGQL[] | null,
323
121
  queryCount?: number | boolean,
324
122
  ): Schedule.ScheduleTimeOffGQL[] | null {
325
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleTimeOff), queryCount);
326
- return useMemo(
327
- () =>
328
- live?.filter(
329
- (
330
- row: Schedule.ScheduleTimeOffGQL & {
331
- __deleted?: boolean;
332
- deletedAt?: string | null;
333
- },
334
- ) => !row.__deleted && !row.deletedAt,
335
- ) ?? null,
336
- [live],
337
- );
123
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleTimeOff, rows, queryCount);
338
124
  }
339
125
 
340
- /* Observe one violation row using the server's canonical fragment key. */
341
- export function useReactiveScheduleViolation(
342
- id: string | null | undefined,
343
- data: Schedule.ScheduleViolationGQL | null,
344
- queryCount?: number | boolean,
345
- ): Schedule.ScheduleViolationGQL | null {
346
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.scheduleViolation, id)] : [], queryCount);
347
- return row?.__deleted || row?.deletedAt ? null : row;
348
- }
349
-
350
- /* Observe violation rows and remove authoritative deletion tombstones. */
126
+ /* Observe rule findings and remove authoritative deletion tombstones. */
351
127
  export function useReactiveScheduleViolationMap(
352
128
  rows: Schedule.ScheduleViolationGQL[] | null,
353
129
  queryCount?: number | boolean,
354
130
  ): Schedule.ScheduleViolationGQL[] | null {
355
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.scheduleViolation), queryCount);
356
- return useMemo(
357
- () =>
358
- live?.filter(
359
- (
360
- row: Schedule.ScheduleViolationGQL & {
361
- __deleted?: boolean;
362
- deletedAt?: string | null;
363
- },
364
- ) => !row.__deleted && !row.deletedAt,
365
- ) ?? null,
366
- [live],
367
- );
131
+ return useReactiveScheduleRows(FRAGMENT_NAMES.scheduleViolation, rows, queryCount);
368
132
  }
369
133
 
370
- /* Observe one publication row using the server's canonical fragment key. */
371
- export function useReactiveSchedulePublication(
372
- id: string | null | undefined,
373
- data: Schedule.SchedulePublicationGQL | null,
374
- queryCount?: number | boolean,
375
- ): Schedule.SchedulePublicationGQL | null {
376
- const row = useReactiveFragment(data, id ? [makeFragmentKey(FRAGMENT_NAMES.schedulePublication, id)] : [], queryCount);
377
- return row?.__deleted || row?.deletedAt ? null : row;
378
- }
379
-
380
- /* Observe publication rows and remove authoritative deletion tombstones. */
381
- export function useReactiveSchedulePublicationMap(
382
- rows: Schedule.SchedulePublicationGQL[] | null,
383
- queryCount?: number | boolean,
384
- ): Schedule.SchedulePublicationGQL[] | null {
385
- const live = useReactiveFragmentMap(rows, getFragmentBaseName(FRAGMENT_NAMES.schedulePublication), queryCount);
386
- return useMemo(
387
- () =>
388
- live?.filter(
389
- (
390
- row: Schedule.SchedulePublicationGQL & {
391
- __deleted?: boolean;
392
- deletedAt?: string | null;
393
- },
394
- ) => !row.__deleted && !row.deletedAt,
395
- ) ?? null,
396
- [live],
397
- );
134
+ /* Reset the calendar-scoped window queries (seats and findings) of one calendar. */
135
+ function resetScheduleCalendarWindows(
136
+ calendarId: string,
137
+ organizationId: string | undefined,
138
+ updateObservers: ReturnType<typeof useUpdateObservers>,
139
+ ) {
140
+ const match = { calendarId, ...(organizationId ? { organizationId } : {}) };
141
+ for (const name of [QUERY_NAMES.scheduleShifts, QUERY_NAMES.scheduleViolations]) {
142
+ resetQueryByTarget({ name, match }, true, updateObservers);
143
+ }
398
144
  }
399
145
 
400
- const REVISION_QUERIES = {
401
- project: gql`query scheduleProject($projectId: GenericID!) { scheduleProject(projectId: $projectId) { id networkRevision } }`,
402
- calendar: gql`query scheduleCalendar($calendarId: GenericID!) { scheduleCalendar(calendarId: $calendarId) { id revision } }`,
403
- };
404
-
405
146
  /* Recover missed realtime events with one indexed revision read on focus or reconnect. */
406
147
  function useScheduleRevisionCheck(p: {
407
148
  kind: 'project' | 'calendar';
@@ -425,27 +166,18 @@ function useScheduleRevisionCheck(p: {
425
166
  lastCheck.current = Date.now();
426
167
  controller?.abort();
427
168
  controller = new AbortController();
428
- const variables = input.kind === 'project' ? { projectId: input.id } : { calendarId: input.id };
429
- const result = await graphqlRequestNoStore(REVISION_QUERIES[input.kind], variables, undefined, controller.signal);
169
+ const result =
170
+ input.kind === 'project'
171
+ ? await graphqlRequestNoStore(scheduleProjectRevisionQry, { projectId: input.id }, undefined, controller.signal)
172
+ : await graphqlRequestNoStore(scheduleCalendarRevisionQry, { calendarId: input.id }, undefined, controller.signal);
430
173
  if (disposed || current.current.id !== input.id || result.error || result.aborted) return;
431
174
  const server = input.kind === 'project' ? result.scheduleProject?.networkRevision : result.scheduleCalendar?.revision;
432
175
  if (server == null || String(server) === String(current.current.revision)) return;
433
- resetQueryByTarget(
434
- input.kind === 'project'
435
- ? {
436
- name: QUERY_NAMES.scheduleProjectNetwork,
437
- match: { projectId: input.id },
438
- }
439
- : {
440
- name: QUERY_NAMES.scheduleOccurrences,
441
- match: {
442
- calendarId: input.id,
443
- ...(input.organizationId ? { organizationId: input.organizationId } : {}),
444
- },
445
- },
446
- true,
447
- updateObservers,
448
- );
176
+ if (input.kind === 'project') {
177
+ resetQueryByTarget({ name: QUERY_NAMES.scheduleProjectNetwork, match: { projectId: input.id } }, true, updateObservers);
178
+ } else {
179
+ resetScheduleCalendarWindows(input.id, input.organizationId, updateObservers);
180
+ }
449
181
  };
450
182
  void check();
451
183
  document.addEventListener('visibilitychange', check);
@@ -471,7 +203,7 @@ export function useScheduleProjectRevisionCheck(
471
203
  });
472
204
  }
473
205
 
474
- /* Reconcile a calendar window after a missed socket event or background interval. */
206
+ /* Reconcile a calendar's seats and findings after a missed socket event or background interval. */
475
207
  export function useScheduleCalendarRevisionCheck(
476
208
  calendarId: string | null | undefined,
477
209
  loadedRevision: string | number | null | undefined,
@@ -106,7 +106,7 @@ export function useSheetAccess(sheetId?: string | null, params: UseQueryParams =
106
106
  /*
107
107
  * Keep viewer-specific Sheet access live after an openSheet bootstrap. The
108
108
  * initial refetch is intentionally effect-driven so it never blocks bootstrap
109
- * paint; subsequent server RESET_ONLY events are handled by useQuery.
109
+ * paint; later `touched` sheetAccess changes refetch it through useQuery.
110
110
  */
111
111
  export function useSheetAccessMonitor(sheetId?: string | null, enabled: boolean = true, monitorScopeId: string = '') {
112
112
  const activeSheetId = enabled ? String(sheetId || '') : '';
@@ -284,3 +284,8 @@ export function useReactiveSheetImportJobFragment(importJobId: string, currentDa
284
284
  export function getSheetViewFragmentKey(sheetViewId: string) {
285
285
  return makeFragmentKey(FRAGMENT_NAMES.sheetView, sheetViewId);
286
286
  }
287
+
288
+ /* Observe cached sheet metadata for a list of identities without fetching documents or opening collaboration sessions. */
289
+ export function useReactiveSheetFragmentMap(currentData: { id: string }[] | null) {
290
+ return useReactiveFragmentMap(currentData, getFragmentBaseName(FRAGMENT_NAMES.sheet));
291
+ }
@@ -1,9 +1,13 @@
1
1
  import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
- import { OpenModalPopUpFn } from '@jsb188/react/states';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
3
  import {
4
4
  cancelReminderMtn,
5
5
  deleteWorkflowMtn,
6
+ discardWorkflowDraftMtn,
6
7
  editProgramWorkflowMtn,
8
+ publishWorkflowMtn,
9
+ removeWorkflowAddedBehaviorMtn,
10
+ setWorkflowActiveMtn,
7
11
  updateReminderMtn,
8
12
  } from '../gql/mutations/workflowMutations.ts';
9
13
  import { useMutation } from './index.ts';
@@ -70,3 +74,43 @@ export function useDeleteWorkflow(params: UseMutationParams = {}, openModalPopUp
70
74
  const [deleteWorkflow, mtnValues, mtnHandlers] = useMutation(deleteWorkflowMtn, { openModalPopUp, ...params });
71
75
  return { deleteWorkflow, ...mtnValues, ...mtnHandlers };
72
76
  }
77
+
78
+ /*
79
+ * Make the draft at the given revision the live version and switch the workflow on; the returned workflow updates its
80
+ * cached fragment. A stale revision fails with the revision conflict error and leaves the cached (newer) draft as it is.
81
+ */
82
+ export function usePublishWorkflow(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
83
+ const [publishWorkflow, mtnValues, mtnHandlers] = useMutation(publishWorkflowMtn, { openModalPopUp, ...params });
84
+ return { publishWorkflow, ...mtnValues, ...mtnHandlers };
85
+ }
86
+
87
+ /*
88
+ * Pause or resume a log workflow that has a live version, or a form's workflow; the returned workflow updates its
89
+ * cached fragment.
90
+ */
91
+ export function useSetWorkflowActive(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
92
+ const [setWorkflowActive, mtnValues, mtnHandlers] = useMutation(setWorkflowActiveMtn, { openModalPopUp, ...params });
93
+ return { setWorkflowActive, ...mtnValues, ...mtnHandlers };
94
+ }
95
+
96
+ /*
97
+ * Delete a workflow's draft; the returned workflow updates its cached fragment. The result is null when a log workflow
98
+ * was never published and was deleted with its draft: the server's deleted change then marks the cached record
99
+ * __deleted, as for deleteWorkflow.
100
+ */
101
+ export function useDiscardWorkflowDraft(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
102
+ const [discardWorkflowDraft, mtnValues, mtnHandlers] = useMutation(discardWorkflowDraftMtn, { openModalPopUp, ...params });
103
+ return { discardWorkflowDraft, ...mtnValues, ...mtnHandlers };
104
+ }
105
+
106
+ /*
107
+ * Remove what the organization added to a form's workflow, so the form goes back to only filling; the returned
108
+ * workflow updates its cached fragment.
109
+ */
110
+ export function useRemoveWorkflowAddedBehavior(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
111
+ const [removeWorkflowAddedBehavior, mtnValues, mtnHandlers] = useMutation(removeWorkflowAddedBehaviorMtn, {
112
+ openModalPopUp,
113
+ ...params,
114
+ });
115
+ return { removeWorkflowAddedBehavior, ...mtnValues, ...mtnHandlers };
116
+ }
@@ -1,8 +1,8 @@
1
1
  import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '@jsb188/graphql/client';
2
- import type { WorkflowRunsFilterGQL, WorkflowsFilterGQL } from '@jsb188/mday/types/workflow.d.ts';
3
2
  import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
3
+ import type { WorkflowRunsFilterGQL, WorkflowsFilterGQL } from '@jsb188/mday/types/workflow.d.ts';
4
4
  import { useCallback } from 'react';
5
- import { workflowQry, workflowRunQry, workflowRunsQry, workflowsQry } from '../gql/queries/workflowQueries.ts';
5
+ import { fieldDocWorkflowQry, workflowQry, workflowRunQry, workflowRunsQry, workflowsQry } from '../gql/queries/workflowQueries.ts';
6
6
  import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
7
7
 
8
8
  /*
@@ -45,6 +45,7 @@ function normalizeWorkflowsFilter(filter?: Record<string, any> | null): Workflow
45
45
  return {
46
46
  activeOnly: filter?.activeOnly === true,
47
47
  kind: filter?.kind || null,
48
+ fieldDocId: filter?.fieldDocId || null,
48
49
  startDate: filter?.startDate || null,
49
50
  endDate: filter?.endDate || null,
50
51
  };
@@ -124,6 +125,25 @@ export function useWorkflows(
124
125
  };
125
126
  }
126
127
 
128
+ /*
129
+ * Fetch the workflow of one form (null while the form has none yet); a live query that refetches by itself.
130
+ */
131
+ export function useFieldDocWorkflow(
132
+ variables: { organizationId?: string | null; fieldDocId?: string | null },
133
+ params: UseQueryParams = {},
134
+ ) {
135
+ const { data, ...rest } = useQuery(fieldDocWorkflowQry, {
136
+ ...params,
137
+ variables,
138
+ skip: !variables.organizationId || !variables.fieldDocId || params.skip,
139
+ });
140
+
141
+ return {
142
+ workflow: data?.fieldDocWorkflow?.[0] || null,
143
+ ...rest,
144
+ };
145
+ }
146
+
127
147
  /**
128
148
  * Fetch the paginated runs list for an organization,
129
149
  * optionally scoped to one workflow via filter.workflowId