@jsb188/graphql 1.1.7 → 1.1.10
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/cache/config.ts +14 -4
- package/cache/index.test.ts +319 -0
- package/cache/index.ts +522 -85
- package/client/index.ts +2 -2
- package/client/request.ts +48 -9
- package/deno.test.json +6 -0
- package/gql/fragments/accountFragments.ts +1 -0
- package/gql/fragments/aiChatFragments.ts +1 -0
- package/gql/fragments/dataTableFragments.ts +212 -0
- package/gql/fragments/emailFragments.ts +26 -0
- package/gql/fragments/inboundContactFragments.ts +15 -0
- package/gql/fragments/integrationFragments.ts +22 -0
- package/gql/fragments/logFragments.ts +40 -12
- package/gql/fragments/organizationFragments.ts +59 -24
- package/gql/fragments/productFragments.ts +0 -24
- package/gql/fragments/reportFragments.ts +52 -10
- package/gql/fragments/sheetFragments.ts +145 -0
- package/gql/fragments/storageFragments.ts +3 -1
- package/gql/fragments/workflowFragments.ts +43 -0
- package/gql/mutations/accountMutations.ts +24 -2
- package/gql/mutations/aiChatMutations.ts +28 -1
- package/gql/mutations/authMutations.ts +3 -3
- package/gql/mutations/billingMutations.ts +1 -1
- package/gql/mutations/dataTableMutations.ts +84 -0
- package/gql/mutations/inboundContactMutations.ts +24 -0
- package/gql/mutations/index.ts +12 -8
- package/gql/mutations/integrationMutations.ts +25 -0
- package/gql/mutations/logMutations.ts +15 -1
- package/gql/mutations/organizationMutations.ts +151 -2
- package/gql/mutations/sheetMutations.ts +168 -0
- package/gql/mutations/storageMutations.ts +1 -2
- package/gql/queries/aiChatQueries.ts +1 -1
- package/gql/queries/billingQueries.ts +1 -1
- package/gql/queries/dataTableQueries.ts +45 -0
- package/gql/queries/emailQueries.ts +44 -0
- package/gql/queries/inboundContactQueries.ts +40 -0
- package/gql/queries/index.ts +11 -6
- package/gql/queries/logQueries.ts +47 -20
- package/gql/queries/organizationQueries.ts +62 -8
- package/gql/queries/productQueries.ts +1 -40
- package/gql/queries/reportQueries.ts +81 -13
- package/gql/queries/sheetQueries.ts +72 -0
- package/gql/queries/workflowQueries.ts +30 -0
- package/hooks/index.ts +208 -58
- package/hooks/use-account-mtn.ts +52 -4
- package/hooks/use-aiChat-mtn.ts +62 -6
- package/hooks/use-aiChat-qry.ts +76 -24
- package/hooks/use-app-qry.ts +2 -2
- package/hooks/use-auth-mtn.ts +5 -5
- package/hooks/use-dataTable-mtn.ts +87 -0
- package/hooks/use-dataTable-qry.ts +172 -0
- package/hooks/use-email-qry.ts +112 -0
- package/hooks/use-inboundContact-mtn.ts +31 -0
- package/hooks/use-inboundContact-qry.ts +88 -0
- package/hooks/use-integration-mtn.ts +59 -0
- package/hooks/use-integration-qry.ts +15 -0
- package/hooks/use-log-mtn.ts +6 -6
- package/hooks/use-log-qry.ts +38 -35
- package/hooks/use-organization-mtn.ts +288 -16
- package/hooks/use-organization-qry.ts +71 -22
- package/hooks/use-product-qry.ts +4 -46
- package/hooks/use-report-qry.ts +94 -10
- package/hooks/use-sheet-mtn.ts +181 -0
- package/hooks/use-sheet-qry.ts +157 -0
- package/hooks/use-storage-mtn.ts +6 -5
- package/hooks/use-storage-qry.ts +1 -1
- package/hooks/use-workflow-qry.ts +72 -0
- package/package.json +23 -4
- package/sse.ts +2 -2
- package/tsconfig.json +12 -0
- package/types.d.ts +2 -1
- package/utils.ts +2 -4
- package/gql/fragments/actionFragments.ts +0 -16
package/hooks/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getENVVariable } from '@jsb188/app';
|
|
2
|
-
import type { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app.d';
|
|
3
|
-
import { normalizeServerError } from '@jsb188/app/utils/api';
|
|
4
|
-
import { delay, makeVariablesKey } from '@jsb188/app/utils/logic';
|
|
2
|
+
import type { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app.d.ts';
|
|
3
|
+
import { normalizeServerError } from '@jsb188/app/utils/api.ts';
|
|
4
|
+
import { delay, makeVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
5
5
|
import { isServerErrorGQL } from '@jsb188/graphql/utils';
|
|
6
|
-
import { useConnectedToServerValue,
|
|
6
|
+
import { useConnectedToServerValue, useQueryObserverValue, useScreenIsFocusedValue, useSetFragmentObserver, useSetQueryObserver } from '@jsb188/react/states';
|
|
7
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
-
import { checkDataCompleteness, clearQueryResetStatus, fetchCachedData, getQueryRefreshTime, loadDataFromCache, loadFragment, removeStaleCache } from '../cache';
|
|
9
|
-
import { QUERY_EXPIRE_TIMES } from '../cache/config';
|
|
10
|
-
import { graphqlRequest } from '../client/request';
|
|
11
|
-
import type { AnyModalPopUpFn, GraphQLHandlers, GraphQLQueryOptions, OnCompletedGQLFn, OnErrorGQLFn, UpdateDataObserverArgs, UpdateObserversFn } from '../types';
|
|
8
|
+
import { checkDataCompleteness, clearQueryResetStatus, fetchCachedData, getQueryRefreshTime, loadDataFromCache, loadFragment, removeStaleCache } from '../cache/index.ts';
|
|
9
|
+
import { QUERY_EXPIRE_TIMES } from '../cache/config.ts';
|
|
10
|
+
import { graphqlRequest } from '../client/request.ts';
|
|
11
|
+
import type { AnyModalPopUpFn, GraphQLHandlers, GraphQLQueryOptions, OnCompletedGQLFn, OnErrorGQLFn, UpdateDataObserverArgs, UpdateObserversFn } from '../types.d.ts';
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -63,6 +63,7 @@ type GraphQLQueryResult = {
|
|
|
63
63
|
queryName: string;
|
|
64
64
|
queryKey: string;
|
|
65
65
|
refreshTime: string;
|
|
66
|
+
resetOnlyTime: string;
|
|
66
67
|
variablesKey: string;
|
|
67
68
|
updatedCount: number;
|
|
68
69
|
updateObservers: UpdateObserversFn;
|
|
@@ -75,6 +76,86 @@ type GraphQLQueryResult = {
|
|
|
75
76
|
*/
|
|
76
77
|
|
|
77
78
|
const QRY_TRACKER = new Map();
|
|
79
|
+
const FRAGMENT_OBSERVER_LISTENERS = new Map<string, Set<(fragmentIds: string[]) => void>>();
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Convert reactive fragment observe entries into exact fragment observer keys.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
function getReactiveFragmentObserveKeys(observe: Array<string | [string, string | null]>) {
|
|
86
|
+
return observe.map((key) => {
|
|
87
|
+
return Array.isArray(key) ? key[0] : key;
|
|
88
|
+
}).filter(Boolean);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Subscribe to exact fragment observer keys.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
function subscribeFragmentObserverKeys(
|
|
96
|
+
fragmentIds: string[],
|
|
97
|
+
listener: (fragmentIds: string[]) => void,
|
|
98
|
+
) {
|
|
99
|
+
for (const fragmentId of fragmentIds) {
|
|
100
|
+
const listeners = FRAGMENT_OBSERVER_LISTENERS.get(fragmentId) || new Set();
|
|
101
|
+
listeners.add(listener);
|
|
102
|
+
FRAGMENT_OBSERVER_LISTENERS.set(fragmentId, listeners);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return () => {
|
|
106
|
+
for (const fragmentId of fragmentIds) {
|
|
107
|
+
const listeners = FRAGMENT_OBSERVER_LISTENERS.get(fragmentId);
|
|
108
|
+
listeners?.delete(listener);
|
|
109
|
+
|
|
110
|
+
if (!listeners?.size) {
|
|
111
|
+
FRAGMENT_OBSERVER_LISTENERS.delete(fragmentId);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Notify keyed reactive fragment subscribers for only the changed fragment ids.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
function notifyFragmentObserverListeners(fragmentIds: string[]) {
|
|
122
|
+
const notifiedListeners = new Set<(fragmentIds: string[]) => void>();
|
|
123
|
+
|
|
124
|
+
for (const fragmentId of fragmentIds) {
|
|
125
|
+
const listeners = FRAGMENT_OBSERVER_LISTENERS.get(fragmentId);
|
|
126
|
+
|
|
127
|
+
listeners?.forEach((listener) => {
|
|
128
|
+
if (!notifiedListeners.has(listener)) {
|
|
129
|
+
notifiedListeners.add(listener);
|
|
130
|
+
listener(fragmentIds);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Observe only the exact fragment keys needed by one reactive fragment hook.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
function useFragmentKeyObserver(observe: Array<string | [string, string | null]>) {
|
|
141
|
+
const observeStr = getReactiveFragmentObserveKeys(observe).join(',');
|
|
142
|
+
const observeKeys = useMemo(() => observeStr.split(',').filter(Boolean), [observeStr]);
|
|
143
|
+
const [fragmentObserver, setFragmentObserver] = useState({
|
|
144
|
+
count: 0,
|
|
145
|
+
list: [] as string[],
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
return subscribeFragmentObserverKeys(observeKeys, (fragmentIds) => {
|
|
150
|
+
setFragmentObserver((prev) => ({
|
|
151
|
+
count: prev.count + 1,
|
|
152
|
+
list: fragmentIds,
|
|
153
|
+
}));
|
|
154
|
+
});
|
|
155
|
+
}, [observeKeys]);
|
|
156
|
+
|
|
157
|
+
return fragmentObserver;
|
|
158
|
+
}
|
|
78
159
|
|
|
79
160
|
/**
|
|
80
161
|
* Global; unset query tracker
|
|
@@ -109,6 +190,7 @@ export function useUpdateObservers(): UpdateObserversFn {
|
|
|
109
190
|
count: (prev.name === args.queryId ? prev.count : 0) + 1,
|
|
110
191
|
name: args.queryId as string,
|
|
111
192
|
forceRefetch: !!args.forceRefetch,
|
|
193
|
+
resetOnly: !!args.resetOnly,
|
|
112
194
|
}));
|
|
113
195
|
}
|
|
114
196
|
|
|
@@ -117,6 +199,7 @@ export function useUpdateObservers(): UpdateObserversFn {
|
|
|
117
199
|
count: (prev.count || 0) + 1,
|
|
118
200
|
list: args.fragmentIds as string[],
|
|
119
201
|
}));
|
|
202
|
+
notifyFragmentObserverListeners(args.fragmentIds as string[]);
|
|
120
203
|
}
|
|
121
204
|
};
|
|
122
205
|
}
|
|
@@ -130,7 +213,7 @@ export function useWatchQuery(
|
|
|
130
213
|
variablesKey: string,
|
|
131
214
|
lastUpdatedCount: number,
|
|
132
215
|
loading: boolean,
|
|
133
|
-
) {
|
|
216
|
+
) {
|
|
134
217
|
|
|
135
218
|
const qryObserver = useQueryObserverValue();
|
|
136
219
|
const [qryReset, setQryReset] = useState({
|
|
@@ -139,7 +222,7 @@ export function useWatchQuery(
|
|
|
139
222
|
refreshTimeActive: '', // This value resets when loading starts
|
|
140
223
|
});
|
|
141
224
|
|
|
142
|
-
const queryWatcher = useMemo(() => {
|
|
225
|
+
const queryWatcher = useMemo<[number, boolean, string, string]>(() => {
|
|
143
226
|
if (qryObserver.name) {
|
|
144
227
|
const queryDefs = query.definitions.filter((d: any) => d.kind === 'OperationDefinition');
|
|
145
228
|
const queryName = queryDefs?.[0]?.name?.value;
|
|
@@ -150,23 +233,39 @@ export function useWatchQuery(
|
|
|
150
233
|
if (qryTriggerTime) {
|
|
151
234
|
clearQueryResetStatus(queryName, variablesKey);
|
|
152
235
|
console.dev(`... (1) Query [${queryName}:${variablesKey}] is being force refetched via observer.`);
|
|
153
|
-
return [lastUpdatedCount + 1, true, qryTriggerTime];
|
|
236
|
+
return [lastUpdatedCount + 1, true, qryTriggerTime, ''];
|
|
154
237
|
}
|
|
155
238
|
}
|
|
156
239
|
|
|
157
240
|
const matchedQry = queryDefs
|
|
158
|
-
.find((d: any) =>
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
241
|
+
.find((d: any) => {
|
|
242
|
+
const queryName = d.name.value;
|
|
243
|
+
const fullQueryKey = `#${queryName}:${variablesKey}`;
|
|
244
|
+
const queryNameKey = `#${queryName}:`;
|
|
245
|
+
|
|
246
|
+
if (qryObserver.name.startsWith('^')) {
|
|
247
|
+
try {
|
|
248
|
+
return new RegExp(qryObserver.name).test(fullQueryKey);
|
|
249
|
+
} catch (_err) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
qryObserver.name === fullQueryKey ||
|
|
256
|
+
qryObserver.name === queryNameKey ||
|
|
257
|
+
fullQueryKey.startsWith(qryObserver.name)
|
|
258
|
+
);
|
|
259
|
+
});
|
|
162
260
|
|
|
163
261
|
if (!matchedQry) {
|
|
164
|
-
return [0, false, ''];
|
|
262
|
+
return [0, false, '', ''];
|
|
165
263
|
}
|
|
166
264
|
|
|
167
265
|
const matchedQueryName = matchedQry.name.value;
|
|
168
266
|
const matchedQueryId = `#${matchedQueryName}:${variablesKey}`;
|
|
169
267
|
const forceRefetch = !!qryObserver.forceRefetch;
|
|
268
|
+
const resetOnlyTime = qryObserver.resetOnly ? `${Date.now()}:${qryObserver.count}` : '';
|
|
170
269
|
|
|
171
270
|
let newUpdatedCount = qryObserver.name === matchedQueryId || forceRefetch ? qryObserver.count : 0;
|
|
172
271
|
if (forceRefetch) {
|
|
@@ -177,10 +276,10 @@ export function useWatchQuery(
|
|
|
177
276
|
console.dev(`... (2) Query [${matchedQueryId}] is being force refetched via observer.`);
|
|
178
277
|
}
|
|
179
278
|
|
|
180
|
-
return [newUpdatedCount, forceRefetch, ''];
|
|
279
|
+
return [newUpdatedCount, forceRefetch, '', resetOnlyTime];
|
|
181
280
|
}
|
|
182
281
|
|
|
183
|
-
return [0, false, ''];
|
|
282
|
+
return [0, false, '', ''];
|
|
184
283
|
}, [qryObserver]);
|
|
185
284
|
|
|
186
285
|
useEffect(() => {
|
|
@@ -211,6 +310,7 @@ export function useWatchQuery(
|
|
|
211
310
|
return {
|
|
212
311
|
updatedCount: queryWatcher[0],
|
|
213
312
|
forceRefetch: queryWatcher[1],
|
|
313
|
+
resetOnlyTime: queryWatcher[3],
|
|
214
314
|
qryReset
|
|
215
315
|
};
|
|
216
316
|
}
|
|
@@ -224,11 +324,12 @@ export function useReactiveFragment(
|
|
|
224
324
|
observe: Array<string | [string, string | null]>,
|
|
225
325
|
qryObsCount?: number | boolean,
|
|
226
326
|
otherCheck?: (latestData: any, updatedKeys: any[]) => boolean,
|
|
327
|
+
mainPrioritizedFields?: string[],
|
|
227
328
|
ignoreIDWarning?: boolean,
|
|
228
329
|
isTest?: boolean
|
|
229
330
|
) {
|
|
230
331
|
|
|
231
|
-
const fragmentObserver =
|
|
332
|
+
const fragmentObserver = useFragmentKeyObserver(observe);
|
|
232
333
|
const frgObsCount = fragmentObserver.count;
|
|
233
334
|
const dataId = data?.id;
|
|
234
335
|
|
|
@@ -238,7 +339,7 @@ export function useReactiveFragment(
|
|
|
238
339
|
|
|
239
340
|
observe.forEach((key) => {
|
|
240
341
|
const isMapped = Array.isArray(key);
|
|
241
|
-
const fragmentData = loadFragment(isMapped ? key[0] : key);
|
|
342
|
+
const fragmentData = loadFragment(isMapped ? key[0] : key, mainPrioritizedFields);
|
|
242
343
|
|
|
243
344
|
if (fragmentData) {
|
|
244
345
|
if (isMapped) {
|
|
@@ -336,7 +437,7 @@ export function useReactiveFragment(
|
|
|
336
437
|
}
|
|
337
438
|
}
|
|
338
439
|
|
|
339
|
-
const fragmentData = loadFragment(isMapped ? key[0] : key);
|
|
440
|
+
const fragmentData = loadFragment(isMapped ? key[0] : key, mainPrioritizedFields);
|
|
340
441
|
|
|
341
442
|
// if (isTest) {
|
|
342
443
|
// console.log('fragmentKey', key);
|
|
@@ -395,6 +496,36 @@ export function useReactiveFragment(
|
|
|
395
496
|
return changedData.data ?? null;
|
|
396
497
|
}
|
|
397
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Merge mapped array data with the latest fragment cache values.
|
|
501
|
+
*/
|
|
502
|
+
|
|
503
|
+
function getReactiveFragmentMapData(
|
|
504
|
+
data: any[] | null,
|
|
505
|
+
observe?: string[] | null,
|
|
506
|
+
) {
|
|
507
|
+
if (!data || !observe?.length) {
|
|
508
|
+
return data;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return data.map((item, i) => {
|
|
512
|
+
const key = observe[i];
|
|
513
|
+
if (!key) {
|
|
514
|
+
return item;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const fragmentData = loadFragment(key);
|
|
518
|
+
if (!fragmentData) {
|
|
519
|
+
return item;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
...item,
|
|
524
|
+
...fragmentData,
|
|
525
|
+
};
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
398
529
|
/**
|
|
399
530
|
* Observe query changes; but for Arrays
|
|
400
531
|
*/
|
|
@@ -404,13 +535,23 @@ export function useReactiveFragmentMap(
|
|
|
404
535
|
fragmentName_: string,
|
|
405
536
|
) {
|
|
406
537
|
const fragmentName = `$${fragmentName_}`;
|
|
407
|
-
const
|
|
408
|
-
const
|
|
538
|
+
const observeStr = useMemo<string>(() => data?.map((d) => fragmentName + ':' + d.id).join(',') || '', [data, fragmentName]);
|
|
539
|
+
const observe = useMemo<string[]>(() => observeStr.split(',').filter(Boolean), [observeStr]);
|
|
540
|
+
const observeIndex = useMemo<Map<string, number>>(() => {
|
|
541
|
+
const indexMap = new Map<string, number>();
|
|
542
|
+
|
|
543
|
+
observe.forEach((key: string, index: number) => {
|
|
544
|
+
indexMap.set(key, index);
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
return indexMap;
|
|
548
|
+
}, [observe]);
|
|
549
|
+
const fragmentObserver = useFragmentKeyObserver(observe);
|
|
409
550
|
|
|
410
551
|
const [changedData, setChangedData] = useState({
|
|
411
552
|
count: fragmentObserver.count,
|
|
412
|
-
|
|
413
|
-
data
|
|
553
|
+
lastObserveStr: observeStr,
|
|
554
|
+
data: getReactiveFragmentMapData(data, observe)
|
|
414
555
|
});
|
|
415
556
|
|
|
416
557
|
useEffect(() => {
|
|
@@ -418,55 +559,61 @@ export function useReactiveFragmentMap(
|
|
|
418
559
|
// But that caused the render to happen 3 times more, I don't know why.
|
|
419
560
|
// I only solved it by using useEffect()
|
|
420
561
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
dataToUpdate &&
|
|
424
|
-
observe &&
|
|
425
|
-
fragmentObserver.count !== changedData.count
|
|
426
|
-
) {
|
|
562
|
+
if (fragmentObserver.count !== changedData.count) {
|
|
563
|
+
const dataToUpdate = changedData.data || data;
|
|
427
564
|
let newData;
|
|
428
|
-
for (let i = 0; i < observe.length; i++) {
|
|
429
|
-
const key = observe[i];
|
|
430
565
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
566
|
+
for (const key of fragmentObserver.list) {
|
|
567
|
+
const index = observeIndex.get(key);
|
|
568
|
+
if (index === undefined || !dataToUpdate?.[index]) {
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
435
571
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
}
|
|
572
|
+
const fragmentData = loadFragment(key);
|
|
573
|
+
if (!fragmentData) {
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (!newData) {
|
|
578
|
+
newData = dataToUpdate.slice(0);
|
|
445
579
|
}
|
|
580
|
+
|
|
581
|
+
newData[index] = {
|
|
582
|
+
...newData[index],
|
|
583
|
+
...fragmentData,
|
|
584
|
+
};
|
|
446
585
|
}
|
|
447
586
|
|
|
448
587
|
if (newData) {
|
|
449
588
|
setChangedData({
|
|
450
589
|
...changedData,
|
|
451
590
|
count: fragmentObserver.count,
|
|
452
|
-
data: newData
|
|
591
|
+
data: newData,
|
|
592
|
+
});
|
|
593
|
+
} else {
|
|
594
|
+
setChangedData({
|
|
595
|
+
...changedData,
|
|
596
|
+
count: fragmentObserver.count,
|
|
453
597
|
});
|
|
454
598
|
}
|
|
455
599
|
}
|
|
456
|
-
}, [fragmentObserver.
|
|
600
|
+
}, [fragmentObserver.count]);
|
|
457
601
|
|
|
458
|
-
const observeStr = observe?.join(',');
|
|
459
602
|
useEffect(() => {
|
|
460
|
-
if (changedData.
|
|
603
|
+
if (changedData.lastObserveStr !== observeStr) {
|
|
461
604
|
setChangedData({
|
|
462
605
|
...changedData,
|
|
463
|
-
data,
|
|
464
|
-
|
|
606
|
+
data: getReactiveFragmentMapData(data, observe),
|
|
607
|
+
lastObserveStr: observeStr,
|
|
465
608
|
});
|
|
466
609
|
}
|
|
467
610
|
}, [observeStr]);
|
|
468
611
|
|
|
469
|
-
|
|
612
|
+
if (changedData.lastObserveStr !== observeStr) {
|
|
613
|
+
return getReactiveFragmentMapData(data, observe);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
return changedData.data || data;
|
|
470
617
|
}
|
|
471
618
|
|
|
472
619
|
/**
|
|
@@ -678,8 +825,9 @@ export function useQuery(
|
|
|
678
825
|
lastUpdatedCount: 0,
|
|
679
826
|
lastRefreshTriggerTime: '',
|
|
680
827
|
});
|
|
828
|
+
const qryValuesVariablesKey = makeVariablesKey(qryValues.variables);
|
|
681
829
|
|
|
682
|
-
const { updatedCount, forceRefetch, qryReset: { triggerTime, refreshTime } } = useWatchQuery(
|
|
830
|
+
const { updatedCount, forceRefetch, resetOnlyTime, qryReset: { triggerTime, refreshTime } } = useWatchQuery(
|
|
683
831
|
query,
|
|
684
832
|
variablesKey,
|
|
685
833
|
qryValues.lastUpdatedCount,
|
|
@@ -830,7 +978,7 @@ export function useQuery(
|
|
|
830
978
|
!skip && (
|
|
831
979
|
(triggerTime && triggerTime !== qryValues.lastRefreshTriggerTime) ||
|
|
832
980
|
updatedCount !== qryValues.lastUpdatedCount ||
|
|
833
|
-
variablesKey !==
|
|
981
|
+
variablesKey !== qryValuesVariablesKey ||
|
|
834
982
|
!checkDataCompleteness(qryValues.data, query)
|
|
835
983
|
)
|
|
836
984
|
) {
|
|
@@ -857,7 +1005,7 @@ export function useQuery(
|
|
|
857
1005
|
doQuery();
|
|
858
1006
|
}
|
|
859
1007
|
}
|
|
860
|
-
}, [variablesKey, skip, updatedCount, triggerTime]);
|
|
1008
|
+
}, [variablesKey, qryValuesVariablesKey, qryValues.loading, skip, updatedCount, triggerTime]);
|
|
861
1009
|
|
|
862
1010
|
// Refetch when the app reconnects and has no data
|
|
863
1011
|
|
|
@@ -910,8 +1058,9 @@ export function useQuery(
|
|
|
910
1058
|
return result;
|
|
911
1059
|
}, [doQuery, skip]);
|
|
912
1060
|
|
|
1061
|
+
const qryValuesMatchVariables = variablesKey === qryValuesVariablesKey;
|
|
913
1062
|
const queryData = loadDataFromCache(
|
|
914
|
-
qryValues.data,
|
|
1063
|
+
qryValuesMatchVariables ? qryValues.data : null,
|
|
915
1064
|
query,
|
|
916
1065
|
variablesKey,
|
|
917
1066
|
cacheMap,
|
|
@@ -932,7 +1081,7 @@ export function useQuery(
|
|
|
932
1081
|
refreshTime,
|
|
933
1082
|
data: queryData,
|
|
934
1083
|
});
|
|
935
|
-
}, [queryData[queryName]]);
|
|
1084
|
+
}, [queryKey, refreshTime, queryData[queryName]]);
|
|
936
1085
|
|
|
937
1086
|
return {
|
|
938
1087
|
...qryValues,
|
|
@@ -940,6 +1089,7 @@ export function useQuery(
|
|
|
940
1089
|
queryKey: queryOutput.queryKey,
|
|
941
1090
|
data: queryOutput.data || queryData,
|
|
942
1091
|
refreshTime: queryOutput.refreshTime,
|
|
1092
|
+
resetOnlyTime,
|
|
943
1093
|
variablesKey,
|
|
944
1094
|
refetch,
|
|
945
1095
|
fetchMore,
|
package/hooks/use-account-mtn.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
2
|
import { OpenModalPopUpFn, useCurrentAccount } from '@jsb188/react/states';
|
|
3
|
-
import { requestChangeEmailMtn, editAccountMtn } from '../gql/mutations/accountMutations';
|
|
4
|
-
import { useMutation } from './index';
|
|
3
|
+
import { changePhoneMtn, requestChangeEmailMtn, requestChangePhoneMtn, editAccountMtn } from '../gql/mutations/accountMutations.ts';
|
|
4
|
+
import { useMutation } from './index.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Edit logged in user's account
|
|
@@ -43,7 +43,7 @@ export function useEditAccount(
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Change logged in user's
|
|
46
|
+
* Change logged in user's email address
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
49
|
export function useRequestChangeEmail(
|
|
@@ -65,4 +65,52 @@ export function useRequestChangeEmail(
|
|
|
65
65
|
...mtnValues,
|
|
66
66
|
...mtnHandlers,
|
|
67
67
|
};
|
|
68
|
-
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Change logged in user's phone number
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
export function useRequestChangePhone(
|
|
75
|
+
params?: UseMutationParams | null,
|
|
76
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
77
|
+
) {
|
|
78
|
+
|
|
79
|
+
const [requestChangePhone, mtnValues, mtnHandlers] = useMutation(
|
|
80
|
+
requestChangePhoneMtn,
|
|
81
|
+
{
|
|
82
|
+
openModalPopUp,
|
|
83
|
+
...params,
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
requestChangePhone,
|
|
89
|
+
...mtnValues,
|
|
90
|
+
...mtnHandlers,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Confirm logged in user's phone number change
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
export function useChangePhone(
|
|
99
|
+
params?: UseMutationParams | null,
|
|
100
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
101
|
+
) {
|
|
102
|
+
|
|
103
|
+
const [changePhone, mtnValues, mtnHandlers] = useMutation(
|
|
104
|
+
changePhoneMtn,
|
|
105
|
+
{
|
|
106
|
+
openModalPopUp,
|
|
107
|
+
...params,
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
changePhone,
|
|
113
|
+
...mtnValues,
|
|
114
|
+
...mtnHandlers,
|
|
115
|
+
};
|
|
116
|
+
}
|
package/hooks/use-aiChat-mtn.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { resetQuery, updateQuery } from '../cache/';
|
|
2
|
-
import { useMutation } from '../client';
|
|
3
|
-
import { updateAIChats } from './use-aiChat-qry';
|
|
4
|
-
import { sendAIChatMessageMtn, startAIChatMtn, stopAIChatMessageMtn } from '../gql/mutations/aiChatMutations';
|
|
5
|
-
import type { UseMutationParams } from '../types.d';
|
|
1
|
+
import { resetQuery, updateFragment, updateQuery } from '../cache/index.ts';
|
|
2
|
+
import { useMutation } from '../client/index.ts';
|
|
3
|
+
import { updateAIChats } from './use-aiChat-qry.ts';
|
|
4
|
+
import { deleteAIChatMtn, editAIChatMtn, sendAIChatMessageMtn, startAIChatMtn, stopAIChatMessageMtn } from '../gql/mutations/aiChatMutations.ts';
|
|
5
|
+
import type { UseMutationParams } from '../types.d.ts';
|
|
6
6
|
import { useOpenModalPopUp } from '@jsb188/react/states';
|
|
7
7
|
import { useEffect, useRef } from 'react';
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ export function useStartAIChat(params: UseMutationParams = {}) {
|
|
|
23
23
|
onCompleted?.(data, err, variables);
|
|
24
24
|
|
|
25
25
|
const aiChat = data.startAIChat?.node;
|
|
26
|
-
updateAIChats(aiChat, updateObservers);
|
|
26
|
+
updateAIChats(aiChat, variables?.organizationId, updateObservers);
|
|
27
27
|
},
|
|
28
28
|
onError,
|
|
29
29
|
},
|
|
@@ -35,6 +35,31 @@ export function useStartAIChat(params: UseMutationParams = {}) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Edit AI chat
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export function useEditAIChat(params: UseMutationParams = {}) {
|
|
43
|
+
|
|
44
|
+
const { onCompleted, onError } = params;
|
|
45
|
+
const openModalPopUp = useOpenModalPopUp();
|
|
46
|
+
|
|
47
|
+
const [editAIChat, mtnValues, mtnHandlers] = useMutation(
|
|
48
|
+
editAIChatMtn,
|
|
49
|
+
{
|
|
50
|
+
openModalPopUp,
|
|
51
|
+
onCompleted,
|
|
52
|
+
onError,
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
editAIChat,
|
|
58
|
+
...mtnValues,
|
|
59
|
+
...mtnHandlers,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
38
63
|
/**
|
|
39
64
|
* Send a new message to AI Chat
|
|
40
65
|
*/
|
|
@@ -110,3 +135,34 @@ export function useAIChatTextarea(variablesKey: string, params: UseMutationParam
|
|
|
110
135
|
}
|
|
111
136
|
};
|
|
112
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Delete AI chat
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
export function useDeleteAIChat(params: UseMutationParams = {}) {
|
|
144
|
+
|
|
145
|
+
const { onCompleted, onError } = params;
|
|
146
|
+
const openModalPopUp = useOpenModalPopUp();
|
|
147
|
+
|
|
148
|
+
const [deleteAIChat, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
149
|
+
deleteAIChatMtn,
|
|
150
|
+
{
|
|
151
|
+
openModalPopUp,
|
|
152
|
+
onCompleted: (data: any, err: any, variables: any) => {
|
|
153
|
+
if (data?.deleteAIChat) {
|
|
154
|
+
updateFragment(`$aiChatFragment:${variables.aiChatId}`, { __deleted: true }, null, false, updateObservers);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
onCompleted?.(data, err, variables);
|
|
158
|
+
},
|
|
159
|
+
onError,
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
deleteAIChat,
|
|
165
|
+
...mtnValues,
|
|
166
|
+
...mtnHandlers,
|
|
167
|
+
};
|
|
168
|
+
}
|