@leaflink/stash 49.3.1 → 49.3.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/DataViewFilters.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref as B, computed as C, defineComponent as j, useSlots as O, inject as
|
|
1
|
+
import { ref as B, computed as C, defineComponent as j, useSlots as O, inject as z, provide as J, 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
2
|
import q from "./useMediaQuery.js";
|
|
3
3
|
import { SCREEN_SIZES as H } from "./constants.js";
|
|
4
4
|
import { t as d } from "./locale.js";
|
|
@@ -27,69 +27,70 @@ 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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
var re = /* @__PURE__ */ ((l) => (l.Cascade = "cascade", l.Nested = "nested", l))(re || {});
|
|
31
|
+
function Pe({
|
|
32
|
+
schema: l,
|
|
33
|
+
dataViewRef: N
|
|
33
34
|
}) {
|
|
34
35
|
const e = B({}), o = B({});
|
|
35
|
-
for (const
|
|
36
|
-
e.value[
|
|
37
|
-
const y =
|
|
36
|
+
for (const r in l)
|
|
37
|
+
e.value[r] = l[r].defaultValue, o.value[r] = l[r].defaultValue;
|
|
38
|
+
const y = N;
|
|
38
39
|
function h() {
|
|
39
40
|
e.value = L(o.value), y.value.updateCurrentFilters(e.value, { shouldEmit: !0 });
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
-
for (const
|
|
43
|
-
e.value[
|
|
42
|
+
function V() {
|
|
43
|
+
for (const r in l)
|
|
44
|
+
e.value[r] = l[r].defaultValue, o.value[r] = l[r].defaultValue;
|
|
44
45
|
y.value.updateCurrentFilters(e.value, { shouldEmit: !0 });
|
|
45
46
|
}
|
|
46
|
-
function b(
|
|
47
|
-
for (const i in
|
|
48
|
-
|
|
47
|
+
function b(r) {
|
|
48
|
+
for (const i in l)
|
|
49
|
+
l[i].group === r && (e.value[i] = l[i].defaultValue, o.value[i] = l[i].defaultValue);
|
|
49
50
|
y.value.updateCurrentFilters(e.value, { shouldEmit: !0 });
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
+
function E() {
|
|
52
53
|
o.value = L(e.value);
|
|
53
54
|
}
|
|
54
55
|
const g = C(() => {
|
|
55
56
|
var i;
|
|
56
|
-
const
|
|
57
|
-
for (const c in
|
|
58
|
-
const n =
|
|
59
|
-
(((i = n.isActive) == null ? void 0 : i.call(n, s)) || W(s)) && n.group && (
|
|
57
|
+
const r = {};
|
|
58
|
+
for (const c in l) {
|
|
59
|
+
const n = l[c], s = e.value[c];
|
|
60
|
+
(((i = n.isActive) == null ? void 0 : i.call(n, s)) || W(s)) && n.group && (r[n.group] = (r[n.group] ?? 0) + 1);
|
|
60
61
|
}
|
|
61
|
-
return
|
|
62
|
+
return r;
|
|
62
63
|
}), S = C(() => {
|
|
63
64
|
var i;
|
|
64
|
-
let
|
|
65
|
-
for (const c in
|
|
66
|
-
const n =
|
|
67
|
-
(((i = n.isActive) == null ? void 0 : i.call(n, s)) || W(s)) && (
|
|
65
|
+
let r = 0;
|
|
66
|
+
for (const c in l) {
|
|
67
|
+
const n = l[c], s = e.value[c];
|
|
68
|
+
(((i = n.isActive) == null ? void 0 : i.call(n, s)) || W(s)) && (r += 1);
|
|
68
69
|
}
|
|
69
|
-
return
|
|
70
|
+
return r;
|
|
70
71
|
});
|
|
71
72
|
return {
|
|
72
73
|
applyFilters: h,
|
|
73
|
-
resetAllFilters:
|
|
74
|
+
resetAllFilters: V,
|
|
74
75
|
// @ts-expect-error "could be instantiated with a different subtype": TODO: figure out how to resolve the types
|
|
75
76
|
resetFilterGroup: b,
|
|
76
|
-
undoWorkingFilters:
|
|
77
|
+
undoWorkingFilters: E,
|
|
77
78
|
activeFiltersCounts: g,
|
|
78
79
|
totalActiveFiltersCount: S,
|
|
79
80
|
appliedFilters: e,
|
|
80
81
|
workingFilters: o
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
|
-
const
|
|
84
|
+
const ae = {
|
|
84
85
|
key: 1,
|
|
85
86
|
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
|
-
},
|
|
87
|
+
}, se = { class: "tw-hidden md:tw-block" }, ie = { class: "tw-flex tw-gap-4" }, oe = { class: "tw-inline-flex tw-items-center tw-gap-3" }, ne = { class: "tw-flex tw-justify-end tw-gap-gutter" }, Re = /* @__PURE__ */ j({
|
|
87
88
|
__name: "DataViewFilters",
|
|
88
89
|
props: {
|
|
89
90
|
filtersLabelText: { default: d("ll.filterBy") },
|
|
90
91
|
searchBarProps: { default: void 0 },
|
|
91
92
|
showSearch: { type: Boolean, default: !0 },
|
|
92
|
-
drawerStyle: { default: "
|
|
93
|
+
drawerStyle: { default: "cascade" },
|
|
93
94
|
drawerProps: { default: void 0 },
|
|
94
95
|
showDrawerPreviousButton: { type: Boolean, default: !1 },
|
|
95
96
|
useFiltersInstance: { default: void 0 },
|
|
@@ -97,48 +98,48 @@ const re = {
|
|
|
97
98
|
activeGroup: { default: void 0 }
|
|
98
99
|
},
|
|
99
100
|
emits: ["open-drawer", "dismiss", "previous", "reset-group", "reset-all"],
|
|
100
|
-
setup(
|
|
101
|
-
const e =
|
|
102
|
-
density:
|
|
101
|
+
setup(l, { emit: N }) {
|
|
102
|
+
const e = l, o = N, y = O(), h = q(`(min-width: ${H.lg})`), V = C(() => e.drawerStyle === "nested" && !e.activeGroup), b = C(() => e.drawerStyle === "nested" && e.activeGroup), {
|
|
103
|
+
density: E,
|
|
103
104
|
isLoading: g,
|
|
104
105
|
isWithinModule: S,
|
|
105
|
-
currentSearch:
|
|
106
|
+
currentSearch: r,
|
|
106
107
|
updateCurrentSearch: i
|
|
107
|
-
} =
|
|
108
|
-
|
|
108
|
+
} = z(R.key, R.defaults);
|
|
109
|
+
J(le.key, {
|
|
109
110
|
useFiltersInstance: e.useFiltersInstance,
|
|
110
111
|
drawerStyle: e.drawerStyle
|
|
111
112
|
});
|
|
112
113
|
const c = C(() => {
|
|
113
|
-
var
|
|
114
|
-
return ((
|
|
114
|
+
var a;
|
|
115
|
+
return ((a = e.useFiltersInstance) == null ? void 0 : a.totalActiveFiltersCount.value) ?? 0;
|
|
115
116
|
}), n = C(
|
|
116
117
|
() => {
|
|
117
|
-
var
|
|
118
|
-
return Number(e.activeGroup && ((
|
|
118
|
+
var a;
|
|
119
|
+
return Number(e.activeGroup && ((a = e.useFiltersInstance) == null ? void 0 : a.activeFiltersCounts.value[e.activeGroup])) || 0;
|
|
119
120
|
}
|
|
120
121
|
), s = B(!1);
|
|
121
|
-
async function
|
|
122
|
+
async function D() {
|
|
122
123
|
var v, F;
|
|
123
|
-
const { preventDismiss:
|
|
124
|
-
|
|
124
|
+
const { preventDismiss: a } = await ((v = e.onApply) == null ? void 0 : v.call(e)) || ((F = e.useFiltersInstance) == null ? void 0 : F.applyFilters()) || {};
|
|
125
|
+
a || (s.value = !1);
|
|
125
126
|
}
|
|
126
127
|
function M() {
|
|
127
|
-
var
|
|
128
|
-
e.activeGroup && ((
|
|
128
|
+
var a;
|
|
129
|
+
e.activeGroup && ((a = e.useFiltersInstance) == null || a.resetFilterGroup(e.activeGroup), o("reset-group"), s.value = !1);
|
|
129
130
|
}
|
|
130
131
|
function x() {
|
|
131
|
-
var
|
|
132
|
-
(
|
|
132
|
+
var a;
|
|
133
|
+
(a = e.useFiltersInstance) == null || a.resetAllFilters(), o("reset-all"), s.value = !1;
|
|
133
134
|
}
|
|
134
135
|
function T() {
|
|
135
|
-
var
|
|
136
|
-
(
|
|
136
|
+
var a;
|
|
137
|
+
(a = e.useFiltersInstance) == null || a.undoWorkingFilters(), s.value = !1, o("dismiss");
|
|
137
138
|
}
|
|
138
139
|
return Q(s, () => {
|
|
139
140
|
s.value && o("open-drawer");
|
|
140
|
-
}), (
|
|
141
|
-
class: U(["stash-data-view-filters tw-grid tw-grid-cols-12 tw-gap-6 tw-p-3", { "lg:tw-p-6": t(
|
|
141
|
+
}), (a, v) => (p(), m(K, {
|
|
142
|
+
class: U(["stash-data-view-filters tw-grid tw-grid-cols-12 tw-gap-6 tw-p-3", { "lg:tw-p-6": t(E) === "comfortable", "tw-mb-3": !t(S) }]),
|
|
142
143
|
radius: t(S) ? "none" : "rounded",
|
|
143
144
|
"data-test": "stash-data-view-filters",
|
|
144
145
|
"disable-padding": ""
|
|
@@ -150,13 +151,13 @@ const re = {
|
|
|
150
151
|
"data-test": "stash-data-view-filters|search-bar",
|
|
151
152
|
"is-loading": t(g),
|
|
152
153
|
label: t(d)("ll.search"),
|
|
153
|
-
"model-value": t(
|
|
154
|
+
"model-value": t(r)
|
|
154
155
|
}, e.searchBarProps, {
|
|
155
156
|
onSearch: v[0] || (v[0] = (F) => t(i)(F, { shouldEmit: !0 }))
|
|
156
157
|
}), null, 16, ["is-loading", "label", "model-value"])) : f("", !0),
|
|
157
|
-
y.default ? (p(), Z("div",
|
|
158
|
-
A("div",
|
|
159
|
-
G(
|
|
158
|
+
y.default ? (p(), Z("div", ae, [
|
|
159
|
+
A("div", se, [
|
|
160
|
+
G(a.$slots, "filters-label", {}, () => [
|
|
160
161
|
I(Y, null, {
|
|
161
162
|
default: u(() => [
|
|
162
163
|
k(w(e.filtersLabelText), 1)
|
|
@@ -165,7 +166,7 @@ const re = {
|
|
|
165
166
|
})
|
|
166
167
|
])
|
|
167
168
|
]),
|
|
168
|
-
A("div",
|
|
169
|
+
A("div", ie, [
|
|
169
170
|
I(X, {
|
|
170
171
|
secondary: "",
|
|
171
172
|
class: "!tw-flex tw-w-full tw-justify-center tw-gap-4 md:!tw-inline-flex md:tw-w-auto",
|
|
@@ -174,7 +175,7 @@ const re = {
|
|
|
174
175
|
onClick: v[1] || (v[1] = (F) => s.value = !0)
|
|
175
176
|
}, {
|
|
176
177
|
default: u(() => [
|
|
177
|
-
A("span",
|
|
178
|
+
A("span", oe, [
|
|
178
179
|
I(P, {
|
|
179
180
|
name: "filter-line",
|
|
180
181
|
class: "tw-text-ice-700"
|
|
@@ -184,7 +185,7 @@ const re = {
|
|
|
184
185
|
]),
|
|
185
186
|
_: 1
|
|
186
187
|
}, 8, ["filter-count"]),
|
|
187
|
-
t(h) ? G(
|
|
188
|
+
t(h) ? G(a.$slots, "default", { key: 0 }) : f("", !0),
|
|
188
189
|
c.value > 0 && t(h) ? (p(), m(_, {
|
|
189
190
|
key: 1,
|
|
190
191
|
inline: "",
|
|
@@ -202,6 +203,7 @@ const re = {
|
|
|
202
203
|
"data-test": "stash-data-view-filters|drawer",
|
|
203
204
|
"disable-body-padding": "",
|
|
204
205
|
position: "right",
|
|
206
|
+
size: "narrow",
|
|
205
207
|
"is-open": s.value,
|
|
206
208
|
title: t(d)("ll.allFilters")
|
|
207
209
|
}, e.drawerProps, { onDismiss: T }), {
|
|
@@ -222,7 +224,7 @@ const re = {
|
|
|
222
224
|
}, 8, ["aria-label", "title"])) : f("", !0)
|
|
223
225
|
]),
|
|
224
226
|
footer: u(() => [
|
|
225
|
-
A("div",
|
|
227
|
+
A("div", ne, [
|
|
226
228
|
c.value === 0 ? (p(), m(_, {
|
|
227
229
|
key: 0,
|
|
228
230
|
secondary: "",
|
|
@@ -233,7 +235,7 @@ const re = {
|
|
|
233
235
|
]),
|
|
234
236
|
_: 1
|
|
235
237
|
})) : f("", !0),
|
|
236
|
-
(
|
|
238
|
+
(V.value || e.drawerStyle === "cascade") && c.value > 0 ? (p(), m(_, {
|
|
237
239
|
key: 1,
|
|
238
240
|
secondary: "",
|
|
239
241
|
disabled: t(g),
|
|
@@ -258,7 +260,7 @@ const re = {
|
|
|
258
260
|
b.value || e.drawerStyle === "cascade" ? (p(), m(_, {
|
|
259
261
|
key: 3,
|
|
260
262
|
disabled: t(g),
|
|
261
|
-
onClick:
|
|
263
|
+
onClick: D
|
|
262
264
|
}, {
|
|
263
265
|
default: u(() => [
|
|
264
266
|
k(w(t(d)("ll.apply")), 1)
|
|
@@ -268,7 +270,7 @@ const re = {
|
|
|
268
270
|
])
|
|
269
271
|
]),
|
|
270
272
|
default: u(() => [
|
|
271
|
-
G(
|
|
273
|
+
G(a.$slots, "drawer")
|
|
272
274
|
]),
|
|
273
275
|
_: 3
|
|
274
276
|
}, 16, ["is-open", "title"])) : f("", !0)
|
|
@@ -279,7 +281,8 @@ const re = {
|
|
|
279
281
|
});
|
|
280
282
|
export {
|
|
281
283
|
le as DATA_VIEW_FILTERS_UTILS_INJECTION,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
+
re as DrawerStyle,
|
|
285
|
+
Re as default,
|
|
286
|
+
Pe as useFilters
|
|
284
287
|
};
|
|
285
288
|
//# 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 /**\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,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,EAAe,OAAO,EAAE,YAAY,IAAM;AAAA,EAC7E;AAKA,WAASU,IAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"DataViewFilters.js","sources":["../src/components/DataViewFilters/DataViewFilters.types.ts","../src/components/DataViewFilters/useFilters.ts","../src/components/DataViewFilters/DataViewFilters.vue"],"sourcesContent":["import { UseFiltersReturnType } from './useFilters';\n\n/**\n * A function that is called when the user clicks one of the \"Apply\" buttons in DataViewFilters.\n *\n * A return value of `{ preventDismiss: true }` can be used to prevent the DataViewFilters drawer or a FilterDropdown from closing, such as when some filters have invalid values.\n */\nexport type OnApplyFilters = () => Promise<{ preventDismiss?: boolean } | void> | { preventDismiss?: boolean } | void;\n\nexport enum DrawerStyle {\n /** Displays all groups and their fields without the need for navigating submenus. */\n Cascade = 'cascade',\n /** Displays only group names or fields; navigation between the group names and a submenu of fields is required. */\n Nested = 'nested',\n}\n\nexport type DrawerStyles = `${DrawerStyle}`;\n\nexport interface DataViewFiltersUtilsInjection {\n useFiltersInstance?: UseFiltersReturnType;\n drawerStyle?: DrawerStyles;\n}\n","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 { DrawerStyles, 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?: DrawerStyles;\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: 'cascade',\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 size=\"narrow\"\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":["DrawerStyle","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASY,IAAAA,uBAAAA,OAEVA,EAAA,UAAU,WAEVA,EAAA,SAAS,UAJCA,IAAAA,MAAA,CAAA,CAAA;AC+BL,SAASC,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,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;AAAA,IACpB,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -44,8 +44,8 @@ export declare interface DataViewFiltersProps {
|
|
|
44
44
|
*/
|
|
45
45
|
searchBarProps?: SearchBarProps;
|
|
46
46
|
showSearch?: boolean;
|
|
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
|
-
drawerStyle?:
|
|
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
|
+
drawerStyle?: DrawerStyles;
|
|
49
49
|
drawerProps?: ModalProps;
|
|
50
50
|
/**
|
|
51
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').
|
|
@@ -74,7 +74,7 @@ export declare interface DataViewFiltersSlots {
|
|
|
74
74
|
|
|
75
75
|
export declare interface DataViewFiltersUtilsInjection {
|
|
76
76
|
useFiltersInstance?: UseFiltersReturnType;
|
|
77
|
-
drawerStyle?:
|
|
77
|
+
drawerStyle?: DrawerStyles;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
declare const _default: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<DataViewFiltersProps>, {
|
|
@@ -115,7 +115,7 @@ declare const _default: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes
|
|
|
115
115
|
filtersLabelText: string;
|
|
116
116
|
searchBarProps: SearchBarProps;
|
|
117
117
|
showSearch: boolean;
|
|
118
|
-
drawerStyle:
|
|
118
|
+
drawerStyle: "cascade" | "nested";
|
|
119
119
|
drawerProps: ModalProps;
|
|
120
120
|
showDrawerPreviousButton: boolean;
|
|
121
121
|
useFiltersInstance: UseFiltersReturnType<object, string>;
|
|
@@ -124,7 +124,14 @@ declare const _default: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes
|
|
|
124
124
|
}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, Readonly<DataViewFiltersSlots> & DataViewFiltersSlots>;
|
|
125
125
|
export default _default;
|
|
126
126
|
|
|
127
|
-
export declare
|
|
127
|
+
export declare enum DrawerStyle {
|
|
128
|
+
/** Displays all groups and their fields without the need for navigating submenus. */
|
|
129
|
+
Cascade = "cascade",
|
|
130
|
+
/** Displays only group names or fields; navigation between the group names and a submenu of fields is required. */
|
|
131
|
+
Nested = "nested"
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export declare type DrawerStyles = `${DrawerStyle}`;
|
|
128
135
|
|
|
129
136
|
declare interface Injection<T> {
|
|
130
137
|
key: InjectionKey<T>;
|