@servicetitan/dte-unlayer 0.121.0 → 0.123.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.
Files changed (47) hide show
  1. package/dist/display-conditions/ConditionGroup.d.ts +6 -2
  2. package/dist/display-conditions/ConditionGroup.d.ts.map +1 -1
  3. package/dist/display-conditions/ConditionGroup.js +8 -3
  4. package/dist/display-conditions/ConditionGroup.js.map +1 -1
  5. package/dist/display-conditions/ConditionGroupsSection.d.ts +6 -2
  6. package/dist/display-conditions/ConditionGroupsSection.d.ts.map +1 -1
  7. package/dist/display-conditions/ConditionGroupsSection.js +4 -1
  8. package/dist/display-conditions/ConditionGroupsSection.js.map +1 -1
  9. package/dist/display-conditions/ConditionRow.d.ts +6 -2
  10. package/dist/display-conditions/ConditionRow.d.ts.map +1 -1
  11. package/dist/display-conditions/ConditionRow.js +240 -110
  12. package/dist/display-conditions/ConditionRow.js.map +1 -1
  13. package/dist/display-conditions/DisplayConditionModal.d.ts +3 -0
  14. package/dist/display-conditions/DisplayConditionModal.d.ts.map +1 -1
  15. package/dist/display-conditions/DisplayConditionModal.js +97 -7
  16. package/dist/display-conditions/DisplayConditionModal.js.map +1 -1
  17. package/dist/display-conditions/nunjucks.d.ts.map +1 -1
  18. package/dist/display-conditions/nunjucks.js +17 -6
  19. package/dist/display-conditions/nunjucks.js.map +1 -1
  20. package/dist/display-conditions/types.d.ts +3 -0
  21. package/dist/display-conditions/types.d.ts.map +1 -1
  22. package/dist/display-conditions/types.js.map +1 -1
  23. package/dist/editor-core-source.d.ts +2 -2
  24. package/dist/editor-core-source.d.ts.map +1 -1
  25. package/dist/editor-core-source.js +2 -2
  26. package/dist/editor-core-source.js.map +1 -1
  27. package/dist/editor.d.ts.map +1 -1
  28. package/dist/editor.js +3 -1
  29. package/dist/editor.js.map +1 -1
  30. package/dist/shared/forms.d.ts +26 -0
  31. package/dist/shared/forms.d.ts.map +1 -1
  32. package/dist/shared/forms.js +75 -1
  33. package/dist/shared/forms.js.map +1 -1
  34. package/dist/unlayer-interface.d.ts +2 -0
  35. package/dist/unlayer-interface.d.ts.map +1 -1
  36. package/dist/unlayer-interface.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/display-conditions/ConditionGroup.tsx +12 -3
  39. package/src/display-conditions/ConditionGroupsSection.tsx +11 -1
  40. package/src/display-conditions/ConditionRow.tsx +229 -86
  41. package/src/display-conditions/DisplayConditionModal.tsx +106 -4
  42. package/src/display-conditions/nunjucks.ts +18 -9
  43. package/src/display-conditions/types.ts +4 -0
  44. package/src/editor-core-source.ts +2 -2
  45. package/src/editor.tsx +7 -1
  46. package/src/shared/forms.ts +85 -0
  47. package/src/unlayer-interface.tsx +9 -0
@@ -1,9 +1,13 @@
1
- import { ConditionGroup as ConditionGroupType } from './types';
1
+ import { FormInfo } from '../shared/forms';
2
+ import { ConditionGroup as ConditionGroupType, FormFieldOption } from './types';
2
3
  import type { DataPointOption } from './types';
3
4
  export interface ConditionGroupProps {
4
5
  dataPointOptions: DataPointOption[];
6
+ formFieldOptions: FormFieldOption[];
7
+ forms: FormInfo[];
5
8
  group: ConditionGroupType;
9
+ onFormSelect: (formId: number) => void;
6
10
  onUpdate: (g: ConditionGroupType) => void;
7
11
  }
8
- export declare function ConditionGroup({ dataPointOptions, group, onUpdate, }: Readonly<ConditionGroupProps>): import("react/jsx-runtime").JSX.Element;
12
+ export declare function ConditionGroup({ dataPointOptions, formFieldOptions, forms, group, onFormSelect, onUpdate, }: Readonly<ConditionGroupProps>): import("react/jsx-runtime").JSX.Element;
9
13
  //# sourceMappingURL=ConditionGroup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionGroup.d.ts","sourceRoot":"","sources":["../../src/display-conditions/ConditionGroup.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAmB,MAAM,SAAS,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAChC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAC7C;AAED,wBAAgB,cAAc,CAAC,EAC3B,gBAAgB,EAChB,KAAK,EACL,QAAQ,GACX,EAAE,QAAQ,CAAC,mBAAmB,CAAC,2CA+D/B"}
