@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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The search box: the list follows as typing pauses; Enter closes it. */
|
|
2
|
+
export declare const SearchBox: ({ onDone }: {
|
|
3
|
+
onDone: () => void;
|
|
4
|
+
}) => import("react").JSX.Element;
|
|
5
|
+
/** The search as a chip: what is searched, which opens the box; remove clears it. */
|
|
6
|
+
export declare const SearchChip: () => import("react").JSX.Element | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Button } from "../../../components/button.js";
|
|
2
|
+
import { Popover } from "../../../components/popover.js";
|
|
3
|
+
import { TypedInput } from "../../conditions/TypedInput.js";
|
|
4
|
+
import { useListConditions } from "./listFilterQuery.js";
|
|
5
|
+
import { Chip } from "./RuleChips.js";
|
|
6
|
+
import { IconSearch } from "@tabler/icons-react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { useTranslation } from "react-i18next";
|
|
10
|
+
// src/modules/list/filter/SearchChip.tsx
|
|
11
|
+
/** The search box: the list follows as typing pauses; Enter closes it. */
|
|
12
|
+
const SearchBox = ({ onDone }) => {
|
|
13
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
14
|
+
const { search, setSearch } = useListConditions();
|
|
15
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
16
|
+
className: "flex items-center gap-2 p-2",
|
|
17
|
+
children: [/* @__PURE__ */ jsx(IconSearch, { className: "size-4 shrink-0 text-muted-foreground" }), /* @__PURE__ */ jsx(TypedInput, {
|
|
18
|
+
focusOnMount: true,
|
|
19
|
+
className: "h-8",
|
|
20
|
+
"aria-label": t("search", "Search"),
|
|
21
|
+
placeholder: t("search-placeholder", "Search…"),
|
|
22
|
+
initial: search ?? "",
|
|
23
|
+
onCommit: (text) => setSearch(text.trim() || null),
|
|
24
|
+
onEnter: onDone
|
|
25
|
+
})]
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
/** The search as a chip: what is searched, which opens the box; remove clears it. */
|
|
29
|
+
const SearchChip = () => {
|
|
30
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
31
|
+
const { search, setSearch } = useListConditions();
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
if (!search) return null;
|
|
34
|
+
return /* @__PURE__ */ jsx(Chip, {
|
|
35
|
+
removeLabel: t("remove-search", "Clear the search"),
|
|
36
|
+
onRemove: () => setSearch(null),
|
|
37
|
+
children: /* @__PURE__ */ jsxs(Popover, {
|
|
38
|
+
open,
|
|
39
|
+
onOpenChange: setOpen,
|
|
40
|
+
children: [/* @__PURE__ */ jsxs(Popover.Trigger, {
|
|
41
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
42
|
+
variant: "segment",
|
|
43
|
+
className: "max-w-60 min-w-0 gap-1.5 rounded-l px-2"
|
|
44
|
+
}),
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsx(IconSearch, { className: "text-muted-foreground" }),
|
|
47
|
+
/* @__PURE__ */ jsx("span", {
|
|
48
|
+
className: "text-muted-foreground",
|
|
49
|
+
children: t("search", "Search")
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ jsxs("span", {
|
|
52
|
+
className: "truncate font-medium",
|
|
53
|
+
children: [
|
|
54
|
+
"“",
|
|
55
|
+
search,
|
|
56
|
+
"”"
|
|
57
|
+
]
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
}), /* @__PURE__ */ jsx(Popover.Content, {
|
|
61
|
+
variant: "flush",
|
|
62
|
+
align: "start",
|
|
63
|
+
className: "w-72",
|
|
64
|
+
children: /* @__PURE__ */ jsx(SearchBox, { onDone: () => setOpen(false) })
|
|
65
|
+
})]
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
export { SearchBox, SearchChip };
|
|
@@ -1,46 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
/** One thing the list's filter requires: a rule, or a group of rules (from the advanced filter). */
|
|
4
|
-
export type FilterPart = TConditionRule | TConditionGroup;
|
|
5
|
-
type Operator = TConditionRule['op'];
|
|
6
|
-
/** The list's filter as parts that must all hold; an "any" group of several rules is one part. */
|
|
7
|
-
export declare const partsOf: (group: TConditionGroup | null) => FilterPart[];
|
|
8
|
-
/** Parts back to the list's filter: null when there are none. */
|
|
9
|
-
export declare const groupOf: (parts: FilterPart[]) => TConditionGroup | null;
|
|
1
|
+
import { TConditionGroup, TConditionRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { TFilterRule } from "../../conditions/filterRule.js";
|
|
10
3
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
4
|
+
* The list's filter as chips: rules that must all hold. Null when it has "or" or nested groups:
|
|
5
|
+
* the advanced filter edits it, and the bar shows it as one chip.
|
|
13
6
|
*/
|
|
14
|
-
export declare const
|
|
15
|
-
/**
|
|
16
|
-
export declare const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export declare const inMenu: (rule: TConditionRule, field: TListFilterField | undefined) => boolean;
|
|
20
|
-
/** Which part the menu of `field` changes: the one being edited, else its existing single rule, else a new one. */
|
|
21
|
-
export declare const targetOf: (parts: FilterPart[], field: TListFilterField, editing: number | null) => number | null;
|
|
7
|
+
export declare const chipsOf: (group: TConditionGroup | null) => TFilterRule[] | null;
|
|
8
|
+
/** Parts back to the list's filter: null when there are none; one group stands for itself. */
|
|
9
|
+
export declare const groupOf: (parts: FilterPart[]) => TConditionGroup | null;
|
|
10
|
+
/** A top-level entry of the filter: a rule, or a group (the advanced filter's, or a "between"). */
|
|
11
|
+
export type FilterPart = TConditionRule | TConditionGroup;
|
|
22
12
|
/**
|
|
23
|
-
* The
|
|
24
|
-
*
|
|
13
|
+
* The parts that must all hold: the chips, or the advanced filter as one part, so a chip added
|
|
14
|
+
* beside it narrows it.
|
|
25
15
|
*/
|
|
26
|
-
export declare const
|
|
27
|
-
/** An "is any of" rule; null when nothing is picked. */
|
|
28
|
-
export declare const anyOf: (path: string, values: string[]) => TConditionRule | null;
|
|
16
|
+
export declare const partsOf: (group: TConditionGroup | null) => FilterPart[];
|
|
29
17
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
18
|
+
* Replaces the part at `index`, appends when `index` is null, removes when `next` is null.
|
|
19
|
+
* Parts stay distinct: a part already there isn't added twice.
|
|
32
20
|
*/
|
|
33
|
-
export declare const
|
|
34
|
-
key: string;
|
|
35
|
-
label: string;
|
|
36
|
-
op: Operator;
|
|
37
|
-
value?: RelativeAmount;
|
|
38
|
-
}[];
|
|
39
|
-
/** The preset a rule is, if any. */
|
|
40
|
-
export declare const presetOf: (rule: TConditionRule | undefined) => {
|
|
41
|
-
key: string;
|
|
42
|
-
label: string;
|
|
43
|
-
op: Operator;
|
|
44
|
-
value?: RelativeAmount;
|
|
45
|
-
} | undefined;
|
|
46
|
-
export {};
|
|
21
|
+
export declare const withPart: (parts: FilterPart[], index: number | null, next: FilterPart | null) => FilterPart[];
|
|
@@ -1,166 +1,37 @@
|
|
|
1
1
|
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isFilterRule } from "../../conditions/filterRule.js";
|
|
3
3
|
// src/modules/list/filter/filterRules.ts
|
|
4
|
-
/** The list's filter as parts that must all hold; an "any" group of several rules is one part. */
|
|
5
|
-
const partsOf = (group) => !group ? [] : group.match === "all" || group.rules.length < 2 ? group.rules : [group];
|
|
6
|
-
/** Parts back to the list's filter: null when there are none. */
|
|
7
|
-
const groupOf = (parts) => parts.length ? {
|
|
8
|
-
match: "all",
|
|
9
|
-
rules: parts
|
|
10
|
-
} : null;
|
|
11
|
-
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
12
4
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
5
|
+
* The list's filter as chips: rules that must all hold. Null when it has "or" or nested groups:
|
|
6
|
+
* the advanced filter edits it, and the bar shows it as one chip.
|
|
15
7
|
*/
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
if (
|
|
19
|
-
return
|
|
20
|
-
};
|
|
21
|
-
/** Comparisons of a number, as the menu writes them. */
|
|
22
|
-
const NUMBER_OPS = [
|
|
23
|
-
"eq",
|
|
24
|
-
"neq",
|
|
25
|
-
"gt",
|
|
26
|
-
"gte",
|
|
27
|
-
"lt",
|
|
28
|
-
"lte"
|
|
29
|
-
];
|
|
30
|
-
const NUMBER_SYMBOLS = {
|
|
31
|
-
eq: "=",
|
|
32
|
-
neq: "≠",
|
|
33
|
-
gt: ">",
|
|
34
|
-
gte: "≥",
|
|
35
|
-
lt: "<",
|
|
36
|
-
lte: "≤"
|
|
37
|
-
};
|
|
38
|
-
/** The operators the filter menu shows and edits for each kind of field; other rules open the advanced filter. */
|
|
39
|
-
const MENU_OPS = {
|
|
40
|
-
select: ["in", "eq"],
|
|
41
|
-
member: ["in", "eq"],
|
|
42
|
-
tags: ["in", "eq"],
|
|
43
|
-
boolean: ["eq"],
|
|
44
|
-
date: [
|
|
45
|
-
"within_last",
|
|
46
|
-
"more_than_ago",
|
|
47
|
-
"within_next",
|
|
48
|
-
"exists",
|
|
49
|
-
"not_exists"
|
|
50
|
-
],
|
|
51
|
-
number: NUMBER_OPS,
|
|
52
|
-
text: ["contains"]
|
|
8
|
+
const chipsOf = (group) => {
|
|
9
|
+
if (!group) return [];
|
|
10
|
+
if (group.match === "any" && group.rules.length > 1) return null;
|
|
11
|
+
return group.rules.every(isFilterRule) ? group.rules : null;
|
|
53
12
|
};
|
|
54
|
-
/**
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"date"
|
|
63
|
-
]);
|
|
64
|
-
/** Which part the menu of `field` changes: the one being edited, else its existing single rule, else a new one. */
|
|
65
|
-
const targetOf = (parts, field, editing) => {
|
|
66
|
-
if (editing !== null) return editing;
|
|
67
|
-
if (!SINGLE.has(field.type)) return null;
|
|
68
|
-
const index = parts.findIndex((part) => isRule(part) && part.path === field.path && inMenu(part, field));
|
|
69
|
-
return index < 0 ? null : index;
|
|
13
|
+
/** Parts back to the list's filter: null when there are none; one group stands for itself. */
|
|
14
|
+
const groupOf = (parts) => {
|
|
15
|
+
const [only] = parts;
|
|
16
|
+
if (parts.length === 1 && only && !isRule(only) && !isFilterRule(only)) return only;
|
|
17
|
+
return parts.length ? {
|
|
18
|
+
match: "all",
|
|
19
|
+
rules: parts
|
|
20
|
+
} : null;
|
|
70
21
|
};
|
|
71
|
-
const Values = z.array(z.union([z.string(), z.number()]).transform(String));
|
|
72
22
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
23
|
+
* The parts that must all hold: the chips, or the advanced filter as one part, so a chip added
|
|
24
|
+
* beside it narrows it.
|
|
75
25
|
*/
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
return Values.safeParse(rule.op === "in" ? rule.value : [rule.value]).data ?? [];
|
|
79
|
-
};
|
|
80
|
-
/** An "is any of" rule; null when nothing is picked. */
|
|
81
|
-
const anyOf = (path, values) => values.length ? {
|
|
82
|
-
path,
|
|
83
|
-
op: "in",
|
|
84
|
-
value: values
|
|
85
|
-
} : null;
|
|
86
|
-
const days = (amount) => ({
|
|
87
|
-
amount,
|
|
88
|
-
unit: "days"
|
|
89
|
-
});
|
|
90
|
-
const months = (amount) => ({
|
|
91
|
-
amount,
|
|
92
|
-
unit: "months"
|
|
93
|
-
});
|
|
26
|
+
const partsOf = (group) => chipsOf(group) ?? (group ? [group] : []);
|
|
27
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
94
28
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
29
|
+
* Replaces the part at `index`, appends when `index` is null, removes when `next` is null.
|
|
30
|
+
* Parts stay distinct: a part already there isn't added twice.
|
|
97
31
|
*/
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
key: "past-week",
|
|
107
|
-
label: "Past 7 days",
|
|
108
|
-
op: "within_last",
|
|
109
|
-
value: days(7)
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
key: "past-month",
|
|
113
|
-
label: "Past 30 days",
|
|
114
|
-
op: "within_last",
|
|
115
|
-
value: days(30)
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
key: "past-quarter",
|
|
119
|
-
label: "Past 3 months",
|
|
120
|
-
op: "within_last",
|
|
121
|
-
value: months(3)
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
key: "past-year",
|
|
125
|
-
label: "Past year",
|
|
126
|
-
op: "within_last",
|
|
127
|
-
value: months(12)
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
key: "older-month",
|
|
131
|
-
label: "More than 30 days ago",
|
|
132
|
-
op: "more_than_ago",
|
|
133
|
-
value: days(30)
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
key: "older-year",
|
|
137
|
-
label: "More than a year ago",
|
|
138
|
-
op: "more_than_ago",
|
|
139
|
-
value: months(12)
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
key: "next-week",
|
|
143
|
-
label: "Next 7 days",
|
|
144
|
-
op: "within_next",
|
|
145
|
-
value: days(7)
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
key: "next-month",
|
|
149
|
-
label: "Next 30 days",
|
|
150
|
-
op: "within_next",
|
|
151
|
-
value: days(30)
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
key: "set",
|
|
155
|
-
label: "Is set",
|
|
156
|
-
op: "exists"
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
key: "empty",
|
|
160
|
-
label: "Is empty",
|
|
161
|
-
op: "not_exists"
|
|
162
|
-
}
|
|
163
|
-
];
|
|
164
|
-
/** The preset a rule is, if any. */
|
|
165
|
-
const presetOf = (rule) => rule && DATE_PRESETS.find((preset) => preset.op === rule.op && JSON.stringify(preset.value) === JSON.stringify(rule.value));
|
|
166
|
-
export { DATE_PRESETS, NUMBER_OPS, NUMBER_SYMBOLS, anyOf, groupOf, inMenu, partsOf, presetOf, targetOf, valuesOf, withPart };
|
|
32
|
+
const withPart = (parts, index, next) => {
|
|
33
|
+
if (next && parts.some((part, at) => at !== index && same(part, next))) return index === null ? parts : parts.filter((_, at) => at !== index);
|
|
34
|
+
if (index === null) return next ? [...parts, next] : parts;
|
|
35
|
+
return next ? parts.map((part, at) => at === index ? next : part) : parts.filter((_, at) => at !== index);
|
|
36
|
+
};
|
|
37
|
+
export { chipsOf, groupOf, partsOf, withPart };
|
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
import { TConditionLookups } from "../../conditions/conditions.js";
|
|
1
|
+
import { TConditionGroup, TConditionLookups } from "../../conditions/conditions.js";
|
|
2
|
+
import { TFilterRule } from "../../conditions/filterRule.js";
|
|
2
3
|
import { TListFilterField } from "../ListFilter.js";
|
|
3
4
|
import { FilterPart } from "./filterRules.js";
|
|
4
|
-
/**
|
|
5
|
+
/** Where the field picker opens: from the view bar's filter button, or the filter row's "+ Filter". */
|
|
6
|
+
export type AddFrom = 'bar' | 'row';
|
|
7
|
+
/** What the filter row, its chips, the field picker and the advanced filter share. */
|
|
5
8
|
export interface ListFilterState {
|
|
6
9
|
fields: TListFilterField[];
|
|
7
10
|
/** Where `member` and `tags` fields pick from. */
|
|
8
11
|
lookups: TConditionLookups;
|
|
9
|
-
/** The list's filter
|
|
12
|
+
/** The list's filter. */
|
|
13
|
+
advanced: TConditionGroup | null;
|
|
14
|
+
/** The filter as chips; null when it needs the advanced filter (an "or", a nested group). */
|
|
15
|
+
chips: TFilterRule[] | null;
|
|
16
|
+
/** The parts that must all hold (`partsOf`): the chips, or the advanced filter as one. */
|
|
10
17
|
parts: FilterPart[];
|
|
11
|
-
/** Changes
|
|
18
|
+
/** Changes a part as `withPart` does. */
|
|
12
19
|
setPart: (index: number | null, next: FilterPart | null) => void;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
setAdvanced: (next: TConditionGroup | null) => void;
|
|
21
|
+
/** The field picker that is open. */
|
|
22
|
+
adding: AddFrom | null;
|
|
23
|
+
setAdding: (from: AddFrom | null) => void;
|
|
24
|
+
advancedOpen: boolean;
|
|
25
|
+
setAdvancedOpen: (open: boolean) => void;
|
|
26
|
+
/** While the fields load, and why they didn't; the field picker says so. */
|
|
27
|
+
loading?: boolean;
|
|
28
|
+
error?: Error | null;
|
|
29
|
+
/** How many records match, for the advanced filter's "N match". */
|
|
30
|
+
totalCount?: number | null;
|
|
31
|
+
totalCapped?: boolean;
|
|
18
32
|
}
|
|
19
33
|
export declare const ListFilterContext: import("react").Context<ListFilterState | null>;
|
|
20
34
|
export declare const useListFilter: () => ListFilterState;
|
|
21
|
-
/**
|
|
22
|
-
export declare const
|
|
23
|
-
options: {
|
|
24
|
-
value: string;
|
|
25
|
-
label: string;
|
|
26
|
-
}[];
|
|
27
|
-
loading: boolean;
|
|
28
|
-
error: Error | null;
|
|
29
|
-
};
|
|
35
|
+
/** A field by its path; one no list field has (a removed property) reads as text. */
|
|
36
|
+
export declare const useFieldAt: (path: string) => TListFilterField;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
-
import { useMemberOptions, useTagOptions } from "../../pickers/LookupPicker.js";
|
|
3
|
-
import { valuesOf } from "./filterRules.js";
|
|
4
1
|
import { createContext, useContext } from "react";
|
|
5
|
-
import { useTranslation } from "react-i18next";
|
|
6
2
|
// src/modules/list/filter/listFilterContext.ts
|
|
7
3
|
const ListFilterContext = createContext(null);
|
|
8
4
|
const useListFilter = () => {
|
|
@@ -10,25 +6,13 @@ const useListFilter = () => {
|
|
|
10
6
|
if (!state) throw new Error("useListFilter is only available inside <ListFilter>");
|
|
11
7
|
return state;
|
|
12
8
|
};
|
|
13
|
-
/**
|
|
14
|
-
const
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (field.type === "member") return {
|
|
21
|
-
...members,
|
|
22
|
-
options: [{
|
|
23
|
-
value: "me",
|
|
24
|
-
label: t("me", "Me")
|
|
25
|
-
}, ...members.options]
|
|
26
|
-
};
|
|
27
|
-
if (field.type === "tags") return tags;
|
|
28
|
-
return {
|
|
29
|
-
options: field.options ?? [],
|
|
30
|
-
loading: false,
|
|
31
|
-
error: null
|
|
9
|
+
/** A field by its path; one no list field has (a removed property) reads as text. */
|
|
10
|
+
const useFieldAt = (path) => {
|
|
11
|
+
const { fields } = useListFilter();
|
|
12
|
+
return fields.find((field) => field.path === path) ?? {
|
|
13
|
+
path,
|
|
14
|
+
label: path,
|
|
15
|
+
type: "text"
|
|
32
16
|
};
|
|
33
17
|
};
|
|
34
|
-
export { ListFilterContext,
|
|
18
|
+
export { ListFilterContext, useFieldAt, useListFilter };
|
|
@@ -12,5 +12,9 @@ export declare const listFilterQuery: {
|
|
|
12
12
|
export declare const useListConditions: () => {
|
|
13
13
|
advanced: TConditionGroup | null;
|
|
14
14
|
search: string | null;
|
|
15
|
+
/** Whether the list is filtered or searched. */
|
|
16
|
+
active: boolean;
|
|
15
17
|
setAdvanced: (next: TConditionGroup | null) => undefined;
|
|
18
|
+
setSearch: (next: string | null) => undefined;
|
|
19
|
+
clear: () => undefined;
|
|
16
20
|
};
|
|
@@ -13,10 +13,18 @@ const listFilterQuery = {
|
|
|
13
13
|
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
14
14
|
const useListConditions = () => {
|
|
15
15
|
const [{ advanced, searchValue }, setQueries] = useQueryStates(listFilterQuery, { history: "replace" });
|
|
16
|
+
const filter = advanced?.rules.length ? advanced : null;
|
|
16
17
|
return {
|
|
17
|
-
advanced:
|
|
18
|
+
advanced: filter,
|
|
18
19
|
search: searchValue,
|
|
19
|
-
|
|
20
|
+
/** Whether the list is filtered or searched. */
|
|
21
|
+
active: filter !== null || Boolean(searchValue),
|
|
22
|
+
setAdvanced: (next) => void setQueries({ advanced: next?.rules.length ? next : null }),
|
|
23
|
+
setSearch: (next) => void setQueries({ searchValue: next || null }),
|
|
24
|
+
clear: () => void setQueries({
|
|
25
|
+
advanced: null,
|
|
26
|
+
searchValue: null
|
|
27
|
+
})
|
|
20
28
|
};
|
|
21
29
|
};
|
|
22
30
|
export { listFilterQuery, useListConditions };
|
package/dist/theme.css
CHANGED
|
@@ -126,8 +126,9 @@
|
|
|
126
126
|
--grid-template-columns-field: 6.5rem minmax(0, 1fr);
|
|
127
127
|
/* A side column of 18 to 24rem beside the content. */
|
|
128
128
|
--grid-template-columns-aside: minmax(18rem, 24rem) minmax(0, 1fr);
|
|
129
|
-
/* A condition row: field
|
|
130
|
-
|
|
129
|
+
/* A condition row: "Where", "And" or "Or", the field, the operator, the value, then remove. */
|
|
130
|
+
/* 5.5rem holds the And/Or picker in Mongolian ("Эсвэл"). */
|
|
131
|
+
--grid-template-columns-condition: 5.5rem minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 1.2fr) auto;
|
|
131
132
|
|
|
132
133
|
/* Panels and sidebars sliding open or shut. */
|
|
133
134
|
--ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
|
package/exports.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TConditionField, TConditionLookups, TConditionRule } from "./conditions.js";
|
|
2
|
-
type ValueProps = TConditionLookups & {
|
|
3
|
-
rule: TConditionRule;
|
|
4
|
-
field?: TConditionField;
|
|
5
|
-
onChange: (value: unknown) => void;
|
|
6
|
-
disabled?: boolean;
|
|
7
|
-
};
|
|
8
|
-
/** The value side of a rule, shaped by the operator and the field's type. */
|
|
9
|
-
export declare const ConditionValueInput: (props: ValueProps) => import("react").JSX.Element;
|
|
10
|
-
export {};
|