@erxes/ui 4.0.0-v2.13 → 4.0.0-v2.14
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/CATALOG.md +3 -2
- package/README.md +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/modules/conditions/ConditionsEditor.d.ts +5 -3
- package/dist/modules/conditions/ConditionsEditor.js +139 -177
- package/dist/modules/conditions/DateEditors.d.ts +8 -0
- package/dist/modules/conditions/DateEditors.js +188 -0
- package/dist/modules/conditions/FieldPicker.d.ts +17 -0
- package/dist/modules/conditions/FieldPicker.js +99 -0
- package/dist/modules/conditions/RuleParts.d.ts +30 -0
- package/dist/modules/conditions/RuleParts.js +78 -0
- package/dist/modules/conditions/RuleRow.d.ts +27 -0
- package/dist/modules/conditions/RuleRow.js +156 -0
- package/dist/modules/conditions/TypedInput.d.ts +13 -0
- package/dist/modules/conditions/TypedInput.js +36 -0
- package/dist/modules/conditions/ValueEditor.d.ts +18 -0
- package/dist/modules/conditions/ValueEditor.js +164 -0
- package/dist/modules/conditions/conditions.d.ts +14 -9
- package/dist/modules/conditions/conditions.js +1 -75
- package/dist/modules/conditions/fieldIcons.d.ts +6 -0
- package/dist/modules/conditions/fieldIcons.js +19 -0
- package/dist/modules/conditions/fieldOptions.d.ts +13 -0
- package/dist/modules/conditions/fieldOptions.js +26 -0
- package/dist/modules/conditions/filterRule.d.ts +45 -0
- package/dist/modules/conditions/filterRule.js +169 -0
- package/dist/modules/conditions/filterText.d.ts +16 -0
- package/dist/modules/conditions/filterText.js +156 -0
- package/dist/modules/filter/components/Filter.d.ts +1 -1
- package/dist/modules/filter/components/Filter.js +1 -1
- package/dist/modules/list/ListFilter.d.ts +16 -5
- package/dist/modules/list/ListFilter.js +50 -17
- package/dist/modules/list/ViewBar.d.ts +2 -0
- package/dist/modules/list/ViewBar.js +21 -10
- package/dist/modules/list/filter/AddFilter.d.ts +10 -0
- package/dist/modules/list/filter/AddFilter.js +140 -0
- package/dist/modules/list/filter/AdvancedPopover.d.ts +8 -0
- package/dist/modules/list/filter/AdvancedPopover.js +103 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +3 -3
- package/dist/modules/list/filter/ListFilterBar.js +104 -205
- package/dist/modules/list/filter/RuleChips.d.ts +12 -2
- package/dist/modules/list/filter/RuleChips.js +132 -134
- package/dist/modules/list/filter/SearchChip.d.ts +6 -0
- package/dist/modules/list/filter/SearchChip.js +69 -0
- package/dist/modules/list/filter/filterRules.d.ts +15 -40
- package/dist/modules/list/filter/filterRules.js +27 -156
- package/dist/modules/list/filter/listFilterContext.d.ts +25 -18
- package/dist/modules/list/filter/listFilterContext.js +8 -24
- package/dist/modules/list/filter/listFilterQuery.d.ts +4 -0
- package/dist/modules/list/filter/listFilterQuery.js +10 -2
- package/dist/theme.css +3 -2
- package/exports.txt +1 -0
- package/package.json +1 -1
- package/dist/modules/conditions/ConditionValueInput.d.ts +0 -10
- package/dist/modules/conditions/ConditionValueInput.js +0 -166
- package/dist/modules/conditions/PathPicker.d.ts +0 -8
- package/dist/modules/conditions/PathPicker.js +0 -56
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +0 -5
- package/dist/modules/list/filter/AdvancedFilterDialog.js +0 -52
- package/dist/modules/list/filter/FieldMenus.d.ts +0 -5
- package/dist/modules/list/filter/FieldMenus.js +0 -184
- package/dist/modules/list/filter/fieldIcons.d.ts +0 -7
- package/dist/modules/list/filter/fieldIcons.js +0 -16
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Button } from "../../components/button.js";
|
|
2
|
+
import { Empty } from "../../components/empty.js";
|
|
2
3
|
import { useListConditions } from "./filter/listFilterQuery.js";
|
|
3
4
|
import { useListViews } from "./ViewBar.js";
|
|
4
|
-
import {
|
|
5
|
+
import { IconFilterOff } from "@tabler/icons-react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
7
|
import { Suspense, lazy } from "react";
|
|
8
|
+
import { useTranslation } from "react-i18next";
|
|
6
9
|
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
|
7
10
|
// src/modules/list/ListFilter.tsx
|
|
8
11
|
/**
|
|
@@ -11,10 +14,11 @@ import { useAutoAnimate } from "@formkit/auto-animate/react";
|
|
|
11
14
|
*/
|
|
12
15
|
const ListFilterBar = lazy(async () => ({ default: (await import("./filter/ListFilterBar.js")).ListFilterBar }));
|
|
13
16
|
/**
|
|
14
|
-
* A list's filter bar,
|
|
15
|
-
* The
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* A list's filter: a view bar button, and a chip row while it filters.
|
|
18
|
+
* The field picker opens on `F` and holds search and the advanced filter, a popover of
|
|
19
|
+
* "Where / And / Or" rows. Each chip is one condition whose field, operator and value open in
|
|
20
|
+
* place. The conditions and search live in the address (shared links and reloads keep them);
|
|
21
|
+
* `useListFilterParams()` reads them for the list's query. `member` fields pick
|
|
18
22
|
* from `members` and `tags` fields from `tags`: in erxes `memberQueries` from
|
|
19
23
|
* `@erxes/core-contract/client` and the tags query of the record type; outside erxes, the
|
|
20
24
|
* plugin's own.
|
|
@@ -23,16 +27,13 @@ const ListFilter = ({ recordType, ...props }) => {
|
|
|
23
27
|
const [barRef] = useAutoAnimate({ duration: 150 });
|
|
24
28
|
const host = useListViews();
|
|
25
29
|
const status = props.status ?? (recordType && host && /* @__PURE__ */ jsx(host.Changes, { recordType }));
|
|
26
|
-
return /* @__PURE__ */ jsx(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
status
|
|
34
|
-
}) })
|
|
35
|
-
})
|
|
30
|
+
return /* @__PURE__ */ jsx("div", {
|
|
31
|
+
ref: barRef,
|
|
32
|
+
className: "flex min-w-0 flex-1 items-center justify-end gap-1",
|
|
33
|
+
children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(ListFilterBar, {
|
|
34
|
+
...props,
|
|
35
|
+
status
|
|
36
|
+
}) })
|
|
36
37
|
});
|
|
37
38
|
};
|
|
38
39
|
/**
|
|
@@ -47,4 +48,36 @@ const useListFilterParams = () => {
|
|
|
47
48
|
search: search || void 0
|
|
48
49
|
};
|
|
49
50
|
};
|
|
50
|
-
|
|
51
|
+
/**
|
|
52
|
+
* A list's empty state while `ListFilter` filters it, with Clear filters.
|
|
53
|
+
* "No customers match these filters" and a button that clears them; `fallback`, the list's own
|
|
54
|
+
* empty state, when it isn't filtered.
|
|
55
|
+
* `records` names them ("customers"); "records" by default.
|
|
56
|
+
*/
|
|
57
|
+
const ListFilterEmpty = ({ records, fallback = null }) => {
|
|
58
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
59
|
+
const { active, clear } = useListConditions();
|
|
60
|
+
if (!active) return fallback;
|
|
61
|
+
return /* @__PURE__ */ jsxs(Empty, {
|
|
62
|
+
className: "pointer-events-none absolute inset-x-0 top-2/5",
|
|
63
|
+
children: [/* @__PURE__ */ jsxs(Empty.Header, { children: [
|
|
64
|
+
/* @__PURE__ */ jsx(Empty.Media, {
|
|
65
|
+
variant: "icon",
|
|
66
|
+
children: /* @__PURE__ */ jsx(IconFilterOff, {})
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx(Empty.Title, { children: t("no-records", {
|
|
69
|
+
records: records ?? t("records", "records"),
|
|
70
|
+
defaultValue: "No {{records}} match these filters"
|
|
71
|
+
}) }),
|
|
72
|
+
/* @__PURE__ */ jsx(Empty.Description, { children: t("no-records-hint", "Change a condition or clear them to see every record.") })
|
|
73
|
+
] }), /* @__PURE__ */ jsx(Empty.Content, {
|
|
74
|
+
className: "pointer-events-auto",
|
|
75
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
76
|
+
variant: "outline",
|
|
77
|
+
onClick: clear,
|
|
78
|
+
children: t("clear-filters", "Clear filters")
|
|
79
|
+
})
|
|
80
|
+
})]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
export { ListFilter, ListFilterEmpty, useListFilterParams };
|
|
@@ -18,6 +18,8 @@ export type TListViews = {
|
|
|
18
18
|
};
|
|
19
19
|
/** The host's saved views, for `ViewBar` and `ListFilter`. Null outside erxes. */
|
|
20
20
|
export declare const useListViews: () => TListViews | null;
|
|
21
|
+
/** Where `ListFilter` puts its row of chips: under the `ViewBar` it sits in; null outside one. */
|
|
22
|
+
export declare const useFilterRowSlot: () => HTMLElement | null;
|
|
21
23
|
/**
|
|
22
24
|
* Gives every list with a `recordType` saved views, as core's lists have.
|
|
23
25
|
* Web provides its tabs (save, rename, share, copy a link) and the filter's save, once, around
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { TabButton } from "../../components/tabs.js";
|
|
2
2
|
import { IconLayoutList } from "@tabler/icons-react";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
import { Suspense, createContext, use } from "react";
|
|
4
|
+
import { Suspense, createContext, use, useState } from "react";
|
|
5
5
|
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
|
6
6
|
// src/modules/list/ViewBar.tsx
|
|
7
7
|
const ListViewsContext = createContext(null);
|
|
8
8
|
/** The host's saved views, for `ViewBar` and `ListFilter`. Null outside erxes. */
|
|
9
9
|
const useListViews = () => use(ListViewsContext);
|
|
10
|
+
const FilterRowContext = createContext(null);
|
|
11
|
+
const FilterRowSlot = FilterRowContext.Provider;
|
|
12
|
+
/** Where `ListFilter` puts its row of chips: under the `ViewBar` it sits in; null outside one. */
|
|
13
|
+
const useFilterRowSlot = () => use(FilterRowContext);
|
|
10
14
|
/**
|
|
11
15
|
* Gives every list with a `recordType` saved views, as core's lists have.
|
|
12
16
|
* Web provides its tabs (save, rename, share, copy a link) and the filter's save, once, around
|
|
@@ -26,6 +30,7 @@ const ListViewsProvider = ({ views, children }) => /* @__PURE__ */ jsx(ListViews
|
|
|
26
30
|
const ViewBar = ({ allLabel, recordType, tabs, children }) => {
|
|
27
31
|
const [tabsRef] = useAutoAnimate({ duration: 150 });
|
|
28
32
|
const host = useListViews();
|
|
33
|
+
const [slot, setSlot] = useState(null);
|
|
29
34
|
const all = /* @__PURE__ */ jsxs(TabButton, {
|
|
30
35
|
type: "button",
|
|
31
36
|
"aria-current": "page",
|
|
@@ -39,16 +44,22 @@ const ViewBar = ({ allLabel, recordType, tabs, children }) => {
|
|
|
39
44
|
allLabel
|
|
40
45
|
})
|
|
41
46
|
});
|
|
42
|
-
return /* @__PURE__ */ jsxs(
|
|
43
|
-
|
|
44
|
-
children: [/* @__PURE__ */
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
return /* @__PURE__ */ jsxs(FilterRowSlot, {
|
|
48
|
+
value: slot,
|
|
49
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
50
|
+
className: "flex h-10 shrink-0 items-center gap-3 border-b bg-background pr-3",
|
|
51
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
52
|
+
ref: tabsRef,
|
|
53
|
+
className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto p-1 hide-scroll",
|
|
54
|
+
children: tabs ?? saved ?? all
|
|
55
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
56
|
+
className: "flex min-w-0 max-w-13/20 shrink-0 items-center justify-end",
|
|
57
|
+
children
|
|
58
|
+
})]
|
|
48
59
|
}), /* @__PURE__ */ jsx("div", {
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
ref: setSlot,
|
|
61
|
+
className: "contents"
|
|
51
62
|
})]
|
|
52
63
|
});
|
|
53
64
|
};
|
|
54
|
-
export { ListViewsProvider, ViewBar, useListViews };
|
|
65
|
+
export { ListViewsProvider, ViewBar, useFilterRowSlot, useListViews };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AddFrom } from "./listFilterContext.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* "Add a filter": the fields to pick from, then the picked field's operator and value. It opens
|
|
5
|
+
* from the view bar's filter button (`F`) or the filter row's "+ Filter".
|
|
6
|
+
*/
|
|
7
|
+
export declare const AddFilter: ({ from, trigger }: {
|
|
8
|
+
from: AddFrom;
|
|
9
|
+
trigger: ReactElement;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Command } from "../../../components/command.js";
|
|
2
|
+
import { Popover } from "../../../components/popover.js";
|
|
3
|
+
import { Select } from "../../../components/select.js";
|
|
4
|
+
import { CONDITION_OPERATORS, NO_VALUE } from "../../conditions/conditions.js";
|
|
5
|
+
import { isFilled, opOf, operatorsFor, ruleFor, withOperator } from "../../conditions/filterRule.js";
|
|
6
|
+
import { FieldPicker } from "../../conditions/FieldPicker.js";
|
|
7
|
+
import { FieldIcon } from "../../conditions/fieldIcons.js";
|
|
8
|
+
import { useOperatorLabel } from "../../conditions/filterText.js";
|
|
9
|
+
import { ValueEditor } from "../../conditions/ValueEditor.js";
|
|
10
|
+
import { useListFilter } from "./listFilterContext.js";
|
|
11
|
+
import { SearchBox } from "./SearchChip.js";
|
|
12
|
+
import { IconAdjustmentsHorizontal, IconSearch } from "@tabler/icons-react";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { useRef, useState } from "react";
|
|
15
|
+
import { useTranslation } from "react-i18next";
|
|
16
|
+
// src/modules/list/filter/AddFilter.tsx
|
|
17
|
+
const asOperator = (value) => value === "between" ? "between" : CONDITION_OPERATORS.find((op) => op === value);
|
|
18
|
+
/**
|
|
19
|
+
* A new rule on `field`: its operator, then its value. The rule joins the filter once it says
|
|
20
|
+
* enough (a pick, a typed value) and changes in place as editing goes on.
|
|
21
|
+
*/
|
|
22
|
+
const NewRule = ({ field, onDone }) => {
|
|
23
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
24
|
+
const { lookups, parts, setPart } = useListFilter();
|
|
25
|
+
const label = useOperatorLabel();
|
|
26
|
+
const [rule, setRule] = useState(() => ruleFor(field));
|
|
27
|
+
const index = useRef(null);
|
|
28
|
+
const ops = operatorsFor(field.type);
|
|
29
|
+
const change = (next) => {
|
|
30
|
+
setRule(next);
|
|
31
|
+
if (isFilled(next)) {
|
|
32
|
+
setPart(index.current, next);
|
|
33
|
+
index.current ??= parts.length;
|
|
34
|
+
} else if (index.current !== null) {
|
|
35
|
+
setPart(index.current, null);
|
|
36
|
+
index.current = null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const op = opOf(rule);
|
|
40
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
41
|
+
className: "flex flex-col",
|
|
42
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
43
|
+
className: "flex h-10 items-center gap-2 border-b px-3 text-sm",
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ jsx(FieldIcon, {
|
|
46
|
+
field,
|
|
47
|
+
className: "size-4 shrink-0 text-muted-foreground"
|
|
48
|
+
}),
|
|
49
|
+
/* @__PURE__ */ jsx("span", {
|
|
50
|
+
className: "min-w-0 flex-1 truncate font-medium",
|
|
51
|
+
children: field.label
|
|
52
|
+
}),
|
|
53
|
+
ops.length > 1 && /* @__PURE__ */ jsxs(Select, {
|
|
54
|
+
value: op,
|
|
55
|
+
onValueChange: (next) => {
|
|
56
|
+
const picked = asOperator(next);
|
|
57
|
+
if (!picked) return;
|
|
58
|
+
change(withOperator(rule, picked));
|
|
59
|
+
if (NO_VALUE.has(picked)) onDone();
|
|
60
|
+
},
|
|
61
|
+
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
62
|
+
className: "h-7 w-auto max-w-40",
|
|
63
|
+
"aria-label": t("operator", "Operator"),
|
|
64
|
+
children: /* @__PURE__ */ jsx(Select.Value, { children: label(op, field.type) })
|
|
65
|
+
}), /* @__PURE__ */ jsx(Select.Content, { children: ops.map((one) => /* @__PURE__ */ jsx(Select.Item, {
|
|
66
|
+
value: one,
|
|
67
|
+
children: label(one, field.type)
|
|
68
|
+
}, one)) })]
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
72
|
+
className: field.type === "number" || field.type === "text" ? "p-2" : void 0,
|
|
73
|
+
children: /* @__PURE__ */ jsx(ValueEditor, {
|
|
74
|
+
rule,
|
|
75
|
+
field,
|
|
76
|
+
lookups,
|
|
77
|
+
onChange: change,
|
|
78
|
+
onDone
|
|
79
|
+
}, op)
|
|
80
|
+
})]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
/** The picker's pages: the fields (with search and the advanced filter), then the chosen one. */
|
|
84
|
+
const AddFilterContent = ({ onDone }) => {
|
|
85
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
86
|
+
const { fields, loading, error, setAdvancedOpen, setAdding } = useListFilter();
|
|
87
|
+
const [view, setView] = useState({ kind: "fields" });
|
|
88
|
+
const search = t("search", "Search");
|
|
89
|
+
const advanced = t("advanced", "Advanced filter");
|
|
90
|
+
if (view.kind === "search") return /* @__PURE__ */ jsx(SearchBox, { onDone });
|
|
91
|
+
if (view.kind === "rule") return /* @__PURE__ */ jsx(NewRule, {
|
|
92
|
+
field: view.field,
|
|
93
|
+
onDone
|
|
94
|
+
});
|
|
95
|
+
return /* @__PURE__ */ jsx(FieldPicker, {
|
|
96
|
+
fields,
|
|
97
|
+
loading,
|
|
98
|
+
error,
|
|
99
|
+
onSelect: (field) => {
|
|
100
|
+
const found = fields.find((one) => one.path === field.path);
|
|
101
|
+
if (found) setView({
|
|
102
|
+
kind: "rule",
|
|
103
|
+
field: found
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
children: /* @__PURE__ */ jsxs(Command.Group, { children: [/* @__PURE__ */ jsxs(Command.Item, {
|
|
107
|
+
value: "search",
|
|
108
|
+
keywords: [search],
|
|
109
|
+
onSelect: () => setView({ kind: "search" }),
|
|
110
|
+
children: [/* @__PURE__ */ jsx(IconSearch, {}), search]
|
|
111
|
+
}), /* @__PURE__ */ jsxs(Command.Item, {
|
|
112
|
+
value: "advanced",
|
|
113
|
+
keywords: [advanced],
|
|
114
|
+
onSelect: () => {
|
|
115
|
+
setAdding(null);
|
|
116
|
+
setAdvancedOpen(true);
|
|
117
|
+
},
|
|
118
|
+
children: [/* @__PURE__ */ jsx(IconAdjustmentsHorizontal, {}), advanced]
|
|
119
|
+
})] })
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* "Add a filter": the fields to pick from, then the picked field's operator and value. It opens
|
|
124
|
+
* from the view bar's filter button (`F`) or the filter row's "+ Filter".
|
|
125
|
+
*/
|
|
126
|
+
const AddFilter = ({ from, trigger }) => {
|
|
127
|
+
const { adding, setAdding } = useListFilter();
|
|
128
|
+
const open = adding === from;
|
|
129
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
130
|
+
open,
|
|
131
|
+
onOpenChange: (next) => setAdding(next ? from : null),
|
|
132
|
+
children: [/* @__PURE__ */ jsx(Popover.Trigger, { render: trigger }), /* @__PURE__ */ jsx(Popover.Content, {
|
|
133
|
+
variant: "flush",
|
|
134
|
+
align: from === "bar" ? "end" : "start",
|
|
135
|
+
className: "w-72",
|
|
136
|
+
children: open && /* @__PURE__ */ jsx(AddFilterContent, { onDone: () => setAdding(null) })
|
|
137
|
+
})]
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
export { AddFilter };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The advanced filter: rows "Where / And / Or" with nested groups, in a popover anchored to the
|
|
4
|
+
* filter row. It doesn't block the page: the list updates behind it as the rules change.
|
|
5
|
+
*/
|
|
6
|
+
export declare const AdvancedPopover: ({ anchor }: {
|
|
7
|
+
anchor: RefObject<HTMLElement | null>;
|
|
8
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Button } from "../../../components/button.js";
|
|
2
|
+
import { Popover } from "../../../components/popover.js";
|
|
3
|
+
import { Skeleton } from "../../../components/skeleton.js";
|
|
4
|
+
import { useFormat } from "../../../lib/format.js";
|
|
5
|
+
import { isUndefinedOrNull } from "../../../utils/IsUndefinedOrNull.js";
|
|
6
|
+
import { completeOf } from "../../conditions/filterRule.js";
|
|
7
|
+
import { ConditionsEditor } from "../../conditions/ConditionsEditor.js";
|
|
8
|
+
import { useListFilter } from "./listFilterContext.js";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { useTranslation } from "react-i18next";
|
|
12
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
13
|
+
// src/modules/list/filter/AdvancedPopover.tsx
|
|
14
|
+
/** How long the list waits after an edit before it follows. */
|
|
15
|
+
const APPLY_MS = 300;
|
|
16
|
+
/** "1,204 match", from the list's own count as it follows the edits. */
|
|
17
|
+
const MatchCount = () => {
|
|
18
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
19
|
+
const { totalCount, totalCapped } = useListFilter();
|
|
20
|
+
const fmt = useFormat();
|
|
21
|
+
if (isUndefinedOrNull(totalCount)) return /* @__PURE__ */ jsx(Skeleton, { className: "h-3.5 w-16" });
|
|
22
|
+
return /* @__PURE__ */ jsx("output", {
|
|
23
|
+
"aria-live": "polite",
|
|
24
|
+
className: "text-xs tabular-nums text-muted-foreground",
|
|
25
|
+
children: t("match", {
|
|
26
|
+
count: totalCapped ? 2 : totalCount,
|
|
27
|
+
formatted: fmt.count(totalCount, totalCapped),
|
|
28
|
+
defaultValue_one: "{{formatted}} match",
|
|
29
|
+
defaultValue_other: "{{formatted}} match"
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Mounted while open, so the draft starts from the list's filter. Unfinished rules stay in the
|
|
35
|
+
* draft; the finished ones reach the list as editing pauses, and the table behind follows.
|
|
36
|
+
*/
|
|
37
|
+
const AdvancedEditor = ({ onDone }) => {
|
|
38
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
39
|
+
const { fields, lookups, advanced, setAdvanced } = useListFilter();
|
|
40
|
+
const [draft, setDraft] = useState(advanced ?? void 0);
|
|
41
|
+
const apply = useDebouncedCallback((next) => setAdvanced(next ? completeOf(next) : null), APPLY_MS);
|
|
42
|
+
useEffect(() => () => apply.flush(), [apply]);
|
|
43
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
44
|
+
className: "flex flex-col",
|
|
45
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
46
|
+
className: "max-h-popup overflow-y-auto p-3",
|
|
47
|
+
children: /* @__PURE__ */ jsx(ConditionsEditor, {
|
|
48
|
+
fields,
|
|
49
|
+
...lookups,
|
|
50
|
+
value: draft,
|
|
51
|
+
onChange: (next) => {
|
|
52
|
+
setDraft(next);
|
|
53
|
+
apply(next);
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
57
|
+
className: "flex h-10 items-center gap-2 border-t px-3",
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ jsx(MatchCount, {}),
|
|
60
|
+
/* @__PURE__ */ jsx(Button, {
|
|
61
|
+
size: "sm",
|
|
62
|
+
variant: "ghost",
|
|
63
|
+
tone: "muted",
|
|
64
|
+
className: "ml-auto",
|
|
65
|
+
disabled: !draft,
|
|
66
|
+
onClick: () => {
|
|
67
|
+
setDraft(void 0);
|
|
68
|
+
apply(void 0);
|
|
69
|
+
},
|
|
70
|
+
children: t("clear-all", "Clear all")
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ jsx(Button, {
|
|
73
|
+
size: "sm",
|
|
74
|
+
variant: "secondary",
|
|
75
|
+
onClick: onDone,
|
|
76
|
+
children: t("done", "Done")
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
})]
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The advanced filter: rows "Where / And / Or" with nested groups, in a popover anchored to the
|
|
84
|
+
* filter row. It doesn't block the page: the list updates behind it as the rules change.
|
|
85
|
+
*/
|
|
86
|
+
const AdvancedPopover = ({ anchor }) => {
|
|
87
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
88
|
+
const { advancedOpen, setAdvancedOpen } = useListFilter();
|
|
89
|
+
return /* @__PURE__ */ jsx(Popover, {
|
|
90
|
+
open: advancedOpen,
|
|
91
|
+
onOpenChange: setAdvancedOpen,
|
|
92
|
+
children: /* @__PURE__ */ jsx(Popover.Content, {
|
|
93
|
+
anchor,
|
|
94
|
+
align: "start",
|
|
95
|
+
variant: "flush",
|
|
96
|
+
collisionPadding: 16,
|
|
97
|
+
"aria-label": t("advanced", "Advanced filter"),
|
|
98
|
+
className: "w-3xl max-w-full",
|
|
99
|
+
children: advancedOpen && /* @__PURE__ */ jsx(AdvancedEditor, { onDone: () => setAdvancedOpen(false) })
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
export { AdvancedPopover };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TListFilterProps } from "../ListFilter.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* In the view bar: the count, the list's own controls and the filter button (`F`). Under it,
|
|
4
|
+
* while the list is filtered, the filter row: in the view bar's slot, else right after the bar.
|
|
5
5
|
*/
|
|
6
|
-
export declare const ListFilterBar: (
|
|
6
|
+
export declare const ListFilterBar: (props: TListFilterProps) => import("react").JSX.Element;
|