@box/metadata-filter 1.26.1 → 1.26.2
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/esm/lib/components/metadata-filter-fields/components/metadata-date-field/metadata-date-field-advanced.js +81 -77
- package/dist/esm/lib/components/metadata-filter-fields/components/metadata-date-field/utils.js +9 -2
- package/dist/types/lib/components/metadata-filter-fields/components/metadata-date-field/utils.d.ts +4 -0
- package/package.json +2 -2
|
@@ -3,179 +3,183 @@ import me from "clsx";
|
|
|
3
3
|
import { useFormikContext as fe, getIn as ve, Field as b } from "formik";
|
|
4
4
|
import { useState as L, useRef as X, useCallback as v, useEffect as pe, useMemo as q } from "react";
|
|
5
5
|
import { useIntl as he } from "react-intl";
|
|
6
|
-
import { R as
|
|
6
|
+
import { R as s } from "../../../../../../chunks/types.js";
|
|
7
7
|
import { DEFAULT_MAX_DATE as z } from "./constants.js";
|
|
8
8
|
import { getRelativeFromToValues as J, convertToFormikValueRanged as K } from "./date-conversion-utils.js";
|
|
9
9
|
import { s as p } from "../../../../../../chunks/metadata-date-field.module.js";
|
|
10
10
|
import { E as A } from "../../../../../../chunks/types2.js";
|
|
11
11
|
import { useDateValidation as ge } from "./use-date-validation.js";
|
|
12
12
|
import { useIntegerValidation as Fe } from "./use-integer-validation.js";
|
|
13
|
-
import { getDynamicMaxMinValue as Q } from "./utils.js";
|
|
13
|
+
import { processRelativeDaysInput as De, getDynamicMaxMinValue as Q } from "./utils.js";
|
|
14
14
|
import i from "../../../../messages.js";
|
|
15
|
-
import { jsx as
|
|
15
|
+
import { jsx as n, jsxs as W } from "react/jsx-runtime";
|
|
16
16
|
import { A as Me } from "../../../../../../chunks/index.js";
|
|
17
|
-
const
|
|
17
|
+
const _e = ({
|
|
18
18
|
disableForm: h,
|
|
19
|
-
fieldNamePrefix:
|
|
20
|
-
label:
|
|
19
|
+
fieldNamePrefix: u,
|
|
20
|
+
label: I,
|
|
21
21
|
locale: C,
|
|
22
|
-
portalElement:
|
|
22
|
+
portalElement: M,
|
|
23
23
|
filterOptionsMap: Y,
|
|
24
24
|
onAdvancedFilterOptionChange: g,
|
|
25
|
-
fieldAdvancedFilterOptions:
|
|
25
|
+
fieldAdvancedFilterOptions: N,
|
|
26
26
|
hasAccordion: Z
|
|
27
27
|
}) => {
|
|
28
|
-
const T = `${
|
|
28
|
+
const T = `${u}.value.advancedFilterOption`, m = `${u}.value.relativeDays`, o = `${u}.value.range.gt`, r = `${u}.value.range.lt`, {
|
|
29
29
|
values: E,
|
|
30
30
|
setFieldValue: a,
|
|
31
|
-
setFieldTouched:
|
|
31
|
+
setFieldTouched: S
|
|
32
32
|
} = fe(), {
|
|
33
|
-
validateDates:
|
|
33
|
+
validateDates: B,
|
|
34
34
|
fromDatePickerValue: F,
|
|
35
|
-
toDatePickerValue:
|
|
35
|
+
toDatePickerValue: D,
|
|
36
36
|
fromErrorType: x,
|
|
37
37
|
toErrorType: P
|
|
38
|
-
} = ge(E,
|
|
38
|
+
} = ge(E, o, r, C, !0), {
|
|
39
39
|
validatePositiveInteger: ee
|
|
40
|
-
} = Fe(), l = he(), [
|
|
40
|
+
} = Fe(), l = he(), [f, te] = L(N || ""), [U, V] = L(!1), d = ve(E, m), [_, R] = L(s.FROM), y = X(F), O = X(D), $ = {
|
|
41
41
|
clearDatePickerAriaLabel: l.formatMessage(i.clearSelectedDate),
|
|
42
42
|
nextMonthAriaLabel: l.formatMessage(i.switchToNextMonth),
|
|
43
43
|
openCalendarDropdownAriaLabel: l.formatMessage(i.openCalendar),
|
|
44
44
|
previousMonthAriaLabel: l.formatMessage(i.switchToNextMonth)
|
|
45
45
|
}, w = v(() => {
|
|
46
|
-
if (
|
|
46
|
+
if (f === "today") {
|
|
47
47
|
const {
|
|
48
48
|
from: e,
|
|
49
49
|
to: t
|
|
50
50
|
} = J("today", void 0);
|
|
51
|
-
a(
|
|
52
|
-
} else if (
|
|
53
|
-
const e = typeof
|
|
51
|
+
a(o, e), a(r, t);
|
|
52
|
+
} else if (d !== void 0) {
|
|
53
|
+
const e = typeof d == "string" ? Number(d) : d;
|
|
54
54
|
if (!isNaN(e) && e > 0) {
|
|
55
|
-
const t =
|
|
55
|
+
const t = f;
|
|
56
56
|
if (["next", "past", "olderThan"].includes(t)) {
|
|
57
57
|
const {
|
|
58
|
-
from:
|
|
59
|
-
to:
|
|
58
|
+
from: c,
|
|
59
|
+
to: k
|
|
60
60
|
} = J(t, e);
|
|
61
|
-
a(
|
|
61
|
+
a(o, c), a(r, k);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
}, [
|
|
65
|
+
}, [f, d, o, r, a]);
|
|
66
66
|
pe(() => {
|
|
67
67
|
U && (w(), V(!1));
|
|
68
68
|
}, [U, w]);
|
|
69
69
|
const ae = v((e) => {
|
|
70
70
|
const t = e;
|
|
71
|
-
te(t), a(T, t), g && g(
|
|
72
|
-
const
|
|
73
|
-
a(
|
|
74
|
-
},
|
|
75
|
-
a(
|
|
71
|
+
te(t), a(T, t), g && g(u, t);
|
|
72
|
+
const c = () => {
|
|
73
|
+
a(m, void 0), a(o, void 0), a(r, void 0);
|
|
74
|
+
}, k = () => {
|
|
75
|
+
a(o, void 0), a(r, void 0);
|
|
76
76
|
};
|
|
77
|
-
["isBlank", "isNotBlank", "selectFilterType"].includes(t) || !t || t === "customRange" ?
|
|
78
|
-
}, [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
["isBlank", "isNotBlank", "selectFilterType"].includes(t) || !t || t === "customRange" ? c() : t === "today" ? (a(m, void 0), V(!0)) : k();
|
|
78
|
+
}, [u, g, a, T, m, o, r]), oe = v((e) => {
|
|
79
|
+
const {
|
|
80
|
+
valueToStore: t,
|
|
81
|
+
shouldTriggerUpdate: c
|
|
82
|
+
} = De(e);
|
|
83
|
+
a(m, t), c && V(!0);
|
|
84
|
+
}, [a, m]), re = v((e) => {
|
|
85
|
+
const t = K(e, s.FROM);
|
|
86
|
+
y.current = e, a(o, t), R(s.FROM);
|
|
87
|
+
}, [a, o]), se = v((e) => {
|
|
88
|
+
const t = K(e, s.TO);
|
|
89
|
+
O.current = e, a(r, t), R(s.TO);
|
|
90
|
+
}, [a, r]), j = v((e) => {
|
|
91
|
+
const t = e === s.FROM ? o : r;
|
|
92
|
+
S(t, !0), R(e);
|
|
93
|
+
}, [S, o, r]), ne = q(() => Q(D, z), [D]), le = q(() => Q(F), [F]), G = (e, t, c) => !!(t === A.MAX && e === A.OVERLAPPING || e === A.OVERLAPPING && c), ie = ["isBlank", "isNotBlank", "selectFilterType", "today"], ce = () => !f || ie.includes(f) ? null : f === "customRange" ? /* @__PURE__ */ W("div", {
|
|
90
94
|
className: me(p.rangeInputsContainer, p.verticalLayout),
|
|
91
|
-
children: [/* @__PURE__ */
|
|
92
|
-
name:
|
|
93
|
-
validate: (e) =>
|
|
95
|
+
children: [/* @__PURE__ */ n(b, {
|
|
96
|
+
name: o,
|
|
97
|
+
validate: (e) => B(y.current, O.current, s.FROM),
|
|
94
98
|
children: ({
|
|
95
99
|
field: e,
|
|
96
100
|
meta: t
|
|
97
|
-
}) => /* @__PURE__ */
|
|
101
|
+
}) => /* @__PURE__ */ n("div", {
|
|
98
102
|
className: p.datePicker,
|
|
99
|
-
children: /* @__PURE__ */
|
|
103
|
+
children: /* @__PURE__ */ n(H, {
|
|
100
104
|
...e,
|
|
101
105
|
...$,
|
|
102
106
|
calendarAriaLabel: l.formatMessage(i.selectStartDate),
|
|
103
|
-
error: !G(x, P, _ !==
|
|
107
|
+
error: !G(x, P, _ !== s.FROM) && t.error,
|
|
104
108
|
isDisabled: h,
|
|
105
109
|
label: l.formatMessage(i.afterDate),
|
|
106
|
-
maxValue:
|
|
107
|
-
onBlur: () => j(
|
|
108
|
-
onChange:
|
|
109
|
-
portalElement:
|
|
110
|
+
maxValue: ne,
|
|
111
|
+
onBlur: () => j(s.FROM),
|
|
112
|
+
onChange: re,
|
|
113
|
+
portalElement: M,
|
|
110
114
|
value: F
|
|
111
115
|
})
|
|
112
116
|
})
|
|
113
|
-
}), /* @__PURE__ */
|
|
114
|
-
name:
|
|
115
|
-
validate: (e) =>
|
|
117
|
+
}), /* @__PURE__ */ n(b, {
|
|
118
|
+
name: r,
|
|
119
|
+
validate: (e) => B(y.current, O.current, s.TO),
|
|
116
120
|
children: ({
|
|
117
121
|
field: e,
|
|
118
122
|
meta: t
|
|
119
|
-
}) => /* @__PURE__ */
|
|
123
|
+
}) => /* @__PURE__ */ n("div", {
|
|
120
124
|
className: p.datePicker,
|
|
121
|
-
children: /* @__PURE__ */
|
|
125
|
+
children: /* @__PURE__ */ n(H, {
|
|
122
126
|
...e,
|
|
123
127
|
...$,
|
|
124
128
|
calendarAriaLabel: l.formatMessage(i.selectEndDate),
|
|
125
|
-
error: !G(P, x, _ !==
|
|
129
|
+
error: !G(P, x, _ !== s.TO) && t.error,
|
|
126
130
|
isDisabled: h,
|
|
127
131
|
label: l.formatMessage(i.beforeDate),
|
|
128
132
|
maxValue: z,
|
|
129
133
|
minValue: le,
|
|
130
|
-
onBlur: () => j(
|
|
131
|
-
onChange:
|
|
132
|
-
portalElement:
|
|
133
|
-
value:
|
|
134
|
+
onBlur: () => j(s.TO),
|
|
135
|
+
onChange: se,
|
|
136
|
+
portalElement: M,
|
|
137
|
+
value: D
|
|
134
138
|
})
|
|
135
139
|
})
|
|
136
140
|
})]
|
|
137
|
-
}) : /* @__PURE__ */
|
|
138
|
-
name:
|
|
141
|
+
}) : /* @__PURE__ */ n(b, {
|
|
142
|
+
name: m,
|
|
139
143
|
validate: (e) => ee((e == null ? void 0 : e.toString()) || ""),
|
|
140
144
|
children: ({
|
|
141
145
|
field: e,
|
|
142
146
|
meta: t
|
|
143
|
-
}) => /* @__PURE__ */
|
|
147
|
+
}) => /* @__PURE__ */ n("div", {
|
|
144
148
|
className: p.daysInputContainer,
|
|
145
|
-
children: /* @__PURE__ */
|
|
149
|
+
children: /* @__PURE__ */ n(ue, {
|
|
146
150
|
...e,
|
|
147
151
|
disabled: h,
|
|
148
152
|
error: t.touched && t.error,
|
|
149
153
|
hideLabel: !0,
|
|
150
154
|
label: l.formatMessage(i.relativeDaysSelectLabel),
|
|
151
|
-
onChange: (
|
|
155
|
+
onChange: (c) => oe(c.target.value),
|
|
152
156
|
placeholder: l.formatMessage(i.numberOfDays),
|
|
153
|
-
value: (
|
|
157
|
+
value: (d == null ? void 0 : d.toString()) || ""
|
|
154
158
|
})
|
|
155
159
|
})
|
|
156
160
|
});
|
|
157
|
-
return /* @__PURE__ */
|
|
161
|
+
return /* @__PURE__ */ n(de, {
|
|
158
162
|
locale: C,
|
|
159
163
|
children: /* @__PURE__ */ W("div", {
|
|
160
164
|
className: p.advancedDateContainer,
|
|
161
|
-
"data-testid": `${
|
|
162
|
-
children: [/* @__PURE__ */
|
|
165
|
+
"data-testid": `${I}-advanced-field`,
|
|
166
|
+
children: [/* @__PURE__ */ n(Me, {
|
|
163
167
|
advancedFilterFieldName: T,
|
|
164
168
|
disableForm: h,
|
|
165
|
-
fieldAdvancedFilterOptions:
|
|
166
|
-
fieldNamePrefix:
|
|
169
|
+
fieldAdvancedFilterOptions: N,
|
|
170
|
+
fieldNamePrefix: u,
|
|
167
171
|
filterOptionsMap: Y,
|
|
168
|
-
label:
|
|
172
|
+
label: I,
|
|
169
173
|
onAdvancedFilterOptionChange: g,
|
|
170
174
|
onValueChange: ae,
|
|
171
|
-
portalElement:
|
|
175
|
+
portalElement: M,
|
|
172
176
|
showLabel: !Z,
|
|
173
|
-
value:
|
|
177
|
+
value: f
|
|
174
178
|
}), ce()]
|
|
175
179
|
})
|
|
176
180
|
});
|
|
177
181
|
};
|
|
178
182
|
export {
|
|
179
|
-
|
|
180
|
-
|
|
183
|
+
_e as MetadataDateFieldAdvanced,
|
|
184
|
+
_e as default
|
|
181
185
|
};
|
package/dist/esm/lib/components/metadata-filter-fields/components/metadata-date-field/utils.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { DEFAULT_MAX_DATE as i } from "./constants.js";
|
|
2
|
-
const
|
|
2
|
+
const s = (r, t) => r ? r.compare(i) > 0 ? i : r : t, n = (r) => {
|
|
3
|
+
const t = Number(r), e = !isNaN(t) && t > 0 && /^\d+$/.test(r.trim());
|
|
4
|
+
return {
|
|
5
|
+
valueToStore: e ? t : r,
|
|
6
|
+
shouldTriggerUpdate: e
|
|
7
|
+
};
|
|
8
|
+
};
|
|
3
9
|
export {
|
|
4
|
-
|
|
10
|
+
s as getDynamicMaxMinValue,
|
|
11
|
+
n as processRelativeDaysInput
|
|
5
12
|
};
|
package/dist/types/lib/components/metadata-filter-fields/components/metadata-date-field/utils.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { CalendarDateType } from './types';
|
|
2
2
|
export declare const getDynamicMaxMinValue: (calendarDate: CalendarDateType, nullDefault?: CalendarDateType) => import('@internationalized/date').CalendarDate;
|
|
3
|
+
export declare const processRelativeDaysInput: (value: string) => {
|
|
4
|
+
valueToStore: string | number;
|
|
5
|
+
shouldTriggerUpdate: boolean;
|
|
6
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/metadata-filter",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@box/blueprint-web": "^7.8.0",
|
|
6
6
|
"@box/blueprint-web-assets": "^4.16.0",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"react-intl": "6.4.2"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@box/blueprint-web": "^12.64.
|
|
14
|
+
"@box/blueprint-web": "^12.64.4",
|
|
15
15
|
"@box/blueprint-web-assets": "^4.65.0",
|
|
16
16
|
"@box/storybook-utils": "^0.14.1",
|
|
17
17
|
"react": "^18.3.0",
|