@box/metadata-filter 1.26.0 → 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.
@@ -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 n } from "../../../../../../chunks/types.js";
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 s, jsxs as W } from "react/jsx-runtime";
15
+ import { jsx as n, jsxs as W } from "react/jsx-runtime";
16
16
  import { A as Me } from "../../../../../../chunks/index.js";
17
- const Ue = ({
17
+ const _e = ({
18
18
  disableForm: h,
19
- fieldNamePrefix: d,
20
- label: N,
19
+ fieldNamePrefix: u,
20
+ label: I,
21
21
  locale: C,
22
- portalElement: D,
22
+ portalElement: M,
23
23
  filterOptionsMap: Y,
24
24
  onAdvancedFilterOptionChange: g,
25
- fieldAdvancedFilterOptions: I,
25
+ fieldAdvancedFilterOptions: N,
26
26
  hasAccordion: Z
27
27
  }) => {
28
- const T = `${d}.value.advancedFilterOption`, u = `${d}.value.relativeDays`, r = `${d}.value.range.gt`, o = `${d}.value.range.lt`, {
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: B
31
+ setFieldTouched: S
32
32
  } = fe(), {
33
- validateDates: S,
33
+ validateDates: B,
34
34
  fromDatePickerValue: F,
35
- toDatePickerValue: M,
35
+ toDatePickerValue: D,
36
36
  fromErrorType: x,
37
37
  toErrorType: P
38
- } = ge(E, r, o, C, !0), {
38
+ } = ge(E, o, r, C, !0), {
39
39
  validatePositiveInteger: ee
40
- } = Fe(), l = he(), [m, te] = L(I || ""), [U, V] = L(!1), c = ve(E, u), [_, O] = L(n.FROM), R = X(F), k = X(M), $ = {
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 (m === "today") {
46
+ if (f === "today") {
47
47
  const {
48
48
  from: e,
49
49
  to: t
50
50
  } = J("today", void 0);
51
- a(r, e), a(o, t);
52
- } else if (c !== void 0) {
53
- const e = typeof c == "string" ? Number(c) : c;
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 = m;
55
+ const t = f;
56
56
  if (["next", "past", "olderThan"].includes(t)) {
57
57
  const {
58
- from: f,
59
- to: y
58
+ from: c,
59
+ to: k
60
60
  } = J(t, e);
61
- a(r, f), a(o, y);
61
+ a(o, c), a(r, k);
62
62
  }
63
63
  }
64
64
  }
65
- }, [m, c, r, o, a]);
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(d, t);
72
- const f = () => {
73
- a(u, void 0), a(r, void 0), a(o, void 0);
74
- }, y = () => {
75
- a(r, void 0), a(o, void 0);
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" ? f() : t === "today" ? (a(u, void 0), V(!0)) : y();
78
- }, [d, g, a, T, u, r, o]), re = v((e) => {
79
- a(u, e), Number(e) > 0 && V(!0);
80
- }, [a, u]), oe = v((e) => {
81
- const t = K(e, n.FROM);
82
- R.current = e, a(r, t), O(n.FROM);
83
- }, [a, r]), ne = v((e) => {
84
- const t = K(e, n.TO);
85
- k.current = e, a(o, t), O(n.TO);
86
- }, [a, o]), j = v((e) => {
87
- const t = e === n.FROM ? r : o;
88
- B(t, !0), O(e);
89
- }, [B, r, o]), se = q(() => Q(M, z), [M]), le = q(() => Q(F), [F]), G = (e, t, f) => !!(t === A.MAX && e === A.OVERLAPPING || e === A.OVERLAPPING && f), ie = ["isBlank", "isNotBlank", "selectFilterType", "today"], ce = () => !m || ie.includes(m) ? null : m === "customRange" ? /* @__PURE__ */ W("div", {
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__ */ s(b, {
92
- name: r,
93
- validate: (e) => S(R.current, k.current, n.FROM),
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__ */ s("div", {
101
+ }) => /* @__PURE__ */ n("div", {
98
102
  className: p.datePicker,
99
- children: /* @__PURE__ */ s(H, {
103
+ children: /* @__PURE__ */ n(H, {
100
104
  ...e,
101
105
  ...$,
102
106
  calendarAriaLabel: l.formatMessage(i.selectStartDate),
103
- error: !G(x, P, _ !== n.FROM) && t.error,
107
+ error: !G(x, P, _ !== s.FROM) && t.error,
104
108
  isDisabled: h,
105
109
  label: l.formatMessage(i.afterDate),
106
- maxValue: se,
107
- onBlur: () => j(n.FROM),
108
- onChange: oe,
109
- portalElement: D,
110
+ maxValue: ne,
111
+ onBlur: () => j(s.FROM),
112
+ onChange: re,
113
+ portalElement: M,
110
114
  value: F
111
115
  })
112
116
  })
113
- }), /* @__PURE__ */ s(b, {
114
- name: o,
115
- validate: (e) => S(R.current, k.current, n.TO),
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__ */ s("div", {
123
+ }) => /* @__PURE__ */ n("div", {
120
124
  className: p.datePicker,
121
- children: /* @__PURE__ */ s(H, {
125
+ children: /* @__PURE__ */ n(H, {
122
126
  ...e,
123
127
  ...$,
124
128
  calendarAriaLabel: l.formatMessage(i.selectEndDate),
125
- error: !G(P, x, _ !== n.TO) && t.error,
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(n.TO),
131
- onChange: ne,
132
- portalElement: D,
133
- value: M
134
+ onBlur: () => j(s.TO),
135
+ onChange: se,
136
+ portalElement: M,
137
+ value: D
134
138
  })
135
139
  })
136
140
  })]
137
- }) : /* @__PURE__ */ s(b, {
138
- name: u,
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__ */ s("div", {
147
+ }) => /* @__PURE__ */ n("div", {
144
148
  className: p.daysInputContainer,
145
- children: /* @__PURE__ */ s(ue, {
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: (f) => re(f.target.value),
155
+ onChange: (c) => oe(c.target.value),
152
156
  placeholder: l.formatMessage(i.numberOfDays),
153
- value: (c == null ? void 0 : c.toString()) || ""
157
+ value: (d == null ? void 0 : d.toString()) || ""
154
158
  })
155
159
  })
156
160
  });
157
- return /* @__PURE__ */ s(de, {
161
+ return /* @__PURE__ */ n(de, {
158
162
  locale: C,
159
163
  children: /* @__PURE__ */ W("div", {
160
164
  className: p.advancedDateContainer,
161
- "data-testid": `${N}-advanced-field`,
162
- children: [/* @__PURE__ */ s(Me, {
165
+ "data-testid": `${I}-advanced-field`,
166
+ children: [/* @__PURE__ */ n(Me, {
163
167
  advancedFilterFieldName: T,
164
168
  disableForm: h,
165
- fieldAdvancedFilterOptions: I,
166
- fieldNamePrefix: d,
169
+ fieldAdvancedFilterOptions: N,
170
+ fieldNamePrefix: u,
167
171
  filterOptionsMap: Y,
168
- label: N,
172
+ label: I,
169
173
  onAdvancedFilterOptionChange: g,
170
174
  onValueChange: ae,
171
- portalElement: D,
175
+ portalElement: M,
172
176
  showLabel: !Z,
173
- value: m
177
+ value: f
174
178
  }), ce()]
175
179
  })
176
180
  });
177
181
  };
178
182
  export {
179
- Ue as MetadataDateFieldAdvanced,
180
- Ue as default
183
+ _e as MetadataDateFieldAdvanced,
184
+ _e as default
181
185
  };
@@ -1,5 +1,12 @@
1
1
  import { DEFAULT_MAX_DATE as i } from "./constants.js";
2
- const m = (r, o) => r ? r.compare(i) > 0 ? i : r : o;
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
- m as getDynamicMaxMinValue
10
+ s as getDynamicMaxMinValue,
11
+ n as processRelativeDaysInput
5
12
  };
@@ -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.0",
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.2",
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",