@leaflink/stash 49.3.0 → 49.3.1
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/DataViewFilters.js +151 -141
- package/dist/DataViewFilters.js.map +1 -1
- package/dist/DataViewFilters.vue.d.ts +12 -3
- package/package.json +1 -1
package/dist/DataViewFilters.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import
|
|
3
|
-
import { SCREEN_SIZES as
|
|
1
|
+
import { ref as B, computed as C, defineComponent as j, useSlots as O, inject as J, provide as z, watch as Q, openBlock as p, createBlock as m, normalizeClass as U, unref as t, withCtx as u, mergeProps as $, createCommentVNode as f, createElementBlock as Z, createElementVNode as A, renderSlot as G, createVNode as I, createTextVNode as k, toDisplayString as w } from "vue";
|
|
2
|
+
import q from "./useMediaQuery.js";
|
|
3
|
+
import { SCREEN_SIZES as H } from "./constants.js";
|
|
4
4
|
import { t as d } from "./locale.js";
|
|
5
|
-
import { _ as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
5
|
+
import { _ as K } from "./Box.vue_vue_type_script_setup_true_lang-69e5176b.js";
|
|
6
|
+
import _ from "./Button.js";
|
|
7
|
+
import L from "lodash-es/cloneDeep";
|
|
8
|
+
import P from "./Icon.js";
|
|
9
9
|
import "./Paginate.vue_used_vue_type_style_index_0_lang.module-18343da7.js";
|
|
10
|
-
import { D as
|
|
11
|
-
import
|
|
12
|
-
import { _ as
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { D as
|
|
16
|
-
import { i as
|
|
10
|
+
import { D as R } from "./DataView.vue_used_vue_type_style_index_0_lang.module-5c180dba.js";
|
|
11
|
+
import X from "./FilterChip.js";
|
|
12
|
+
import { _ as Y } from "./Label.vue_vue_type_script_setup_true_lang-4b02087f.js";
|
|
13
|
+
import ee from "./Modal.js";
|
|
14
|
+
import te from "./SearchBar.js";
|
|
15
|
+
import { D as le } from "./DataViewFilters.keys-c80ffabe.js";
|
|
16
|
+
import { i as W } from "./isDefined-2ce6cde4.js";
|
|
17
17
|
import "lodash-es/get";
|
|
18
18
|
import "./Button.vue_used_vue_type_style_index_0_lang.module-4dabc2a9.js";
|
|
19
19
|
import "./_plugin-vue_export-helper-dad06003.js";
|
|
@@ -27,63 +27,63 @@ import "./Input.js";
|
|
|
27
27
|
import "lodash-es/isNil";
|
|
28
28
|
import "./utils/i18n.js";
|
|
29
29
|
import "./Field.vue_vue_type_script_setup_true_lang-e1e4ff03.js";
|
|
30
|
-
function
|
|
31
|
-
schema:
|
|
32
|
-
dataViewRef:
|
|
30
|
+
function Le({
|
|
31
|
+
schema: a,
|
|
32
|
+
dataViewRef: V
|
|
33
33
|
}) {
|
|
34
|
-
const e =
|
|
35
|
-
for (const
|
|
36
|
-
e.value[
|
|
37
|
-
const
|
|
34
|
+
const e = B({}), o = B({});
|
|
35
|
+
for (const l in a)
|
|
36
|
+
e.value[l] = a[l].defaultValue, o.value[l] = a[l].defaultValue;
|
|
37
|
+
const y = V;
|
|
38
38
|
function h() {
|
|
39
|
-
e.value =
|
|
39
|
+
e.value = L(o.value), y.value.updateCurrentFilters(e.value, { shouldEmit: !0 });
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
for (const
|
|
43
|
-
e.value[
|
|
44
|
-
|
|
41
|
+
function N() {
|
|
42
|
+
for (const l in a)
|
|
43
|
+
e.value[l] = a[l].defaultValue, o.value[l] = a[l].defaultValue;
|
|
44
|
+
y.value.updateCurrentFilters(e.value, { shouldEmit: !0 });
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
for (const i in
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
function b(l) {
|
|
47
|
+
for (const i in a)
|
|
48
|
+
a[i].group === l && (e.value[i] = a[i].defaultValue, o.value[i] = a[i].defaultValue);
|
|
49
|
+
y.value.updateCurrentFilters(e.value, { shouldEmit: !0 });
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
o.value =
|
|
51
|
+
function D() {
|
|
52
|
+
o.value = L(e.value);
|
|
53
53
|
}
|
|
54
|
-
const
|
|
54
|
+
const g = C(() => {
|
|
55
55
|
var i;
|
|
56
|
-
const
|
|
57
|
-
for (const
|
|
58
|
-
const n =
|
|
59
|
-
(((i = n.isActive) == null ? void 0 : i.call(n,
|
|
56
|
+
const l = {};
|
|
57
|
+
for (const c in a) {
|
|
58
|
+
const n = a[c], s = e.value[c];
|
|
59
|
+
(((i = n.isActive) == null ? void 0 : i.call(n, s)) || W(s)) && n.group && (l[n.group] = (l[n.group] ?? 0) + 1);
|
|
60
60
|
}
|
|
61
|
-
return
|
|
62
|
-
}),
|
|
61
|
+
return l;
|
|
62
|
+
}), S = C(() => {
|
|
63
63
|
var i;
|
|
64
|
-
let
|
|
65
|
-
for (const
|
|
66
|
-
const n =
|
|
67
|
-
(((i = n.isActive) == null ? void 0 : i.call(n,
|
|
64
|
+
let l = 0;
|
|
65
|
+
for (const c in a) {
|
|
66
|
+
const n = a[c], s = e.value[c];
|
|
67
|
+
(((i = n.isActive) == null ? void 0 : i.call(n, s)) || W(s)) && (l += 1);
|
|
68
68
|
}
|
|
69
|
-
return
|
|
69
|
+
return l;
|
|
70
70
|
});
|
|
71
71
|
return {
|
|
72
72
|
applyFilters: h,
|
|
73
|
-
resetAllFilters:
|
|
73
|
+
resetAllFilters: N,
|
|
74
74
|
// @ts-expect-error "could be instantiated with a different subtype": TODO: figure out how to resolve the types
|
|
75
|
-
resetFilterGroup:
|
|
76
|
-
undoWorkingFilters:
|
|
77
|
-
activeFiltersCounts:
|
|
78
|
-
totalActiveFiltersCount:
|
|
75
|
+
resetFilterGroup: b,
|
|
76
|
+
undoWorkingFilters: D,
|
|
77
|
+
activeFiltersCounts: g,
|
|
78
|
+
totalActiveFiltersCount: S,
|
|
79
79
|
appliedFilters: e,
|
|
80
80
|
workingFilters: o
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
const
|
|
83
|
+
const re = {
|
|
84
84
|
key: 1,
|
|
85
85
|
class: "tw-col-span-12 tw-row-start-2 md:tw-col-start-7 md:tw-row-start-1 lg:tw-col-span-8 lg:tw-col-start-5"
|
|
86
|
-
},
|
|
86
|
+
}, ae = { class: "tw-hidden md:tw-block" }, se = { class: "tw-flex tw-gap-4" }, ie = { class: "tw-inline-flex tw-items-center tw-gap-3" }, oe = { class: "tw-flex tw-justify-end tw-gap-gutter" }, Pe = /* @__PURE__ */ j({
|
|
87
87
|
__name: "DataViewFilters",
|
|
88
88
|
props: {
|
|
89
89
|
filtersLabelText: { default: d("ll.filterBy") },
|
|
@@ -94,182 +94,192 @@ const te = {
|
|
|
94
94
|
showDrawerPreviousButton: { type: Boolean, default: !1 },
|
|
95
95
|
useFiltersInstance: { default: void 0 },
|
|
96
96
|
onApply: { type: Function, default: void 0 },
|
|
97
|
-
activeGroup: { default:
|
|
97
|
+
activeGroup: { default: void 0 }
|
|
98
98
|
},
|
|
99
99
|
emits: ["open-drawer", "dismiss", "previous", "reset-group", "reset-all"],
|
|
100
|
-
setup(
|
|
101
|
-
const e =
|
|
102
|
-
density:
|
|
103
|
-
isLoading:
|
|
104
|
-
isWithinModule:
|
|
105
|
-
currentSearch:
|
|
106
|
-
updateCurrentSearch:
|
|
107
|
-
} =
|
|
108
|
-
|
|
100
|
+
setup(a, { emit: V }) {
|
|
101
|
+
const e = a, o = V, y = O(), h = q(`(min-width: ${H.lg})`), N = C(() => e.drawerStyle === "nested" && !e.activeGroup), b = C(() => e.drawerStyle === "nested" && e.activeGroup), {
|
|
102
|
+
density: D,
|
|
103
|
+
isLoading: g,
|
|
104
|
+
isWithinModule: S,
|
|
105
|
+
currentSearch: l,
|
|
106
|
+
updateCurrentSearch: i
|
|
107
|
+
} = J(R.key, R.defaults);
|
|
108
|
+
z(le.key, {
|
|
109
109
|
useFiltersInstance: e.useFiltersInstance,
|
|
110
110
|
drawerStyle: e.drawerStyle
|
|
111
111
|
});
|
|
112
|
-
const
|
|
113
|
-
var
|
|
114
|
-
return ((
|
|
115
|
-
}),
|
|
112
|
+
const c = C(() => {
|
|
113
|
+
var r;
|
|
114
|
+
return ((r = e.useFiltersInstance) == null ? void 0 : r.totalActiveFiltersCount.value) ?? 0;
|
|
115
|
+
}), n = C(
|
|
116
116
|
() => {
|
|
117
|
-
var
|
|
118
|
-
return ((
|
|
117
|
+
var r;
|
|
118
|
+
return Number(e.activeGroup && ((r = e.useFiltersInstance) == null ? void 0 : r.activeFiltersCounts.value[e.activeGroup])) || 0;
|
|
119
119
|
}
|
|
120
|
-
),
|
|
121
|
-
async function
|
|
122
|
-
var
|
|
123
|
-
const { preventDismiss:
|
|
124
|
-
|
|
120
|
+
), s = B(!1);
|
|
121
|
+
async function E() {
|
|
122
|
+
var v, F;
|
|
123
|
+
const { preventDismiss: r } = await ((v = e.onApply) == null ? void 0 : v.call(e)) || ((F = e.useFiltersInstance) == null ? void 0 : F.applyFilters()) || {};
|
|
124
|
+
r || (s.value = !1);
|
|
125
125
|
}
|
|
126
|
-
function
|
|
127
|
-
var
|
|
128
|
-
(
|
|
126
|
+
function M() {
|
|
127
|
+
var r;
|
|
128
|
+
e.activeGroup && ((r = e.useFiltersInstance) == null || r.resetFilterGroup(e.activeGroup), o("reset-group"), s.value = !1);
|
|
129
129
|
}
|
|
130
|
-
function
|
|
131
|
-
var
|
|
132
|
-
(
|
|
130
|
+
function x() {
|
|
131
|
+
var r;
|
|
132
|
+
(r = e.useFiltersInstance) == null || r.resetAllFilters(), o("reset-all"), s.value = !1;
|
|
133
133
|
}
|
|
134
|
-
function
|
|
135
|
-
var
|
|
136
|
-
(
|
|
134
|
+
function T() {
|
|
135
|
+
var r;
|
|
136
|
+
(r = e.useFiltersInstance) == null || r.undoWorkingFilters(), s.value = !1, o("dismiss");
|
|
137
137
|
}
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
}), (
|
|
141
|
-
class:
|
|
142
|
-
radius:
|
|
138
|
+
return Q(s, () => {
|
|
139
|
+
s.value && o("open-drawer");
|
|
140
|
+
}), (r, v) => (p(), m(K, {
|
|
141
|
+
class: U(["stash-data-view-filters tw-grid tw-grid-cols-12 tw-gap-6 tw-p-3", { "lg:tw-p-6": t(D) === "comfortable", "tw-mb-3": !t(S) }]),
|
|
142
|
+
radius: t(S) ? "none" : "rounded",
|
|
143
143
|
"data-test": "stash-data-view-filters",
|
|
144
144
|
"disable-padding": ""
|
|
145
145
|
}, {
|
|
146
146
|
default: u(() => [
|
|
147
|
-
e.showSearch ? (
|
|
147
|
+
e.showSearch ? (p(), m(te, $({
|
|
148
148
|
key: 0,
|
|
149
149
|
class: "tw-col-span-12 md:tw-col-span-6 lg:tw-col-span-4",
|
|
150
150
|
"data-test": "stash-data-view-filters|search-bar",
|
|
151
|
-
"is-loading":
|
|
152
|
-
label:
|
|
153
|
-
"model-value":
|
|
151
|
+
"is-loading": t(g),
|
|
152
|
+
label: t(d)("ll.search"),
|
|
153
|
+
"model-value": t(l)
|
|
154
154
|
}, e.searchBarProps, {
|
|
155
|
-
onSearch:
|
|
156
|
-
}), null, 16, ["is-loading", "label", "model-value"])) :
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
I(
|
|
155
|
+
onSearch: v[0] || (v[0] = (F) => t(i)(F, { shouldEmit: !0 }))
|
|
156
|
+
}), null, 16, ["is-loading", "label", "model-value"])) : f("", !0),
|
|
157
|
+
y.default ? (p(), Z("div", re, [
|
|
158
|
+
A("div", ae, [
|
|
159
|
+
G(r.$slots, "filters-label", {}, () => [
|
|
160
|
+
I(Y, null, {
|
|
161
161
|
default: u(() => [
|
|
162
|
-
k(
|
|
162
|
+
k(w(e.filtersLabelText), 1)
|
|
163
163
|
]),
|
|
164
164
|
_: 1
|
|
165
165
|
})
|
|
166
166
|
])
|
|
167
167
|
]),
|
|
168
|
-
|
|
169
|
-
I(
|
|
168
|
+
A("div", se, [
|
|
169
|
+
I(X, {
|
|
170
170
|
secondary: "",
|
|
171
171
|
class: "!tw-flex tw-w-full tw-justify-center tw-gap-4 md:!tw-inline-flex md:tw-w-auto",
|
|
172
172
|
"data-test": "stash-data-view-filters|drawer-toggle-button",
|
|
173
|
-
"filter-count":
|
|
174
|
-
onClick:
|
|
173
|
+
"filter-count": c.value,
|
|
174
|
+
onClick: v[1] || (v[1] = (F) => s.value = !0)
|
|
175
175
|
}, {
|
|
176
176
|
default: u(() => [
|
|
177
|
-
|
|
178
|
-
I(
|
|
177
|
+
A("span", ie, [
|
|
178
|
+
I(P, {
|
|
179
179
|
name: "filter-line",
|
|
180
180
|
class: "tw-text-ice-700"
|
|
181
181
|
}),
|
|
182
|
-
|
|
182
|
+
A("span", null, w(t(d)("ll.filters")), 1)
|
|
183
183
|
])
|
|
184
184
|
]),
|
|
185
185
|
_: 1
|
|
186
186
|
}, 8, ["filter-count"]),
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
t(h) ? G(r.$slots, "default", { key: 0 }) : f("", !0),
|
|
188
|
+
c.value > 0 && t(h) ? (p(), m(_, {
|
|
189
189
|
key: 1,
|
|
190
190
|
inline: "",
|
|
191
|
-
onClick:
|
|
191
|
+
onClick: x
|
|
192
192
|
}, {
|
|
193
193
|
default: u(() => [
|
|
194
|
-
k(
|
|
194
|
+
k(w(t(d)("ll.resetAll")), 1)
|
|
195
195
|
]),
|
|
196
196
|
_: 1
|
|
197
|
-
})) :
|
|
197
|
+
})) : f("", !0)
|
|
198
198
|
])
|
|
199
|
-
])) :
|
|
200
|
-
|
|
199
|
+
])) : f("", !0),
|
|
200
|
+
y.drawer ? (p(), m(ee, $({
|
|
201
201
|
key: 2,
|
|
202
202
|
"data-test": "stash-data-view-filters|drawer",
|
|
203
203
|
"disable-body-padding": "",
|
|
204
204
|
position: "right",
|
|
205
|
-
"is-open":
|
|
206
|
-
title:
|
|
207
|
-
}, e.drawerProps, { onDismiss:
|
|
205
|
+
"is-open": s.value,
|
|
206
|
+
title: t(d)("ll.allFilters")
|
|
207
|
+
}, e.drawerProps, { onDismiss: T }), {
|
|
208
208
|
headerAction: u(() => [
|
|
209
|
-
|
|
209
|
+
b.value ? (p(), m(_, {
|
|
210
210
|
key: 0,
|
|
211
211
|
icon: "",
|
|
212
212
|
class: "tw-text-ice-100",
|
|
213
213
|
"data-test": "stash-data-view-filters|drawer-previous-button",
|
|
214
|
-
"aria-label":
|
|
215
|
-
title:
|
|
216
|
-
onClick:
|
|
214
|
+
"aria-label": t(d)("ll.previous"),
|
|
215
|
+
title: t(d)("ll.previous"),
|
|
216
|
+
onClick: v[2] || (v[2] = (F) => o("previous"))
|
|
217
217
|
}, {
|
|
218
218
|
default: u(() => [
|
|
219
|
-
I(
|
|
219
|
+
I(P, { name: "chevron-left" })
|
|
220
220
|
]),
|
|
221
221
|
_: 1
|
|
222
|
-
}, 8, ["aria-label", "title"])) :
|
|
222
|
+
}, 8, ["aria-label", "title"])) : f("", !0)
|
|
223
223
|
]),
|
|
224
224
|
footer: u(() => [
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
A("div", oe, [
|
|
226
|
+
c.value === 0 ? (p(), m(_, {
|
|
227
227
|
key: 0,
|
|
228
228
|
secondary: "",
|
|
229
|
-
|
|
230
|
-
onClick: b
|
|
229
|
+
onClick: T
|
|
231
230
|
}, {
|
|
232
231
|
default: u(() => [
|
|
233
|
-
k(
|
|
232
|
+
k(w(t(d)("ll.cancel")), 1)
|
|
234
233
|
]),
|
|
235
234
|
_: 1
|
|
236
|
-
}
|
|
237
|
-
(
|
|
235
|
+
})) : f("", !0),
|
|
236
|
+
(N.value || e.drawerStyle === "cascade") && c.value > 0 ? (p(), m(_, {
|
|
238
237
|
key: 1,
|
|
239
238
|
secondary: "",
|
|
240
|
-
disabled:
|
|
241
|
-
onClick:
|
|
239
|
+
disabled: t(g),
|
|
240
|
+
onClick: x
|
|
242
241
|
}, {
|
|
243
242
|
default: u(() => [
|
|
244
|
-
k(
|
|
243
|
+
k(w(t(d)("ll.resetAll")), 1)
|
|
245
244
|
]),
|
|
246
245
|
_: 1
|
|
247
|
-
}, 8, ["disabled"])) :
|
|
248
|
-
|
|
246
|
+
}, 8, ["disabled"])) : f("", !0),
|
|
247
|
+
b.value && n.value > 0 ? (p(), m(_, {
|
|
249
248
|
key: 2,
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
secondary: "",
|
|
250
|
+
disabled: t(g),
|
|
251
|
+
onClick: M
|
|
252
|
+
}, {
|
|
253
|
+
default: u(() => [
|
|
254
|
+
k(w(t(d)("ll.reset")), 1)
|
|
255
|
+
]),
|
|
256
|
+
_: 1
|
|
257
|
+
}, 8, ["disabled"])) : f("", !0),
|
|
258
|
+
b.value || e.drawerStyle === "cascade" ? (p(), m(_, {
|
|
259
|
+
key: 3,
|
|
260
|
+
disabled: t(g),
|
|
261
|
+
onClick: E
|
|
252
262
|
}, {
|
|
253
263
|
default: u(() => [
|
|
254
|
-
k(
|
|
264
|
+
k(w(t(d)("ll.apply")), 1)
|
|
255
265
|
]),
|
|
256
266
|
_: 1
|
|
257
|
-
}, 8, ["disabled"])) :
|
|
267
|
+
}, 8, ["disabled"])) : f("", !0)
|
|
258
268
|
])
|
|
259
269
|
]),
|
|
260
270
|
default: u(() => [
|
|
261
|
-
|
|
271
|
+
G(r.$slots, "drawer")
|
|
262
272
|
]),
|
|
263
273
|
_: 3
|
|
264
|
-
}, 16, ["is-open", "title"])) :
|
|
274
|
+
}, 16, ["is-open", "title"])) : f("", !0)
|
|
265
275
|
]),
|
|
266
276
|
_: 3
|
|
267
277
|
}, 8, ["class", "radius"]));
|
|
268
278
|
}
|
|
269
279
|
});
|
|
270
280
|
export {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
281
|
+
le as DATA_VIEW_FILTERS_UTILS_INJECTION,
|
|
282
|
+
Pe as default,
|
|
283
|
+
Le as useFilters
|
|
274
284
|
};
|
|
275
285
|
//# sourceMappingURL=DataViewFilters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataViewFilters.js","sources":["../src/components/DataViewFilters/useFilters.ts","../src/components/DataViewFilters/DataViewFilters.vue"],"sourcesContent":["import cloneDeep from 'lodash-es/cloneDeep';\nimport { computed, ComputedRef, Ref, ref } from 'vue';\n\nimport isDefined from '../../composables/useValidation/utils/isDefined';\nimport DataView from '../DataView/DataView.vue';\n\ntype DataViewInstance = InstanceType<typeof DataView>;\n\n/**\n * Contains metadata and configuration for the filters.\n * @see https://www.typescriptlang.org/docs/handbook/2/mapped-types.html\n */\nexport type UseFiltersSchema<Values extends object, Groups extends string> = {\n [Property in keyof Values]: {\n defaultValue?: Values[Property];\n group?: Groups;\n isActive?: (value: Values[Property]) => boolean;\n };\n};\n\nexport interface UseFiltersArgs<Values extends object, Groups extends string> {\n schema: UseFiltersSchema<Values, Groups>;\n /** A ref for an instance of DataView */\n dataViewRef: Ref<unknown>; // Note: using `Ref<InstanceType<typeof DataView>>` here causes type errors when providing a value for this argument\n}\n\nexport interface UseFiltersReturnType<Values = object, Groups extends string = string> {\n applyFilters: () => void;\n resetAllFilters: () => void;\n resetFilterGroup: (group: string) => void; // Note: group is intentionally not typed as `Groups` since there is no way to pass in a Groups type to UseFiltersReturnType within DataViewFilters.vue\n undoWorkingFilters: () => void;\n activeFiltersCounts: ComputedRef<Record<Groups, number>>;\n totalActiveFiltersCount: ComputedRef<number>;\n appliedFilters: Ref<Values>;\n workingFilters: Ref<Values>;\n}\n\n/**\n * Provides utility functions for working with `DataViewFilters`.\n */\nexport function useFilters<Values extends object, Groups extends string>({\n schema,\n dataViewRef,\n}: UseFiltersArgs<Values, Groups>): UseFiltersReturnType<Values, Groups> {\n const appliedFilters = ref({}) as Ref<Values>;\n const workingFilters = ref({}) as Ref<Values>;\n\n for (const filterName in schema) {\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n appliedFilters.value[filterName] = schema[filterName].defaultValue;\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n workingFilters.value[filterName] = schema[filterName].defaultValue;\n }\n\n const dvRef = dataViewRef as Ref<DataViewInstance>;\n\n /**\n * For when an \"Apply\" button is clicked. It does the following:\n * 1) applies the working filter state\n * 2) sets the current page to 1\n * 3) emits the \"update\" event from DataView\n */\n function applyFilters() {\n appliedFilters.value = cloneDeep(workingFilters.value);\n dvRef.value.updateCurrentFilters(appliedFilters.value, { shouldEmit: true });\n }\n\n /**\n * For when a \"Reset all\" button is clicked. It does the following:\n * 1) applies the defaultValue filter values to all filters\n * 2) sets the current page to 1\n * 3) emits the \"update\" event from DataView\n */\n function resetAllFilters() {\n for (const filterName in schema) {\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n appliedFilters.value[filterName] = schema[filterName].defaultValue;\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n workingFilters.value[filterName] = schema[filterName].defaultValue;\n }\n\n dvRef.value.updateCurrentFilters(appliedFilters.value, { shouldEmit: true });\n }\n\n /**\n * For when a \"Reset\" button is clicked. It does the following:\n * 1) applies the defaultValue filter values to the given filter group\n * 2) sets the current page to 1\n * 3) emits the \"update\" event from DataView\n */\n function resetFilterGroup(group: Groups) {\n for (const filterName in schema) {\n if (schema[filterName].group === group) {\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n appliedFilters.value[filterName] = schema[filterName].defaultValue;\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n workingFilters.value[filterName] = schema[filterName].defaultValue;\n }\n }\n\n dvRef.value.updateCurrentFilters(appliedFilters.value, { shouldEmit: true });\n }\n\n /**\n * Resets the `workingFilters` to match the `appliedFilters`. This can be used when the FilterDrawer or a FilterDropdown is dismissed without clicking \"Reset\" or \"Apply\".\n */\n function undoWorkingFilters() {\n workingFilters.value = cloneDeep(appliedFilters.value);\n }\n\n const activeFiltersCounts = computed(() => {\n const counts = {} as Record<Groups, number>;\n\n for (const filterName in schema) {\n const config = schema[filterName];\n const value = appliedFilters.value[filterName];\n const isActive = config.isActive?.(value) || isDefined(value);\n\n if (isActive && config.group) {\n counts[config.group] = (counts[config.group] ?? 0) + 1;\n }\n }\n\n return counts;\n });\n\n const totalActiveFiltersCount = computed(() => {\n let count = 0;\n\n for (const filterName in schema) {\n const config = schema[filterName];\n const value = appliedFilters.value[filterName];\n const isActive = config.isActive?.(value) || isDefined(value);\n\n if (isActive) {\n count += 1;\n }\n }\n\n return count;\n });\n\n return {\n applyFilters,\n resetAllFilters,\n // @ts-expect-error \"could be instantiated with a different subtype\": TODO: figure out how to resolve the types\n resetFilterGroup,\n undoWorkingFilters,\n activeFiltersCounts,\n totalActiveFiltersCount,\n appliedFilters,\n workingFilters,\n };\n}\n\nexport default useFilters;\n","<script lang=\"ts\">\n export * from './DataViewFilters.keys';\n export * from './DataViewFilters.types';\n export * from './useFilters';\n</script>\n\n<script setup lang=\"ts\">\n import { computed, inject, provide, ref, watch } from 'vue';\n\n import useMediaQuery from '../../composables/useMediaQuery/useMediaQuery';\n import { SCREEN_SIZES } from '../../constants';\n import { t } from '../../locale';\n import Box from '../Box/Box.vue';\n import Button from '../Button/Button.vue';\n import { DATA_VIEW_INJECTION } from '../DataView/DataView.vue';\n import FilterChip from '../FilterChip/FilterChip.vue';\n import Icon from '../Icon/Icon.vue';\n import Label from '../Label/Label.vue';\n import Modal, { type ModalProps } from '../Modal/Modal.vue';\n import SearchBar, { SearchBarProps } from '../SearchBar/SearchBar.vue';\n import { DATA_VIEW_FILTERS_UTILS_INJECTION } from './DataViewFilters.keys';\n import type { DrawerStyle, OnApplyFilters } from './DataViewFilters.types';\n import type { UseFiltersReturnType } from './useFilters';\n\n export interface DataViewFiltersProps {\n filtersLabelText?: string;\n /**\n * Props to pass to the `SearchBar` component.\n */\n searchBarProps?: SearchBarProps;\n showSearch?: boolean;\n /** 'cascade' displays all fields within every filter group; 'nested' displays only the group names and requires clicking a group to view its fields */\n drawerStyle?: DrawerStyle;\n drawerProps?: ModalProps;\n showDrawerPreviousButton?: boolean;\n /**\n * Required when using filters. This prop should contain the return value of the `useFilters()` composable.\n */\n useFiltersInstance?: UseFiltersReturnType;\n onApply?: OnApplyFilters;\n /** The name of the active filter group. The active filter group is determined by which instance of FilterDropdown or FilterDrawerItem is open. */\n activeGroup?: string;\n }\n\n export interface DataViewFiltersSlots {\n default?: void;\n drawer?: void;\n 'filters-label'?: void;\n }\n\n const props = withDefaults(defineProps<DataViewFiltersProps>(), {\n filtersLabelText: t('ll.filterBy'),\n isLoading: false,\n drawerStyle: 'nested',\n drawerProps: undefined,\n searchBarProps: undefined,\n showDrawerPreviousButton: false,\n showSearch: true,\n useFiltersInstance: undefined,\n onApply: undefined,\n activeGroup: '',\n });\n\n const emit = defineEmits<{\n /** When the drawer is opened */\n (e: 'open-drawer'): void;\n /** When the drawer is dismissed */\n (e: 'dismiss'): void;\n /** When the \"Previous\" button in the header is clicked */\n (e: 'previous'): void;\n /** When the \"Reset\" button is clicked while viewing a filter group */\n (e: 'reset-group'): void;\n /** When one of the \"Reset All\" buttons is clicked */\n (e: 'reset-all'): void;\n }>();\n\n const slots = defineSlots<DataViewFiltersSlots>();\n\n const isDesktop = useMediaQuery(`(min-width: ${SCREEN_SIZES.lg})`);\n\n const {\n density,\n isLoading: isDataViewLoading,\n isWithinModule,\n currentSearch,\n updateCurrentSearch,\n } = inject(DATA_VIEW_INJECTION.key, DATA_VIEW_INJECTION.defaults);\n\n provide(DATA_VIEW_FILTERS_UTILS_INJECTION.key, {\n useFiltersInstance: props.useFiltersInstance,\n drawerStyle: props.drawerStyle,\n });\n\n const totalActiveFiltersCount = computed(() => props.useFiltersInstance?.totalActiveFiltersCount.value ?? 0);\n const activeGroupActiveFiltersCount = computed(\n () => props.useFiltersInstance?.activeFiltersCounts.value[props.activeGroup] ?? 0,\n );\n const isDrawerOpen = ref(false);\n\n async function handleApplyClick() {\n const { preventDismiss } = (await props.onApply?.()) || props.useFiltersInstance?.applyFilters() || {};\n\n if (!preventDismiss) {\n isDrawerOpen.value = false;\n }\n }\n\n function handleResetGroupClick() {\n props.useFiltersInstance?.resetFilterGroup(props.activeGroup);\n emit('reset-group');\n isDrawerOpen.value = false;\n }\n\n function handleResetAllClick() {\n props.useFiltersInstance?.resetAllFilters();\n emit('reset-all');\n isDrawerOpen.value = false;\n }\n\n function onDismiss() {\n props.useFiltersInstance?.undoWorkingFilters();\n isDrawerOpen.value = false;\n emit('dismiss');\n }\n\n watch(isDrawerOpen, () => {\n if (isDrawerOpen.value) {\n emit('open-drawer');\n }\n });\n</script>\n\n<template>\n <Box\n class=\"stash-data-view-filters tw-grid tw-grid-cols-12 tw-gap-6 tw-p-3\"\n :class=\"{ 'lg:tw-p-6': density === 'comfortable', 'tw-mb-3': !isWithinModule }\"\n :radius=\"isWithinModule ? 'none' : 'rounded'\"\n data-test=\"stash-data-view-filters\"\n disable-padding\n >\n <SearchBar\n v-if=\"props.showSearch\"\n class=\"tw-col-span-12 md:tw-col-span-6 lg:tw-col-span-4\"\n data-test=\"stash-data-view-filters|search-bar\"\n :is-loading=\"isDataViewLoading\"\n :label=\"t('ll.search')\"\n :model-value=\"currentSearch\"\n v-bind=\"props.searchBarProps\"\n @search=\"(searchTerm) => updateCurrentSearch(searchTerm, { shouldEmit: true })\"\n />\n <div\n v-if=\"slots.default\"\n class=\"tw-col-span-12 tw-row-start-2 md:tw-col-start-7 md:tw-row-start-1 lg:tw-col-span-8 lg:tw-col-start-5\"\n >\n <div class=\"tw-hidden md:tw-block\">\n <slot name=\"filters-label\">\n <Label>{{ props.filtersLabelText }}</Label>\n </slot>\n </div>\n <div class=\"tw-flex tw-gap-4\">\n <FilterChip\n secondary\n class=\"!tw-flex tw-w-full tw-justify-center tw-gap-4 md:!tw-inline-flex md:tw-w-auto\"\n data-test=\"stash-data-view-filters|drawer-toggle-button\"\n :filter-count=\"totalActiveFiltersCount\"\n @click=\"isDrawerOpen = true\"\n >\n <span class=\"tw-inline-flex tw-items-center tw-gap-3\">\n <Icon name=\"filter-line\" class=\"tw-text-ice-700\" />\n <span>{{ t('ll.filters') }}</span>\n </span>\n </FilterChip>\n <slot v-if=\"isDesktop\"></slot>\n <Button v-if=\"totalActiveFiltersCount > 0 && isDesktop\" inline @click=\"handleResetAllClick\">\n {{ t('ll.resetAll') }}\n </Button>\n </div>\n </div>\n <Modal\n v-if=\"slots.drawer\"\n data-test=\"stash-data-view-filters|drawer\"\n disable-body-padding\n position=\"right\"\n :is-open=\"isDrawerOpen\"\n :title=\"t('ll.allFilters')\"\n v-bind=\"props.drawerProps\"\n @dismiss=\"onDismiss\"\n >\n <template #headerAction>\n <Button\n v-if=\"props.showDrawerPreviousButton\"\n icon\n class=\"tw-text-ice-100\"\n data-test=\"stash-data-view-filters|drawer-previous-button\"\n :aria-label=\"t('ll.previous')\"\n :title=\"t('ll.previous')\"\n @click=\"emit('previous')\"\n >\n <Icon name=\"chevron-left\" />\n </Button>\n </template>\n\n <slot name=\"drawer\"></slot>\n\n <template #footer>\n <div class=\"tw-flex tw-flex-col-reverse tw-gap-gutter lg:tw-flex-row lg:tw-justify-end\">\n <Button\n v-if=\"!props.showDrawerPreviousButton && totalActiveFiltersCount > 0\"\n secondary\n :disabled=\"isDataViewLoading\"\n @click=\"handleResetAllClick\"\n >\n {{ t('ll.resetAll') }}\n </Button>\n <Button\n v-if=\"\n (props.showDrawerPreviousButton || props.drawerStyle === 'cascade') && activeGroupActiveFiltersCount > 0\n \"\n secondary\n :disabled=\"isDataViewLoading\"\n @click=\"handleResetGroupClick\"\n >\n {{ t('ll.reset') }}\n </Button>\n <Button\n v-if=\"props.showDrawerPreviousButton || props.drawerStyle === 'cascade'\"\n :disabled=\"isDataViewLoading\"\n @click=\"handleApplyClick\"\n >\n {{ t('ll.apply') }}\n </Button>\n </div>\n </template>\n </Modal>\n </Box>\n</template>\n"],"names":["useFilters","schema","dataViewRef","appliedFilters","ref","workingFilters","filterName","dvRef","applyFilters","cloneDeep","resetAllFilters","resetFilterGroup","group","undoWorkingFilters","activeFiltersCounts","computed","counts","config","value","_a","isDefined","totalActiveFiltersCount","count","props","__props","emit","__emit","slots","_useSlots","isDesktop","useMediaQuery","SCREEN_SIZES","density","isDataViewLoading","isWithinModule","currentSearch","updateCurrentSearch","inject","DATA_VIEW_INJECTION","provide","DATA_VIEW_FILTERS_UTILS_INJECTION","activeGroupActiveFiltersCount","isDrawerOpen","handleApplyClick","preventDismiss","_b","handleResetGroupClick","handleResetAllClick","onDismiss","watch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCO,SAASA,GAAyD;AAAA,EACvE,QAAAC;AAAA,EACA,aAAAC;AACF,GAAyE;AACjE,QAAAC,IAAiBC,EAAI,CAAA,CAAE,GACvBC,IAAiBD,EAAI,CAAA,CAAE;AAE7B,aAAWE,KAAcL;AAEvB,IAAAE,EAAe,MAAMG,CAAU,IAAIL,EAAOK,CAAU,EAAE,cAEtDD,EAAe,MAAMC,CAAU,IAAIL,EAAOK,CAAU,EAAE;AAGxD,QAAMC,IAAQL;AAQd,WAASM,IAAe;AACP,IAAAL,EAAA,QAAQM,EAAUJ,EAAe,KAAK,GACrDE,EAAM,MAAM,qBAAqBJ,EAAe,OAAO,EAAE,YAAY,IAAM;AAAA,EAC7E;AAQA,WAASO,IAAkB;AACzB,eAAWJ,KAAcL;AAEvB,MAAAE,EAAe,MAAMG,CAAU,IAAIL,EAAOK,CAAU,EAAE,cAEtDD,EAAe,MAAMC,CAAU,IAAIL,EAAOK,CAAU,EAAE;AAGxD,IAAAC,EAAM,MAAM,qBAAqBJ,EAAe,OAAO,EAAE,YAAY,IAAM;AAAA,EAC7E;AAQA,WAASQ,EAAiBC,GAAe;AACvC,eAAWN,KAAcL;AACvB,MAAIA,EAAOK,CAAU,EAAE,UAAUM,MAE/BT,EAAe,MAAMG,CAAU,IAAIL,EAAOK,CAAU,EAAE,cAEtDD,EAAe,MAAMC,CAAU,IAAIL,EAAOK,CAAU,EAAE;AAI1D,IAAAC,EAAM,MAAM,qBAAqBJ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
1
|
+
{"version":3,"file":"DataViewFilters.js","sources":["../src/components/DataViewFilters/useFilters.ts","../src/components/DataViewFilters/DataViewFilters.vue"],"sourcesContent":["import cloneDeep from 'lodash-es/cloneDeep';\nimport { computed, ComputedRef, Ref, ref } from 'vue';\n\nimport isDefined from '../../composables/useValidation/utils/isDefined';\nimport DataView from '../DataView/DataView.vue';\n\ntype DataViewInstance = InstanceType<typeof DataView>;\n\n/**\n * Contains metadata and configuration for the filters.\n * @see https://www.typescriptlang.org/docs/handbook/2/mapped-types.html\n */\nexport type UseFiltersSchema<Values extends object, Groups extends string> = {\n [Property in keyof Values]: {\n defaultValue?: Values[Property];\n group?: Groups;\n isActive?: (value: Values[Property]) => boolean;\n };\n};\n\nexport interface UseFiltersArgs<Values extends object, Groups extends string> {\n schema: UseFiltersSchema<Values, Groups>;\n /** A ref for an instance of DataView */\n dataViewRef: Ref<unknown>; // Note: using `Ref<InstanceType<typeof DataView>>` here causes type errors when providing a value for this argument\n}\n\nexport interface UseFiltersReturnType<Values = object, Groups extends string = string> {\n applyFilters: () => void;\n resetAllFilters: () => void;\n resetFilterGroup: (group: string) => void; // Note: group is intentionally not typed as `Groups` since there is no way to pass in a Groups type to UseFiltersReturnType within DataViewFilters.vue\n undoWorkingFilters: () => void;\n activeFiltersCounts: ComputedRef<Record<Groups, number>>;\n totalActiveFiltersCount: ComputedRef<number>;\n appliedFilters: Ref<Values>;\n workingFilters: Ref<Values>;\n}\n\n/**\n * Provides utility functions for working with `DataViewFilters`.\n */\nexport function useFilters<Values extends object, Groups extends string>({\n schema,\n dataViewRef,\n}: UseFiltersArgs<Values, Groups>): UseFiltersReturnType<Values, Groups> {\n const appliedFilters = ref({}) as Ref<Values>;\n const workingFilters = ref({}) as Ref<Values>;\n\n for (const filterName in schema) {\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n appliedFilters.value[filterName] = schema[filterName].defaultValue;\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n workingFilters.value[filterName] = schema[filterName].defaultValue;\n }\n\n const dvRef = dataViewRef as Ref<DataViewInstance>;\n\n /**\n * For when an \"Apply\" button is clicked. It does the following:\n * 1) applies the working filter state\n * 2) sets the current page to 1\n * 3) emits the \"update\" event from DataView\n */\n function applyFilters() {\n appliedFilters.value = cloneDeep(workingFilters.value);\n dvRef.value.updateCurrentFilters(appliedFilters.value, { shouldEmit: true });\n }\n\n /**\n * For when a \"Reset all\" button is clicked. It does the following:\n * 1) applies the defaultValue filter values to all filters\n * 2) sets the current page to 1\n * 3) emits the \"update\" event from DataView\n */\n function resetAllFilters() {\n for (const filterName in schema) {\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n appliedFilters.value[filterName] = schema[filterName].defaultValue;\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n workingFilters.value[filterName] = schema[filterName].defaultValue;\n }\n\n dvRef.value.updateCurrentFilters(appliedFilters.value, { shouldEmit: true });\n }\n\n /**\n * For when a \"Reset\" button is clicked. It does the following:\n * 1) applies the defaultValue filter values to the given filter group\n * 2) sets the current page to 1\n * 3) emits the \"update\" event from DataView\n */\n function resetFilterGroup(group: Groups) {\n for (const filterName in schema) {\n if (schema[filterName].group === group) {\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n appliedFilters.value[filterName] = schema[filterName].defaultValue;\n // @ts-expect-error \"could be instantiated with an arbitrary type\"; TODO: figure out how to resolve the types\n workingFilters.value[filterName] = schema[filterName].defaultValue;\n }\n }\n\n dvRef.value.updateCurrentFilters(appliedFilters.value, { shouldEmit: true });\n }\n\n /**\n * Resets the `workingFilters` to match the `appliedFilters`. This can be used when the FilterDrawer or a FilterDropdown is dismissed without clicking \"Reset\" or \"Apply\".\n */\n function undoWorkingFilters() {\n workingFilters.value = cloneDeep(appliedFilters.value);\n }\n\n const activeFiltersCounts = computed(() => {\n const counts = {} as Record<Groups, number>;\n\n for (const filterName in schema) {\n const config = schema[filterName];\n const value = appliedFilters.value[filterName];\n const isActive = config.isActive?.(value) || isDefined(value);\n\n if (isActive && config.group) {\n counts[config.group] = (counts[config.group] ?? 0) + 1;\n }\n }\n\n return counts;\n });\n\n const totalActiveFiltersCount = computed(() => {\n let count = 0;\n\n for (const filterName in schema) {\n const config = schema[filterName];\n const value = appliedFilters.value[filterName];\n const isActive = config.isActive?.(value) || isDefined(value);\n\n if (isActive) {\n count += 1;\n }\n }\n\n return count;\n });\n\n return {\n applyFilters,\n resetAllFilters,\n // @ts-expect-error \"could be instantiated with a different subtype\": TODO: figure out how to resolve the types\n resetFilterGroup,\n undoWorkingFilters,\n activeFiltersCounts,\n totalActiveFiltersCount,\n appliedFilters,\n workingFilters,\n };\n}\n\nexport default useFilters;\n","<script lang=\"ts\">\n export * from './DataViewFilters.keys';\n export * from './DataViewFilters.types';\n export * from './useFilters';\n</script>\n\n<script setup lang=\"ts\">\n import { computed, inject, provide, ref, watch } from 'vue';\n\n import useMediaQuery from '../../composables/useMediaQuery/useMediaQuery';\n import { SCREEN_SIZES } from '../../constants';\n import { t } from '../../locale';\n import Box from '../Box/Box.vue';\n import Button from '../Button/Button.vue';\n import { DATA_VIEW_INJECTION } from '../DataView/DataView.vue';\n import FilterChip from '../FilterChip/FilterChip.vue';\n import Icon from '../Icon/Icon.vue';\n import Label from '../Label/Label.vue';\n import Modal, { type ModalProps } from '../Modal/Modal.vue';\n import SearchBar, { SearchBarProps } from '../SearchBar/SearchBar.vue';\n import { DATA_VIEW_FILTERS_UTILS_INJECTION } from './DataViewFilters.keys';\n import type { DrawerStyle, OnApplyFilters } from './DataViewFilters.types';\n import type { UseFiltersReturnType } from './useFilters';\n\n export interface DataViewFiltersProps {\n filtersLabelText?: string;\n /**\n * Props to pass to the `SearchBar` component.\n */\n searchBarProps?: SearchBarProps;\n showSearch?: boolean;\n /** 'cascade' displays all fields within every filter group; 'nested' displays only the group names and requires clicking a group to view its fields */\n drawerStyle?: DrawerStyle;\n drawerProps?: ModalProps;\n /**\n * @deprecated The `activeGroup` prop is a sufficient replacement for this prop. A falsy `activeGroup` will hide the button and a truthy `activeGroup` will show it (when the `drawerStyle` is 'nested').\n *\n * **Note:** This prop has no effect when using a \"cascade\" `drawerStyle`.\n */\n showDrawerPreviousButton?: boolean;\n /**\n * Required when using filters. This prop should contain the return value of the `useFilters()` composable.\n */\n useFiltersInstance?: UseFiltersReturnType;\n onApply?: OnApplyFilters;\n /**\n * The name of the active filter group. The active filter group is determined by which instance of FilterDropdown or FilterDrawerItem is open.\n *\n * **Note:** This prop is required when using a \"nested\" `drawerStyle`, but has no effect when using a \"cascade\" `drawerStyle`.\n */\n activeGroup?: string;\n }\n\n export interface DataViewFiltersSlots {\n default?: void;\n drawer?: void;\n 'filters-label'?: void;\n }\n\n const props = withDefaults(defineProps<DataViewFiltersProps>(), {\n filtersLabelText: t('ll.filterBy'),\n isLoading: false,\n drawerStyle: 'nested',\n drawerProps: undefined,\n searchBarProps: undefined,\n showDrawerPreviousButton: false,\n showSearch: true,\n useFiltersInstance: undefined,\n onApply: undefined,\n activeGroup: undefined,\n });\n\n const emit = defineEmits<{\n /** When the drawer is opened */\n (e: 'open-drawer'): void;\n /** When the drawer is dismissed */\n (e: 'dismiss'): void;\n /** When the \"Previous\" button in the header is clicked */\n (e: 'previous'): void;\n /** When the \"Reset\" button is clicked while viewing a filter group */\n (e: 'reset-group'): void;\n /** When one of the \"Reset All\" buttons is clicked */\n (e: 'reset-all'): void;\n }>();\n\n const slots = defineSlots<DataViewFiltersSlots>();\n\n const isDesktop = useMediaQuery(`(min-width: ${SCREEN_SIZES.lg})`);\n const isViewingGroupsMenu = computed(() => props.drawerStyle === 'nested' && !props.activeGroup);\n const isViewingSingleGroup = computed(() => props.drawerStyle === 'nested' && props.activeGroup);\n\n const {\n density,\n isLoading: isDataViewLoading,\n isWithinModule,\n currentSearch,\n updateCurrentSearch,\n } = inject(DATA_VIEW_INJECTION.key, DATA_VIEW_INJECTION.defaults);\n\n provide(DATA_VIEW_FILTERS_UTILS_INJECTION.key, {\n useFiltersInstance: props.useFiltersInstance,\n drawerStyle: props.drawerStyle,\n });\n\n const totalActiveFiltersCount = computed(() => props.useFiltersInstance?.totalActiveFiltersCount.value ?? 0);\n /** The number of active filters in the currently active group. This is only used when the drawerStyle is 'nested'. */\n const activeGroupActiveFiltersCount = computed(\n () => Number(props.activeGroup && props.useFiltersInstance?.activeFiltersCounts.value[props.activeGroup]) || 0,\n );\n const isDrawerOpen = ref(false);\n\n async function handleApplyClick() {\n const { preventDismiss } = (await props.onApply?.()) || props.useFiltersInstance?.applyFilters() || {};\n\n if (!preventDismiss) {\n isDrawerOpen.value = false;\n }\n }\n\n function handleResetGroupClick() {\n if (!props.activeGroup) {\n return;\n }\n\n props.useFiltersInstance?.resetFilterGroup(props.activeGroup);\n emit('reset-group');\n isDrawerOpen.value = false;\n }\n\n function handleResetAllClick() {\n props.useFiltersInstance?.resetAllFilters();\n emit('reset-all');\n isDrawerOpen.value = false;\n }\n\n function onDismiss() {\n props.useFiltersInstance?.undoWorkingFilters();\n isDrawerOpen.value = false;\n emit('dismiss');\n }\n\n watch(isDrawerOpen, () => {\n if (isDrawerOpen.value) {\n emit('open-drawer');\n }\n });\n</script>\n\n<template>\n <Box\n class=\"stash-data-view-filters tw-grid tw-grid-cols-12 tw-gap-6 tw-p-3\"\n :class=\"{ 'lg:tw-p-6': density === 'comfortable', 'tw-mb-3': !isWithinModule }\"\n :radius=\"isWithinModule ? 'none' : 'rounded'\"\n data-test=\"stash-data-view-filters\"\n disable-padding\n >\n <SearchBar\n v-if=\"props.showSearch\"\n class=\"tw-col-span-12 md:tw-col-span-6 lg:tw-col-span-4\"\n data-test=\"stash-data-view-filters|search-bar\"\n :is-loading=\"isDataViewLoading\"\n :label=\"t('ll.search')\"\n :model-value=\"currentSearch\"\n v-bind=\"props.searchBarProps\"\n @search=\"(searchTerm) => updateCurrentSearch(searchTerm, { shouldEmit: true })\"\n />\n <div\n v-if=\"slots.default\"\n class=\"tw-col-span-12 tw-row-start-2 md:tw-col-start-7 md:tw-row-start-1 lg:tw-col-span-8 lg:tw-col-start-5\"\n >\n <div class=\"tw-hidden md:tw-block\">\n <slot name=\"filters-label\">\n <Label>{{ props.filtersLabelText }}</Label>\n </slot>\n </div>\n <div class=\"tw-flex tw-gap-4\">\n <FilterChip\n secondary\n class=\"!tw-flex tw-w-full tw-justify-center tw-gap-4 md:!tw-inline-flex md:tw-w-auto\"\n data-test=\"stash-data-view-filters|drawer-toggle-button\"\n :filter-count=\"totalActiveFiltersCount\"\n @click=\"isDrawerOpen = true\"\n >\n <span class=\"tw-inline-flex tw-items-center tw-gap-3\">\n <Icon name=\"filter-line\" class=\"tw-text-ice-700\" />\n <span>{{ t('ll.filters') }}</span>\n </span>\n </FilterChip>\n <slot v-if=\"isDesktop\"></slot>\n <Button v-if=\"totalActiveFiltersCount > 0 && isDesktop\" inline @click=\"handleResetAllClick\">\n {{ t('ll.resetAll') }}\n </Button>\n </div>\n </div>\n <Modal\n v-if=\"slots.drawer\"\n data-test=\"stash-data-view-filters|drawer\"\n disable-body-padding\n position=\"right\"\n :is-open=\"isDrawerOpen\"\n :title=\"t('ll.allFilters')\"\n v-bind=\"props.drawerProps\"\n @dismiss=\"onDismiss\"\n >\n <template #headerAction>\n <Button\n v-if=\"isViewingSingleGroup\"\n icon\n class=\"tw-text-ice-100\"\n data-test=\"stash-data-view-filters|drawer-previous-button\"\n :aria-label=\"t('ll.previous')\"\n :title=\"t('ll.previous')\"\n @click=\"emit('previous')\"\n >\n <Icon name=\"chevron-left\" />\n </Button>\n </template>\n\n <slot name=\"drawer\"></slot>\n\n <template #footer>\n <div class=\"tw-flex tw-justify-end tw-gap-gutter\">\n <Button v-if=\"totalActiveFiltersCount === 0\" secondary @click=\"onDismiss\">\n {{ t('ll.cancel') }}\n </Button>\n <Button\n v-if=\"(isViewingGroupsMenu || props.drawerStyle === 'cascade') && totalActiveFiltersCount > 0\"\n secondary\n :disabled=\"isDataViewLoading\"\n @click=\"handleResetAllClick\"\n >\n {{ t('ll.resetAll') }}\n </Button>\n <Button\n v-if=\"isViewingSingleGroup && activeGroupActiveFiltersCount > 0\"\n secondary\n :disabled=\"isDataViewLoading\"\n @click=\"handleResetGroupClick\"\n >\n {{ t('ll.reset') }}\n </Button>\n <Button\n v-if=\"isViewingSingleGroup || props.drawerStyle === 'cascade'\"\n :disabled=\"isDataViewLoading\"\n @click=\"handleApplyClick\"\n >\n {{ t('ll.apply') }}\n </Button>\n </div>\n </template>\n </Modal>\n </Box>\n</template>\n"],"names":["useFilters","schema","dataViewRef","appliedFilters","ref","workingFilters","filterName","dvRef","applyFilters","cloneDeep","resetAllFilters","resetFilterGroup","group","undoWorkingFilters","activeFiltersCounts","computed","counts","config","value","_a","isDefined","totalActiveFiltersCount","count","props","__props","emit","__emit","slots","_useSlots","isDesktop","useMediaQuery","SCREEN_SIZES","isViewingGroupsMenu","isViewingSingleGroup","density","isDataViewLoading","isWithinModule","currentSearch","updateCurrentSearch","inject","DATA_VIEW_INJECTION","provide","DATA_VIEW_FILTERS_UTILS_INJECTION","activeGroupActiveFiltersCount","isDrawerOpen","handleApplyClick","preventDismiss","_b","handleResetGroupClick","handleResetAllClick","onDismiss","watch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCO,SAASA,GAAyD;AAAA,EACvE,QAAAC;AAAA,EACA,aAAAC;AACF,GAAyE;AACjE,QAAAC,IAAiBC,EAAI,CAAA,CAAE,GACvBC,IAAiBD,EAAI,CAAA,CAAE;AAE7B,aAAWE,KAAcL;AAEvB,IAAAE,EAAe,MAAMG,CAAU,IAAIL,EAAOK,CAAU,EAAE,cAEtDD,EAAe,MAAMC,CAAU,IAAIL,EAAOK,CAAU,EAAE;AAGxD,QAAMC,IAAQL;AAQd,WAASM,IAAe;AACP,IAAAL,EAAA,QAAQM,EAAUJ,EAAe,KAAK,GACrDE,EAAM,MAAM,qBAAqBJ,EAA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AAQ;AAAA,IAEzB;AAEA,aAASI,IAAwB;;AAC3B,MAACzB,EAAM,iBAILJ,IAAAI,EAAA,uBAAA,QAAAJ,EAAoB,iBAAiBI,EAAM,cACjDE,EAAK,aAAa,GAClBmB,EAAa,QAAQ;AAAA,IACvB;AAEA,aAASK,IAAsB;;AAC7B,OAAA9B,IAAAI,EAAM,uBAAN,QAAAJ,EAA0B,mBAC1BM,EAAK,WAAW,GAChBmB,EAAa,QAAQ;AAAA,IACvB;AAEA,aAASM,IAAY;;AACnB,OAAA/B,IAAAI,EAAM,uBAAN,QAAAJ,EAA0B,sBAC1ByB,EAAa,QAAQ,IACrBnB,EAAK,SAAS;AAAA,IAChB;AAEA,WAAA0B,EAAMP,GAAc,MAAM;AACxB,MAAIA,EAAa,SACfnB,EAAK,aAAa;AAAA,IACpB,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -47,13 +47,22 @@ export declare interface DataViewFiltersProps {
|
|
|
47
47
|
/** 'cascade' displays all fields within every filter group; 'nested' displays only the group names and requires clicking a group to view its fields */
|
|
48
48
|
drawerStyle?: DrawerStyle;
|
|
49
49
|
drawerProps?: ModalProps;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated The `activeGroup` prop is a sufficient replacement for this prop. A falsy `activeGroup` will hide the button and a truthy `activeGroup` will show it (when the `drawerStyle` is 'nested').
|
|
52
|
+
*
|
|
53
|
+
* **Note:** This prop has no effect when using a "cascade" `drawerStyle`.
|
|
54
|
+
*/
|
|
50
55
|
showDrawerPreviousButton?: boolean;
|
|
51
56
|
/**
|
|
52
57
|
* Required when using filters. This prop should contain the return value of the `useFilters()` composable.
|
|
53
58
|
*/
|
|
54
59
|
useFiltersInstance?: UseFiltersReturnType;
|
|
55
60
|
onApply?: OnApplyFilters;
|
|
56
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* The name of the active filter group. The active filter group is determined by which instance of FilterDropdown or FilterDrawerItem is open.
|
|
63
|
+
*
|
|
64
|
+
* **Note:** This prop is required when using a "nested" `drawerStyle`, but has no effect when using a "cascade" `drawerStyle`.
|
|
65
|
+
*/
|
|
57
66
|
activeGroup?: string;
|
|
58
67
|
}
|
|
59
68
|
|
|
@@ -78,7 +87,7 @@ declare const _default: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes
|
|
|
78
87
|
showSearch: boolean;
|
|
79
88
|
useFiltersInstance: undefined;
|
|
80
89
|
onApply: undefined;
|
|
81
|
-
activeGroup:
|
|
90
|
+
activeGroup: undefined;
|
|
82
91
|
}>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
83
92
|
"open-drawer": () => void;
|
|
84
93
|
dismiss: () => void;
|
|
@@ -95,7 +104,7 @@ declare const _default: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes
|
|
|
95
104
|
showSearch: boolean;
|
|
96
105
|
useFiltersInstance: undefined;
|
|
97
106
|
onApply: undefined;
|
|
98
|
-
activeGroup:
|
|
107
|
+
activeGroup: undefined;
|
|
99
108
|
}>>> & Readonly<{
|
|
100
109
|
onDismiss?: (() => any) | undefined;
|
|
101
110
|
"onOpen-drawer"?: (() => any) | undefined;
|