@servicetitan/dte-unlayer 0.154.0 → 0.156.0
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/dist/display-conditions/ConditionRow.d.ts.map +1 -1
- package/dist/display-conditions/ConditionRow.js +111 -95
- package/dist/display-conditions/ConditionRow.js.map +1 -1
- package/dist/display-conditions/DisplayConditionModal.d.ts +3 -3
- package/dist/display-conditions/DisplayConditionModal.d.ts.map +1 -1
- package/dist/display-conditions/DisplayConditionModal.js +8 -95
- package/dist/display-conditions/DisplayConditionModal.js.map +1 -1
- package/dist/display-conditions/useConditionForms.d.ts +22 -0
- package/dist/display-conditions/useConditionForms.d.ts.map +1 -0
- package/dist/display-conditions/useConditionForms.js +110 -0
- package/dist/display-conditions/useConditionForms.js.map +1 -0
- package/dist/e-sign-offset/ESignDateSignedOffsetModal.d.ts +11 -0
- package/dist/e-sign-offset/ESignDateSignedOffsetModal.d.ts.map +1 -0
- package/dist/e-sign-offset/ESignDateSignedOffsetModal.js +192 -0
- package/dist/e-sign-offset/ESignDateSignedOffsetModal.js.map +1 -0
- package/dist/e-sign-offset/ESignOffsetRuleRow.d.ts +20 -0
- package/dist/e-sign-offset/ESignOffsetRuleRow.d.ts.map +1 -0
- package/dist/e-sign-offset/ESignOffsetRuleRow.js +87 -0
- package/dist/e-sign-offset/ESignOffsetRuleRow.js.map +1 -0
- package/dist/e-sign-offset/eSignOffsetController.d.ts +10 -0
- package/dist/e-sign-offset/eSignOffsetController.d.ts.map +1 -0
- package/dist/e-sign-offset/eSignOffsetController.js +27 -0
- package/dist/e-sign-offset/eSignOffsetController.js.map +1 -0
- package/dist/editor-core-source.d.ts +2 -2
- package/dist/editor-core-source.d.ts.map +1 -1
- package/dist/editor-core-source.js +2 -2
- package/dist/editor-core-source.js.map +1 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +8 -0
- package/dist/editor.js.map +1 -1
- package/dist/image-upload-error.d.ts +5 -0
- package/dist/image-upload-error.d.ts.map +1 -0
- package/dist/image-upload-error.js +8 -0
- package/dist/image-upload-error.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/shared/const.d.ts +30 -0
- package/dist/shared/const.d.ts.map +1 -1
- package/dist/shared/const.js +5 -0
- package/dist/shared/const.js.map +1 -1
- package/dist/shared/e-sign-offset.d.ts +21 -0
- package/dist/shared/e-sign-offset.d.ts.map +1 -0
- package/dist/shared/e-sign-offset.js +130 -0
- package/dist/shared/e-sign-offset.js.map +1 -0
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +36 -11
- package/dist/store.js.map +1 -1
- package/dist/tools.d.ts +6 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +21 -1
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/e-sign-offset.test.ts +281 -0
- package/src/__tests__/store.image-upload.test.ts +132 -0
- package/src/display-conditions/ConditionRow.tsx +86 -81
- package/src/display-conditions/DisplayConditionModal.tsx +12 -116
- package/src/display-conditions/useConditionForms.ts +146 -0
- package/src/e-sign-offset/ESignDateSignedOffsetModal.tsx +197 -0
- package/src/e-sign-offset/ESignOffsetRuleRow.tsx +101 -0
- package/src/e-sign-offset/eSignOffsetController.ts +39 -0
- package/src/editor-core-source.ts +2 -2
- package/src/editor.tsx +9 -0
- package/src/image-upload-error.ts +7 -0
- package/src/index.ts +1 -0
- package/src/shared/const.ts +37 -0
- package/src/shared/e-sign-offset.ts +173 -0
- package/src/store.ts +53 -8
- package/src/tools.ts +36 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionRow.d.ts","sourceRoot":"","sources":["../../src/display-conditions/ConditionRow.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAqB,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAoB,eAAe,E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AE,MAAM,IAAI,CAAC;CACxB;AAaD,wBAAgB,YAAY,CAAC,EACzB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,QAAQ,GACX,EAAE,QAAQ,CAAC,iBAAiB,CAAC,+BA4R7B"}
|
|
@@ -134,6 +134,10 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
134
134
|
width: '100%'
|
|
135
135
|
},
|
|
136
136
|
children: /*#__PURE__*/ _jsxs(Combobox.Select, {
|
|
137
|
+
flex: 1,
|
|
138
|
+
style: {
|
|
139
|
+
width: '100%'
|
|
140
|
+
},
|
|
137
141
|
disableClearSelection: true,
|
|
138
142
|
itemToKey: (item)=>{
|
|
139
143
|
var _ref;
|
|
@@ -169,8 +173,6 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
169
173
|
alignItems: "flex-end",
|
|
170
174
|
gap: "2",
|
|
171
175
|
style: {
|
|
172
|
-
flexWrap: 'wrap',
|
|
173
|
-
rowGap: 8,
|
|
174
176
|
width: '100%'
|
|
175
177
|
},
|
|
176
178
|
children: [
|
|
@@ -186,113 +188,127 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
186
188
|
size: "small"
|
|
187
189
|
})
|
|
188
190
|
}),
|
|
189
|
-
/*#__PURE__*/
|
|
191
|
+
/*#__PURE__*/ _jsxs(Flex, {
|
|
190
192
|
flex: 1,
|
|
193
|
+
direction: "row",
|
|
194
|
+
alignItems: "flex-end",
|
|
195
|
+
gap: "2",
|
|
191
196
|
style: {
|
|
192
|
-
minWidth:
|
|
197
|
+
minWidth: 0,
|
|
198
|
+
width: '100%'
|
|
193
199
|
},
|
|
194
|
-
children:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
children:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
200
|
+
children: [
|
|
201
|
+
/*#__PURE__*/ _jsx(Flex, {
|
|
202
|
+
flex: 1,
|
|
203
|
+
style: {
|
|
204
|
+
minWidth: 0,
|
|
205
|
+
width: '100%'
|
|
206
|
+
},
|
|
207
|
+
children: /*#__PURE__*/ _jsxs(Combobox.Select, {
|
|
208
|
+
flex: 1,
|
|
209
|
+
style: {
|
|
210
|
+
width: '100%'
|
|
211
|
+
},
|
|
212
|
+
disableClearSelection: true,
|
|
213
|
+
itemToKey: (item)=>{
|
|
214
|
+
var _ref;
|
|
215
|
+
return (_ref = item === null || item === void 0 ? void 0 : item.fullKey) !== null && _ref !== void 0 ? _ref : '';
|
|
216
|
+
},
|
|
217
|
+
itemToString: (item)=>{
|
|
218
|
+
var _ref;
|
|
219
|
+
return (_ref = item === null || item === void 0 ? void 0 : item.title) !== null && _ref !== void 0 ? _ref : '';
|
|
220
|
+
},
|
|
221
|
+
items: activeDataPointOptions,
|
|
222
|
+
selectedItem: selectedDataPoint,
|
|
223
|
+
onChange: handleDataPointChange,
|
|
224
|
+
children: [
|
|
225
|
+
/*#__PURE__*/ _jsx(Combobox.SelectTrigger, {
|
|
226
|
+
label: "Data Point",
|
|
227
|
+
placeholder: currentFormId ? 'Select form field...' : 'Select data point...',
|
|
228
|
+
size: "small"
|
|
229
|
+
}),
|
|
230
|
+
/*#__PURE__*/ _jsx(Combobox.Content, {
|
|
231
|
+
children: ({ items })=>/*#__PURE__*/ _jsx(Combobox.List, {
|
|
232
|
+
children: items.map((item, i)=>/*#__PURE__*/ _jsx(Combobox.Item, {
|
|
233
|
+
index: i,
|
|
234
|
+
item: item,
|
|
235
|
+
children: item.title
|
|
236
|
+
}, item.fullKey))
|
|
237
|
+
})
|
|
224
238
|
})
|
|
239
|
+
]
|
|
225
240
|
})
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
241
|
+
}),
|
|
242
|
+
/*#__PURE__*/ _jsx(Flex, {
|
|
243
|
+
flex: 1,
|
|
244
|
+
style: {
|
|
245
|
+
minWidth: 0,
|
|
246
|
+
width: '100%'
|
|
247
|
+
},
|
|
248
|
+
children: /*#__PURE__*/ _jsxs(Combobox.Select, {
|
|
249
|
+
flex: 1,
|
|
250
|
+
style: {
|
|
251
|
+
width: '100%'
|
|
252
|
+
},
|
|
253
|
+
disableClearSelection: true,
|
|
254
|
+
itemToKey: (item)=>{
|
|
255
|
+
var _ref;
|
|
256
|
+
return (_ref = item === null || item === void 0 ? void 0 : item.value) !== null && _ref !== void 0 ? _ref : '';
|
|
257
|
+
},
|
|
258
|
+
itemToString: (item)=>{
|
|
259
|
+
var _ref;
|
|
260
|
+
return (_ref = item === null || item === void 0 ? void 0 : item.label) !== null && _ref !== void 0 ? _ref : '';
|
|
261
|
+
},
|
|
262
|
+
items: operatorItems,
|
|
263
|
+
selectedItem: selectedOperator,
|
|
264
|
+
onChange: (item)=>{
|
|
265
|
+
var _ref;
|
|
266
|
+
return onChange({
|
|
267
|
+
...condition,
|
|
268
|
+
operator: (_ref = item === null || item === void 0 ? void 0 : item.value) !== null && _ref !== void 0 ? _ref : 'is_equal_to'
|
|
269
|
+
});
|
|
270
|
+
},
|
|
271
|
+
children: [
|
|
272
|
+
/*#__PURE__*/ _jsx(Combobox.SelectTrigger, {
|
|
273
|
+
label: "Condition",
|
|
274
|
+
placeholder: "Select...",
|
|
275
|
+
size: "small"
|
|
276
|
+
}),
|
|
277
|
+
/*#__PURE__*/ _jsx(Combobox.Content, {
|
|
278
|
+
children: ({ items })=>/*#__PURE__*/ _jsx(Combobox.List, {
|
|
279
|
+
children: items.map((item, i)=>/*#__PURE__*/ _jsx(Combobox.Item, {
|
|
280
|
+
index: i,
|
|
281
|
+
item: item,
|
|
282
|
+
children: item.label
|
|
283
|
+
}, item.value))
|
|
284
|
+
})
|
|
270
285
|
})
|
|
286
|
+
]
|
|
271
287
|
})
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
value
|
|
288
|
+
}),
|
|
289
|
+
!isValueLess && /*#__PURE__*/ _jsx(Flex, {
|
|
290
|
+
flex: "0 0 186px",
|
|
291
|
+
style: {
|
|
292
|
+
minWidth: 0
|
|
293
|
+
},
|
|
294
|
+
children: /*#__PURE__*/ _jsx(LookupValueControl, {
|
|
295
|
+
value: condition.value,
|
|
296
|
+
fieldType: fieldType,
|
|
297
|
+
lookupSource: selectedDataPoint === null || selectedDataPoint === void 0 ? void 0 : selectedDataPoint.lookupSource,
|
|
298
|
+
onChange: (value)=>onChange({
|
|
299
|
+
...condition,
|
|
300
|
+
value
|
|
301
|
+
})
|
|
287
302
|
})
|
|
288
|
-
|
|
303
|
+
})
|
|
304
|
+
]
|
|
289
305
|
}),
|
|
290
306
|
canRemove && /*#__PURE__*/ _jsx("div", {
|
|
291
307
|
style: {
|
|
292
308
|
display: 'flex',
|
|
293
309
|
alignItems: 'flex-end',
|
|
294
310
|
flexShrink: 0,
|
|
295
|
-
|
|
311
|
+
paddingBottom: 4
|
|
296
312
|
},
|
|
297
313
|
children: /*#__PURE__*/ _jsx(Button, {
|
|
298
314
|
appearance: "secondary",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/display-conditions/ConditionRow.tsx"],"sourcesContent":["import { Button, Chip, Combobox, Flex } from '@servicetitan/anvil2';\nimport TrashIcon from '@servicetitan/anvil2/assets/icons/material/round/delete.svg';\nimport { useEffect, useMemo, useState } from 'react';\nimport { FormInfo, parseFormFieldKey } from '../shared/forms';\nimport { LookupValueControl } from './LookupValueControl';\nimport { NUMBER_OPERATORS, SingleCondition, STRING_OPERATORS, VALUE_LESS_OPERATORS } from './types';\nimport type { DataPointOption, FormFieldOption } from './types';\n\nexport interface ConditionRowProps {\n canRemove: boolean;\n condition: SingleCondition;\n dataPointOptions: DataPointOption[];\n formFieldOptions: FormFieldOption[];\n forms: FormInfo[];\n onChange: (c: SingleCondition) => void;\n onFormSelect: (formId: number) => void;\n onRemove: () => void;\n}\n\ninterface OperatorOption {\n label: string;\n value: string;\n}\n\ninterface SourceOption {\n formId?: number;\n label: string;\n value: string;\n}\n\nexport function ConditionRow({\n canRemove,\n condition,\n dataPointOptions,\n formFieldOptions,\n forms,\n onChange,\n onFormSelect,\n onRemove,\n}: Readonly<ConditionRowProps>) {\n const selectedFormFieldMeta = useMemo(\n () => parseFormFieldKey(condition.dataPointKey),\n [condition.dataPointKey],\n );\n const [selectedSourceValue, setSelectedSourceValue] = useState<string>(\n selectedFormFieldMeta ? `form:${selectedFormFieldMeta.formId}` : 'schema',\n );\n\n const sourceOptions = useMemo<SourceOption[]>(\n () => [\n { label: 'Data point', value: 'schema' },\n ...forms.map(form => ({\n formId: form.id,\n label: form.name,\n value: `form:${form.id}`,\n })),\n ],\n [forms],\n );\n\n const selectedSource = useMemo<SourceOption | null>(() => {\n return (\n sourceOptions.find(opt => opt.value === selectedSourceValue) ?? sourceOptions[0] ?? null\n );\n }, [selectedSourceValue, sourceOptions]);\n\n useEffect(() => {\n if (selectedFormFieldMeta) {\n setSelectedSourceValue(`form:${selectedFormFieldMeta.formId}`);\n return;\n }\n if (!condition.dataPointKey) {\n return;\n }\n const hasSchemaMatch = dataPointOptions.some(opt => opt.fullKey === condition.dataPointKey);\n if (hasSchemaMatch) {\n setSelectedSourceValue('schema');\n }\n }, [condition.dataPointKey, dataPointOptions, selectedFormFieldMeta]);\n\n const currentFormId = selectedSource?.formId;\n const activeDataPointOptions = useMemo(\n () =>\n currentFormId\n ? formFieldOptions.filter(option => option.formId === currentFormId)\n : dataPointOptions,\n [currentFormId, dataPointOptions, formFieldOptions],\n );\n\n const selectedDataPoint = useMemo(\n () => activeDataPointOptions.find(opt => opt.fullKey === condition.dataPointKey) ?? null,\n [activeDataPointOptions, condition.dataPointKey],\n );\n\n const fieldType = selectedDataPoint?.fieldType ?? 'string';\n\n const isValueLess = VALUE_LESS_OPERATORS.includes(condition.operator);\n\n const operatorItems: OperatorOption[] = useMemo(\n () =>\n fieldType === 'number'\n ? ([...NUMBER_OPERATORS] as OperatorOption[])\n : ([...STRING_OPERATORS] as OperatorOption[]),\n [fieldType],\n );\n\n const selectedOperator = useMemo(\n () => operatorItems.find(op => op.value === condition.operator) ?? null,\n [operatorItems, condition.operator],\n );\n\n const handleDataPointChange = (item: DataPointOption | null) => {\n const nextIsNumber = item?.fieldType === 'number';\n const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;\n const operatorReset = !nextOperatorItems.some(op => op.value === condition.operator);\n onChange({\n ...condition,\n dataPointKey: item?.fullKey ?? '',\n operator: operatorReset\n ? nextIsNumber\n ? 'num_eq'\n : 'is_equal_to'\n : condition.operator,\n });\n };\n\n const handleSourceChange = (item: SourceOption | null) => {\n if (!item) {\n return;\n }\n setSelectedSourceValue(item.value);\n\n if (!item.formId) {\n const schemaField =\n dataPointOptions.find(opt => opt.fullKey === condition.dataPointKey) ?? null;\n const nextFieldType = schemaField?.fieldType ?? 'string';\n const nextIsNumber = nextFieldType === 'number';\n const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;\n const operatorReset = !nextOperatorItems.some(op => op.value === condition.operator);\n\n onChange({\n ...condition,\n dataPointKey: schemaField?.fullKey ?? '',\n operator: operatorReset\n ? nextIsNumber\n ? 'num_eq'\n : 'is_equal_to'\n : condition.operator,\n });\n return;\n }\n\n onFormSelect(item.formId);\n const nextFormFieldOptions = formFieldOptions.filter(\n option => option.formId === item.formId,\n );\n const currentSelected = nextFormFieldOptions.find(\n opt => opt.fullKey === condition.dataPointKey,\n );\n const nextSelected = currentSelected ?? nextFormFieldOptions[0] ?? null;\n const nextFieldType = nextSelected?.fieldType ?? 'string';\n const nextIsNumber = nextFieldType === 'number';\n const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;\n const operatorReset = !nextOperatorItems.some(op => op.value === condition.operator);\n\n onChange({\n ...condition,\n dataPointKey: nextSelected?.fullKey ?? '',\n operator: operatorReset\n ? nextIsNumber\n ? 'num_eq'\n : 'is_equal_to'\n : condition.operator,\n });\n };\n\n return (\n <Flex direction=\"column\" gap=\"3\" style={{ width: '100%' }}>\n <div style={{ width: '100%' }}>\n <Combobox.Select\n disableClearSelection\n itemToKey={(item: SourceOption | null) => item?.value ?? ''}\n itemToString={(item: SourceOption | null) => item?.label ?? ''}\n items={sourceOptions}\n selectedItem={selectedSource}\n onChange={handleSourceChange}\n >\n <Combobox.SelectTrigger\n label=\"Data Type\"\n placeholder=\"Select source...\"\n size=\"small\"\n />\n <Combobox.Content>\n {({ items }: { items: SourceOption[] }) => (\n <Combobox.List>\n {items.map((item, i) => (\n <Combobox.Item index={i} item={item} key={item.value}>\n {item.label}\n </Combobox.Item>\n ))}\n </Combobox.List>\n )}\n </Combobox.Content>\n </Combobox.Select>\n </div>\n <Flex\n direction=\"row\"\n alignItems=\"flex-end\"\n gap=\"2\"\n style={{ flexWrap: 'wrap', rowGap: 8, width: '100%' }}\n >\n <div\n style={{\n display: 'flex',\n alignItems: 'flex-end',\n flexShrink: 0,\n padding: '4px 8px',\n }}\n >\n <Chip label=\"IF\" size=\"small\" />\n </div>\n <Flex flex={1} style={{ minWidth: 160 }}>\n <Combobox.Select\n flex={1}\n style={{ width: '100%' }}\n disableClearSelection\n itemToKey={(item: DataPointOption | null) => item?.fullKey ?? ''}\n itemToString={(item: DataPointOption | null) => item?.title ?? ''}\n items={activeDataPointOptions}\n selectedItem={selectedDataPoint}\n onChange={handleDataPointChange}\n >\n <Combobox.SelectTrigger\n label=\"Data Point\"\n placeholder={\n currentFormId ? 'Select form field...' : 'Select data point...'\n }\n size=\"small\"\n />\n <Combobox.Content>\n {({ items }: { items: DataPointOption[] }) => (\n <Combobox.List>\n {items.map((item, i) => (\n <Combobox.Item index={i} item={item} key={item.fullKey}>\n {item.title}\n </Combobox.Item>\n ))}\n </Combobox.List>\n )}\n </Combobox.Content>\n </Combobox.Select>\n </Flex>\n <Flex flex={1} style={{ minWidth: 160 }}>\n <Combobox.Select\n flex={1}\n style={{ width: '100%' }}\n disableClearSelection\n itemToKey={(item: OperatorOption | null) => item?.value ?? ''}\n itemToString={(item: OperatorOption | null) => item?.label ?? ''}\n items={operatorItems}\n selectedItem={selectedOperator}\n onChange={(item: OperatorOption | null) =>\n onChange({\n ...condition,\n operator: (item?.value ??\n 'is_equal_to') as SingleCondition['operator'],\n })\n }\n >\n <Combobox.SelectTrigger\n label=\"Condition\"\n placeholder=\"Select...\"\n size=\"small\"\n />\n <Combobox.Content>\n {({ items }: { items: OperatorOption[] }) => (\n <Combobox.List>\n {items.map((item, i) => (\n <Combobox.Item index={i} item={item} key={item.value}>\n {item.label}\n </Combobox.Item>\n ))}\n </Combobox.List>\n )}\n </Combobox.Content>\n </Combobox.Select>\n </Flex>\n {!isValueLess && (\n <Flex flex={1} style={{ minWidth: 160 }}>\n <LookupValueControl\n value={condition.value}\n fieldType={fieldType}\n lookupSource={selectedDataPoint?.lookupSource}\n onChange={value => onChange({ ...condition, value })}\n />\n </Flex>\n )}\n {canRemove && (\n <div\n style={{\n display: 'flex',\n alignItems: 'flex-end',\n flexShrink: 0,\n padding: '4px 8px',\n }}\n >\n <Button\n appearance=\"secondary\"\n aria-label=\"Remove condition\"\n icon={{ before: TrashIcon }}\n size=\"small\"\n onClick={onRemove}\n />\n </div>\n )}\n </Flex>\n </Flex>\n );\n}\n"],"names":["Button","Chip","Combobox","Flex","TrashIcon","useEffect","useMemo","useState","parseFormFieldKey","LookupValueControl","NUMBER_OPERATORS","STRING_OPERATORS","VALUE_LESS_OPERATORS","ConditionRow","canRemove","condition","dataPointOptions","formFieldOptions","forms","onChange","onFormSelect","onRemove","selectedFormFieldMeta","dataPointKey","selectedSourceValue","setSelectedSourceValue","formId","sourceOptions","label","value","map","form","id","name","selectedSource","find","opt","hasSchemaMatch","some","fullKey","currentFormId","activeDataPointOptions","filter","option","selectedDataPoint","fieldType","isValueLess","includes","operator","operatorItems","selectedOperator","op","handleDataPointChange","item","nextIsNumber","nextOperatorItems","operatorReset","handleSourceChange","currentSelected","schemaField","nextFieldType","nextFormFieldOptions","nextSelected","direction","gap","style","width","div","Select","disableClearSelection","itemToKey","itemToString","items","selectedItem","SelectTrigger","placeholder","size","Content","List","i","Item","index","alignItems","flexWrap","rowGap","display","flexShrink","padding","flex","minWidth","title","lookupSource","appearance","aria-label","icon","before","onClick"],"mappings":";AAAA,SAASA,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,IAAI,QAAQ,uBAAuB;AACpE,OAAOC,eAAe,8DAA8D;AACpF,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACrD,SAAmBC,iBAAiB,QAA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C3B,SAASwE,aAAa;oCACnB9C,OAAM;oCACN+C,aAAY;oCACZC,MAAK;;8CAET,KAAC1E,SAAS2E,OAAO;8CACZ,CAAC,EAAEL,KAAK,EAA+B,iBACpC,KAACtE,SAAS4E,IAAI;sDACTN,MAAM1C,GAAG,CAAC,CAACuB,MAAM0B,kBACd,KAAC7E,SAAS8E,IAAI;oDAACC,OAAOF;oDAAG1B,MAAMA;8DAC1BA,KAAKzB,KAAK;mDAD2ByB,KAAKxB,KAAK;;;;;;oBAS3E,CAACiB,6BACE,KAAC3C;wBAAKqF,MAAM;wBAAGvB,OAAO;4BAAEwB,UAAU;wBAAI;kCAClC,cAAA,KAAChF;4BACGoB,OAAOd,UAAUc,KAAK;4BACtBgB,WAAWA;4BACX8C,YAAY,EAAE/C,8BAAAA,wCAAAA,kBAAmB+C,YAAY;4BAC7CxE,UAAUU,CAAAA,QAASV,SAAS;oCAAE,GAAGJ,SAAS;oCAAEc;gCAAM;;;oBAI7Df,2BACG,KAACqD;wBACGF,OAAO;4BACHoB,SAAS;4BACTH,YAAY;4BACZI,YAAY;4BACZC,SAAS;wBACb;kCAEA,cAAA,KAACvF;4BACG4F,YAAW;4BACXC,cAAW;4BACXC,MAAM;gCAAEC,QAAQ3F;4BAAU;4BAC1BwE,MAAK;4BACLoB,SAAS3E;;;;;;;AAOrC"}
|
|
1
|
+
{"version":3,"sources":["../../src/display-conditions/ConditionRow.tsx"],"sourcesContent":["import { Button, Chip, Combobox, Flex } from '@servicetitan/anvil2';\nimport TrashIcon from '@servicetitan/anvil2/assets/icons/material/round/delete.svg';\nimport { useEffect, useMemo, useState } from 'react';\nimport { FormInfo, parseFormFieldKey } from '../shared/forms';\nimport { LookupValueControl } from './LookupValueControl';\nimport { NUMBER_OPERATORS, SingleCondition, STRING_OPERATORS, VALUE_LESS_OPERATORS } from './types';\nimport type { DataPointOption, FormFieldOption } from './types';\n\nexport interface ConditionRowProps {\n canRemove: boolean;\n condition: SingleCondition;\n dataPointOptions: DataPointOption[];\n formFieldOptions: FormFieldOption[];\n forms: FormInfo[];\n onChange: (c: SingleCondition) => void;\n onFormSelect: (formId: number) => void;\n onRemove: () => void;\n}\n\ninterface OperatorOption {\n label: string;\n value: string;\n}\n\ninterface SourceOption {\n formId?: number;\n label: string;\n value: string;\n}\n\nexport function ConditionRow({\n canRemove,\n condition,\n dataPointOptions,\n formFieldOptions,\n forms,\n onChange,\n onFormSelect,\n onRemove,\n}: Readonly<ConditionRowProps>) {\n const selectedFormFieldMeta = useMemo(\n () => parseFormFieldKey(condition.dataPointKey),\n [condition.dataPointKey],\n );\n const [selectedSourceValue, setSelectedSourceValue] = useState<string>(\n selectedFormFieldMeta ? `form:${selectedFormFieldMeta.formId}` : 'schema',\n );\n\n const sourceOptions = useMemo<SourceOption[]>(\n () => [\n { label: 'Data point', value: 'schema' },\n ...forms.map(form => ({\n formId: form.id,\n label: form.name,\n value: `form:${form.id}`,\n })),\n ],\n [forms],\n );\n\n const selectedSource = useMemo<SourceOption | null>(() => {\n return (\n sourceOptions.find(opt => opt.value === selectedSourceValue) ?? sourceOptions[0] ?? null\n );\n }, [selectedSourceValue, sourceOptions]);\n\n useEffect(() => {\n if (selectedFormFieldMeta) {\n setSelectedSourceValue(`form:${selectedFormFieldMeta.formId}`);\n return;\n }\n if (!condition.dataPointKey) {\n return;\n }\n const hasSchemaMatch = dataPointOptions.some(opt => opt.fullKey === condition.dataPointKey);\n if (hasSchemaMatch) {\n setSelectedSourceValue('schema');\n }\n }, [condition.dataPointKey, dataPointOptions, selectedFormFieldMeta]);\n\n const currentFormId = selectedSource?.formId;\n const activeDataPointOptions = useMemo(\n () =>\n currentFormId\n ? formFieldOptions.filter(option => option.formId === currentFormId)\n : dataPointOptions,\n [currentFormId, dataPointOptions, formFieldOptions],\n );\n\n const selectedDataPoint = useMemo(\n () => activeDataPointOptions.find(opt => opt.fullKey === condition.dataPointKey) ?? null,\n [activeDataPointOptions, condition.dataPointKey],\n );\n\n const fieldType = selectedDataPoint?.fieldType ?? 'string';\n\n const isValueLess = VALUE_LESS_OPERATORS.includes(condition.operator);\n\n const operatorItems: OperatorOption[] = useMemo(\n () =>\n fieldType === 'number'\n ? ([...NUMBER_OPERATORS] as OperatorOption[])\n : ([...STRING_OPERATORS] as OperatorOption[]),\n [fieldType],\n );\n\n const selectedOperator = useMemo(\n () => operatorItems.find(op => op.value === condition.operator) ?? null,\n [operatorItems, condition.operator],\n );\n\n const handleDataPointChange = (item: DataPointOption | null) => {\n const nextIsNumber = item?.fieldType === 'number';\n const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;\n const operatorReset = !nextOperatorItems.some(op => op.value === condition.operator);\n onChange({\n ...condition,\n dataPointKey: item?.fullKey ?? '',\n operator: operatorReset\n ? nextIsNumber\n ? 'num_eq'\n : 'is_equal_to'\n : condition.operator,\n });\n };\n\n const handleSourceChange = (item: SourceOption | null) => {\n if (!item) {\n return;\n }\n setSelectedSourceValue(item.value);\n\n if (!item.formId) {\n const schemaField =\n dataPointOptions.find(opt => opt.fullKey === condition.dataPointKey) ?? null;\n const nextFieldType = schemaField?.fieldType ?? 'string';\n const nextIsNumber = nextFieldType === 'number';\n const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;\n const operatorReset = !nextOperatorItems.some(op => op.value === condition.operator);\n\n onChange({\n ...condition,\n dataPointKey: schemaField?.fullKey ?? '',\n operator: operatorReset\n ? nextIsNumber\n ? 'num_eq'\n : 'is_equal_to'\n : condition.operator,\n });\n return;\n }\n\n onFormSelect(item.formId);\n const nextFormFieldOptions = formFieldOptions.filter(\n option => option.formId === item.formId,\n );\n const currentSelected = nextFormFieldOptions.find(\n opt => opt.fullKey === condition.dataPointKey,\n );\n const nextSelected = currentSelected ?? nextFormFieldOptions[0] ?? null;\n const nextFieldType = nextSelected?.fieldType ?? 'string';\n const nextIsNumber = nextFieldType === 'number';\n const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;\n const operatorReset = !nextOperatorItems.some(op => op.value === condition.operator);\n\n onChange({\n ...condition,\n dataPointKey: nextSelected?.fullKey ?? '',\n operator: operatorReset\n ? nextIsNumber\n ? 'num_eq'\n : 'is_equal_to'\n : condition.operator,\n });\n };\n\n return (\n <Flex direction=\"column\" gap=\"3\" style={{ width: '100%' }}>\n <div style={{ width: '100%' }}>\n <Combobox.Select\n flex={1}\n style={{ width: '100%' }}\n disableClearSelection\n itemToKey={(item: SourceOption | null) => item?.value ?? ''}\n itemToString={(item: SourceOption | null) => item?.label ?? ''}\n items={sourceOptions}\n selectedItem={selectedSource}\n onChange={handleSourceChange}\n >\n <Combobox.SelectTrigger\n label=\"Data Type\"\n placeholder=\"Select source...\"\n size=\"small\"\n />\n <Combobox.Content>\n {({ items }: { items: SourceOption[] }) => (\n <Combobox.List>\n {items.map((item, i) => (\n <Combobox.Item index={i} item={item} key={item.value}>\n {item.label}\n </Combobox.Item>\n ))}\n </Combobox.List>\n )}\n </Combobox.Content>\n </Combobox.Select>\n </div>\n <Flex direction=\"row\" alignItems=\"flex-end\" gap=\"2\" style={{ width: '100%' }}>\n <div\n style={{\n display: 'flex',\n alignItems: 'flex-end',\n flexShrink: 0,\n padding: '4px 8px',\n }}\n >\n <Chip label=\"IF\" size=\"small\" />\n </div>\n <Flex\n flex={1}\n direction=\"row\"\n alignItems=\"flex-end\"\n gap=\"2\"\n style={{ minWidth: 0, width: '100%' }}\n >\n <Flex flex={1} style={{ minWidth: 0, width: '100%' }}>\n <Combobox.Select\n flex={1}\n style={{ width: '100%' }}\n disableClearSelection\n itemToKey={(item: DataPointOption | null) => item?.fullKey ?? ''}\n itemToString={(item: DataPointOption | null) => item?.title ?? ''}\n items={activeDataPointOptions}\n selectedItem={selectedDataPoint}\n onChange={handleDataPointChange}\n >\n <Combobox.SelectTrigger\n label=\"Data Point\"\n placeholder={\n currentFormId ? 'Select form field...' : 'Select data point...'\n }\n size=\"small\"\n />\n <Combobox.Content>\n {({ items }: { items: DataPointOption[] }) => (\n <Combobox.List>\n {items.map((item, i) => (\n <Combobox.Item index={i} item={item} key={item.fullKey}>\n {item.title}\n </Combobox.Item>\n ))}\n </Combobox.List>\n )}\n </Combobox.Content>\n </Combobox.Select>\n </Flex>\n <Flex flex={1} style={{ minWidth: 0, width: '100%' }}>\n <Combobox.Select\n flex={1}\n style={{ width: '100%' }}\n disableClearSelection\n itemToKey={(item: OperatorOption | null) => item?.value ?? ''}\n itemToString={(item: OperatorOption | null) => item?.label ?? ''}\n items={operatorItems}\n selectedItem={selectedOperator}\n onChange={(item: OperatorOption | null) =>\n onChange({\n ...condition,\n operator: (item?.value ??\n 'is_equal_to') as SingleCondition['operator'],\n })\n }\n >\n <Combobox.SelectTrigger\n label=\"Condition\"\n placeholder=\"Select...\"\n size=\"small\"\n />\n <Combobox.Content>\n {({ items }: { items: OperatorOption[] }) => (\n <Combobox.List>\n {items.map((item, i) => (\n <Combobox.Item index={i} item={item} key={item.value}>\n {item.label}\n </Combobox.Item>\n ))}\n </Combobox.List>\n )}\n </Combobox.Content>\n </Combobox.Select>\n </Flex>\n {!isValueLess && (\n <Flex flex=\"0 0 186px\" style={{ minWidth: 0 }}>\n <LookupValueControl\n value={condition.value}\n fieldType={fieldType}\n lookupSource={selectedDataPoint?.lookupSource}\n onChange={value => onChange({ ...condition, value })}\n />\n </Flex>\n )}\n </Flex>\n {canRemove && (\n <div\n style={{\n display: 'flex',\n alignItems: 'flex-end',\n flexShrink: 0,\n paddingBottom: 4,\n }}\n >\n <Button\n appearance=\"secondary\"\n aria-label=\"Remove condition\"\n icon={{ before: TrashIcon }}\n size=\"small\"\n onClick={onRemove}\n />\n </div>\n )}\n </Flex>\n </Flex>\n );\n}\n"],"names":["Button","Chip","Combobox","Flex","TrashIcon","useEffect","useMemo","useState","parseFormFieldKey","LookupValueControl","NUMBER_OPERATORS","STRING_OPERATORS","VALUE_LESS_OPERATORS","ConditionRow","canRemove","condition","dataPointOptions","formFieldOptions","forms","onChange","onFormSelect","onRemove","selectedFormFieldMeta","dataPointKey","selectedSourceValue","setSelectedSourceValue","formId","sourceOptions","label","value","map","form","id","name","selectedSource","find","opt","hasSchemaMatch","some","fullKey","currentFormId","activeDataPointOptions","filter","option","selectedDataPoint","fieldType","isValueLess","includes","operator","operatorItems","selectedOperator","op","handleDataPointChange","item","nextIsNumber","nextOperatorItems","operatorReset","handleSourceChange","currentSelected","schemaField","nextFieldType","nextFormFieldOptions","nextSelected","direction","gap","style","width","div","Select","flex","disableClearSelection","itemToKey","itemToString","items","selectedItem","SelectTrigger","placeholder","size","Content","List","i","Item","index","alignItems","display","flexShrink","padding","minWidth","title","lookupSource","paddingBottom","appearance","aria-label","icon","before","onClick"],"mappings":";AAAA,SAASA,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,IAAI,QAAQ,uBAAuB;AACpE,OAAOC,eAAe,8DAA8D;AACpF,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACrD,SAAmBC,iBAAiB,QAAQ,kBAAkB;AAC9D,SAASC,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,gBAAgB,EAAmBC,gBAAgB,EAAEC,oBAAoB,QAAQ,UAAU;AAyBpG,OAAO,SAASC,aAAa,EACzBC,SAAS,EACTC,SAAS,EACTC,gBAAgB,EAChBC,gBAAgB,EAChBC,KAAK,EACLC,QAAQ,EACRC,YAAY,EACZC,QAAQ,EACkB;;IAC1B,MAAMC,wBAAwBhB,QAC1B,IAAME,kBAAkBO,UAAUQ,YAAY,GAC9C;QAACR,UAAUQ,YAAY;KAAC;IAE5B,MAAM,CAACC,qBAAqBC,uBAAuB,GAAGlB,SAClDe,wBAAwB,CAAC,KAAK,EAAEA,sBAAsBI,MAAM,EAAE,GAAG;IAGrE,MAAMC,gBAAgBrB,QAClB,IAAM;YACF;gBAAEsB,OAAO;gBAAcC,OAAO;YAAS;eACpCX,MAAMY,GAAG,CAACC,CAAAA,OAAS,CAAA;oBAClBL,QAAQK,K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GoB,OAAOd,UAAUc,KAAK;oCACtBgB,WAAWA;oCACX4C,YAAY,EAAE7C,8BAAAA,wCAAAA,kBAAmB6C,YAAY;oCAC7CtE,UAAUU,CAAAA,QAASV,SAAS;4CAAE,GAAGJ,SAAS;4CAAEc;wCAAM;;;;;oBAKjEf,2BACG,KAACqD;wBACGF,OAAO;4BACHmB,SAAS;4BACTD,YAAY;4BACZE,YAAY;4BACZK,eAAe;wBACnB;kCAEA,cAAA,KAAC1F;4BACG2F,YAAW;4BACXC,cAAW;4BACXC,MAAM;gCAAEC,QAAQ1F;4BAAU;4BAC1ByE,MAAK;4BACLkB,SAAS1E;;;;;;;AAOrC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConditionalsOpenHandler, ConditionFormSelectHandler } from './useConditionForms';
|
|
2
2
|
export interface DisplayConditionModalProps {
|
|
3
3
|
/**
|
|
4
4
|
* Optional portal target. Prefer leaving unset so the dialog stays under the host
|
|
@@ -6,8 +6,8 @@ export interface DisplayConditionModalProps {
|
|
|
6
6
|
* content is wrapped in `ThemeProvider` so Anvil2 styles still apply after portaling.
|
|
7
7
|
*/
|
|
8
8
|
portalContainer?: Element | DocumentFragment | null;
|
|
9
|
-
onConditionFormSelect?:
|
|
10
|
-
onConditionalsOpen?:
|
|
9
|
+
onConditionFormSelect?: ConditionFormSelectHandler;
|
|
10
|
+
onConditionalsOpen?: ConditionalsOpenHandler;
|
|
11
11
|
schema?: import('../shared/schema').SchemaObject;
|
|
12
12
|
}
|
|
13
13
|
export declare const DisplayConditionModal: (props: DisplayConditionModalProps) => import("react").JSX.Element | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayConditionModal.d.ts","sourceRoot":"","sources":["../../src/display-conditions/DisplayConditionModal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DisplayConditionModal.d.ts","sourceRoot":"","sources":["../../src/display-conditions/DisplayConditionModal.tsx"],"names":[],"mappings":"AAcA,OAAO,EACH,uBAAuB,EACvB,0BAA0B,EAE7B,MAAM,qBAAqB,CAAC;AAuC7B,MAAM,WAAW,0BAA0B;IACvC;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAAC;IACpD,qBAAqB,CAAC,EAAE,0BAA0B,CAAC;IACnD,kBAAkB,CAAC,EAAE,uBAAuB,CAAC;IAC7C,MAAM,CAAC,EAAE,OAAO,kBAAkB,EAAE,YAAY,CAAC;CACpD;AAED,eAAO,MAAM,qBAAqB,GAAI,OAAO,0BAA0B,uCAwNtE,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Button, Combobox, Dialog, Flex, Text, ThemeProvider } from '@servicetitan/anvil2';
|
|
3
|
-
import { useCallback, useEffect, useMemo,
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
|
-
import { buildFormFieldKey, getConditionalFieldTypeFromFormItemType, parseFormFieldKey } from '../shared/forms';
|
|
6
5
|
import { ConditionGroupsSection } from './ConditionGroupsSection';
|
|
7
6
|
import { defaultState, MODAL_CONTENT_MAX_HEIGHT } from './constants';
|
|
8
7
|
import { onDisplayCondition } from './displayConditionController';
|
|
9
8
|
import { buildUnlayerDisplayCondition, parseUnlayerDisplayCondition } from './nunjucks';
|
|
10
9
|
import { getSchemaDataPointOptions } from './schemaDataPoints';
|
|
10
|
+
import { useConditionForms } from './useConditionForms';
|
|
11
11
|
const BEHAVIOR_OPTIONS = [
|
|
12
12
|
{
|
|
13
13
|
label: 'Show',
|
|
@@ -51,40 +51,13 @@ export const DisplayConditionModal = (props)=>{
|
|
|
51
51
|
const [isOpen, setIsOpen] = useState(false);
|
|
52
52
|
const [state, setState] = useState(defaultState);
|
|
53
53
|
const [matchType, setMatchType] = useState('all');
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const formFieldsByFormIdRef = useRef({});
|
|
59
|
-
const loadingFormIdsRef = useRef([]);
|
|
54
|
+
const { formFieldOptions, forms, isFieldDataLoading, loadForms, requestFormFields } = useConditionForms({
|
|
55
|
+
onConditionFormSelect,
|
|
56
|
+
onConditionalsOpen
|
|
57
|
+
});
|
|
60
58
|
const dataPointOptions = useMemo(()=>getSchemaDataPointOptions(schema), [
|
|
61
59
|
schema
|
|
62
60
|
]);
|
|
63
|
-
const formFieldOptions = useMemo(()=>{
|
|
64
|
-
const nextOptions = [];
|
|
65
|
-
for (const form of forms){
|
|
66
|
-
const fields = formFieldsByFormId[form.id];
|
|
67
|
-
if (!fields) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
for (const field of fields){
|
|
71
|
-
const fieldType = getConditionalFieldTypeFromFormItemType(field.itemType);
|
|
72
|
-
if (!fieldType) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
nextOptions.push({
|
|
76
|
-
fieldType,
|
|
77
|
-
formId: form.id,
|
|
78
|
-
fullKey: buildFormFieldKey(form.id, field.id),
|
|
79
|
-
title: field.header
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return nextOptions.sort((left, right)=>left.title.localeCompare(right.title));
|
|
84
|
-
}, [
|
|
85
|
-
forms,
|
|
86
|
-
formFieldsByFormId
|
|
87
|
-
]);
|
|
88
61
|
const allFieldOptions = useMemo(()=>[
|
|
89
62
|
...dataPointOptions,
|
|
90
63
|
...formFieldOptions
|
|
@@ -92,79 +65,19 @@ export const DisplayConditionModal = (props)=>{
|
|
|
92
65
|
dataPointOptions,
|
|
93
66
|
formFieldOptions
|
|
94
67
|
]);
|
|
95
|
-
const isFieldDataLoading = isFormsListLoading || loadingFormIds.length > 0;
|
|
96
|
-
useEffect(()=>{
|
|
97
|
-
formFieldsByFormIdRef.current = formFieldsByFormId;
|
|
98
|
-
}, [
|
|
99
|
-
formFieldsByFormId
|
|
100
|
-
]);
|
|
101
|
-
useEffect(()=>{
|
|
102
|
-
loadingFormIdsRef.current = loadingFormIds;
|
|
103
|
-
}, [
|
|
104
|
-
loadingFormIds
|
|
105
|
-
]);
|
|
106
|
-
const requestFormFields = useCallback((formId)=>{
|
|
107
|
-
if (!onConditionFormSelect) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (formFieldsByFormIdRef.current[formId] || loadingFormIdsRef.current.includes(formId)) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
setLoadingFormIds((prev)=>prev.includes(formId) ? prev : [
|
|
114
|
-
...prev,
|
|
115
|
-
formId
|
|
116
|
-
]);
|
|
117
|
-
onConditionFormSelect(formId, (selectedFormId, fields)=>{
|
|
118
|
-
setFormFieldsByFormId((prev)=>({
|
|
119
|
-
...prev,
|
|
120
|
-
[selectedFormId]: fields
|
|
121
|
-
}));
|
|
122
|
-
setLoadingFormIds((prev)=>prev.filter((id)=>id !== selectedFormId));
|
|
123
|
-
});
|
|
124
|
-
}, [
|
|
125
|
-
onConditionFormSelect
|
|
126
|
-
]);
|
|
127
68
|
useEffect(()=>{
|
|
128
69
|
return onDisplayCondition((nextRequest)=>{
|
|
129
70
|
setRequest(nextRequest);
|
|
130
71
|
const existing = nextRequest.data;
|
|
131
72
|
const parsed = parseUnlayerDisplayCondition(existing);
|
|
132
73
|
const initialState = parsed !== null && parsed !== void 0 ? parsed : defaultState();
|
|
133
|
-
|
|
134
|
-
var _parseFormFieldKey;
|
|
135
|
-
return (_parseFormFieldKey = parseFormFieldKey(condition.dataPointKey)) === null || _parseFormFieldKey === void 0 ? void 0 : _parseFormFieldKey.formId;
|
|
136
|
-
}).filter((formId)=>formId != null)));
|
|
137
|
-
setForms([]);
|
|
138
|
-
setFormFieldsByFormId({});
|
|
139
|
-
setIsFormsListLoading(!!onConditionalsOpen);
|
|
140
|
-
setLoadingFormIds([]);
|
|
141
|
-
if (onConditionalsOpen) {
|
|
142
|
-
onConditionalsOpen(usedFormIds, (nextForms)=>{
|
|
143
|
-
setForms(nextForms);
|
|
144
|
-
setIsFormsListLoading(false);
|
|
145
|
-
}, (formId, fields)=>{
|
|
146
|
-
setFormFieldsByFormId((prev)=>({
|
|
147
|
-
...prev,
|
|
148
|
-
[formId]: fields
|
|
149
|
-
}));
|
|
150
|
-
setLoadingFormIds((prev)=>prev.filter((id)=>id !== formId));
|
|
151
|
-
});
|
|
152
|
-
/*
|
|
153
|
-
* Keep display-condition flow aligned with calculated-field flow:
|
|
154
|
-
* when modal opens, request fields for already-used forms so labels
|
|
155
|
-
* are available in edit mode.
|
|
156
|
-
*/ usedFormIds.forEach((formId)=>requestFormFields(formId));
|
|
157
|
-
} else {
|
|
158
|
-
setIsFormsListLoading(false);
|
|
159
|
-
setLoadingFormIds([]);
|
|
160
|
-
}
|
|
74
|
+
loadForms(initialState.groups);
|
|
161
75
|
setState(initialState);
|
|
162
76
|
setMatchType(deriveMatchType(initialState));
|
|
163
77
|
setIsOpen(true);
|
|
164
78
|
});
|
|
165
79
|
}, [
|
|
166
|
-
|
|
167
|
-
requestFormFields
|
|
80
|
+
loadForms
|
|
168
81
|
]);
|
|
169
82
|
const handleClose = useCallback(()=>{
|
|
170
83
|
setRequest(null);
|