@servicetitan/dte-unlayer 0.141.0 → 0.143.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 +28 -114
- package/dist/display-conditions/ConditionRow.js.map +1 -1
- package/dist/display-conditions/LookupValueControl.d.ts +19 -0
- package/dist/display-conditions/LookupValueControl.d.ts.map +1 -0
- package/dist/display-conditions/LookupValueControl.js +158 -0
- package/dist/display-conditions/LookupValueControl.js.map +1 -0
- package/dist/display-conditions/lookupOptionsController.d.ts +29 -7
- package/dist/display-conditions/lookupOptionsController.d.ts.map +1 -1
- package/dist/display-conditions/lookupOptionsController.js +10 -7
- package/dist/display-conditions/lookupOptionsController.js.map +1 -1
- package/dist/display-conditions/useLookupOptions.d.ts +24 -8
- package/dist/display-conditions/useLookupOptions.d.ts.map +1 -1
- package/dist/display-conditions/useLookupOptions.js +63 -10
- package/dist/display-conditions/useLookupOptions.js.map +1 -1
- package/package.json +1 -1
- package/src/display-conditions/ConditionRow.tsx +18 -99
- package/src/display-conditions/LookupValueControl.tsx +175 -0
- package/src/display-conditions/lookupOptionsController.ts +29 -10
- package/src/display-conditions/useLookupOptions.ts +78 -15
|
@@ -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,EAA0C,MAAM,SAAS,CAAC;AACpG,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
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,EAA0C,MAAM,SAAS,CAAC;AACpG,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEhE,MAAM,WAAW,iBAAiB;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,eAAe,CAAC;IAC3B,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IACvC,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,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,2CAuR7B"}
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, Chip, Combobox, Flex
|
|
2
|
+
import { Button, Chip, Combobox, Flex } from '@servicetitan/anvil2';
|
|
3
3
|
import TrashIcon from '@servicetitan/anvil2/assets/icons/material/round/delete.svg';
|
|
4
4
|
import { useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import { parseFormFieldKey } from '../shared/forms';
|
|
6
|
+
import { LookupValueControl } from './LookupValueControl';
|
|
6
7
|
import { NUMBER_OPERATORS, STRING_OPERATORS, VALUE_LESS_OPERATORS } from './types';
|
|
7
|
-
import { useLookupOptions } from './useLookupOptions';
|
|
8
|
-
function sanitizeNumericInput(raw) {
|
|
9
|
-
// Allow only a single leading minus and one decimal separator.
|
|
10
|
-
let value = raw.replaceAll(/[^0-9.-]/g, '');
|
|
11
|
-
const isNegative = value.startsWith('-');
|
|
12
|
-
value = value.replaceAll('-', '');
|
|
13
|
-
if (isNegative) {
|
|
14
|
-
value = `-${value}`;
|
|
15
|
-
}
|
|
16
|
-
const firstDot = value.indexOf('.');
|
|
17
|
-
if (firstDot >= 0) {
|
|
18
|
-
value = `${value.slice(0, firstDot + 1)}${value.slice(firstDot + 1).replaceAll('.', '')}`;
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
8
|
export function ConditionRow({ canRemove, condition, dataPointOptions, formFieldOptions, forms, onChange, onFormSelect, onRemove }) {
|
|
23
9
|
const selectedFormFieldMeta = useMemo(()=>parseFormFieldKey(condition.dataPointKey), [
|
|
24
10
|
condition.dataPointKey
|
|
@@ -77,15 +63,6 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
77
63
|
var _selectedDataPoint_fieldType;
|
|
78
64
|
const fieldType = (_selectedDataPoint_fieldType = selectedDataPoint === null || selectedDataPoint === void 0 ? void 0 : selectedDataPoint.fieldType) !== null && _selectedDataPoint_fieldType !== void 0 ? _selectedDataPoint_fieldType : 'string';
|
|
79
65
|
const isValueLess = VALUE_LESS_OPERATORS.includes(condition.operator);
|
|
80
|
-
// Value-less operators (is empty / is not empty) need no value, so skip the host lookup.
|
|
81
|
-
const { options: lookupOptions, status: lookupStatus } = useLookupOptions(isValueLess ? undefined : selectedDataPoint === null || selectedDataPoint === void 0 ? void 0 : selectedDataPoint.lookupSource);
|
|
82
|
-
const selectedLookupOption = useMemo(()=>{
|
|
83
|
-
var _lookupOptions_find;
|
|
84
|
-
return (_lookupOptions_find = lookupOptions.find((opt)=>opt.key === condition.value)) !== null && _lookupOptions_find !== void 0 ? _lookupOptions_find : null;
|
|
85
|
-
}, [
|
|
86
|
-
lookupOptions,
|
|
87
|
-
condition.value
|
|
88
|
-
]);
|
|
89
66
|
const operatorItems = useMemo(()=>fieldType === 'number' ? [
|
|
90
67
|
...NUMBER_OPERATORS
|
|
91
68
|
] : [
|
|
@@ -100,85 +77,6 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
100
77
|
operatorItems,
|
|
101
78
|
condition.operator
|
|
102
79
|
]);
|
|
103
|
-
const handleValueChange = (raw)=>{
|
|
104
|
-
const value = fieldType === 'number' ? sanitizeNumericInput(raw) : raw;
|
|
105
|
-
onChange({
|
|
106
|
-
...condition,
|
|
107
|
-
value
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
const renderValueControl = ()=>{
|
|
111
|
-
if (lookupStatus === 'loading') {
|
|
112
|
-
return /*#__PURE__*/ _jsx(TextField, {
|
|
113
|
-
disabled: true,
|
|
114
|
-
label: "Value",
|
|
115
|
-
size: "small",
|
|
116
|
-
value: "",
|
|
117
|
-
placeholder: "",
|
|
118
|
-
style: {
|
|
119
|
-
width: '100%'
|
|
120
|
-
},
|
|
121
|
-
"aria-label": "Value"
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
if (lookupStatus === 'ready') {
|
|
125
|
-
return /*#__PURE__*/ _jsxs(Combobox, {
|
|
126
|
-
itemToKey: (item)=>{
|
|
127
|
-
var _item_key;
|
|
128
|
-
return (_item_key = item === null || item === void 0 ? void 0 : item.key) !== null && _item_key !== void 0 ? _item_key : '';
|
|
129
|
-
},
|
|
130
|
-
itemToString: (item)=>{
|
|
131
|
-
var _item_label;
|
|
132
|
-
return (_item_label = item === null || item === void 0 ? void 0 : item.label) !== null && _item_label !== void 0 ? _item_label : '';
|
|
133
|
-
},
|
|
134
|
-
items: lookupOptions,
|
|
135
|
-
selectedItem: selectedLookupOption,
|
|
136
|
-
onChange: (item)=>{
|
|
137
|
-
var _item_key;
|
|
138
|
-
return onChange({
|
|
139
|
-
...condition,
|
|
140
|
-
value: (_item_key = item === null || item === void 0 ? void 0 : item.key) !== null && _item_key !== void 0 ? _item_key : ''
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
filterOptions: {
|
|
144
|
-
keys: [
|
|
145
|
-
'label'
|
|
146
|
-
]
|
|
147
|
-
},
|
|
148
|
-
children: [
|
|
149
|
-
/*#__PURE__*/ _jsx(Combobox.SearchField, {
|
|
150
|
-
label: "Value",
|
|
151
|
-
placeholder: "Search value...",
|
|
152
|
-
size: "small"
|
|
153
|
-
}),
|
|
154
|
-
/*#__PURE__*/ _jsx(Combobox.Content, {
|
|
155
|
-
children: ({ items })=>/*#__PURE__*/ _jsx(Combobox.List, {
|
|
156
|
-
children: items.map((item, i)=>/*#__PURE__*/ _jsx(Combobox.Item, {
|
|
157
|
-
index: i,
|
|
158
|
-
item: item,
|
|
159
|
-
children: item.label
|
|
160
|
-
}, item.key))
|
|
161
|
-
})
|
|
162
|
-
})
|
|
163
|
-
]
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
// idle / fallback (empty/error/timeout) -> never block the user.
|
|
167
|
-
return /*#__PURE__*/ _jsx(TextField, {
|
|
168
|
-
label: "Value",
|
|
169
|
-
size: "small",
|
|
170
|
-
value: condition.value,
|
|
171
|
-
onChange: (e)=>handleValueChange(e.target.value),
|
|
172
|
-
placeholder: fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...',
|
|
173
|
-
style: {
|
|
174
|
-
width: '100%'
|
|
175
|
-
},
|
|
176
|
-
"aria-label": "Value",
|
|
177
|
-
...fieldType === 'number' && {
|
|
178
|
-
inputMode: 'decimal'
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
80
|
const handleDataPointChange = (item)=>{
|
|
183
81
|
const nextIsNumber = (item === null || item === void 0 ? void 0 : item.fieldType) === 'number';
|
|
184
82
|
const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;
|
|
@@ -292,12 +190,16 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
292
190
|
size: "small"
|
|
293
191
|
})
|
|
294
192
|
}),
|
|
295
|
-
/*#__PURE__*/ _jsx(
|
|
193
|
+
/*#__PURE__*/ _jsx(Flex, {
|
|
194
|
+
flex: 1,
|
|
296
195
|
style: {
|
|
297
|
-
|
|
298
|
-
minWidth: 200
|
|
196
|
+
minWidth: 160
|
|
299
197
|
},
|
|
300
198
|
children: /*#__PURE__*/ _jsxs(Combobox.Select, {
|
|
199
|
+
flex: 1,
|
|
200
|
+
style: {
|
|
201
|
+
width: '100%'
|
|
202
|
+
},
|
|
301
203
|
disableClearSelection: true,
|
|
302
204
|
itemToKey: (item)=>{
|
|
303
205
|
var _item_fullKey;
|
|
@@ -328,12 +230,16 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
328
230
|
]
|
|
329
231
|
})
|
|
330
232
|
}),
|
|
331
|
-
/*#__PURE__*/ _jsx(
|
|
233
|
+
/*#__PURE__*/ _jsx(Flex, {
|
|
234
|
+
flex: 1,
|
|
332
235
|
style: {
|
|
333
|
-
|
|
334
|
-
minWidth: 150
|
|
236
|
+
minWidth: 160
|
|
335
237
|
},
|
|
336
238
|
children: /*#__PURE__*/ _jsxs(Combobox.Select, {
|
|
239
|
+
flex: 1,
|
|
240
|
+
style: {
|
|
241
|
+
width: '100%'
|
|
242
|
+
},
|
|
337
243
|
disableClearSelection: true,
|
|
338
244
|
itemToKey: (item)=>{
|
|
339
245
|
var _item_value;
|
|
@@ -370,12 +276,20 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, formField
|
|
|
370
276
|
]
|
|
371
277
|
})
|
|
372
278
|
}),
|
|
373
|
-
!isValueLess && /*#__PURE__*/ _jsx(
|
|
279
|
+
!isValueLess && /*#__PURE__*/ _jsx(Flex, {
|
|
280
|
+
flex: 1,
|
|
374
281
|
style: {
|
|
375
|
-
|
|
376
|
-
minWidth: 150
|
|
282
|
+
minWidth: 160
|
|
377
283
|
},
|
|
378
|
-
children:
|
|
284
|
+
children: /*#__PURE__*/ _jsx(LookupValueControl, {
|
|
285
|
+
value: condition.value,
|
|
286
|
+
fieldType: fieldType,
|
|
287
|
+
lookupSource: selectedDataPoint === null || selectedDataPoint === void 0 ? void 0 : selectedDataPoint.lookupSource,
|
|
288
|
+
onChange: (value)=>onChange({
|
|
289
|
+
...condition,
|
|
290
|
+
value
|
|
291
|
+
})
|
|
292
|
+
})
|
|
379
293
|
}),
|
|
380
294
|
canRemove && /*#__PURE__*/ _jsx("div", {
|
|
381
295
|
style: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/display-conditions/ConditionRow.tsx"],"sourcesContent":["import { Button, Chip, Combobox, Flex, TextField } 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 type { LookupOption } from './lookupOptionsController';\nimport { NUMBER_OPERATORS, SingleCondition, STRING_OPERATORS, VALUE_LESS_OPERATORS } from './types';\nimport type { DataPointOption, FormFieldOption } from './types';\nimport { useLookupOptions } from './useLookupOptions';\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\nfunction sanitizeNumericInput(raw: string): string {\n // Allow only a single leading minus and one decimal separator.\n let value = raw.replaceAll(/[^0-9.-]/g, '');\n const isNegative = value.startsWith('-');\n value = value.replaceAll('-', '');\n if (isNegative) {\n value = `-${value}`;\n }\n const firstDot = value.indexOf('.');\n if (firstDot >= 0) {\n value = `${value.slice(0, firstDot + 1)}${value.slice(firstDot + 1).replaceAll('.', '')}`;\n }\n return value;\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 // Value-less operators (is empty / is not empty) need no value, so skip the host lookup.\n const { options: lookupOptions, status: lookupStatus } = useLookupOptions(\n isValueLess ? undefined : selectedDataPoint?.lookupSource,\n );\n const selectedLookupOption = useMemo(\n () => lookupOptions.find(opt => opt.key === condition.value) ?? null,\n [lookupOptions, condition.value],\n );\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 handleValueChange = (raw: string) => {\n const value = fieldType === 'number' ? sanitizeNumericInput(raw) : raw;\n onChange({ ...condition, value });\n };\n\n const renderValueControl = () => {\n if (lookupStatus === 'loading') {\n return (\n <TextField\n disabled\n label=\"Value\"\n size=\"small\"\n value=\"\"\n placeholder=\"\"\n style={{ width: '100%' }}\n aria-label=\"Value\"\n />\n );\n }\n\n if (lookupStatus === 'ready') {\n return (\n <Combobox\n itemToKey={(item: LookupOption | null) => item?.key ?? ''}\n itemToString={(item: LookupOption | null) => item?.label ?? ''}\n items={lookupOptions}\n selectedItem={selectedLookupOption}\n onChange={(item: LookupOption | null) =>\n onChange({ ...condition, value: item?.key ?? '' })\n }\n filterOptions={{ keys: ['label'] }}\n >\n <Combobox.SearchField\n label=\"Value\"\n placeholder=\"Search value...\"\n size=\"small\"\n />\n <Combobox.Content>\n {({ items }: { items: LookupOption[] }) => (\n <Combobox.List>\n {items.map((item, i) => (\n <Combobox.Item index={i} item={item} key={item.key}>\n {item.label}\n </Combobox.Item>\n ))}\n </Combobox.List>\n )}\n </Combobox.Content>\n </Combobox>\n );\n }\n\n // idle / fallback (empty/error/timeout) -> never block the user.\n return (\n <TextField\n label=\"Value\"\n size=\"small\"\n value={condition.value}\n onChange={e => handleValueChange(e.target.value)}\n placeholder={fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...'}\n style={{ width: '100%' }}\n aria-label=\"Value\"\n {...(fieldType === 'number' && { inputMode: 'decimal' })}\n />\n );\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 <div style={{ flex: '2 1 240px', minWidth: 200 }}>\n <Combobox.Select\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 </div>\n <div style={{ flex: '1 1 180px', minWidth: 150 }}>\n <Combobox.Select\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 </div>\n {!isValueLess && (\n <div style={{ flex: '1 1 180px', minWidth: 150 }}>{renderValueControl()}</div>\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","TextField","TrashIcon","useEffect","useMemo","useState","parseFormFieldKey","NUMBER_OPERATORS","STRING_OPERATORS","VALUE_LESS_OPERATORS","useLookupOptions","sanitizeNumericInput","raw","value","replaceAll","isNegative","startsWith","firstDot","indexOf","slice","ConditionRow","canRemove","condition","dataPointOptions","formFieldOptions","forms","onChange","onFormSelect","onRemove","selectedFormFieldMeta","dataPointKey","selectedSourceValue","setSelectedSourceValue","formId","sourceOptions","label","map","form","id","name","selectedSource","find","opt","hasSchemaMatch","some","fullKey","currentFormId","activeDataPointOptions","filter","option","selectedDataPoint","fieldType","isValueLess","includes","operator","options","lookupOptions","status","lookupStatus","undefined","lookupSource","selectedLookupOption","key","operatorItems","selectedOperator","op","handleValueChange","renderValueControl","disabled","size","placeholder","style","width","aria-label","itemToKey","item","itemToString","items","selectedItem","filterOptions","keys","SearchField","Content","List","i","Item","index","e","target","inputMode","handleDataPointChange","nextIsNumber","nextOperatorItems","operatorReset","handleSourceChange","schemaField","nextFieldType","nextFormFieldOptions","currentSelected","nextSelected","direction","gap","div","Select","disableClearSelection","SelectTrigger","alignItems","flexWrap","rowGap","display","flexShrink","padding","flex","minWidth","title","appearance","icon","before","onClick"],"mappings":";AAAA,SAASA,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,SAAS,QAAQ,uBAA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AAX8D,yBAAAA,cAAe;;4BAC3DC,cAAc,CAACD;oCAAgCA;uCAAAA,CAAAA,cAAAA,iBAAAA,2BAAAA,KAAMxC,KAAK,cAAXwC,yBAAAA,cAAe;;4BAC9DE,OAAOd;4BACPe,cAAcd;4BACdtC,UAAU,CAACiD;oCAGQA;uCAFfjD,SAAS;oCACL,GAAGJ,SAAS;oCACZgC,UAAWqB,CAAAA,cAAAA,iBAAAA,2BAAAA,KAAM9D,KAAK,cAAX8D,yBAAAA,cACP;gCACR;;;8CAGJ,KAAC5E,SAAS0G,aAAa;oCACnBtE,OAAM;oCACNmC,aAAY;oCACZD,MAAK;;8CAET,KAACtE,SAASmF,OAAO;8CACZ,CAAC,EAAEL,KAAK,EAA+B,iBACpC,KAAC9E,SAASoF,IAAI;sDACTN,MAAMzC,GAAG,CAAC,CAACuC,MAAMS,kBACd,KAACrF,SAASsF,IAAI;oDAACC,OAAOF;oDAAGT,MAAMA;8DAC1BA,KAAKxC,KAAK;mDAD2BwC,KAAK9D,KAAK;;;;;;oBAS3E,CAACuC,6BACE,KAACkD;wBAAI/B,OAAO;4BAAEyC,MAAM;4BAAaC,UAAU;wBAAI;kCAAI9C;;oBAEtD9C,2BACG,KAACiF;wBACG/B,OAAO;4BACHsC,SAAS;4BACTH,YAAY;4BACZI,YAAY;4BACZC,SAAS;wBACb;kCAEA,cAAA,KAAClH;4BACGsH,YAAW;4BACX1C,cAAW;4BACX2C,MAAM;gCAAEC,QAAQnH;4BAAU;4BAC1BmE,MAAK;4BACLiD,SAAS1F;;;;;;;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 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","schemaField","nextFieldType","nextFormFieldOptions","currentSelected","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,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,C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ACN+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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface LookupValueControlProps {
|
|
2
|
+
value: string;
|
|
3
|
+
fieldType: 'number' | 'string';
|
|
4
|
+
/** The selected data point's `options.fieldLookupSource`; empty -> free-text input. */
|
|
5
|
+
lookupSource?: string;
|
|
6
|
+
onChange: (value: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Renders the value control for a single condition based on the field's lookup source:
|
|
10
|
+
* - `static` -> full list returned by the host, filtered locally (`SelectFieldSync`).
|
|
11
|
+
* - `searchable` -> host searches per typed query (`SelectField` + `loadOptions`).
|
|
12
|
+
* - `idle`/`fallback`/`loading` -> free-text input (never block the user).
|
|
13
|
+
*
|
|
14
|
+
* Unlayer persists conditions as a Nunjucks string, so a saved searchable value
|
|
15
|
+
* has no stored label — we display the saved key as the label until the user
|
|
16
|
+
* re-searches and re-selects.
|
|
17
|
+
*/
|
|
18
|
+
export declare function LookupValueControl({ fieldType, lookupSource, onChange, value, }: Readonly<LookupValueControlProps>): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=LookupValueControl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LookupValueControl.d.ts","sourceRoot":"","sources":["../../src/display-conditions/LookupValueControl.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,uBAAuB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAqBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,EAC/B,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,KAAK,GACR,EAAE,QAAQ,CAAC,uBAAuB,CAAC,2CA8HnC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { TextField } from '@servicetitan/anvil2';
|
|
3
|
+
import { SelectField, SelectFieldSync } from '@servicetitan/anvil2/beta';
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { useLookupOptions } from './useLookupOptions';
|
|
6
|
+
const toOption = (option)=>({
|
|
7
|
+
id: option.key,
|
|
8
|
+
label: option.label
|
|
9
|
+
});
|
|
10
|
+
const sanitizeNumericInput = (raw)=>{
|
|
11
|
+
let value = raw.replaceAll(/[^0-9.-]/g, '');
|
|
12
|
+
const isNegative = value.startsWith('-');
|
|
13
|
+
value = value.replaceAll('-', '');
|
|
14
|
+
if (isNegative) {
|
|
15
|
+
value = `-${value}`;
|
|
16
|
+
}
|
|
17
|
+
const firstDot = value.indexOf('.');
|
|
18
|
+
if (firstDot >= 0) {
|
|
19
|
+
value = `${value.slice(0, firstDot + 1)}${value.slice(firstDot + 1).replaceAll('.', '')}`;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Renders the value control for a single condition based on the field's lookup source:
|
|
25
|
+
* - `static` -> full list returned by the host, filtered locally (`SelectFieldSync`).
|
|
26
|
+
* - `searchable` -> host searches per typed query (`SelectField` + `loadOptions`).
|
|
27
|
+
* - `idle`/`fallback`/`loading` -> free-text input (never block the user).
|
|
28
|
+
*
|
|
29
|
+
* Unlayer persists conditions as a Nunjucks string, so a saved searchable value
|
|
30
|
+
* has no stored label — we display the saved key as the label until the user
|
|
31
|
+
* re-searches and re-selects.
|
|
32
|
+
*/ export function LookupValueControl({ fieldType, lookupSource, onChange, value }) {
|
|
33
|
+
const { loadOptions, options, resolveOptions, status } = useLookupOptions(lookupSource);
|
|
34
|
+
const staticSelected = useMemo(()=>{
|
|
35
|
+
var _options_filter_map_;
|
|
36
|
+
return (_options_filter_map_ = options.filter((option)=>option.key === value).map(toOption)[0]) !== null && _options_filter_map_ !== void 0 ? _options_filter_map_ : null;
|
|
37
|
+
}, [
|
|
38
|
+
options,
|
|
39
|
+
value
|
|
40
|
+
]);
|
|
41
|
+
const [searchableSelected, setSearchableSelected] = useState(value ? {
|
|
42
|
+
id: value,
|
|
43
|
+
label: value
|
|
44
|
+
} : null);
|
|
45
|
+
// Tracks the key we've already turned into a human-readable label so we don't re-resolve it.
|
|
46
|
+
const resolvedKeyRef = useRef(null);
|
|
47
|
+
useEffect(()=>{
|
|
48
|
+
setSearchableSelected((prev)=>{
|
|
49
|
+
if (!value) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if ((prev === null || prev === void 0 ? void 0 : prev.id) === value) {
|
|
53
|
+
return prev;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
id: value,
|
|
57
|
+
label: value
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}, [
|
|
61
|
+
value
|
|
62
|
+
]);
|
|
63
|
+
// On open (or when a saved searchable value appears), ask the host to resolve key -> label.
|
|
64
|
+
useEffect(()=>{
|
|
65
|
+
if (status !== 'searchable' || !value) {
|
|
66
|
+
resolvedKeyRef.current = null;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (resolvedKeyRef.current === value) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let cancelled = false;
|
|
73
|
+
resolveOptions([
|
|
74
|
+
value
|
|
75
|
+
]).then((result)=>{
|
|
76
|
+
if (cancelled) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const match = result.find((option)=>option.key === value);
|
|
80
|
+
if (match) {
|
|
81
|
+
resolvedKeyRef.current = value;
|
|
82
|
+
setSearchableSelected({
|
|
83
|
+
id: match.key,
|
|
84
|
+
label: match.label
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return ()=>{
|
|
89
|
+
cancelled = true;
|
|
90
|
+
};
|
|
91
|
+
}, [
|
|
92
|
+
status,
|
|
93
|
+
value,
|
|
94
|
+
resolveOptions
|
|
95
|
+
]);
|
|
96
|
+
const handleLoadOptions = useCallback(async (query)=>{
|
|
97
|
+
const result = await loadOptions(query);
|
|
98
|
+
return result.map(toOption);
|
|
99
|
+
}, [
|
|
100
|
+
loadOptions
|
|
101
|
+
]);
|
|
102
|
+
if (status === 'loading') {
|
|
103
|
+
return /*#__PURE__*/ _jsx(TextField, {
|
|
104
|
+
label: "Value",
|
|
105
|
+
size: "small",
|
|
106
|
+
flex: 1,
|
|
107
|
+
disabled: true,
|
|
108
|
+
value: "",
|
|
109
|
+
placeholder: "",
|
|
110
|
+
"aria-label": "Value"
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (status === 'static') {
|
|
114
|
+
return /*#__PURE__*/ _jsx(SelectFieldSync, {
|
|
115
|
+
flex: 1,
|
|
116
|
+
size: "small",
|
|
117
|
+
label: "Value",
|
|
118
|
+
placeholder: "Search value...",
|
|
119
|
+
options: options.map(toOption),
|
|
120
|
+
value: staticSelected,
|
|
121
|
+
onSelectedOptionChange: (option)=>onChange(option ? String(option.id) : '')
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (status === 'searchable') {
|
|
125
|
+
return /*#__PURE__*/ _jsx(SelectField, {
|
|
126
|
+
flex: 1,
|
|
127
|
+
size: "small",
|
|
128
|
+
label: "Value",
|
|
129
|
+
placeholder: "Type to search...",
|
|
130
|
+
initialLoad: "open",
|
|
131
|
+
loadOptions: handleLoadOptions,
|
|
132
|
+
value: searchableSelected,
|
|
133
|
+
onSelectedOptionChange: (option)=>{
|
|
134
|
+
resolvedKeyRef.current = option ? String(option.id) : null;
|
|
135
|
+
setSearchableSelected(option);
|
|
136
|
+
onChange(option ? String(option.id) : '');
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// idle / fallback (no source, empty, error, or timeout) -> free text.
|
|
141
|
+
const handleTextChange = (raw)=>{
|
|
142
|
+
onChange(fieldType === 'number' ? sanitizeNumericInput(raw) : raw);
|
|
143
|
+
};
|
|
144
|
+
return /*#__PURE__*/ _jsx(TextField, {
|
|
145
|
+
label: "Value",
|
|
146
|
+
size: "small",
|
|
147
|
+
flex: 1,
|
|
148
|
+
value: value,
|
|
149
|
+
onChange: (e)=>handleTextChange(e.target.value),
|
|
150
|
+
placeholder: fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...',
|
|
151
|
+
"aria-label": "Value",
|
|
152
|
+
...fieldType === 'number' && {
|
|
153
|
+
inputMode: 'decimal'
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=LookupValueControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/display-conditions/LookupValueControl.tsx"],"sourcesContent":["import { TextField } from '@servicetitan/anvil2';\nimport { SelectField, SelectFieldOption, SelectFieldSync } from '@servicetitan/anvil2/beta';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { LookupOption } from './lookupOptionsController';\nimport { useLookupOptions } from './useLookupOptions';\n\nexport interface LookupValueControlProps {\n value: string;\n fieldType: 'number' | 'string';\n /** The selected data point's `options.fieldLookupSource`; empty -> free-text input. */\n lookupSource?: string;\n onChange: (value: string) => void;\n}\n\nconst toOption = (option: LookupOption): SelectFieldOption => ({\n id: option.key,\n label: option.label,\n});\n\nconst sanitizeNumericInput = (raw: string): string => {\n let value = raw.replaceAll(/[^0-9.-]/g, '');\n const isNegative = value.startsWith('-');\n value = value.replaceAll('-', '');\n if (isNegative) {\n value = `-${value}`;\n }\n const firstDot = value.indexOf('.');\n if (firstDot >= 0) {\n value = `${value.slice(0, firstDot + 1)}${value.slice(firstDot + 1).replaceAll('.', '')}`;\n }\n return value;\n};\n\n/**\n * Renders the value control for a single condition based on the field's lookup source:\n * - `static` -> full list returned by the host, filtered locally (`SelectFieldSync`).\n * - `searchable` -> host searches per typed query (`SelectField` + `loadOptions`).\n * - `idle`/`fallback`/`loading` -> free-text input (never block the user).\n *\n * Unlayer persists conditions as a Nunjucks string, so a saved searchable value\n * has no stored label — we display the saved key as the label until the user\n * re-searches and re-selects.\n */\nexport function LookupValueControl({\n fieldType,\n lookupSource,\n onChange,\n value,\n}: Readonly<LookupValueControlProps>) {\n const { loadOptions, options, resolveOptions, status } = useLookupOptions(lookupSource);\n\n const staticSelected = useMemo<SelectFieldOption | null>(\n () => options.filter(option => option.key === value).map(toOption)[0] ?? null,\n [options, value],\n );\n\n const [searchableSelected, setSearchableSelected] = useState<SelectFieldOption | null>(\n value ? { id: value, label: value } : null,\n );\n\n // Tracks the key we've already turned into a human-readable label so we don't re-resolve it.\n const resolvedKeyRef = useRef<string | null>(null);\n\n useEffect(() => {\n setSearchableSelected(prev => {\n if (!value) {\n return null;\n }\n if (prev?.id === value) {\n return prev;\n }\n return { id: value, label: value };\n });\n }, [value]);\n\n // On open (or when a saved searchable value appears), ask the host to resolve key -> label.\n useEffect(() => {\n if (status !== 'searchable' || !value) {\n resolvedKeyRef.current = null;\n return;\n }\n if (resolvedKeyRef.current === value) {\n return;\n }\n\n let cancelled = false;\n resolveOptions([value]).then(result => {\n if (cancelled) {\n return;\n }\n const match = result.find(option => option.key === value);\n if (match) {\n resolvedKeyRef.current = value;\n setSearchableSelected({ id: match.key, label: match.label });\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [status, value, resolveOptions]);\n\n const handleLoadOptions = useCallback(\n async (query: string) => {\n const result = await loadOptions(query);\n return result.map(toOption);\n },\n [loadOptions],\n );\n\n if (status === 'loading') {\n return (\n <TextField\n label=\"Value\"\n size=\"small\"\n flex={1}\n disabled\n value=\"\"\n placeholder=\"\"\n aria-label=\"Value\"\n />\n );\n }\n\n if (status === 'static') {\n return (\n <SelectFieldSync\n flex={1}\n size=\"small\"\n label=\"Value\"\n placeholder=\"Search value...\"\n options={options.map(toOption)}\n value={staticSelected}\n onSelectedOptionChange={option => onChange(option ? String(option.id) : '')}\n />\n );\n }\n\n if (status === 'searchable') {\n return (\n <SelectField\n flex={1}\n size=\"small\"\n label=\"Value\"\n placeholder=\"Type to search...\"\n initialLoad=\"open\"\n loadOptions={handleLoadOptions}\n value={searchableSelected}\n onSelectedOptionChange={option => {\n resolvedKeyRef.current = option ? String(option.id) : null;\n setSearchableSelected(option);\n onChange(option ? String(option.id) : '');\n }}\n />\n );\n }\n\n // idle / fallback (no source, empty, error, or timeout) -> free text.\n const handleTextChange = (raw: string) => {\n onChange(fieldType === 'number' ? sanitizeNumericInput(raw) : raw);\n };\n\n return (\n <TextField\n label=\"Value\"\n size=\"small\"\n flex={1}\n value={value}\n onChange={e => handleTextChange(e.target.value)}\n placeholder={fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...'}\n aria-label=\"Value\"\n {...(fieldType === 'number' && { inputMode: 'decimal' })}\n />\n );\n}\n"],"names":["TextField","SelectField","SelectFieldSync","useCallback","useEffect","useMemo","useRef","useState","useLookupOptions","toOption","option","id","key","label","sanitizeNumericInput","raw","value","replaceAll","isNegative","startsWith","firstDot","indexOf","slice","LookupValueControl","fieldType","lookupSource","onChange","loadOptions","options","resolveOptions","status","staticSelected","filter","map","searchableSelected","setSearchableSelected","resolvedKeyRef","prev","current","cancelled","then","result","match","find","handleLoadOptions","query","size","flex","disabled","placeholder","aria-label","onSelectedOptionChange","String","initialLoad","handleTextChange","e","target","inputMode"],"mappings":";AAAA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,WAAW,EAAqBC,eAAe,QAAQ,4BAA4B;AAC5F,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE1E,SAASC,gBAAgB,QAAQ,qBAAqB;AAUtD,MAAMC,WAAW,CAACC,SAA6C,CAAA;QAC3DC,IAAID,OAAOE,GAAG;QACdC,OAAOH,OAAOG,KAAK;IACvB,CAAA;AAEA,MAAMC,uBAAuB,CAACC;IAC1B,IAAIC,QAAQD,IAAIE,UAAU,CAAC,aAAa;IACxC,MAAMC,aAAaF,MAAMG,UAAU,CAAC;IACpCH,QAAQA,MAAMC,UAAU,CAAC,KAAK;IAC9B,IAAIC,YAAY;QACZF,QAAQ,CAAC,CAAC,EAAEA,OAAO;IACvB;IACA,MAAMI,WAAWJ,MAAMK,OAAO,CAAC;IAC/B,IAAID,YAAY,GAAG;QACfJ,QAAQ,GAAGA,MAAMM,KAAK,CAAC,GAAGF,WAAW,KAAKJ,MAAMM,KAAK,CAACF,WAAW,GAAGH,UAAU,CAAC,KAAK,KAAK;IAC7F;IACA,OAAOD;AACX;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASO,mBAAmB,EAC/BC,SAAS,EACT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E"}
|
|
@@ -6,6 +6,16 @@
|
|
|
6
6
|
* UI, the editor does NOT own the option data — it asks the HOST for it over the
|
|
7
7
|
* EventTarget bus below and renders whatever the host returns.
|
|
8
8
|
*
|
|
9
|
+
* Two host-driven modes are supported (the host decides, the editor adapts):
|
|
10
|
+
* 1. Full-list source (e.g. "state", "jobType"): the host returns every option
|
|
11
|
+
* on the first request and omits `searchable`. The editor caches that list
|
|
12
|
+
* and filters it LOCALLY as the user types — no further requests are sent.
|
|
13
|
+
* 2. Searchable source (e.g. "city"): the list is too large to send at once.
|
|
14
|
+
* The host returns `searchable: true` (typically with an empty list on the
|
|
15
|
+
* first, query-less request). The editor then re-requests with the typed
|
|
16
|
+
* `query` on each keystroke and the host returns a fresh, server-filtered
|
|
17
|
+
* list per query.
|
|
18
|
+
*
|
|
9
19
|
* Transport mirrors the existing `displayConditionController` EventBus pattern.
|
|
10
20
|
*
|
|
11
21
|
* Event names (host <-> editor):
|
|
@@ -29,22 +39,34 @@ export interface LookupOptionsRequest {
|
|
|
29
39
|
requestId: string;
|
|
30
40
|
/** The selected field's `options.fieldLookupSource`. */
|
|
31
41
|
sourceKey: string;
|
|
32
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* The text the user has typed. Sent on each (debounced) keystroke once the
|
|
44
|
+
* host has declared the source `searchable`. Empty/omitted on the first
|
|
45
|
+
* request, where the host decides whether the source is searchable.
|
|
46
|
+
*/
|
|
33
47
|
query?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve mode: the editor is asking the host to return the option(s) for
|
|
50
|
+
* these EXACT stored keys (not a text search). Used on open to turn a saved
|
|
51
|
+
* searchable value (a bare key) back into a human-readable label. When
|
|
52
|
+
* present the host should match by key and ignore `query`.
|
|
53
|
+
*/
|
|
54
|
+
keys?: string[];
|
|
34
55
|
}
|
|
35
56
|
/** host -> editor */
|
|
36
57
|
export interface LookupOptionsResponse {
|
|
37
58
|
requestId: string;
|
|
38
59
|
options: LookupOption[];
|
|
60
|
+
/**
|
|
61
|
+
* Set to `true` by the host when the source must be searched per query
|
|
62
|
+
* (server-side). When omitted/false the editor treats `options` as the
|
|
63
|
+
* complete list and switches to local filtering. Only read from the first
|
|
64
|
+
* (query-less) response for a given source.
|
|
65
|
+
*/
|
|
66
|
+
searchable?: boolean;
|
|
39
67
|
}
|
|
40
68
|
export declare const LOOKUP_OPTIONS_REQUEST_EVENT = "dte-unlayer:lookup-options-request";
|
|
41
69
|
export declare const LOOKUP_OPTIONS_RESPONSE_EVENT = "dte-unlayer:lookup-options-response";
|
|
42
|
-
/**
|
|
43
|
-
* Searchable sources require the host to query an API per typed query. These are
|
|
44
|
-
* skipped for now and fall back to the free-text input.
|
|
45
|
-
*/
|
|
46
|
-
export declare const SEARCHABLE_LOOKUP_SOURCES: readonly ["city"];
|
|
47
|
-
export declare const isSearchableLookupSource: (sourceKey: string | undefined) => boolean;
|
|
48
70
|
/** editor -> host: ask the host to resolve options for a lookup source. */
|
|
49
71
|
export declare const emitLookupOptionsRequest: (request: LookupOptionsRequest) => void;
|
|
50
72
|
/** host side: listen for editor requests. Returns an unsubscribe function. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lookupOptionsController.d.ts","sourceRoot":"","sources":["../../src/display-conditions/lookupOptionsController.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"lookupOptionsController.d.ts","sourceRoot":"","sources":["../../src/display-conditions/lookupOptionsController.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,wDAAwD;AACxD,MAAM,WAAW,YAAY;IACzB,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;CACf;AAED,qBAAqB;AACrB,MAAM,WAAW,oBAAoB;IACjC,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,qBAAqB;AACrB,MAAM,WAAW,qBAAqB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,4BAA4B,uCAAuC,CAAC;AACjF,eAAO,MAAM,6BAA6B,wCAAwC,CAAC;AAInF,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB,GAAI,SAAS,oBAAoB,SAIrE,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,sBAAsB,GAAI,UAAU,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,eAcvF,CAAC;AAEF,mEAAmE;AACnE,eAAO,MAAM,yBAAyB,GAAI,UAAU,qBAAqB,SAIxE,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,GAAI,UAAU,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,eAc1F,CAAC"}
|
|
@@ -6,6 +6,16 @@
|
|
|
6
6
|
* UI, the editor does NOT own the option data — it asks the HOST for it over the
|
|
7
7
|
* EventTarget bus below and renders whatever the host returns.
|
|
8
8
|
*
|
|
9
|
+
* Two host-driven modes are supported (the host decides, the editor adapts):
|
|
10
|
+
* 1. Full-list source (e.g. "state", "jobType"): the host returns every option
|
|
11
|
+
* on the first request and omits `searchable`. The editor caches that list
|
|
12
|
+
* and filters it LOCALLY as the user types — no further requests are sent.
|
|
13
|
+
* 2. Searchable source (e.g. "city"): the list is too large to send at once.
|
|
14
|
+
* The host returns `searchable: true` (typically with an empty list on the
|
|
15
|
+
* first, query-less request). The editor then re-requests with the typed
|
|
16
|
+
* `query` on each keystroke and the host returns a fresh, server-filtered
|
|
17
|
+
* list per query.
|
|
18
|
+
*
|
|
9
19
|
* Transport mirrors the existing `displayConditionController` EventBus pattern.
|
|
10
20
|
*
|
|
11
21
|
* Event names (host <-> editor):
|
|
@@ -17,13 +27,6 @@
|
|
|
17
27
|
* `emitLookupOptionsResponse`.
|
|
18
28
|
*/ /** The single dropdown option shape used end-to-end. */ export const LOOKUP_OPTIONS_REQUEST_EVENT = 'dte-unlayer:lookup-options-request';
|
|
19
29
|
export const LOOKUP_OPTIONS_RESPONSE_EVENT = 'dte-unlayer:lookup-options-response';
|
|
20
|
-
/**
|
|
21
|
-
* Searchable sources require the host to query an API per typed query. These are
|
|
22
|
-
* skipped for now and fall back to the free-text input.
|
|
23
|
-
*/ export const SEARCHABLE_LOOKUP_SOURCES = [
|
|
24
|
-
'city'
|
|
25
|
-
];
|
|
26
|
-
export const isSearchableLookupSource = (sourceKey)=>!!sourceKey && SEARCHABLE_LOOKUP_SOURCES.includes(sourceKey);
|
|
27
30
|
const lookupOptionsEvents = new EventTarget();
|
|
28
31
|
/** editor -> host: ask the host to resolve options for a lookup source. */ export const emitLookupOptionsRequest = (request)=>{
|
|
29
32
|
lookupOptionsEvents.dispatchEvent(new CustomEvent(LOOKUP_OPTIONS_REQUEST_EVENT, {
|