@servicetitan/dte-pdf-editor 1.34.0 → 1.36.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/README.md +28 -12
- package/dist/components/display-conditions/condition-row.d.ts.map +1 -1
- package/dist/components/display-conditions/condition-row.js +1 -1
- package/dist/components/display-conditions/condition-row.js.map +1 -1
- package/dist/components/field-config-panel/advanced-settings.d.ts.map +1 -1
- package/dist/components/field-config-panel/advanced-settings.js +20 -10
- package/dist/components/field-config-panel/advanced-settings.js.map +1 -1
- package/dist/components/field-config-panel/formula-generator.d.ts.map +1 -1
- package/dist/components/field-config-panel/formula-generator.js +2 -1
- package/dist/components/field-config-panel/formula-generator.js.map +1 -1
- package/dist/components/field-config-panel/formula-modal.d.ts.map +1 -1
- package/dist/components/field-config-panel/formula-modal.js +47 -6
- package/dist/components/field-config-panel/formula-modal.js.map +1 -1
- package/dist/components/field-config-panel/formula-workspace.d.ts +1 -0
- package/dist/components/field-config-panel/formula-workspace.d.ts.map +1 -1
- package/dist/components/field-config-panel/formula-workspace.js +10 -4
- package/dist/components/field-config-panel/formula-workspace.js.map +1 -1
- package/dist/components/field-config-panel/result-type-selector.d.ts.map +1 -1
- package/dist/components/field-config-panel/result-type-selector.js +1 -0
- package/dist/components/field-config-panel/result-type-selector.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-calculated.d.ts +1 -0
- package/dist/components/pdf-view/pdf-view-calculated.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view-calculated.js +20 -3
- package/dist/components/pdf-view/pdf-view-calculated.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-fillable.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view-fillable.js +5 -2
- package/dist/components/pdf-view/pdf-view-fillable.js.map +1 -1
- package/dist/components/pdf-view/pdf-view.d.ts +6 -0
- package/dist/components/pdf-view/pdf-view.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view.js +2 -2
- package/dist/components/pdf-view/pdf-view.js.map +1 -1
- package/dist/constants/calculated.constants.d.ts +2 -0
- package/dist/constants/calculated.constants.d.ts.map +1 -1
- package/dist/constants/calculated.constants.js +2 -0
- package/dist/constants/calculated.constants.js.map +1 -1
- package/dist/hooks/useFormulaEditor.d.ts +3 -0
- package/dist/hooks/useFormulaEditor.d.ts.map +1 -1
- package/dist/hooks/useFormulaEditor.js +43 -35
- package/dist/hooks/useFormulaEditor.js.map +1 -1
- package/dist/interface/types.d.ts +7 -1
- package/dist/interface/types.d.ts.map +1 -1
- package/dist/interface/types.js.map +1 -1
- package/dist/utils/conditions/schema-data-points.utils.d.ts.map +1 -1
- package/dist/utils/conditions/schema-data-points.utils.js +4 -1
- package/dist/utils/conditions/schema-data-points.utils.js.map +1 -1
- package/dist/utils/data-model/extract-fields.utils.d.ts.map +1 -1
- package/dist/utils/data-model/extract-fields.utils.js +11 -1
- package/dist/utils/data-model/extract-fields.utils.js.map +1 -1
- package/dist/utils/formula/caret.utils.js +4 -4
- package/dist/utils/formula/caret.utils.js.map +1 -1
- package/dist/utils/formula/dom.utils.js +2 -2
- package/dist/utils/formula/dom.utils.js.map +1 -1
- package/dist/utils/formula/evaluate-formula.utils.d.ts +10 -2
- package/dist/utils/formula/evaluate-formula.utils.d.ts.map +1 -1
- package/dist/utils/formula/evaluate-formula.utils.js +205 -4
- package/dist/utils/formula/evaluate-formula.utils.js.map +1 -1
- package/dist/utils/formula/expression.utils.d.ts +10 -9
- package/dist/utils/formula/expression.utils.d.ts.map +1 -1
- package/dist/utils/formula/expression.utils.js +39 -41
- package/dist/utils/formula/expression.utils.js.map +1 -1
- package/dist/utils/formula/format-calculated-result.utils.d.ts +1 -1
- package/dist/utils/formula/format-calculated-result.utils.d.ts.map +1 -1
- package/dist/utils/formula/format-calculated-result.utils.js +29 -8
- package/dist/utils/formula/format-calculated-result.utils.js.map +1 -1
- package/dist/utils/formula/index.d.ts +0 -2
- package/dist/utils/formula/index.d.ts.map +1 -1
- package/dist/utils/formula/index.js +0 -2
- package/dist/utils/formula/index.js.map +1 -1
- package/dist/utils/formula/validate-formula.utils.d.ts +1 -1
- package/dist/utils/formula/validate-formula.utils.d.ts.map +1 -1
- package/dist/utils/formula/validate-formula.utils.js +15 -1
- package/dist/utils/formula/validate-formula.utils.js.map +1 -1
- package/dist/utils/shared/date.utils.d.ts +2 -0
- package/dist/utils/shared/date.utils.d.ts.map +1 -0
- package/dist/utils/shared/date.utils.js +6 -0
- package/dist/utils/shared/date.utils.js.map +1 -0
- package/dist/utils/shared/index.d.ts +1 -0
- package/dist/utils/shared/index.d.ts.map +1 -1
- package/dist/utils/shared/index.js +1 -0
- package/dist/utils/shared/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/display-conditions/condition-row.tsx +1 -0
- package/src/components/field-config-panel/advanced-settings.tsx +103 -77
- package/src/components/field-config-panel/formula-generator.tsx +2 -1
- package/src/components/field-config-panel/formula-modal.tsx +46 -6
- package/src/components/field-config-panel/formula-workspace.tsx +21 -7
- package/src/components/field-config-panel/result-type-selector.tsx +1 -0
- package/src/components/pdf-view/pdf-view-calculated.tsx +20 -3
- package/src/components/pdf-view/pdf-view-fillable.tsx +6 -3
- package/src/components/pdf-view/pdf-view.tsx +8 -0
- package/src/constants/calculated.constants.ts +4 -0
- package/src/hooks/useFormulaEditor.ts +108 -97
- package/src/interface/types.ts +8 -1
- package/src/utils/conditions/schema-data-points.utils.ts +4 -1
- package/src/utils/data-model/extract-fields.utils.ts +13 -1
- package/src/utils/formula/caret.utils.ts +1 -1
- package/src/utils/formula/dom.utils.ts +1 -1
- package/src/utils/formula/evaluate-formula.utils.ts +271 -5
- package/src/utils/formula/expression.utils.ts +44 -47
- package/src/utils/formula/format-calculated-result.utils.ts +32 -10
- package/src/utils/formula/index.ts +0 -2
- package/src/utils/formula/validate-formula.utils.ts +24 -0
- package/src/utils/shared/date.utils.ts +6 -0
- package/src/utils/shared/index.ts +1 -0
- package/dist/utils/formula/referenced-paths.utils.d.ts +0 -7
- package/dist/utils/formula/referenced-paths.utils.d.ts.map +0 -1
- package/dist/utils/formula/referenced-paths.utils.js +0 -18
- package/dist/utils/formula/referenced-paths.utils.js.map +0 -1
- package/dist/utils/formula/serialize-formula.utils.d.ts +0 -14
- package/dist/utils/formula/serialize-formula.utils.d.ts.map +0 -1
- package/dist/utils/formula/serialize-formula.utils.js +0 -33
- package/dist/utils/formula/serialize-formula.utils.js.map +0 -1
- package/src/utils/formula/referenced-paths.utils.ts +0 -18
- package/src/utils/formula/serialize-formula.utils.ts +0 -40
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-formula.utils.js","sourceRoot":"","sources":["../../../src/utils/formula/validate-formula.utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-formula.utils.js","sourceRoot":"","sources":["../../../src/utils/formula/validate-formula.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAQrD,SAAS,eAAe,CAAC,CAAe;IACpC,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;AACjC,CAAC;AAED,SAAS,cAAc,CAAC,CAAe;IACnC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC3B,OAA6C,EAC7C,UAAuB,EACvB,eAA6B;;IAE7B,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,0CAAE,MAAM,CAAA,EAAE,CAAC;QAC3B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,yBAAyB,CAAC,EAAE,CAAC;IACjE,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAA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,CAC7E,CAAC;YACF,IAAI,cAAc,EAAE,CAAC;gBACjB,MAAM,CAAC,IAAI,CACP,gCAAgC,kBAAkB,wBAAwB,CAC7E,CAAC;YACN,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO;QACH,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACT,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.utils.d.ts","sourceRoot":"","sources":["../../../src/utils/shared/date.utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,YAAY,MAAM,KAAG,MAKlD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.utils.js","sourceRoot":"","sources":["../../../src/utils/shared/date.utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,UAAkB,EAAU,EAAE;IACxD,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAEzD,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -100,6 +100,7 @@ export function ConditionRow({
|
|
|
100
100
|
<Flex flex={1}>
|
|
101
101
|
<Combobox
|
|
102
102
|
flex={1}
|
|
103
|
+
groupBy="group"
|
|
103
104
|
itemToKey={(item: DataPointOption | null) => item?.fullKey ?? ''}
|
|
104
105
|
itemToString={(item: DataPointOption | null) => item?.title ?? ''}
|
|
105
106
|
items={dataPointOptions}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Flex, SegmentedControl, Switch, Text } from '@servicetitan/anvil2';
|
|
2
2
|
import { Dispatch, FC, SetStateAction } from 'react';
|
|
3
|
+
import { DEFAULT_DATE_FORMAT } from '../../constants';
|
|
3
4
|
import { CalculatedFieldFormat } from '../../interface/types';
|
|
4
5
|
|
|
5
6
|
interface AdvancedSettingsProps {
|
|
@@ -13,97 +14,122 @@ const ROUNDING_OPTIONS: { label: string; value: CalculatedFieldFormat['roundingM
|
|
|
13
14
|
{ label: 'Ceil', value: 'ceil' },
|
|
14
15
|
];
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
const DateFormatSettings: FC<AdvancedSettingsProps> = ({ format, setFormat }) => (
|
|
17
18
|
<div className="dte-formula-advanced">
|
|
18
19
|
<Text variant="body" size="small">
|
|
19
|
-
|
|
20
|
+
Date format
|
|
20
21
|
</Text>
|
|
21
|
-
<SegmentedControl
|
|
22
|
-
size="medium"
|
|
23
|
-
selected={format.roundingMode}
|
|
24
|
-
onChange={(roundingMode: CalculatedFieldFormat['roundingMode']) =>
|
|
25
|
-
setFormat(prev => ({ ...prev, roundingMode }))
|
|
26
|
-
}
|
|
27
|
-
fill
|
|
28
|
-
>
|
|
29
|
-
{ROUNDING_OPTIONS.map(opt => (
|
|
30
|
-
<SegmentedControl.Segment key={opt.value} value={opt.value}>
|
|
31
|
-
{opt.label}
|
|
32
|
-
</SegmentedControl.Segment>
|
|
33
|
-
))}
|
|
34
|
-
</SegmentedControl>
|
|
35
|
-
<Flex alignItems="center" justifyContent="space-between">
|
|
36
|
-
<Text variant="body" size="small">
|
|
37
|
-
Decimal places
|
|
38
|
-
</Text>
|
|
39
|
-
<Text variant="body" size="small" className="dte-formula-advanced-value">
|
|
40
|
-
{format.decimals}
|
|
41
|
-
</Text>
|
|
42
|
-
</Flex>
|
|
43
22
|
<input
|
|
44
|
-
type="
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
value={format.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...prev,
|
|
51
|
-
decimals: Number(e.target.value),
|
|
52
|
-
}))
|
|
53
|
-
}
|
|
54
|
-
/>
|
|
55
|
-
<Switch
|
|
56
|
-
checked={format.thousandsSeparator}
|
|
57
|
-
onChange={(_e, { checked }) => {
|
|
58
|
-
setFormat(prev => ({
|
|
59
|
-
...prev,
|
|
60
|
-
thousandsSeparator: checked,
|
|
61
|
-
decimalSeparatorEnabled: checked,
|
|
62
|
-
decimalSeparator: checked ? prev.decimalSeparator : '.',
|
|
63
|
-
}));
|
|
64
|
-
}}
|
|
65
|
-
label="Thousands separator"
|
|
66
|
-
value="switch-example"
|
|
23
|
+
type="text"
|
|
24
|
+
className="dte-formula-advanced-input"
|
|
25
|
+
style={{ width: '100%' }}
|
|
26
|
+
value={format.dateFormat ?? DEFAULT_DATE_FORMAT}
|
|
27
|
+
placeholder={DEFAULT_DATE_FORMAT}
|
|
28
|
+
onChange={e => setFormat(prev => ({ ...prev, dateFormat: e.target.value }))}
|
|
67
29
|
/>
|
|
30
|
+
<Text variant="body" size="small" color="tertiary">
|
|
31
|
+
Tokens: YYYY, YY, MMMM, MMM, MM, M, DD, D
|
|
32
|
+
</Text>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const AdvancedSettings: FC<AdvancedSettingsProps> = ({ format, setFormat }) => {
|
|
37
|
+
if (format.resultType === 'date') {
|
|
38
|
+
return <DateFormatSettings format={format} setFormat={setFormat} />;
|
|
39
|
+
}
|
|
68
40
|
|
|
69
|
-
|
|
41
|
+
return (
|
|
42
|
+
<div className="dte-formula-advanced">
|
|
43
|
+
<Text variant="body" size="small">
|
|
44
|
+
Rounding mode
|
|
45
|
+
</Text>
|
|
70
46
|
<SegmentedControl
|
|
71
47
|
size="medium"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
setFormat(prev => ({ ...prev, decimalSeparator }))
|
|
48
|
+
selected={format.roundingMode}
|
|
49
|
+
onChange={(roundingMode: CalculatedFieldFormat['roundingMode']) =>
|
|
50
|
+
setFormat(prev => ({ ...prev, roundingMode }))
|
|
76
51
|
}
|
|
52
|
+
fill
|
|
77
53
|
>
|
|
78
|
-
{
|
|
79
|
-
<SegmentedControl.Segment key={
|
|
80
|
-
{
|
|
54
|
+
{ROUNDING_OPTIONS.map(opt => (
|
|
55
|
+
<SegmentedControl.Segment key={opt.value} value={opt.value}>
|
|
56
|
+
{opt.label}
|
|
81
57
|
</SegmentedControl.Segment>
|
|
82
58
|
))}
|
|
83
59
|
</SegmentedControl>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
</
|
|
60
|
+
<Flex alignItems="center" justifyContent="space-between">
|
|
61
|
+
<Text variant="body" size="small">
|
|
62
|
+
Decimal places
|
|
63
|
+
</Text>
|
|
64
|
+
<Text variant="body" size="small" className="dte-formula-advanced-value">
|
|
65
|
+
{format.decimals}
|
|
66
|
+
</Text>
|
|
67
|
+
</Flex>
|
|
92
68
|
<input
|
|
93
|
-
type="
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
69
|
+
type="range"
|
|
70
|
+
min={0}
|
|
71
|
+
max={10}
|
|
72
|
+
value={format.decimals}
|
|
73
|
+
onChange={e =>
|
|
74
|
+
setFormat(prev => ({
|
|
75
|
+
...prev,
|
|
76
|
+
decimals: Number(e.target.value),
|
|
77
|
+
}))
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
<Switch
|
|
81
|
+
checked={format.thousandsSeparator}
|
|
82
|
+
onChange={(_e, { checked }) => {
|
|
83
|
+
setFormat(prev => ({
|
|
84
|
+
...prev,
|
|
85
|
+
thousandsSeparator: checked,
|
|
86
|
+
decimalSeparatorEnabled: checked,
|
|
87
|
+
decimalSeparator: checked ? prev.decimalSeparator : '.',
|
|
88
|
+
}));
|
|
89
|
+
}}
|
|
90
|
+
label="Thousands separator"
|
|
91
|
+
value="switch-example"
|
|
97
92
|
/>
|
|
93
|
+
|
|
94
|
+
{format.thousandsSeparator && (
|
|
95
|
+
<SegmentedControl
|
|
96
|
+
size="medium"
|
|
97
|
+
fill
|
|
98
|
+
selected={format.decimalSeparator}
|
|
99
|
+
onChange={(decimalSeparator: CalculatedFieldFormat['decimalSeparator']) =>
|
|
100
|
+
setFormat(prev => ({ ...prev, decimalSeparator }))
|
|
101
|
+
}
|
|
102
|
+
>
|
|
103
|
+
{['.', ','].map(decimalSeparator => (
|
|
104
|
+
<SegmentedControl.Segment key={decimalSeparator} value={decimalSeparator}>
|
|
105
|
+
{decimalSeparator}
|
|
106
|
+
</SegmentedControl.Segment>
|
|
107
|
+
))}
|
|
108
|
+
</SegmentedControl>
|
|
109
|
+
)}
|
|
98
110
|
<Text variant="body" size="small">
|
|
99
|
-
|
|
111
|
+
Result affixes
|
|
100
112
|
</Text>
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
113
|
+
<Flex gap="2" alignItems="center">
|
|
114
|
+
<Text variant="body" size="small">
|
|
115
|
+
Prefix
|
|
116
|
+
</Text>
|
|
117
|
+
<input
|
|
118
|
+
type="text"
|
|
119
|
+
className="dte-formula-advanced-input"
|
|
120
|
+
value={format.prefixText}
|
|
121
|
+
onChange={e => setFormat(prev => ({ ...prev, prefixText: e.target.value }))}
|
|
122
|
+
/>
|
|
123
|
+
<Text variant="body" size="small">
|
|
124
|
+
Postfix
|
|
125
|
+
</Text>
|
|
126
|
+
<input
|
|
127
|
+
type="text"
|
|
128
|
+
className="dte-formula-advanced-input"
|
|
129
|
+
value={format.postfixText}
|
|
130
|
+
onChange={e => setFormat(prev => ({ ...prev, postfixText: e.target.value }))}
|
|
131
|
+
/>
|
|
132
|
+
</Flex>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
@@ -32,6 +32,7 @@ function getFillableFilteredBuySubTypeFields(
|
|
|
32
32
|
type: FieldTypeEnum.fillable,
|
|
33
33
|
subType: f.subType,
|
|
34
34
|
path: f.path,
|
|
35
|
+
fieldType: f.subType === 'date' ? 'date' : 'number',
|
|
35
36
|
}));
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -53,7 +54,7 @@ export const FormulaGenerator: FC<FormulaGeneratorProps> = ({
|
|
|
53
54
|
[dataModel],
|
|
54
55
|
);
|
|
55
56
|
const fillableFieldsFromDocument = useMemo(
|
|
56
|
-
() => getFillableFilteredBuySubTypeFields(documentFields, ['number']),
|
|
57
|
+
() => getFillableFilteredBuySubTypeFields(documentFields, ['number', 'date']),
|
|
57
58
|
[documentFields],
|
|
58
59
|
);
|
|
59
60
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Button, Dialog, Divider, Flex } from '@servicetitan/anvil2';
|
|
2
2
|
import IconRedo from '@servicetitan/anvil2/assets/icons/material/round/redo.svg';
|
|
3
3
|
import IconUndo from '@servicetitan/anvil2/assets/icons/material/round/undo.svg';
|
|
4
|
-
import { FC, useCallback, useMemo, useState } from 'react';
|
|
5
|
-
import { MODAL_CONTENT_MAX_HEIGHT } from '../../constants';
|
|
4
|
+
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import { DEFAULT_DATE_FORMAT, MODAL_CONTENT_MAX_HEIGHT } from '../../constants';
|
|
6
6
|
import { useFormulaEditor } from '../../hooks';
|
|
7
7
|
import {
|
|
8
8
|
CalculatedFieldFormat,
|
|
@@ -92,6 +92,21 @@ export const FormulaModal: FC<FormulaModalProps> = ({
|
|
|
92
92
|
return m;
|
|
93
93
|
}, [allFields, fillableFieldsFromDocument]);
|
|
94
94
|
|
|
95
|
+
const knownDateFields = useMemo(() => {
|
|
96
|
+
const set = new Set<string>();
|
|
97
|
+
for (const f of allFields) {
|
|
98
|
+
if (f.fieldType === 'date' && f.path) {
|
|
99
|
+
set.add(f.path);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const f of fillableFieldsFromDocument) {
|
|
103
|
+
if (f.fieldType === 'date' && f.path) {
|
|
104
|
+
set.add(f.path);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return set;
|
|
108
|
+
}, [allFields, fillableFieldsFromDocument]);
|
|
109
|
+
|
|
95
110
|
const currentExpression = useMemo(() => tokensToExpression(initialFormula), [initialFormula]);
|
|
96
111
|
|
|
97
112
|
const [highlightElementPath, setHighlightElementPath] = useState('');
|
|
@@ -102,18 +117,35 @@ export const FormulaModal: FC<FormulaModalProps> = ({
|
|
|
102
117
|
|
|
103
118
|
const formulaEditor = useFormulaEditor({
|
|
104
119
|
currentExpression,
|
|
120
|
+
knownDateFields,
|
|
105
121
|
opened: true,
|
|
106
122
|
pathToLabel,
|
|
107
123
|
});
|
|
108
124
|
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (formulaEditor.expressionHasDateFields && format.resultType !== 'date') {
|
|
127
|
+
setFormat(prev => ({
|
|
128
|
+
...prev,
|
|
129
|
+
resultType: 'date',
|
|
130
|
+
dateFormat: prev.dateFormat ?? DEFAULT_DATE_FORMAT,
|
|
131
|
+
}));
|
|
132
|
+
setAdvancedOpen(true);
|
|
133
|
+
} else if (!formulaEditor.expressionHasDateFields && format.resultType === 'date') {
|
|
134
|
+
setFormat(prev => ({
|
|
135
|
+
...prev,
|
|
136
|
+
resultType: 'number',
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
}, [formulaEditor.expressionHasDateFields, format.resultType]);
|
|
140
|
+
|
|
109
141
|
const parsedTokens = useMemo(
|
|
110
142
|
() => parseExpression(formulaEditor.draftExpression, validPaths, pathToLabel),
|
|
111
143
|
[formulaEditor.draftExpression, validPaths, pathToLabel],
|
|
112
144
|
);
|
|
113
145
|
|
|
114
146
|
const formulaValidation = useMemo(
|
|
115
|
-
() => validateFormula({ tokens: parsedTokens }, validPaths),
|
|
116
|
-
[parsedTokens, validPaths],
|
|
147
|
+
() => validateFormula({ tokens: parsedTokens }, validPaths, knownDateFields),
|
|
148
|
+
[parsedTokens, validPaths, knownDateFields],
|
|
117
149
|
);
|
|
118
150
|
|
|
119
151
|
const unknownFieldErrors = useMemo(() => {
|
|
@@ -132,9 +164,16 @@ export const FormulaModal: FC<FormulaModalProps> = ({
|
|
|
132
164
|
}, [onClose]);
|
|
133
165
|
|
|
134
166
|
const handleSave = useCallback(() => {
|
|
135
|
-
|
|
167
|
+
const usedDatePaths = parsedTokens
|
|
168
|
+
.filter(t => t.type === 'field' && knownDateFields.has(t.path))
|
|
169
|
+
.map(t => (t as { type: 'field'; path: string }).path);
|
|
170
|
+
const savedFormat: CalculatedFieldFormat = {
|
|
171
|
+
...format,
|
|
172
|
+
dateFieldPaths: usedDatePaths.length > 0 ? [...new Set(usedDatePaths)] : undefined,
|
|
173
|
+
};
|
|
174
|
+
onSave({ tokens: parsedTokens }, savedFormat);
|
|
136
175
|
onClose();
|
|
137
|
-
}, [format, onClose, onSave, parsedTokens]);
|
|
176
|
+
}, [format, knownDateFields, onClose, onSave, parsedTokens]);
|
|
138
177
|
|
|
139
178
|
const validationError = unknownFieldErrors[0] ?? formulaValidation.errors[0] ?? '';
|
|
140
179
|
const isInvalid = !formulaValidation.valid || unknownFieldErrors.length > 0;
|
|
@@ -164,6 +203,7 @@ export const FormulaModal: FC<FormulaModalProps> = ({
|
|
|
164
203
|
selectedPaths={formulaEditor.selectedFieldPaths}
|
|
165
204
|
/>
|
|
166
205
|
<FormulaWorkspace
|
|
206
|
+
disabledOperators={formulaEditor.disabledOperators}
|
|
167
207
|
editorRef={formulaEditor.editorRef}
|
|
168
208
|
isInvalid={isInvalid && formulaEditor.isDirty}
|
|
169
209
|
validationError={validationError}
|
|
@@ -17,6 +17,7 @@ import { ResultTypeSelector } from './result-type-selector';
|
|
|
17
17
|
interface FormulaWorkspaceProps {
|
|
18
18
|
actions: ReactNode;
|
|
19
19
|
advancedOpen: boolean;
|
|
20
|
+
disabledOperators?: Set<string>;
|
|
20
21
|
editorRef: RefObject<HTMLDivElement | null>;
|
|
21
22
|
format: CalculatedFieldFormat;
|
|
22
23
|
isInvalid: boolean;
|
|
@@ -36,6 +37,7 @@ interface FormulaWorkspaceProps {
|
|
|
36
37
|
export const FormulaWorkspace: FC<FormulaWorkspaceProps> = ({
|
|
37
38
|
actions,
|
|
38
39
|
advancedOpen,
|
|
40
|
+
disabledOperators,
|
|
39
41
|
editorRef,
|
|
40
42
|
format,
|
|
41
43
|
isInvalid,
|
|
@@ -73,8 +75,11 @@ export const FormulaWorkspace: FC<FormulaWorkspaceProps> = ({
|
|
|
73
75
|
return (
|
|
74
76
|
<Flex direction="column" flex={1} gap={2} style={{ padding: '12px' }}>
|
|
75
77
|
<Text variant="body" size="small">
|
|
76
|
-
Click a field on the left to add it. Use +, -,
|
|
77
|
-
formulas.
|
|
78
|
+
Click a field on the left to add it. Use +, -,{' '}
|
|
79
|
+
{disabledOperators?.has('*') ? '' : '*, /, and '}parentheses to build formulas.
|
|
80
|
+
{disabledOperators?.has('*')
|
|
81
|
+
? ' Multiply and divide are not available with date fields.'
|
|
82
|
+
: ''}
|
|
78
83
|
</Text>
|
|
79
84
|
<Flex alignItems="center" justifyContent="space-between">
|
|
80
85
|
<Text variant="body" size="small">
|
|
@@ -101,11 +106,20 @@ export const FormulaWorkspace: FC<FormulaWorkspaceProps> = ({
|
|
|
101
106
|
/>
|
|
102
107
|
{isInvalid && validationError && <Alert status="danger" title={validationError} />}
|
|
103
108
|
<Flex gap={1}>
|
|
104
|
-
{CALCULATED_OPERATIONS.map(op =>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
{CALCULATED_OPERATIONS.map(op => {
|
|
110
|
+
const isDisabled = disabledOperators?.has(op) ?? false;
|
|
111
|
+
return (
|
|
112
|
+
<Button
|
|
113
|
+
key={op}
|
|
114
|
+
onClick={() => onOperatorSelect(op)}
|
|
115
|
+
size="small"
|
|
116
|
+
disabled={isDisabled}
|
|
117
|
+
title={isDisabled ? 'Not available with date fields' : undefined}
|
|
118
|
+
>
|
|
119
|
+
{op}
|
|
120
|
+
</Button>
|
|
121
|
+
);
|
|
122
|
+
})}
|
|
109
123
|
</Flex>
|
|
110
124
|
<ResultTypeSelector format={format} onChange={onResultTypeChange} />
|
|
111
125
|
<LinkButton appearance="primary" onClick={onToggleAdvanced}>
|
|
@@ -11,6 +11,7 @@ const RESULT_TYPE_OPTIONS: { label: string; value: CalculatedFieldFormat['result
|
|
|
11
11
|
{ label: 'Number', value: 'number' },
|
|
12
12
|
{ label: 'Currency', value: 'currency' },
|
|
13
13
|
{ label: 'Percent', value: 'percent' },
|
|
14
|
+
{ label: 'Date', value: 'date' },
|
|
14
15
|
];
|
|
15
16
|
|
|
16
17
|
export const ResultTypeSelector: FC<ResultTypeSelectorProps> = ({ format, onChange }) => (
|
|
@@ -5,19 +5,36 @@ import { evaluateFormula, formatCalculatedResult, resolvePdfDataValues } from '.
|
|
|
5
5
|
interface PdfViewCalculatedProps {
|
|
6
6
|
field: PdfField;
|
|
7
7
|
data?: DataModelValues;
|
|
8
|
+
holidays?: string[];
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export const PdfViewCalculated: FC<PdfViewCalculatedProps> = ({ data, field }) => {
|
|
11
|
+
export const PdfViewCalculated: FC<PdfViewCalculatedProps> = ({ data, field, holidays }) => {
|
|
12
|
+
const dateFieldPaths = useMemo(() => {
|
|
13
|
+
const paths = field.formulaFormat?.dateFieldPaths;
|
|
14
|
+
return paths?.length ? new Set(paths) : undefined;
|
|
15
|
+
}, [field.formulaFormat?.dateFieldPaths]);
|
|
16
|
+
|
|
11
17
|
const displayValue = useMemo(() => {
|
|
12
18
|
if (field.formula?.tokens?.length) {
|
|
13
|
-
const value = evaluateFormula(field.formula, data);
|
|
19
|
+
const value = evaluateFormula(field.formula, data, dateFieldPaths, holidays);
|
|
20
|
+
if (value === null) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
14
23
|
return formatCalculatedResult(value, field.formulaFormat);
|
|
15
24
|
}
|
|
16
25
|
if (field.path) {
|
|
17
26
|
return resolvePdfDataValues(data, field.path) ?? '';
|
|
18
27
|
}
|
|
19
28
|
return field.label ?? '';
|
|
20
|
-
}, [
|
|
29
|
+
}, [
|
|
30
|
+
data,
|
|
31
|
+
dateFieldPaths,
|
|
32
|
+
field.formula,
|
|
33
|
+
field.formulaFormat,
|
|
34
|
+
field.label,
|
|
35
|
+
field.path,
|
|
36
|
+
holidays,
|
|
37
|
+
]);
|
|
21
38
|
|
|
22
39
|
return <div className="dte-pdf-field-value">{displayValue}</div>;
|
|
23
40
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { DataChangePayload, DataModelValues, PdfField, PreviewMode } from '../../interface/types';
|
|
3
|
-
import { getFieldPlaceholderText } from '../../utils';
|
|
3
|
+
import { dateToUtcZero, getFieldPlaceholderText } from '../../utils';
|
|
4
4
|
|
|
5
5
|
interface PdfViewFillableProps {
|
|
6
6
|
field: PdfField;
|
|
@@ -103,8 +103,11 @@ export const PdfViewFillable: FC<PdfViewFillableProps> = ({
|
|
|
103
103
|
disabled={!isFillable}
|
|
104
104
|
id={field.path}
|
|
105
105
|
name={field.path}
|
|
106
|
-
value={resolvedValue
|
|
107
|
-
onChange={e =>
|
|
106
|
+
value={resolvedValue ? resolvedValue.slice(0, 10) : ''}
|
|
107
|
+
onChange={e => {
|
|
108
|
+
const dateStr = e.target.value;
|
|
109
|
+
handleDataChange(dateStr ? dateToUtcZero(dateStr) : '');
|
|
110
|
+
}}
|
|
108
111
|
placeholder={getFieldPlaceholderText(field, 'mm/dd/yyyy')}
|
|
109
112
|
/>
|
|
110
113
|
);
|
|
@@ -25,6 +25,12 @@ export interface PdfViewProps {
|
|
|
25
25
|
data?: DataModelValues;
|
|
26
26
|
pdfUrl: string;
|
|
27
27
|
loading?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* UTC date strings (e.g. `'2026-03-17T00:00:00Z'`) treated as non-business days.
|
|
30
|
+
* When provided, date-based calculated fields skip weekends and these holidays
|
|
31
|
+
* when adding/subtracting days or computing date differences.
|
|
32
|
+
*/
|
|
33
|
+
holidays?: string[];
|
|
28
34
|
/*
|
|
29
35
|
* fillingBy defines the list of recipient names
|
|
30
36
|
* who are allowed to fill this field.
|
|
@@ -45,6 +51,7 @@ export const PdfView: FC<PdfViewProps> = ({
|
|
|
45
51
|
errors = {},
|
|
46
52
|
fields,
|
|
47
53
|
fillingBy,
|
|
54
|
+
holidays,
|
|
48
55
|
loading = false,
|
|
49
56
|
loadingPlaceholder,
|
|
50
57
|
onDataChange,
|
|
@@ -106,6 +113,7 @@ export const PdfView: FC<PdfViewProps> = ({
|
|
|
106
113
|
<PdfViewCalculated
|
|
107
114
|
field={field}
|
|
108
115
|
data={previewMode === 'fillable' ? previewData : data}
|
|
116
|
+
holidays={holidays}
|
|
109
117
|
/>
|
|
110
118
|
)}
|
|
111
119
|
{field.type === FieldTypeEnum.fillable && (
|