@jsb188/graphql 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audience.d.ts +343 -0
- package/cache/config.ts +58 -24
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +370 -42
- package/cache/index.ts +326 -799
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +98 -19
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +5 -2
- package/client/index.ts +3 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +130 -215
- package/deno.lock +17 -0
- package/deno.test.json +2 -0
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +36 -10
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +415 -126
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +28 -23
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +10 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +652 -140
- package/gql/fragments/sheetFragments.ts +84 -373
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workflowFragments.ts +13 -1
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +36 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +45 -1
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/campaignMutations.ts +170 -127
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +8 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1052 -354
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +0 -1
- package/gql/mutations/workflowMutations.ts +18 -0
- package/gql/queries/agentMemoryQueries.ts +6 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +56 -4
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +6 -0
- package/gql/queries/billingQueries.ts +95 -6
- package/gql/queries/campaignQueries.ts +132 -23
- package/gql/queries/dataTableQueries.ts +24 -65
- package/gql/queries/emailQueries.ts +18 -61
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +100 -92
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +3 -1
- package/gql/queries/logQueries.ts +62 -7
- package/gql/queries/organizationQueries.ts +13 -0
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +633 -257
- package/gql/queries/sheetQueries.ts +59 -152
- package/gql/queries/workflowQueries.ts +10 -4
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +863 -685
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +96 -112
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +229 -383
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +224 -165
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +631 -54
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +66 -916
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +33 -178
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +506 -333
- package/hooks/use-schedule-qry.ts +682 -101
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +84 -238
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +39 -22
- package/hooks/use-workflow-qry.ts +40 -61
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/{client → libs}/request-managed-session.test.ts +1 -1
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +56 -83
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +42 -17
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/types.d.ts +46 -25
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-no-store.test.ts +0 -157
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/queries/agentDocQueries.ts +0 -120
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- /package/{client → libs}/sse-ticket.test.ts +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { FieldDocSubmissionsFilterArgs } from '@jsb188/mday/types/fieldDoc.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface FieldDocSubmissionsVariables {
|
|
8
|
+
organizationId: string | null;
|
|
9
|
+
filter: FieldDocSubmissionsFilterArgs;
|
|
10
|
+
cursor: string | null;
|
|
11
|
+
after: boolean;
|
|
12
|
+
limit: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Keep a list filter aligned with the FieldDocSubmissionsFilter input shape. Route table filters can carry
|
|
17
|
+
* URL-only keys, and one unknown input field fails the whole query.
|
|
18
|
+
*/
|
|
19
|
+
export function normalizeFieldDocSubmissionsFilter(filter?: Record<string, any> | null): FieldDocSubmissionsFilterArgs {
|
|
20
|
+
return {
|
|
21
|
+
fieldDocProgramId: filter?.fieldDocProgramId || null,
|
|
22
|
+
fieldDocIds: filter?.fieldDocIds || null,
|
|
23
|
+
siteId: filter?.siteId || null,
|
|
24
|
+
statuses: filter?.statuses || null,
|
|
25
|
+
startPeriod: filter?.startPeriod || null,
|
|
26
|
+
endPeriod: filter?.endPeriod || null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* Build the fieldDocSubmissions variables with the logEntries cursor contract: the first page has no cursor and
|
|
32
|
+
* after true, and fetchMore sends the last row's cursor with after false for the next older page. The first page
|
|
33
|
+
* limit is fixed at 100 because the limit is part of the query cache key, so every consumer shares one cache entry.
|
|
34
|
+
*/
|
|
35
|
+
export function getFieldDocSubmissionsVariables(p: {
|
|
36
|
+
organizationId?: string | null;
|
|
37
|
+
filter?: Record<string, any> | null;
|
|
38
|
+
cursor?: string | null;
|
|
39
|
+
after?: boolean;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}): FieldDocSubmissionsVariables {
|
|
42
|
+
return {
|
|
43
|
+
organizationId: p.organizationId || null,
|
|
44
|
+
filter: normalizeFieldDocSubmissionsFilter(p.filter),
|
|
45
|
+
cursor: p.cursor ?? null,
|
|
46
|
+
after: p.after ?? true,
|
|
47
|
+
limit: p.limit ?? 100,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,180 +1,212 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
FieldDocEditSessionGQL,
|
|
3
|
+
FieldDocProgramEnrollmentGQL,
|
|
4
|
+
FieldDocProgramGQL,
|
|
5
|
+
FieldDocSubmissionDocumentGQL,
|
|
6
|
+
FieldDocSubmissionGQL,
|
|
7
|
+
FieldDocSubmissionsFilterArgs,
|
|
4
8
|
} from '@jsb188/mday/types/fieldDoc.d.ts';
|
|
9
|
+
import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
10
|
+
import { getFieldDocOrganizationScopedId } from '@jsb188/mday/utils/fieldDoc.ts';
|
|
11
|
+
import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '../client/index.ts';
|
|
5
12
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
useQuery,
|
|
12
|
-
useReactiveFragment,
|
|
13
|
-
useReactiveFragmentMap,
|
|
14
|
-
} from '../client/index.ts';
|
|
15
|
-
import {
|
|
16
|
-
fieldDocGroupsQry,
|
|
17
|
-
fieldDocQry,
|
|
18
|
-
fieldDocsQry,
|
|
13
|
+
fieldDocEditSessionQry,
|
|
14
|
+
fieldDocProgramCatalogQry,
|
|
15
|
+
fieldDocProgramEnrollmentsQry,
|
|
16
|
+
fieldDocSubmissionDocumentQry,
|
|
19
17
|
fieldDocSubmissionsQry,
|
|
20
18
|
} from '../gql/queries/fieldDocQueries.ts';
|
|
21
19
|
import type { UseQueryParams } from '../types.d.ts';
|
|
20
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
21
|
+
import { getFieldDocSubmissionsVariables } from './use-fieldDoc-qry.helpers.ts';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Get reactive fieldDoc fragment
|
|
24
|
+
* Get reactive fieldDoc program fragment (org-agnostic program fields)
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
export function
|
|
28
|
-
|
|
29
|
-
currentData?: any,
|
|
30
|
-
queryCount?: number,
|
|
31
|
-
) {
|
|
32
|
-
return useReactiveFragment(
|
|
33
|
-
currentData,
|
|
34
|
-
[makeFragmentKey(FRAGMENT_NAMES.fieldDoc, fieldDocId)],
|
|
35
|
-
queryCount,
|
|
36
|
-
);
|
|
27
|
+
export function useReactiveFieldDocProgramFragment(fieldDocProgramId: string, currentData?: any, queryCount?: number) {
|
|
28
|
+
return useReactiveFragment(currentData, [makeFragmentKey(FRAGMENT_NAMES.fieldDocProgram, fieldDocProgramId)], queryCount);
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
/**
|
|
40
|
-
* Get reactive fieldDoc submission fragment
|
|
32
|
+
* Get reactive fieldDoc submission fragment; list rows and the document header share it
|
|
41
33
|
*/
|
|
42
34
|
|
|
43
|
-
export function useReactiveFieldDocSubmissionFragment(
|
|
44
|
-
fieldDocSubmissionId
|
|
45
|
-
currentData?: any,
|
|
46
|
-
queryCount?: number,
|
|
47
|
-
) {
|
|
48
|
-
return useReactiveFragment(
|
|
49
|
-
currentData,
|
|
50
|
-
[makeFragmentKey(FRAGMENT_NAMES.fieldDocSubmission, fieldDocSubmissionId)],
|
|
51
|
-
queryCount,
|
|
52
|
-
);
|
|
35
|
+
export function useReactiveFieldDocSubmissionFragment(fieldDocSubmissionId: string, currentData?: any, queryCount?: number) {
|
|
36
|
+
return useReactiveFragment(currentData, [makeFragmentKey(FRAGMENT_NAMES.fieldDocSubmission, fieldDocSubmissionId)], queryCount);
|
|
53
37
|
}
|
|
54
38
|
|
|
55
39
|
/**
|
|
56
|
-
* Get reactive
|
|
40
|
+
* Get reactive answer fragments for a document's answers. The document returns one answer for every answer-bearing
|
|
41
|
+
* key (UNANSWERED included), so every key of the definition is observed.
|
|
57
42
|
*/
|
|
58
43
|
|
|
59
|
-
export function
|
|
60
|
-
currentData
|
|
61
|
-
) {
|
|
62
|
-
return useReactiveFragmentMap(
|
|
63
|
-
currentData || null,
|
|
64
|
-
getFragmentBaseName(FRAGMENT_NAMES.fieldDocElementData),
|
|
65
|
-
);
|
|
44
|
+
export function useReactiveFieldDocAnswerFragmentMap(currentData?: any[] | null) {
|
|
45
|
+
return useReactiveFragmentMap(currentData || null, getFragmentBaseName(FRAGMENT_NAMES.fieldDocAnswer));
|
|
66
46
|
}
|
|
67
47
|
|
|
68
48
|
/**
|
|
69
|
-
* Fetch
|
|
49
|
+
* Fetch the organization's program enrollments: active ones plus archived ones that can still be restored, each with
|
|
50
|
+
* its program and forms. An optional program scope avoids loading unrelated enrollments. Uses the shared query
|
|
51
|
+
* freshness window; database notifications refresh active queries.
|
|
70
52
|
*/
|
|
71
53
|
|
|
72
|
-
export function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
filter: FieldDocsFilterArgs;
|
|
76
|
-
sort?: FieldDocsSortEnum;
|
|
77
|
-
},
|
|
78
|
-
params: UseQueryParams = {},
|
|
54
|
+
export function useFieldDocProgramEnrollments(
|
|
55
|
+
organizationId: string | null | undefined,
|
|
56
|
+
params: UseQueryParams & { fieldDocProgramId?: string | null } = {},
|
|
79
57
|
) {
|
|
80
|
-
const {
|
|
81
|
-
const {
|
|
82
|
-
const { data, ...rest } = useQuery(fieldDocsQry, {
|
|
83
|
-
variables,
|
|
84
|
-
skip:
|
|
85
|
-
skip ||
|
|
86
|
-
!organizationId ||
|
|
87
|
-
!filter?.fieldDocGroupId ||
|
|
88
|
-
!(filter?.startPeriod || filter?.endPeriod),
|
|
58
|
+
const { skip, fieldDocProgramId, ...restParams } = params;
|
|
59
|
+
const { data, ...rest } = useQuery(fieldDocProgramEnrollmentsQry, {
|
|
89
60
|
...restParams,
|
|
61
|
+
variables: {
|
|
62
|
+
organizationId,
|
|
63
|
+
...(fieldDocProgramId ? { fieldDocProgramId } : {}),
|
|
64
|
+
},
|
|
65
|
+
skip: skip || !organizationId,
|
|
90
66
|
});
|
|
91
67
|
|
|
92
68
|
return {
|
|
93
|
-
|
|
69
|
+
fieldDocProgramEnrollments: data?.fieldDocProgramEnrollments as FieldDocProgramEnrollmentGQL[] | null | undefined,
|
|
94
70
|
...rest,
|
|
95
71
|
};
|
|
96
72
|
}
|
|
97
73
|
|
|
98
74
|
/**
|
|
99
|
-
* Fetch
|
|
75
|
+
* Fetch the catalog programs offered to the organization's operation. Enrolled state comes from
|
|
76
|
+
* useFieldDocProgramEnrollments. Revalidates on entry to recover changes missed while disconnected.
|
|
100
77
|
*/
|
|
101
78
|
|
|
102
|
-
export function
|
|
103
|
-
organizationId: string | null,
|
|
104
|
-
fieldDocSourceId: string | null,
|
|
105
|
-
params: UseQueryParams = {},
|
|
106
|
-
) {
|
|
79
|
+
export function useFieldDocProgramCatalog(organizationId: string | null | undefined, params: UseQueryParams = {}) {
|
|
107
80
|
const { skip, ...restParams } = params;
|
|
108
|
-
const { data, ...rest } = useQuery(
|
|
81
|
+
const { data, ...rest } = useQuery(fieldDocProgramCatalogQry, {
|
|
82
|
+
...restParams,
|
|
83
|
+
persistTime: params.persistTime ?? 0,
|
|
109
84
|
variables: {
|
|
110
85
|
organizationId,
|
|
111
|
-
fieldDocSourceId,
|
|
112
86
|
},
|
|
113
|
-
skip: skip || !organizationId
|
|
114
|
-
...restParams,
|
|
87
|
+
skip: skip || !organizationId,
|
|
115
88
|
});
|
|
116
89
|
|
|
117
90
|
return {
|
|
118
|
-
|
|
91
|
+
fieldDocProgramCatalog: data?.fieldDocProgramCatalog as FieldDocProgramGQL[] | null | undefined,
|
|
119
92
|
...rest,
|
|
120
93
|
};
|
|
121
94
|
}
|
|
122
95
|
|
|
123
96
|
/**
|
|
124
|
-
* Fetch
|
|
97
|
+
* Fetch one owner organization's submissions, newest period first, with the logEntries cursor contract
|
|
98
|
+
* (getFieldDocSubmissionsVariables). fetchMore rebuilds its variables the same way, so route table extras
|
|
99
|
+
* (sort, URL-only filter keys) never reach the query.
|
|
125
100
|
*/
|
|
126
101
|
|
|
127
|
-
export function
|
|
128
|
-
|
|
102
|
+
export function useFieldDocSubmissions(
|
|
103
|
+
variables: {
|
|
104
|
+
organizationId?: string | null;
|
|
105
|
+
filter?: FieldDocSubmissionsFilterArgs | Record<string, any> | null;
|
|
106
|
+
},
|
|
129
107
|
params: UseQueryParams = {},
|
|
130
108
|
) {
|
|
109
|
+
const { organizationId, filter } = variables;
|
|
131
110
|
const { skip, ...restParams } = params;
|
|
132
|
-
const { data, ...rest } = useQuery(
|
|
133
|
-
|
|
134
|
-
|
|
111
|
+
const { data, fetchMore, ...rest } = useQuery(fieldDocSubmissionsQry, {
|
|
112
|
+
...restParams,
|
|
113
|
+
variables: getFieldDocSubmissionsVariables({ organizationId, filter }),
|
|
114
|
+
skip: skip || !organizationId || !filter,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
* Request one more page with the same declared variables as the first page; omitted ones keep the hook's values.
|
|
119
|
+
*/
|
|
120
|
+
const fetchMoreSubmissions = useCallback(
|
|
121
|
+
(options: any) => {
|
|
122
|
+
return fetchMore({
|
|
123
|
+
...options,
|
|
124
|
+
variables: getFieldDocSubmissionsVariables({ organizationId, filter, ...options?.variables }),
|
|
125
|
+
});
|
|
135
126
|
},
|
|
136
|
-
|
|
127
|
+
[fetchMore, filter, organizationId],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
fieldDocSubmissions: data?.fieldDocSubmissions as FieldDocSubmissionGQL[] | null | undefined,
|
|
132
|
+
fetchMore: fetchMoreSubmissions,
|
|
133
|
+
...rest,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Fetch one submission's document: the submission, its pinned definition, every answer and the aside
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
export function useFieldDocSubmissionDocument(fieldDocSubmissionId: string | null | undefined, params: UseQueryParams = {}) {
|
|
142
|
+
const { skip, ...restParams } = params;
|
|
143
|
+
const { data, ...rest } = useQuery(fieldDocSubmissionDocumentQry, {
|
|
137
144
|
...restParams,
|
|
145
|
+
variables: {
|
|
146
|
+
fieldDocSubmissionId,
|
|
147
|
+
},
|
|
148
|
+
skip: skip || !fieldDocSubmissionId,
|
|
138
149
|
});
|
|
139
150
|
|
|
140
151
|
return {
|
|
141
|
-
|
|
152
|
+
fieldDocSubmissionDocument: data?.fieldDocSubmissionDocument as FieldDocSubmissionDocumentGQL | null | undefined,
|
|
142
153
|
...rest,
|
|
143
154
|
};
|
|
144
155
|
}
|
|
145
156
|
|
|
146
157
|
/**
|
|
147
|
-
* Fetch
|
|
158
|
+
* Fetch one form's web editor session for an organization. The session is read through its fragment, so an
|
|
159
|
+
* editFieldDocCustomInstructions result (same selection, same id) updates it without a refetch. Reconnects refetch
|
|
160
|
+
* it, since realtime resets sent while offline are lost. editable means the viewer can change the form's structure:
|
|
161
|
+
* a custom doc and an organization manager.
|
|
148
162
|
*/
|
|
149
163
|
|
|
150
|
-
export function
|
|
164
|
+
export function useFieldDocEditSession(
|
|
151
165
|
variables: {
|
|
152
|
-
organizationId
|
|
153
|
-
|
|
154
|
-
sort?: FieldDocsSortEnum;
|
|
155
|
-
limit?: number;
|
|
166
|
+
organizationId?: string | null;
|
|
167
|
+
fieldDocId?: string | null;
|
|
156
168
|
},
|
|
157
169
|
params: UseQueryParams = {},
|
|
158
170
|
) {
|
|
159
|
-
const {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
} = variables;
|
|
165
|
-
const { skip, ...restParams } = params;
|
|
166
|
-
const { data, ...rest } = useQuery(fieldDocSubmissionsQry, {
|
|
171
|
+
const { organizationId, fieldDocId } = variables;
|
|
172
|
+
const enabled = !params.skip && !!organizationId && !!fieldDocId;
|
|
173
|
+
const { data, refetch, ...rest } = useQuery(fieldDocEditSessionQry, {
|
|
174
|
+
retryTransientErrors: true,
|
|
175
|
+
...params,
|
|
167
176
|
variables: {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
limit,
|
|
177
|
+
organizationId,
|
|
178
|
+
fieldDocId,
|
|
171
179
|
},
|
|
172
|
-
skip:
|
|
173
|
-
...restParams,
|
|
180
|
+
skip: !enabled,
|
|
174
181
|
});
|
|
182
|
+
const wasConnected = useRef(rest.connectedToServer);
|
|
183
|
+
const sessionId = organizationId && fieldDocId ? getFieldDocOrganizationScopedId(organizationId, fieldDocId) : '';
|
|
184
|
+
const fieldDocEditSession = useReactiveFragment(
|
|
185
|
+
data?.fieldDocEditSession || null,
|
|
186
|
+
sessionId ? [makeFragmentKey(FRAGMENT_NAMES.fieldDocEditSession, sessionId)] : [],
|
|
187
|
+
rest.updatedCount,
|
|
188
|
+
) as FieldDocEditSessionGQL | null;
|
|
189
|
+
|
|
190
|
+
/*
|
|
191
|
+
* Refetch once after the realtime connection comes back.
|
|
192
|
+
*/
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
const reconnected = rest.connectedToServer && !wasConnected.current;
|
|
195
|
+
wasConnected.current = rest.connectedToServer;
|
|
196
|
+
if (enabled && reconnected) {
|
|
197
|
+
void refetch().catch(() => {
|
|
198
|
+
// Query state owns the load error; do not create an unhandled reconnect rejection.
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}, [enabled, refetch, rest.connectedToServer]);
|
|
202
|
+
|
|
203
|
+
const manageable = Boolean(fieldDocEditSession?.manageable);
|
|
175
204
|
|
|
176
205
|
return {
|
|
177
|
-
|
|
206
|
+
fieldDocEditSession,
|
|
207
|
+
editable: manageable && fieldDocEditSession?.fieldDoc?.isProgramDoc === false,
|
|
208
|
+
manageable,
|
|
209
|
+
refetch,
|
|
178
210
|
...rest,
|
|
179
211
|
};
|
|
180
212
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
|
|
2
|
-
import type { InboundContactsSortEnum } from '@jsb188/mday/types/inboundContact.d.ts';
|
|
3
2
|
import {
|
|
4
3
|
FRAGMENT_NAMES,
|
|
5
4
|
makeFragmentKey,
|
|
6
5
|
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
6
|
+
import type { InboundContactsQueryArgs } from '@jsb188/mday/types/inboundContact.d.ts';
|
|
7
7
|
import {
|
|
8
8
|
inboundContactQry,
|
|
9
9
|
inboundContactsQry,
|
|
@@ -54,21 +54,19 @@ export function useInboundContact(
|
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
export function useInboundContacts(
|
|
57
|
-
variables: PaginationArgs &
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
57
|
+
variables: PaginationArgs &
|
|
58
|
+
InboundContactsQueryArgs & {
|
|
59
|
+
organizationId?: string | null;
|
|
60
|
+
},
|
|
62
61
|
params: UseQueryParams = {},
|
|
63
62
|
) {
|
|
64
|
-
const { filter: _filter, ...queryVariables } = variables;
|
|
65
63
|
const { data, ...rest } = useQuery(inboundContactsQry, {
|
|
66
64
|
...params,
|
|
67
65
|
variables: {
|
|
68
|
-
...
|
|
66
|
+
...variables,
|
|
69
67
|
cursor: null,
|
|
70
68
|
after: true,
|
|
71
|
-
limit: INBOUND_CONTACTS_LIMIT,
|
|
69
|
+
limit: variables.limit ?? INBOUND_CONTACTS_LIMIT,
|
|
72
70
|
},
|
|
73
71
|
skip: !variables.organizationId || params.skip,
|
|
74
72
|
});
|
package/hooks/use-log-mtn.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { checkACLPermission } from '@jsb188/mday/utils/organization.ts';
|
|
2
1
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
3
|
-
import { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
4
2
|
import {
|
|
5
3
|
FRAGMENT_NAMES,
|
|
6
4
|
makeFragmentKey,
|
|
7
5
|
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
6
|
+
import { checkACLPermission } from '@jsb188/mday/utils/organization.ts';
|
|
7
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
8
8
|
import { useMemo } from 'react';
|
|
9
9
|
import { updateFragment } from '../cache/index.ts';
|
|
10
10
|
import {
|
|
@@ -15,6 +15,26 @@ import { useMutation } from './index.ts';
|
|
|
15
15
|
import { useReactiveLogFragment } from './use-log-qry.ts';
|
|
16
16
|
import { useOrgRelFromMyOrganizations } from './use-organization-qry.ts';
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Prepare the shared edit-log mutation command without subscribing to one log row.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export function useEditLogEntryMutation(
|
|
23
|
+
params: UseMutationParams = {},
|
|
24
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
25
|
+
) {
|
|
26
|
+
const [editLogEntry, mtnValues, mtnHandlers] = useMutation(editLogEntryMtn, {
|
|
27
|
+
openModalPopUp,
|
|
28
|
+
...params,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
editLogEntry,
|
|
33
|
+
...mtnValues,
|
|
34
|
+
...mtnHandlers,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
/**
|
|
19
39
|
* Fetch a single log entry,
|
|
20
40
|
* from cache first; only check server if cache is not found.
|
|
@@ -30,17 +50,12 @@ export function useEditLogEntry(
|
|
|
30
50
|
const { organizationRelationship } =
|
|
31
51
|
useOrgRelFromMyOrganizations(organizationId);
|
|
32
52
|
const notReady = !organizationRelationship;
|
|
33
|
-
|
|
34
|
-
const [editLogEntry, mtnValues, mtnHandlers] = useMutation(editLogEntryMtn, {
|
|
35
|
-
// checkMountedBeforeCallback: true,
|
|
36
|
-
openModalPopUp,
|
|
37
|
-
...params,
|
|
38
|
-
});
|
|
53
|
+
const mutation = useEditLogEntryMutation(params, openModalPopUp);
|
|
39
54
|
|
|
40
55
|
const logEntry = useReactiveLogFragment(
|
|
41
56
|
logEntryId,
|
|
42
57
|
null,
|
|
43
|
-
|
|
58
|
+
mutation.mutationCount,
|
|
44
59
|
);
|
|
45
60
|
|
|
46
61
|
const isMyDocument =
|
|
@@ -55,11 +70,9 @@ export function useEditLogEntry(
|
|
|
55
70
|
|
|
56
71
|
return {
|
|
57
72
|
logEntry,
|
|
58
|
-
editLogEntry,
|
|
59
73
|
notReady,
|
|
60
74
|
allowEdit,
|
|
61
|
-
...
|
|
62
|
-
...mtnHandlers,
|
|
75
|
+
...mutation,
|
|
63
76
|
};
|
|
64
77
|
}
|
|
65
78
|
|
package/hooks/use-log-qry.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
LogSortEnum,
|
|
4
|
-
} from '@jsb188/mday/types/log.d.ts';
|
|
5
|
-
import {
|
|
6
|
-
FRAGMENT_NAMES,
|
|
7
|
-
makeFragmentKey,
|
|
8
|
-
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
1
|
+
import { FRAGMENT_NAMES, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
2
|
+
import type { FilterLogEntriesArgs, LogSortEnum } from '@jsb188/mday/types/log.d.ts';
|
|
9
3
|
import { useQuery, useReactiveFragment } from '../client/index.ts';
|
|
10
4
|
import {
|
|
11
|
-
|
|
5
|
+
fieldDocSubmissionLogsQry,
|
|
12
6
|
logEntriesQry,
|
|
13
7
|
logEntryQry,
|
|
8
|
+
logRevisionProofDownloadUrlQry,
|
|
9
|
+
logRevisionQry,
|
|
10
|
+
logRevisionsQry,
|
|
14
11
|
} from '../gql/queries/logQueries.ts';
|
|
15
12
|
import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
16
13
|
|
|
@@ -22,9 +19,20 @@ import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
|
22
19
|
// Having less data is better for performance for iPads and low-end devices, because it might reduce brief rendering mishaps,
|
|
23
20
|
// But a decent amount of visual load size is needed for Virtualized List to work well.
|
|
24
21
|
const LOG_ENTRIES_LIMIT = 250;
|
|
22
|
+
const LOG_REVISIONS_LIMIT = 50;
|
|
23
|
+
|
|
24
|
+
export type LogRevisionsVariables = PaginationArgs & {
|
|
25
|
+
organizationId?: string | null;
|
|
26
|
+
logEntryId?: string | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type LogRevisionVariables = {
|
|
30
|
+
organizationId?: string | null;
|
|
31
|
+
revisionId?: string | null;
|
|
32
|
+
};
|
|
25
33
|
|
|
26
34
|
/**
|
|
27
|
-
*
|
|
35
|
+
* Reuse the requested reactive log from cache and only query when it is absent.
|
|
28
36
|
*/
|
|
29
37
|
|
|
30
38
|
export function useLogEntry(
|
|
@@ -35,22 +43,23 @@ export function useLogEntry(
|
|
|
35
43
|
params: UseQueryParams = {},
|
|
36
44
|
) {
|
|
37
45
|
const { logEntryId, organizationId } = variables;
|
|
46
|
+
// Read the reactive fragment first; it already loads and observes the log and details in cache.
|
|
47
|
+
// A separate loadFragment() call would duplicate that cache lookup.
|
|
48
|
+
const observedLogEntry = useReactiveLogFragment(logEntryId || '');
|
|
49
|
+
// The observer can retain the previous log until its effect runs after an ID change.
|
|
50
|
+
// Only the requested log may satisfy this read or prevent its query from running.
|
|
51
|
+
const reactiveLogEntry = observedLogEntry?.id === logEntryId ? observedLogEntry : null;
|
|
52
|
+
// Always call the query hook to preserve hook order, but skip its automatic request when
|
|
53
|
+
// the requested log is cached, required IDs are absent, or the caller explicitly skips.
|
|
38
54
|
const { data, ...rest } = useQuery(logEntryQry, {
|
|
39
55
|
...params,
|
|
40
|
-
// A log can be changed outside the websocket mutation path, such as by a
|
|
41
|
-
// database repair. Revalidate it whenever the detail modal is opened.
|
|
42
|
-
persistTime: params.persistTime ?? 0,
|
|
43
56
|
variables,
|
|
44
|
-
skip: !organizationId || !logEntryId || params.skip,
|
|
57
|
+
skip: !!reactiveLogEntry || !organizationId || !logEntryId || params.skip,
|
|
45
58
|
});
|
|
46
|
-
const reactiveLogEntry = useReactiveLogFragment(
|
|
47
|
-
logEntryId || '',
|
|
48
|
-
data?.logEntry,
|
|
49
|
-
rest.updatedCount,
|
|
50
|
-
);
|
|
51
59
|
|
|
52
60
|
return {
|
|
53
|
-
|
|
61
|
+
// Prefer the reactive cache; otherwise use a matching query result while the cache observer catches up.
|
|
62
|
+
logEntry: reactiveLogEntry || (data?.logEntry?.id === logEntryId ? data.logEntry : null),
|
|
54
63
|
...rest,
|
|
55
64
|
};
|
|
56
65
|
}
|
|
@@ -87,30 +96,81 @@ export function useLogEntries(
|
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
/**
|
|
90
|
-
* Fetch
|
|
99
|
+
* Fetch every log linked to one field doc submission (the document page loads it beside the document).
|
|
91
100
|
*/
|
|
92
101
|
|
|
93
|
-
export function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
export function useFieldDocSubmissionLogs(fieldDocSubmissionId: string | null | undefined, params: UseQueryParams = {}) {
|
|
103
|
+
const { data, ...rest } = useQuery(fieldDocSubmissionLogsQry, {
|
|
104
|
+
...params,
|
|
105
|
+
variables: {
|
|
106
|
+
fieldDocSubmissionId,
|
|
107
|
+
},
|
|
108
|
+
skip: !fieldDocSubmissionId || params.skip,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
fieldDocSubmissionLogs: data?.fieldDocSubmissionLogs,
|
|
113
|
+
...rest,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Reuse cached revision-history pages without automatically revalidating them on each modal open.
|
|
119
|
+
*/
|
|
120
|
+
export function useLogRevisions(variables: LogRevisionsVariables, params: UseQueryParams = {}) {
|
|
121
|
+
const { data, ...rest } = useQuery(logRevisionsQry, {
|
|
122
|
+
...params,
|
|
123
|
+
// useQuery already reads its normalized cache for these exact log and pagination variables.
|
|
124
|
+
// Keep cached pages fresh indefinitely and disable mount revalidation so reopening does not refetch them.
|
|
125
|
+
revalidateOnMount: params.revalidateOnMount ?? false,
|
|
126
|
+
persistTime: params.persistTime ?? Infinity,
|
|
127
|
+
variables: {
|
|
128
|
+
...variables,
|
|
129
|
+
cursor: variables.cursor ?? null,
|
|
130
|
+
after: variables.after ?? false,
|
|
131
|
+
limit: variables.limit ?? LOG_REVISIONS_LIMIT,
|
|
132
|
+
},
|
|
133
|
+
// Unlike the single-log read, a cached page must not set skip: true: useQuery also gates
|
|
134
|
+
// fetchMore() and refetch() on skip. Only missing IDs or an explicit caller skip disable those requests.
|
|
135
|
+
skip: !variables.organizationId || !variables.logEntryId || params.skip,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
// Return the cache-backed page from useQuery; a missing page is populated by its normal server request.
|
|
140
|
+
logRevisions: data?.logRevisions,
|
|
141
|
+
...rest,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Fetch one full immutable log revision.
|
|
147
|
+
*/
|
|
148
|
+
export function useLogRevision(variables: LogRevisionVariables, params: UseQueryParams = {}) {
|
|
149
|
+
const { data, ...rest } = useQuery(logRevisionQry, {
|
|
150
|
+
...params,
|
|
151
|
+
variables,
|
|
152
|
+
skip: !variables.organizationId || !variables.revisionId || params.skip,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
logRevision: data?.logRevision,
|
|
157
|
+
...rest,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Request a fresh short-lived download URL for one archived proof.
|
|
163
|
+
*/
|
|
164
|
+
export function useLogRevisionProofDownloadUrl(variables: LogRevisionVariables, params: UseQueryParams = {}) {
|
|
165
|
+
const { data, ...rest } = useQuery(logRevisionProofDownloadUrlQry, {
|
|
103
166
|
...params,
|
|
167
|
+
persistTime: params.persistTime ?? 0,
|
|
104
168
|
variables,
|
|
105
|
-
skip:
|
|
106
|
-
!organizationId ||
|
|
107
|
-
!fieldDocSourceId ||
|
|
108
|
-
!fieldDocSubmissionId ||
|
|
109
|
-
params.skip,
|
|
169
|
+
skip: !variables.organizationId || !variables.revisionId || params.skip,
|
|
110
170
|
});
|
|
111
171
|
|
|
112
172
|
return {
|
|
113
|
-
|
|
173
|
+
logRevisionProofDownloadUrl: data?.logRevisionProofDownloadUrl,
|
|
114
174
|
...rest,
|
|
115
175
|
};
|
|
116
176
|
}
|
|
@@ -119,17 +179,10 @@ export function useLogEntriesForFieldDoc(
|
|
|
119
179
|
* Get reactive log fragment
|
|
120
180
|
*/
|
|
121
181
|
|
|
122
|
-
export function useReactiveLogFragment(
|
|
123
|
-
logEntryId: string,
|
|
124
|
-
currentData?: any,
|
|
125
|
-
queryCount?: number,
|
|
126
|
-
) {
|
|
182
|
+
export function useReactiveLogFragment(logEntryId: string, currentData?: any, queryCount?: number) {
|
|
127
183
|
return useReactiveFragment(
|
|
128
184
|
currentData,
|
|
129
|
-
[
|
|
130
|
-
makeFragmentKey(FRAGMENT_NAMES.logEntry, logEntryId),
|
|
131
|
-
[makeFragmentKey(FRAGMENT_NAMES.logEntryDetails, logEntryId), 'details'],
|
|
132
|
-
],
|
|
185
|
+
[makeFragmentKey(FRAGMENT_NAMES.logEntry, logEntryId), [makeFragmentKey(FRAGMENT_NAMES.logEntryDetails, logEntryId), 'details']],
|
|
133
186
|
queryCount,
|
|
134
187
|
);
|
|
135
188
|
}
|