1
+ {"version":3,"file":"ConditionGroup.d.ts","sourceRoot":"","sources":["../../src/display-conditions/ConditionGroup.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,eAAe,EAAmB,MAAM,SAAS,CAAC;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAChC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAC7C;AAED,wBAAgB,cAAc,CAAC,EAC3B,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,YAAY,EACZ,QAAQ,GACX,EAAE,QAAQ,CAAC,mBAAmB,CAAC,2CAiE/B"}
@@ -4,7 +4,7 @@ import PlusIcon from '@servicetitan/anvil2/assets/icons/material/round/add.svg';
4
4
  import { useCallback } from 'react';
5
5
  import { ConditionRow } from './ConditionRow';
6
6
  import { defaultCondition } from './constants';
7
- export function ConditionGroup({ dataPointOptions, group, onUpdate }) {
7
+ export function ConditionGroup({ dataPointOptions, formFieldOptions, forms, group, onFormSelect, onUpdate }) {
8
8
  const addCondition = useCallback(()=>{
9
9
  const newCondition = {
10
10
  ...defaultCondition(),
@@ -37,9 +37,11 @@ export function ConditionGroup({ dataPointOptions, group, onUpdate }) {
37
37
  const removeCondition = useCallback((index)=>{
38
38
  let next = group.conditions.filter((_, i)=>i !== index);
39
39
  if (index === 0 && next.length > 0) {
40
- const { logicalOperator: _unusedOp, ...rest } = next[0];
41
40
  next = [
42
- rest,
41
+ {
42
+ ...next[0],
43
+ logicalOperator: undefined
44
+ },
43
45
  ...next.slice(1)
44
46
  ];
45
47
  }
@@ -76,7 +78,10 @@ export function ConditionGroup({ dataPointOptions, group, onUpdate }) {
76
78
  canRemove: true,
77
79
  condition: c,
78
80
  dataPointOptions: dataPointOptions,
81
+ forms: forms,
82
+ formFieldOptions: formFieldOptions,
79
83
  onChange: (next)=>updateCondition(i, next),
84
+ onFormSelect: onFormSelect,
80
85
  onRemove: ()=>removeCondition(i)
81
86
  })
82
87
  }, c.id)),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/display-conditions/ConditionGroup.tsx"],"sourcesContent":["import { Button, Flex } from '@servicetitan/anvil2';\nimport PlusIcon from '@servicetitan/anvil2/assets/icons/material/round/add.svg';\nimport { useCallback } from 'react';\nimport { ConditionRow } from './ConditionRow';\nimport { defaultCondition } from './constants';\nimport { ConditionGroup as ConditionGroupType, SingleCondition } from './types';\nimport type { DataPointOption } from './types';\n\nexport interface ConditionGroupProps {\n dataPointOptions: DataPointOption[];\n group: ConditionGroupType;\n onUpdate: (g: ConditionGroupType) => void;\n}\n\nexport function ConditionGroup({\n dataPointOptions,\n group,\n onUpdate,\n}: Readonly<ConditionGroupProps>) {\n const addCondition = useCallback(() => {\n const newCondition: SingleCondition = {\n ...defaultCondition(),\n logicalOperator: 'and',\n };\n onUpdate({\n ...group,\n conditions: [...group.conditions, newCondition],\n });\n }, [group, onUpdate]);\n\n const updateCondition = useCallback(\n (index: number, c: SingleCondition) => {\n const next = [...group.conditions];\n next[index] = c;\n onUpdate({ ...group, conditions: next });\n },\n [group, onUpdate],\n );\n\n const removeCondition = useCallback(\n (index: number) => {\n let next = group.conditions.filter((_, i) => i !== index);\n if (index === 0 && next.length > 0) {\n const { logicalOperator: _unusedOp, ...rest } = next[0];\n next = [rest as SingleCondition, ...next.slice(1)];\n }\n onUpdate({\n ...group,\n conditions: next.length ? next : [defaultCondition()],\n });\n },\n [group, onUpdate],\n );\n\n return (\n <Flex direction=\"column\" gap=\"2\" style={{ width: '100%' }}>\n <Flex direction=\"column\" gap=\"3\" style={{ width: '100%' }}>\n {group.conditions.map((c, i) => (\n <Flex key={c.id} direction=\"column\" gap=\"3\" style={{ padding: '8px 0' }}>\n <ConditionRow\n canRemove\n condition={c}\n dataPointOptions={dataPointOptions}\n onChange={next => updateCondition(i, next)}\n onRemove={() => removeCondition(i)}\n />\n </Flex>\n ))}\n <Flex justifyContent=\"center\" style={{ paddingTop: 8, width: '100%' }}>\n <Button\n appearance=\"secondary\"\n icon={{ before: PlusIcon }}\n size=\"small\"\n onClick={addCondition}\n >\n Add Condition\n </Button>\n </Flex>\n </Flex>\n </Flex>\n );\n}\n"],"names":["Button","Flex","PlusIcon","useCallback","ConditionRow","defaultCondition","ConditionGroup","dataPointOptions","group","onUpdate","addCondition","newCondition","logicalOperator","conditions","updateCondition","index","c","next","removeCondition","filter","_","i","length","_unusedOp","rest","slice","direction","gap","style","width","map","padding","canRemove","condition","onChange","onRemove","id","justifyContent","paddingTop","appearance","icon","before","size","onClick"],"mappings":";AAAA,SAASA,MAAM,EAAEC,IAAI,QAAQ,uBAAuB;AACpD,OAAOC,cAAc,2DAA2D;AAChF,SAASC,WAAW,QAAQ,QAAQ;AACpC,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,gBAAgB,QAAQ,cAAc;AAU/C,OAAO,SAASC,eAAe,EAC3BC,gBAAgB,EAChBC,KAAK,EACLC,QAAQ,EACoB;IAC5B,MAAMC,eAAeP,YAAY;QAC7B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CkB,UAAU,IAAMjB,gBAAgBG;;uBAN7BL,EAAEoB,EAAE;8BAUnB,KAACnC;oBAAKoC,gBAAe;oBAAST,OAAO;wBAAEU,YAAY;wBAAGT,OAAO;oBAAO;8BAChE,cAAA,KAAC7B;wBACGuC,YAAW;wBACXC,MAAM;4BAAEC,QAAQvC;wBAAS;wBACzBwC,MAAK;wBACLC,SAASjC;kCACZ;;;;;;AAOrB"}
1
+ {"version":3,"sources":["../../src/display-conditions/ConditionGroup.tsx"],"sourcesContent":["import { Button, Flex } from '@servicetitan/anvil2';\nimport PlusIcon from '@servicetitan/anvil2/assets/icons/material/round/add.svg';\nimport { useCallback } from 'react';\nimport { FormInfo } from '../shared/forms';\nimport { ConditionRow } from './ConditionRow';\nimport { defaultCondition } from './constants';\nimport { ConditionGroup as ConditionGroupType, FormFieldOption, SingleCondition } from './types';\nimport type { DataPointOption } from './types';\n\nexport interface ConditionGroupProps {\n dataPointOptions: DataPointOption[];\n formFieldOptions: FormFieldOption[];\n forms: FormInfo[];\n group: ConditionGroupType;\n onFormSelect: (formId: number) => void;\n onUpdate: (g: ConditionGroupType) => void;\n}\n\nexport function ConditionGroup({\n dataPointOptions,\n formFieldOptions,\n forms,\n group,\n onFormSelect,\n onUpdate,\n}: Readonly<ConditionGroupProps>) {\n const addCondition = useCallback(() => {\n const newCondition: SingleCondition = {\n ...defaultCondition(),\n logicalOperator: 'and',\n };\n onUpdate({\n ...group,\n conditions: [...group.conditions, newCondition],\n });\n }, [group, onUpdate]);\n\n const updateCondition = useCallback(\n (index: number, c: SingleCondition) => {\n const next = [...group.conditions];\n next[index] = c;\n onUpdate({ ...group, conditions: next });\n },\n [group, onUpdate],\n );\n\n const removeCondition = useCallback(\n (index: number) => {\n let next = group.conditions.filter((_, i) => i !== index);\n if (index === 0 && next.length > 0) {\n next = [{ ...next[0], logicalOperator: undefined }, ...next.slice(1)];\n }\n onUpdate({\n ...group,\n conditions: next.length ? next : [defaultCondition()],\n });\n },\n [group, onUpdate],\n );\n\n return (\n <Flex direction=\"column\" gap=\"2\" style={{ width: '100%' }}>\n <Flex direction=\"column\" gap=\"3\" style={{ width: '100%' }}>\n {group.conditions.map((c, i) => (\n <Flex key={c.id} direction=\"column\" gap=\"3\" style={{ padding: '8px 0' }}>\n <ConditionRow\n canRemove\n condition={c}\n dataPointOptions={dataPointOptions}\n forms={forms}\n formFieldOptions={formFieldOptions}\n onChange={next => updateCondition(i, next)}\n onFormSelect={onFormSelect}\n onRemove={() => removeCondition(i)}\n />\n </Flex>\n ))}\n <Flex justifyContent=\"center\" style={{ paddingTop: 8, width: '100%' }}>\n <Button\n appearance=\"secondary\"\n icon={{ before: PlusIcon }}\n size=\"small\"\n onClick={addCondition}\n >\n Add Condition\n </Button>\n </Flex>\n </Flex>\n </Flex>\n );\n}\n"],"names":["Button","Flex","PlusIcon","useCallback","ConditionRow","defaultCondition","ConditionGroup","dataPointOptions","formFieldOptions","forms","group","onFormSelect","onUpdate","addCondition","newCondition","logicalOperator","conditions","updateCondition","index","c","next","removeCondition","filter","_","i","length","undefined","slice","direction","gap","style","width","map","padding","canRemove","condition","onChange","onRemove","id","justifyContent","paddingTop","appearance","icon","before","size","onClick"],"mappings":";AAAA,SAASA,MAAM,EAAEC,IAAI,QAAQ,uBAAuB;AACpD,OAAOC,cAAc,2DAA2D;AAChF,SAASC,WAAW,QAAQ,QAAQ;AAEpC,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,gBAAgB,QAAQ,cAAc;AAa/C,OAAO,SAASC,eAAe,EAC3BC,gBAAgB,EAChBC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACoB;IAC5B,MAAMC,eAAeV,YAAY;QAC7B,MAAMW,eAAgC;YAClC,GAAGT,kBAAkB;YACrBU,iBAAiB;QACrB;QACAH,SAAS;YACL,GAAGF,KAAK;YACRM,YAAY;mBAAIN,MAAMM,UAAU;gBAAEF;aAAa;QACnD;IACJ,GAAG;QAACJ;QA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,cAAA,KAAC/B;wBACGyC,YAAW;wBACXC,MAAM;4BAAEC,QAAQzC;wBAAS;wBACzB0C,MAAK;wBACLC,SAAShC;kCACZ;;;;;;AAOrB"}
@@ -1,14 +1,18 @@
1
1
  import type { ReactNode } from 'react';
2
- import { ConditionGroup as ConditionGroupType } from './types';
2
+ import { FormInfo } from '../shared/forms';
3
+ import { ConditionGroup as ConditionGroupType, FormFieldOption } from './types';
3
4
  import type { DataPointOption } from './types';
4
5
  export type MatchType = 'all' | 'any';
5
6
  export interface ConditionGroupsSectionProps {
6
7
  behaviorSection?: ReactNode;
7
8
  dataPointOptions: DataPointOption[];
9
+ formFieldOptions: FormFieldOption[];
10
+ forms: FormInfo[];
8
11
  groups: ConditionGroupType[];
9
12
  matchType: MatchType;
13
+ onFormSelect: (formId: number) => void;
10
14
  onMatchTypeChange: (matchType: MatchType) => void;
11
15
  onUpdateGroup: (index: number, group: ConditionGroupType) => void;
12
16
  }
13
- export declare function ConditionGroupsSection({ behaviorSection, dataPointOptions, groups, matchType, onMatchTypeChange, onUpdateGroup, }: Readonly<ConditionGroupsSectionProps>): import("react/jsx-runtime").JSX.Element | null;
17
+ export declare function ConditionGroupsSection({ behaviorSection, dataPointOptions, formFieldOptions, forms, groups, matchType, onFormSelect, onMatchTypeChange, onUpdateGroup, }: Readonly<ConditionGroupsSectionProps>): import("react/jsx-runtime").JSX.Element | null;
14
18
  //# sourceMappingURL=ConditionGroupsSection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionGroupsSection.d.ts","sourceRoot":"","sources":["../../src/display-conditions/ConditionGroupsSection.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAA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AK,IAAI,CAAC;IAClD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACrE;AAED,wBAAgB,sBAAsB,CAAC,EACnC,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,EACL,MAAM,EACN,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,aAAa,GAChB,EAAE,QAAQ,CAAC,2BAA2B,CAAC,kDAuCvC"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Chip, Flex, SegmentedControl, Text } from '@servicetitan/anvil2';
3
3
  import { ConditionGroup } from './ConditionGroup';
4
- export function ConditionGroupsSection({ behaviorSection, dataPointOptions, groups, matchType, onMatchTypeChange, onUpdateGroup }) {
4
+ export function ConditionGroupsSection({ behaviorSection, dataPointOptions, formFieldOptions, forms, groups, matchType, onFormSelect, onMatchTypeChange, onUpdateGroup }) {
5
5
  const firstGroup = groups[0];
6
6
  if (!firstGroup) {
7
7
  return null;
@@ -66,7 +66,10 @@ export function ConditionGroupsSection({ behaviorSection, dataPointOptions, grou
66
66
  behaviorSection,
67
67
  /*#__PURE__*/ _jsx(ConditionGroup, {
68
68
  dataPointOptions: dataPointOptions,
69
+ formFieldOptions: formFieldOptions,
70
+ forms: forms,
69
71
  group: firstGroup,
72
+ onFormSelect: onFormSelect,
70
73
  onUpdate: (g)=>onUpdateGroup(0, g)
71
74
  })
72
75
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/display-conditions/ConditionGroupsSection.tsx"],"sourcesContent":["import { Chip, Flex, SegmentedControl, Text } from '@servicetitan/anvil2';\nimport type { ReactNode } from 'react';\nimport { ConditionGroup } from './ConditionGroup';\nimport { ConditionGroup as ConditionGroupType } from './types';\nimport type { DataPointOption } from './types';\n\nexport type MatchType = 'all' | 'any';\n\nexport interface ConditionGroupsSectionProps {\n behaviorSection?: ReactNode;\n dataPointOptions: DataPointOption[];\n groups: ConditionGroupType[];\n matchType: MatchType;\n onMatchTypeChange: (matchType: MatchType) => void;\n onUpdateGroup: (index: number, group: ConditionGroupType) => void;\n}\n\nexport function ConditionGroupsSection({\n behaviorSection,\n dataPointOptions,\n groups,\n matchType,\n onMatchTypeChange,\n onUpdateGroup,\n}: Readonly<ConditionGroupsSectionProps>) {\n const firstGroup = groups[0];\n if (!firstGroup) {\n return null;\n }\n\n return (\n <Flex direction=\"column\" gap=\"4\">\n <Flex direction=\"row\" alignItems=\"center\" gap=\"1\" style={{ flexWrap: 'wrap' }}>\n <Text size=\"small\" variant=\"body\" style={{ fontWeight: 'bold' }}>\n When\n </Text>\n <SegmentedControl\n selected={matchType}\n size=\"small\"\n onChange={(value: string) => onMatchTypeChange(value as MatchType)}\n >\n <SegmentedControl.Segment value=\"all\">All</SegmentedControl.Segment>\n <SegmentedControl.Segment value=\"any\">Any</SegmentedControl.Segment>\n </SegmentedControl>\n <Text size=\"small\" variant=\"body\" style={{ fontWeight: 'bold' }}>\n of the\n </Text>\n <Chip label=\"IF\" size=\"small\" />\n <Text size=\"small\" variant=\"body\" style={{ fontWeight: 'bold' }}>\n conditions are met\n </Text>\n </Flex>\n {behaviorSection}\n <ConditionGroup\n dataPointOptions={dataPointOptions}\n group={firstGroup}\n onUpdate={g => onUpdateGroup(0, g)}\n />\n </Flex>\n );\n}\n"],"names":["Chip","Flex","SegmentedControl","Text","ConditionGroup","ConditionGroupsSection","behaviorSection","dataPointOptions","groups","matchType","onMatchTypeChange","onUpdateGroup","firstGroup","direction","gap","alignItems","style","flexWrap","size","variant","fontWeight","selected","onChange","value","Segment","label","group","onUpdate","g"],"mappings":";AAAA,SAASA,IAAI,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,IAAI,QAAQ,uBAAuB;AAE1E,SAASC,cAAc,QAAQ,mBAAmB;AAelD,OAAO,SAASC,uBAAuB,EACnCC,eAAe,EACfC,gBAAgB,EAChBC,MAAM,EACNC,SAAS,EACTC,iBAAiB,EACjBC,aAAa,EACuB;IACpC,MAAMC,aAAaJ,MAAM,CAAC,EAAE;IAC5B,IAAI,CAACI,YAAY;QACb,OAAO;IACX;IAEA,qBACI,MAACX;QAAKY,WAAU;QAASC,KAAI;;0BACzB,MAACb;gBAAKY,WAAU;gBAAME,YAAW;gBAASD,KAAI;gBAAIE,OAAO;oBAAEC,UAAU;gBAAO;;kCACxE,KAACd;wBAAKe,MAAK;wBAAQC,SAAQ;wBAAOH,OAAO;4BAAEI,YAAY;wBAAO;kCAAG;;kCAGjE,MAAClB;wBACGmB,UAAUZ;wBACVS,MAAK;wBACLI,UAAU,CAACC,QAAkBb,kBAAkBa;;0CAE/C,KAACrB,iBAAiBsB,OAAO;gCAACD,OAAM;0CAAM;;0CACtC,KAACrB,iBAAiBsB,OAAO;gCAACD,OAAM;0CAAM;;;;kCAE1C,KAACpB;wBAAKe,MAAK;wBAAQC,SAAQ;wBAAOH,OAAO;4BAAEI,YAAY;wBAAO;kCAAG;;kCAGjE,KAACpB;wBAAKyB,OAAM;wBAAKP,MAAK;;kCACtB,KAACf;wBAAKe,MAAK;wBAAQC,SAAQ;wBAAOH,OAAO;4BAAEI,YAAY;wBAAO;kCAAG;;;;YAIpEd;0BACD,KAACF;gBACGG,kBAAkBA;gBAClBmB,OAAOd;gBACPe,UAAUC,CAAAA,IAAKjB,cAAc,GAAGiB;;;;AAIhD"}
1
+ {"version":3,"sources":["../../src/display-conditions/ConditionGroupsSection.tsx"],"sourcesContent":["import { Chip, Flex, SegmentedControl, Text } from '@servicetitan/anvil2';\nimport type { ReactNode } from 'react';\nimport { FormInfo } from '../shared/forms';\nimport { ConditionGroup } from './ConditionGroup';\nimport { ConditionGroup as ConditionGroupType, FormFieldOption } from './types';\nimport type { DataPointOption } from './types';\n\nexport type MatchType = 'all' | 'any';\n\nexport interface ConditionGroupsSectionProps {\n behaviorSection?: ReactNode;\n dataPointOptions: DataPointOption[];\n formFieldOptions: FormFieldOption[];\n forms: FormInfo[];\n groups: ConditionGroupType[];\n matchType: MatchType;\n onFormSelect: (formId: number) => void;\n onMatchTypeChange: (matchType: MatchType) => void;\n onUpdateGroup: (index: number, group: ConditionGroupType) => void;\n}\n\nexport function ConditionGroupsSection({\n behaviorSection,\n dataPointOptions,\n formFieldOptions,\n forms,\n groups,\n matchType,\n onFormSelect,\n onMatchTypeChange,\n onUpdateGroup,\n}: Readonly<ConditionGroupsSectionProps>) {\n const firstGroup = groups[0];\n if (!firstGroup) {\n return null;\n }\n\n return (\n <Flex direction=\"column\" gap=\"4\">\n <Flex direction=\"row\" alignItems=\"center\" gap=\"1\" style={{ flexWrap: 'wrap' }}>\n <Text size=\"small\" variant=\"body\" style={{ fontWeight: 'bold' }}>\n When\n </Text>\n <SegmentedControl\n selected={matchType}\n size=\"small\"\n onChange={(value: string) => onMatchTypeChange(value as MatchType)}\n >\n <SegmentedControl.Segment value=\"all\">All</SegmentedControl.Segment>\n <SegmentedControl.Segment value=\"any\">Any</SegmentedControl.Segment>\n </SegmentedControl>\n <Text size=\"small\" variant=\"body\" style={{ fontWeight: 'bold' }}>\n of the\n </Text>\n <Chip label=\"IF\" size=\"small\" />\n <Text size=\"small\" variant=\"body\" style={{ fontWeight: 'bold' }}>\n conditions are met\n </Text>\n </Flex>\n {behaviorSection}\n <ConditionGroup\n dataPointOptions={dataPointOptions}\n formFieldOptions={formFieldOptions}\n forms={forms}\n group={firstGroup}\n onFormSelect={onFormSelect}\n onUpdate={g => onUpdateGroup(0, g)}\n />\n </Flex>\n );\n}\n"],"names":["Chip","Flex","SegmentedControl","Text","ConditionGroup","ConditionGroupsSection","behaviorSection","dataPointOptions","formFieldOptions","forms","groups","matchType","onFormSelect","onMatchTypeChange","onUpdateGroup","firstGroup","direction","gap","alignItems","style","flexWrap","size","variant","fontWeight","selected","onChange","value","Segment","label","group","onUpdate","g"],"mappings":";AAAA,SAASA,IAAI,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,IAAI,QAAQ,uBAAuB;AAG1E,SAASC,cAAc,QAAQ,mBAAmB;AAkBlD,OAAO,SAASC,uBAAuB,EACnCC,eAAe,EACfC,gBAAgB,EAChBC,gBAAgB,EAChBC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,YAAY,EACZC,iBAAiB,EACjBC,aAAa,EACuB;IACpC,MAAMC,aAAaL,MAAM,CAAC,EAAE;IAC5B,IAAI,CAACK,YAAY;QACb,OAAO;IACX;IAEA,qBACI,MAACd;QAAKe,WAAU;QAASC,KAAI;;0BACzB,MAAChB;gBAAKe,WAAU;gBAAME,YAAW;gBAASD,KAAI;gBAAIE,OAAO;oBAAEC,UAAU;gBAAO;;kCACxE,KAACjB;wBAAKkB,MAAK;wBAAQC,SAAQ;wBAAOH,OAAO;4BAAEI,YAAY;wBAAO;kCAAG;;kCAGjE,MAACrB;wBACGsB,UAAUb;wBACVU,MAAK;wBACLI,UAAU,CAACC,QAAkBb,kBAAkBa;;0CAE/C,KAACxB,iBAAiByB,OAAO;gCAACD,OAAM;0CAAM;;0CACtC,KAACxB,iBAAiByB,OAAO;gCAACD,OAAM;0CAAM;;;;kCAE1C,KAACvB;wBAAKkB,MAAK;wBAAQC,SAAQ;wBAAOH,OAAO;4BAAEI,YAAY;wBAAO;kCAAG;;kCAGjE,KAACvB;wBAAK4B,OAAM;wBAAKP,MAAK;;kCACtB,KAAClB;wBAAKkB,MAAK;wBAAQC,SAAQ;wBAAOH,OAAO;4BAAEI,YAAY;wBAAO;kCAAG;;;;YAIpEjB;0BACD,KAACF;gBACGG,kBAAkBA;gBAClBC,kBAAkBA;gBAClBC,OAAOA;gBACPoB,OAAOd;gBACPH,cAAcA;gBACdkB,UAAUC,CAAAA,IAAKjB,cAAc,GAAGiB;;;;AAIhD"}
@@ -1,11 +1,15 @@
1
+ import { FormInfo } from '../shared/forms';
1
2
  import { SingleCondition } from './types';
2
- import type { DataPointOption } from './types';
3
+ import type { DataPointOption, FormFieldOption } from './types';
3
4
  export interface ConditionRowProps {
4
5
  canRemove: boolean;
5
6
  condition: SingleCondition;
6
7
  dataPointOptions: DataPointOption[];
8
+ formFieldOptions: FormFieldOption[];
9
+ forms: FormInfo[];
7
10
  onChange: (c: SingleCondition) => void;
11
+ onFormSelect: (formId: number) => void;
8
12
  onRemove: () => void;
9
13
  }
10
- export declare function ConditionRow({ canRemove, condition, dataPointOptions, onChange, onRemove, }: Readonly<ConditionRowProps>): import("react/jsx-runtime").JSX.Element;
14
+ export declare function ConditionRow({ canRemove, condition, dataPointOptions, formFieldOptions, forms, onChange, onFormSelect, onRemove, }: Readonly<ConditionRowProps>): import("react/jsx-runtime").JSX.Element;
11
15
  //# sourceMappingURL=ConditionRow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionRow.d.ts","sourceRoot":"","sources":["../../src/display-conditions/ConditionRow.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAoB,eAAe,EAA0C,MAAM,SAAS,CAAC;AACpG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,iBAAiB;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,eAAe,CAAC;IAC3B,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACxB;AAsBD,wBAAgB,YAAY,CAAC,EACzB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,QAAQ,GACX,EAAE,QAAQ,CAAC,iBAAiB,CAAC,2CA0J7B"}
1
+ {"version":3,"file":"ConditionRow.d.ts","sourceRoot":"","sources":["../../src/display-conditions/ConditionRow.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAqB,MAAM,iBAAiB,CAAC;AAC9D,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;AA4BD,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,2CA4R7B"}
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Button, Chip, Combobox, Flex, TextField } from '@servicetitan/anvil2';
3
3
  import TrashIcon from '@servicetitan/anvil2/assets/icons/material/round/delete.svg';
4
- import { useMemo } from 'react';
4
+ import { useEffect, useMemo, useState } from 'react';
5
+ import { parseFormFieldKey } from '../shared/forms';
5
6
  import { NUMBER_OPERATORS, STRING_OPERATORS, VALUE_LESS_OPERATORS } from './types';
6
7
  function sanitizeNumericInput(raw) {
7
8
  // Allow only a single leading minus and one decimal separator.
@@ -17,12 +18,59 @@ function sanitizeNumericInput(raw) {
17
18
  }
18
19
  return value;
19
20
  }
20
- export function ConditionRow({ canRemove, condition, dataPointOptions, onChange, onRemove }) {
21
- const selectedDataPoint = useMemo(()=>{
22
- var _dataPointOptions_find;
23
- return (_dataPointOptions_find = dataPointOptions.find((opt)=>opt.fullKey === condition.dataPointKey)) !== null && _dataPointOptions_find !== void 0 ? _dataPointOptions_find : null;
21
+ export function ConditionRow({ canRemove, condition, dataPointOptions, formFieldOptions, forms, onChange, onFormSelect, onRemove }) {
22
+ const selectedFormFieldMeta = useMemo(()=>parseFormFieldKey(condition.dataPointKey), [
23
+ condition.dataPointKey
24
+ ]);
25
+ const [selectedSourceValue, setSelectedSourceValue] = useState(selectedFormFieldMeta ? `form:${selectedFormFieldMeta.formId}` : 'schema');
26
+ const sourceOptions = useMemo(()=>[
27
+ {
28
+ label: 'Data point',
29
+ value: 'schema'
30
+ },
31
+ ...forms.map((form)=>({
32
+ formId: form.id,
33
+ label: form.name,
34
+ value: `form:${form.id}`
35
+ }))
36
+ ], [
37
+ forms
38
+ ]);
39
+ const selectedSource = useMemo(()=>{
40
+ var _sourceOptions_find, _ref;
41
+ return (_ref = (_sourceOptions_find = sourceOptions.find((opt)=>opt.value === selectedSourceValue)) !== null && _sourceOptions_find !== void 0 ? _sourceOptions_find : sourceOptions[0]) !== null && _ref !== void 0 ? _ref : null;
24
42
  }, [
43
+ selectedSourceValue,
44
+ sourceOptions
45
+ ]);
46
+ useEffect(()=>{
47
+ if (selectedFormFieldMeta) {
48
+ setSelectedSourceValue(`form:${selectedFormFieldMeta.formId}`);
49
+ return;
50
+ }
51
+ if (!condition.dataPointKey) {
52
+ return;
53
+ }
54
+ const hasSchemaMatch = dataPointOptions.some((opt)=>opt.fullKey === condition.dataPointKey);
55
+ if (hasSchemaMatch) {
56
+ setSelectedSourceValue('schema');
57
+ }
58
+ }, [
59
+ condition.dataPointKey,
60
+ dataPointOptions,
61
+ selectedFormFieldMeta
62
+ ]);
63
+ const currentFormId = selectedSource === null || selectedSource === void 0 ? void 0 : selectedSource.formId;
64
+ const activeDataPointOptions = useMemo(()=>currentFormId ? formFieldOptions.filter((option)=>option.formId === currentFormId) : dataPointOptions, [
65
+ currentFormId,
25
66
  dataPointOptions,
67
+ formFieldOptions
68
+ ]);
69
+ const selectedDataPoint = useMemo(()=>{
70
+ var _activeDataPointOptions_find;
71
+ return (_activeDataPointOptions_find = activeDataPointOptions.find((opt)=>opt.fullKey === condition.dataPointKey)) !== null && _activeDataPointOptions_find !== void 0 ? _activeDataPointOptions_find : null;
72
+ }, [
73
+ activeDataPointOptions,
26
74
  condition.dataPointKey
27
75
  ]);
28
76
  var _selectedDataPoint_fieldType;
@@ -50,9 +98,7 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, onChange,
50
98
  });
51
99
  };
52
100
  const handleDataPointChange = (item)=>{
53
- var _item_fieldType;
54
- const nextFieldType = (_item_fieldType = item === null || item === void 0 ? void 0 : item.fieldType) !== null && _item_fieldType !== void 0 ? _item_fieldType : 'string';
55
- const nextIsNumber = nextFieldType === 'number';
101
+ const nextIsNumber = (item === null || item === void 0 ? void 0 : item.fieldType) === 'number';
56
102
  const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;
57
103
  const operatorReset = !nextOperatorItems.some((op)=>op.value === condition.operator);
58
104
  var _item_fullKey;
@@ -62,70 +108,54 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, onChange,
62
108
  operator: operatorReset ? nextIsNumber ? 'num_eq' : 'is_equal_to' : condition.operator
63
109
  });
64
110
  };
111
+ const handleSourceChange = (item)=>{
112
+ if (!item) {
113
+ return;
114
+ }
115
+ setSelectedSourceValue(item.value);
116
+ if (!item.formId) {
117
+ var _dataPointOptions_find;
118
+ const schemaField = (_dataPointOptions_find = dataPointOptions.find((opt)=>opt.fullKey === condition.dataPointKey)) !== null && _dataPointOptions_find !== void 0 ? _dataPointOptions_find : null;
119
+ var _schemaField_fieldType;
120
+ const nextFieldType = (_schemaField_fieldType = schemaField === null || schemaField === void 0 ? void 0 : schemaField.fieldType) !== null && _schemaField_fieldType !== void 0 ? _schemaField_fieldType : 'string';
121
+ const nextIsNumber = nextFieldType === 'number';
122
+ const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;
123
+ const operatorReset = !nextOperatorItems.some((op)=>op.value === condition.operator);
124
+ var _schemaField_fullKey;
125
+ onChange({
126
+ ...condition,
127
+ dataPointKey: (_schemaField_fullKey = schemaField === null || schemaField === void 0 ? void 0 : schemaField.fullKey) !== null && _schemaField_fullKey !== void 0 ? _schemaField_fullKey : '',
128
+ operator: operatorReset ? nextIsNumber ? 'num_eq' : 'is_equal_to' : condition.operator
129
+ });
130
+ return;
131
+ }
132
+ onFormSelect(item.formId);
133
+ const nextFormFieldOptions = formFieldOptions.filter((option)=>option.formId === item.formId);
134
+ const currentSelected = nextFormFieldOptions.find((opt)=>opt.fullKey === condition.dataPointKey);
135
+ var _ref;
136
+ const nextSelected = (_ref = currentSelected !== null && currentSelected !== void 0 ? currentSelected : nextFormFieldOptions[0]) !== null && _ref !== void 0 ? _ref : null;
137
+ var _nextSelected_fieldType;
138
+ const nextFieldType = (_nextSelected_fieldType = nextSelected === null || nextSelected === void 0 ? void 0 : nextSelected.fieldType) !== null && _nextSelected_fieldType !== void 0 ? _nextSelected_fieldType : 'string';
139
+ const nextIsNumber = nextFieldType === 'number';
140
+ const nextOperatorItems = nextIsNumber ? NUMBER_OPERATORS : STRING_OPERATORS;
141
+ const operatorReset = !nextOperatorItems.some((op)=>op.value === condition.operator);
142
+ var _nextSelected_fullKey;
143
+ onChange({
144
+ ...condition,
145
+ dataPointKey: (_nextSelected_fullKey = nextSelected === null || nextSelected === void 0 ? void 0 : nextSelected.fullKey) !== null && _nextSelected_fullKey !== void 0 ? _nextSelected_fullKey : '',
146
+ operator: operatorReset ? nextIsNumber ? 'num_eq' : 'is_equal_to' : condition.operator
147
+ });
148
+ };
65
149
  return /*#__PURE__*/ _jsxs(Flex, {
66
- direction: "row",
67
- alignItems: "flex-end",
68
- gap: "2",
150
+ direction: "column",
151
+ gap: "3",
69
152
  style: {
70
- flexWrap: 'wrap',
71
- rowGap: 8,
72
153
  width: '100%'
73
154
  },
74
155
  children: [
75
156
  /*#__PURE__*/ _jsx("div", {
76
157
  style: {
77
- display: 'flex',
78
- alignItems: 'flex-end',
79
- flexShrink: 0,
80
- padding: '4px 8px'
81
- },
82
- children: /*#__PURE__*/ _jsx(Chip, {
83
- label: "IF",
84
- size: "small"
85
- })
86
- }),
87
- /*#__PURE__*/ _jsx("div", {
88
- style: {
89
- flex: '2 1 240px',
90
- minWidth: 200
91
- },
92
- children: /*#__PURE__*/ _jsxs(Combobox, {
93
- ...{
94
- disableClearSelection: true
95
- },
96
- itemToKey: (item)=>{
97
- var _item_fullKey;
98
- return (_item_fullKey = item === null || item === void 0 ? void 0 : item.fullKey) !== null && _item_fullKey !== void 0 ? _item_fullKey : '';
99
- },
100
- itemToString: (item)=>{
101
- var _item_title;
102
- return (_item_title = item === null || item === void 0 ? void 0 : item.title) !== null && _item_title !== void 0 ? _item_title : '';
103
- },
104
- items: dataPointOptions,
105
- selectedItem: selectedDataPoint,
106
- onChange: handleDataPointChange,
107
- children: [
108
- /*#__PURE__*/ _jsx(Combobox.SelectTrigger, {
109
- label: "Data point",
110
- placeholder: "Select data point...",
111
- size: "small"
112
- }),
113
- /*#__PURE__*/ _jsx(Combobox.Content, {
114
- children: ({ items })=>/*#__PURE__*/ _jsx(Combobox.List, {
115
- children: items.map((item, i)=>/*#__PURE__*/ _jsx(Combobox.Item, {
116
- index: i,
117
- item: item,
118
- children: item.title
119
- }, item.fullKey))
120
- })
121
- })
122
- ]
123
- })
124
- }),
125
- /*#__PURE__*/ _jsx("div", {
126
- style: {
127
- flex: '1 1 180px',
128
- minWidth: 150
158
+ width: '100%'
129
159
  },
130
160
  children: /*#__PURE__*/ _jsxs(Combobox, {
131
161
  ...{
@@ -139,19 +169,13 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, onChange,
139
169
  var _item_label;
140
170
  return (_item_label = item === null || item === void 0 ? void 0 : item.label) !== null && _item_label !== void 0 ? _item_label : '';
141
171
  },
142
- items: operatorItems,
143
- selectedItem: selectedOperator,
144
- onChange: (item)=>{
145
- var _item_value;
146
- return onChange({
147
- ...condition,
148
- operator: (_item_value = item === null || item === void 0 ? void 0 : item.value) !== null && _item_value !== void 0 ? _item_value : 'is_equal_to'
149
- });
150
- },
172
+ items: sourceOptions,
173
+ selectedItem: selectedSource,
174
+ onChange: handleSourceChange,
151
175
  children: [
152
176
  /*#__PURE__*/ _jsx(Combobox.SelectTrigger, {
153
- label: "Condition",
154
- placeholder: "Select...",
177
+ label: "Data Type",
178
+ placeholder: "Select source...",
155
179
  size: "small"
156
180
  }),
157
181
  /*#__PURE__*/ _jsx(Combobox.Content, {
@@ -166,42 +190,148 @@ export function ConditionRow({ canRemove, condition, dataPointOptions, onChange,
166
190
  ]
167
191
  })
168
192
  }),
169
- !isValueLess && /*#__PURE__*/ _jsx("div", {
193
+ /*#__PURE__*/ _jsxs(Flex, {
194
+ direction: "row",
195
+ alignItems: "flex-end",
196
+ gap: "2",
170
197
  style: {
171
- flex: '1 1 180px',
172
- minWidth: 150
198
+ flexWrap: 'wrap',
199
+ rowGap: 8,
200
+ width: '100%'
173
201
  },
174
- children: /*#__PURE__*/ _jsx(TextField, {
175
- label: "Value",
176
- size: "small",
177
- value: condition.value,
178
- onChange: (e)=>handleValueChange(e.target.value),
179
- placeholder: fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...',
180
- style: {
181
- width: '100%'
182
- },
183
- "aria-label": "Value",
184
- ...fieldType === 'number' && {
185
- inputMode: 'decimal'
186
- }
187
- })
188
- }),
189
- canRemove && /*#__PURE__*/ _jsx("div", {
190
- style: {
191
- display: 'flex',
192
- alignItems: 'flex-end',
193
- flexShrink: 0,
194
- padding: '4px 8px'
195
- },
196
- children: /*#__PURE__*/ _jsx(Button, {
197
- appearance: "secondary",
198
- "aria-label": "Remove condition",
199
- icon: {
200
- before: TrashIcon
201
- },
202
- size: "small",
203
- onClick: onRemove
204
- })
202
+ children: [
203
+ /*#__PURE__*/ _jsx("div", {
204
+ style: {
205
+ display: 'flex',
206
+ alignItems: 'flex-end',
207
+ flexShrink: 0,
208
+ padding: '4px 8px'
209
+ },
210
+ children: /*#__PURE__*/ _jsx(Chip, {
211
+ label: "IF",
212
+ size: "small"
213
+ })
214
+ }),
215
+ /*#__PURE__*/ _jsx("div", {
216
+ style: {
217
+ flex: '2 1 240px',
218
+ minWidth: 200
219
+ },
220
+ children: /*#__PURE__*/ _jsxs(Combobox, {
221
+ ...{
222
+ disableClearSelection: true
223
+ },
224
+ itemToKey: (item)=>{
225
+ var _item_fullKey;
226
+ return (_item_fullKey = item === null || item === void 0 ? void 0 : item.fullKey) !== null && _item_fullKey !== void 0 ? _item_fullKey : '';
227
+ },
228
+ itemToString: (item)=>{
229
+ var _item_title;
230
+ return (_item_title = item === null || item === void 0 ? void 0 : item.title) !== null && _item_title !== void 0 ? _item_title : '';
231
+ },
232
+ items: activeDataPointOptions,
233
+ selectedItem: selectedDataPoint,
234
+ onChange: handleDataPointChange,
235
+ children: [
236
+ /*#__PURE__*/ _jsx(Combobox.SelectTrigger, {
237
+ label: "Data Point",
238
+ placeholder: currentFormId ? 'Select form field...' : 'Select data point...',
239
+ size: "small"
240
+ }),
241
+ /*#__PURE__*/ _jsx(Combobox.Content, {
242
+ children: ({ items })=>/*#__PURE__*/ _jsx(Combobox.List, {
243
+ children: items.map((item, i)=>/*#__PURE__*/ _jsx(Combobox.Item, {
244
+ index: i,
245
+ item: item,
246
+ children: item.title
247
+ }, item.fullKey))
248
+ })
249
+ })
250
+ ]
251
+ })
252
+ }),
253
+ /*#__PURE__*/ _jsx("div", {
254
+ style: {
255
+ flex: '1 1 180px',
256
+ minWidth: 150
257
+ },
258
+ children: /*#__PURE__*/ _jsxs(Combobox, {
259
+ ...{
260
+ disableClearSelection: true
261
+ },
262
+ itemToKey: (item)=>{
263
+ var _item_value;
264
+ return (_item_value = item === null || item === void 0 ? void 0 : item.value) !== null && _item_value !== void 0 ? _item_value : '';
265
+ },
266
+ itemToString: (item)=>{
267
+ var _item_label;
268
+ return (_item_label = item === null || item === void 0 ? void 0 : item.label) !== null && _item_label !== void 0 ? _item_label : '';
269
+ },
270
+ items: operatorItems,
271
+ selectedItem: selectedOperator,
272
+ onChange: (item)=>{
273
+ var _item_value;
274
+ return onChange({
275
+ ...condition,
276
+ operator: (_item_value = item === null || item === void 0 ? void 0 : item.value) !== null && _item_value !== void 0 ? _item_value : 'is_equal_to'
277
+ });
278
+ },
279
+ children: [
280
+ /*#__PURE__*/ _jsx(Combobox.SelectTrigger, {
281
+ label: "Condition",
282
+ placeholder: "Select...",
283
+ size: "small"
284
+ }),
285
+ /*#__PURE__*/ _jsx(Combobox.Content, {
286
+ children: ({ items })=>/*#__PURE__*/ _jsx(Combobox.List, {
287
+ children: items.map((item, i)=>/*#__PURE__*/ _jsx(Combobox.Item, {
288
+ index: i,
289
+ item: item,
290
+ children: item.label
291
+ }, item.value))
292
+ })
293
+ })
294
+ ]
295
+ })
296
+ }),
297
+ !isValueLess && /*#__PURE__*/ _jsx("div", {
298
+ style: {
299
+ flex: '1 1 180px',
300
+ minWidth: 150
301
+ },
302
+ children: /*#__PURE__*/ _jsx(TextField, {
303
+ label: "Value",
304
+ size: "small",
305
+ value: condition.value,
306
+ onChange: (e)=>handleValueChange(e.target.value),
307
+ placeholder: fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...',
308
+ style: {
309
+ width: '100%'
310
+ },
311
+ "aria-label": "Value",
312
+ ...fieldType === 'number' && {
313
+ inputMode: 'decimal'
314
+ }
315
+ })
316
+ }),
317
+ canRemove && /*#__PURE__*/ _jsx("div", {
318
+ style: {
319
+ display: 'flex',
320
+ alignItems: 'flex-end',
321
+ flexShrink: 0,
322
+ padding: '4px 8px'
323
+ },
324
+ children: /*#__PURE__*/ _jsx(Button, {
325
+ appearance: "secondary",
326
+ "aria-label": "Remove condition",
327
+ icon: {
328
+ before: TrashIcon
329
+ },
330
+ size: "small",
331
+ onClick: onRemove
332
+ })
333
+ })
334
+ ]
205
335
  })
206
336
  ]
207
337
  });