@erxes/ui 4.0.0-v2.13 → 4.0.0-v2.15
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 +15 -8
- package/README.md +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +4 -3
- 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 +169 -0
- package/dist/modules/conditions/conditions.d.ts +21 -12
- package/dist/modules/conditions/conditions.js +8 -75
- package/dist/modules/conditions/fieldIcons.d.ts +6 -0
- package/dist/modules/conditions/fieldIcons.js +21 -0
- package/dist/modules/conditions/fieldOptions.d.ts +15 -0
- package/dist/modules/conditions/fieldOptions.js +38 -0
- package/dist/modules/conditions/filterRule.d.ts +45 -0
- package/dist/modules/conditions/filterRule.js +171 -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 +22 -10
- package/dist/modules/list/ListFilter.js +53 -20
- 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 +109 -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/modules/pickers/LookupPicker.d.ts +6 -0
- package/dist/modules/pickers/LookupPicker.js +32 -1
- package/dist/modules/record-list/RecordList.d.ts +2 -1
- package/dist/modules/record-list/RecordList.js +2 -1
- package/dist/modules/record-list/RecordListRoot.d.ts +3 -1
- package/dist/modules/record-list/RecordListRoot.js +53 -37
- package/dist/modules/record-table/components/RecordTableHead.d.ts +7 -2
- package/dist/modules/record-table/components/RecordTableHead.js +73 -6
- package/dist/modules/record-table/components/RecordTableProvider.d.ts +22 -1
- package/dist/modules/record-table/components/RecordTableProvider.js +12 -1
- package/dist/modules/records/contacts.d.ts +18 -0
- package/dist/modules/records/openRecord.d.ts +35 -1
- package/dist/modules/records/openRecord.js +27 -4
- package/dist/theme.css +3 -2
- package/dist/types/UIConfig.d.ts +47 -100
- package/dist/types/UIConfig.js +14 -0
- package/exports.txt +10 -3
- 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,153 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { IconAdjustmentsHorizontal } from "@tabler/icons-react";
|
|
10
|
-
import {
|
|
1
|
+
import { Button } from "../../../components/button.js";
|
|
2
|
+
import { useItemKeys } from "../../../hooks/use-item-keys.js";
|
|
3
|
+
import { NO_VALUE } from "../../conditions/conditions.js";
|
|
4
|
+
import { isFilled, opOf, pathOf, ruleCount, withField, withOperator } from "../../conditions/filterRule.js";
|
|
5
|
+
import { FieldIcon } from "../../conditions/fieldIcons.js";
|
|
6
|
+
import { useRuleText } from "../../conditions/filterText.js";
|
|
7
|
+
import { FieldPart, OperatorPart, ValuePart } from "../../conditions/RuleParts.js";
|
|
8
|
+
import { useFieldAt, useListFilter } from "./listFilterContext.js";
|
|
9
|
+
import { IconAdjustmentsHorizontal, IconX } from "@tabler/icons-react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useState } from "react";
|
|
11
12
|
import { useTranslation } from "react-i18next";
|
|
12
13
|
// src/modules/list/filter/RuleChips.tsx
|
|
13
|
-
/** A
|
|
14
|
-
const Chip = ({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/* @__PURE__ */ jsx(Filter.BarClose, { onClick: onRemove })
|
|
24
|
-
]
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
/** Unknown paths (a removed property) read as text. */
|
|
28
|
-
const textField = (path) => ({
|
|
29
|
-
path,
|
|
30
|
-
label: path,
|
|
31
|
-
type: "text"
|
|
14
|
+
/** A chip: joined segments on a muted ground, the last one a remove button. */
|
|
15
|
+
const Chip = ({ children, removeLabel, onRemove }) => /* @__PURE__ */ jsxs("div", {
|
|
16
|
+
className: "flex h-7 max-w-full min-w-0 items-stretch gap-px overflow-hidden rounded bg-muted text-sm shadow-xs",
|
|
17
|
+
children: [children, /* @__PURE__ */ jsx(Button, {
|
|
18
|
+
variant: "segment",
|
|
19
|
+
size: "icon",
|
|
20
|
+
"aria-label": removeLabel,
|
|
21
|
+
onClick: onRemove,
|
|
22
|
+
children: /* @__PURE__ */ jsx(IconX, {})
|
|
23
|
+
})]
|
|
32
24
|
});
|
|
33
|
-
/**
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
defaultValue_other: "{{count}} months"
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/** A rule as words: the operator and the value. */
|
|
49
|
-
const useRuleText = (rule, field) => {
|
|
25
|
+
/** A segment of a chip that opens its editor. */
|
|
26
|
+
const Segment = ({ className, ...props }) => /* @__PURE__ */ jsx(Button, {
|
|
27
|
+
variant: "segment",
|
|
28
|
+
className: className ?? "max-w-60 min-w-0 gap-1.5 px-2",
|
|
29
|
+
...props
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* A condition as a chip: its field, operator and value, each opening its editor in place, and
|
|
33
|
+
* remove. A change that leaves the rule unfinished (an operator that needs another value) waits
|
|
34
|
+
* on the chip until the value is picked; closing it unfinished keeps the rule as it was.
|
|
35
|
+
*/
|
|
36
|
+
const RuleChip = ({ rule, index }) => {
|
|
50
37
|
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
51
|
-
const {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
op,
|
|
67
|
-
value: ""
|
|
68
|
-
};
|
|
69
|
-
if (span.success) {
|
|
70
|
-
const { amount, unit } = span.data;
|
|
71
|
-
return {
|
|
72
|
-
op,
|
|
73
|
-
value: t(`unit.${unit}`, {
|
|
74
|
-
count: amount,
|
|
75
|
-
...UNIT_LABELS[unit]
|
|
76
|
-
})
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
if (field.type === "boolean") return {
|
|
80
|
-
op: is,
|
|
81
|
-
value: textOf(rule.value) === "true" ? t("yes", "Yes") : t("no", "No")
|
|
38
|
+
const { fields, lookups, setPart } = useListFilter();
|
|
39
|
+
const [draft, setDraft] = useState(null);
|
|
40
|
+
const [open, setOpen] = useState(null);
|
|
41
|
+
const shown = draft ?? rule;
|
|
42
|
+
const field = useFieldAt(pathOf(shown));
|
|
43
|
+
const text = useRuleText(shown, field, lookups);
|
|
44
|
+
/** A finished rule applies; an unfinished one waits here, with its value open. */
|
|
45
|
+
const change = (next) => {
|
|
46
|
+
if (isFilled(next)) {
|
|
47
|
+
setDraft(null);
|
|
48
|
+
setPart(index, next);
|
|
49
|
+
} else {
|
|
50
|
+
setDraft(next);
|
|
51
|
+
setOpen("value");
|
|
52
|
+
}
|
|
82
53
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
op: NUMBER_SYMBOLS[numberOp],
|
|
87
|
-
value: field.currency ? money(n, field.currency) : fmt.number(n)
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
if (rule.op === "contains" && field.type === "text") return {
|
|
91
|
-
op,
|
|
92
|
-
value: `“${textOf(rule.value)}”`
|
|
54
|
+
const toggle = (part) => (next) => {
|
|
55
|
+
setOpen(next ? part : null);
|
|
56
|
+
if (!next) setDraft(null);
|
|
93
57
|
};
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
value: values.join(", ")
|
|
58
|
+
const pick = (next) => {
|
|
59
|
+
setOpen(null);
|
|
60
|
+
change(next);
|
|
98
61
|
};
|
|
99
|
-
return {
|
|
100
|
-
op,
|
|
101
|
-
value: values.join(", ")
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
const RuleChip = ({ rule, index }) => {
|
|
105
|
-
const { fields, edit, setPart } = useListFilter();
|
|
106
|
-
const field = fields.find((one) => one.path === rule.path) ?? textField(rule.path);
|
|
107
|
-
const text = useRuleText(rule, field);
|
|
108
|
-
const Icon = field.icon ?? FIELD_ICONS[field.type];
|
|
109
62
|
return /* @__PURE__ */ jsxs(Chip, {
|
|
110
|
-
|
|
111
|
-
|
|
63
|
+
removeLabel: t("remove-named", {
|
|
64
|
+
name: field.label,
|
|
65
|
+
defaultValue: "Remove {{name}} filter"
|
|
66
|
+
}),
|
|
112
67
|
onRemove: () => setPart(index, null),
|
|
113
|
-
children: [
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ jsx(FieldPart, {
|
|
70
|
+
fields,
|
|
71
|
+
field,
|
|
72
|
+
open: open === "field",
|
|
73
|
+
onOpenChange: toggle("field"),
|
|
74
|
+
onSelect: (next) => pick(withField(shown, field, next)),
|
|
75
|
+
button: /* @__PURE__ */ jsxs(Segment, {
|
|
76
|
+
className: "max-w-48 min-w-0 gap-1.5 rounded-l px-2 font-medium",
|
|
77
|
+
children: [/* @__PURE__ */ jsx(FieldIcon, {
|
|
78
|
+
field,
|
|
79
|
+
className: "text-muted-foreground"
|
|
80
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
81
|
+
className: "truncate",
|
|
82
|
+
children: field.label
|
|
83
|
+
})]
|
|
84
|
+
})
|
|
85
|
+
}),
|
|
86
|
+
/* @__PURE__ */ jsx(OperatorPart, {
|
|
87
|
+
rule: shown,
|
|
88
|
+
field,
|
|
89
|
+
open: open === "op",
|
|
90
|
+
onOpenChange: toggle("op"),
|
|
91
|
+
onSelect: (op) => pick(withOperator(shown, op)),
|
|
92
|
+
button: /* @__PURE__ */ jsx(Segment, {
|
|
93
|
+
className: "shrink-0 px-2 text-muted-foreground",
|
|
94
|
+
children: text.op
|
|
95
|
+
})
|
|
96
|
+
}),
|
|
97
|
+
!NO_VALUE.has(opOf(shown)) && /* @__PURE__ */ jsx(ValuePart, {
|
|
98
|
+
rule: shown,
|
|
99
|
+
field,
|
|
100
|
+
lookups,
|
|
101
|
+
onChange: change,
|
|
102
|
+
open: open === "value",
|
|
103
|
+
onOpenChange: toggle("value"),
|
|
104
|
+
button: /* @__PURE__ */ jsx(Segment, {
|
|
105
|
+
"aria-label": t("value-of", {
|
|
106
|
+
name: field.label,
|
|
107
|
+
value: text.value,
|
|
108
|
+
defaultValue: "{{name}}: {{value}}"
|
|
109
|
+
}),
|
|
110
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
111
|
+
className: "truncate font-medium",
|
|
112
|
+
children: text.value
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
]
|
|
120
117
|
});
|
|
121
118
|
};
|
|
122
|
-
/** A
|
|
123
|
-
const
|
|
119
|
+
/** A filter with "or" or nested groups: one chip, which opens the advanced filter. */
|
|
120
|
+
const AdvancedChip = () => {
|
|
124
121
|
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
125
|
-
const {
|
|
126
|
-
const count =
|
|
122
|
+
const { advanced, setAdvanced, setAdvancedOpen } = useListFilter();
|
|
123
|
+
const count = advanced ? ruleCount(advanced) : 0;
|
|
127
124
|
return /* @__PURE__ */ jsx(Chip, {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
defaultValue_other: "{{count}} conditions"
|
|
125
|
+
removeLabel: t("remove-advanced", "Remove the advanced filter"),
|
|
126
|
+
onRemove: () => setAdvanced(null),
|
|
127
|
+
children: /* @__PURE__ */ jsxs(Segment, {
|
|
128
|
+
className: "min-w-0 gap-1.5 rounded-l px-2 font-medium",
|
|
129
|
+
onClick: () => setAdvancedOpen(true),
|
|
130
|
+
children: [/* @__PURE__ */ jsx(IconAdjustmentsHorizontal, { className: "text-muted-foreground" }), t("advanced-chip", {
|
|
131
|
+
count,
|
|
132
|
+
defaultValue_one: "Advanced · {{count}} rule",
|
|
133
|
+
defaultValue_other: "Advanced · {{count}} rules"
|
|
134
|
+
})]
|
|
139
135
|
})
|
|
140
136
|
});
|
|
141
137
|
};
|
|
142
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* The list's conditions as chips, one per rule (keyed by place, so an open editor stays open as
|
|
140
|
+
* its rule changes), or the advanced filter's chip.
|
|
141
|
+
*/
|
|
143
142
|
const RuleChips = () => {
|
|
144
|
-
const {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
group: part,
|
|
143
|
+
const { chips } = useListFilter();
|
|
144
|
+
const keys = useItemKeys(chips?.length ?? 0);
|
|
145
|
+
if (!chips) return /* @__PURE__ */ jsx(AdvancedChip, {});
|
|
146
|
+
return chips.map((rule, index) => /* @__PURE__ */ jsx(RuleChip, {
|
|
147
|
+
rule,
|
|
150
148
|
index
|
|
151
|
-
},
|
|
149
|
+
}, keys.keyAt(index)));
|
|
152
150
|
};
|
|
153
|
-
export { RuleChips };
|
|
151
|
+
export { Chip, RuleChips };
|
|
@@ -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 };
|