@erxes/ui 4.0.0-v2.7 → 4.0.0-v2.9
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/README.md +10 -3
- package/dist/hooks/use-item-keys.d.ts +10 -0
- package/dist/hooks/use-item-keys.js +23 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +10 -2
- package/dist/lib/format.d.ts +2 -0
- package/dist/lib/format.js +6 -1
- package/dist/lib/money.d.ts +10 -0
- package/dist/lib/money.js +18 -0
- package/dist/lib/text.d.ts +7 -0
- package/dist/lib/text.js +14 -0
- package/dist/modules/conditions/ConditionValueInput.d.ts +10 -0
- package/dist/modules/conditions/ConditionValueInput.js +166 -0
- package/dist/modules/conditions/ConditionsEditor.d.ts +11 -0
- package/dist/modules/conditions/ConditionsEditor.js +209 -0
- package/dist/modules/conditions/LazyConditionsEditor.d.ts +9 -0
- package/dist/modules/conditions/LazyConditionsEditor.js +10 -0
- package/dist/modules/conditions/PathPicker.d.ts +8 -0
- package/dist/modules/conditions/PathPicker.js +51 -0
- package/dist/modules/conditions/conditions.d.ts +64 -0
- package/dist/modules/conditions/conditions.js +135 -0
- package/dist/modules/list/DisplayMenu.d.ts +14 -7
- package/dist/modules/list/DisplayMenu.js +48 -28
- package/dist/modules/list/ListFilter.d.ts +25 -11
- package/dist/modules/list/ListFilter.js +30 -26
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +5 -0
- package/dist/modules/list/filter/AdvancedFilterDialog.js +52 -0
- package/dist/modules/list/filter/FieldMenus.d.ts +5 -0
- package/dist/modules/list/filter/FieldMenus.js +184 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +6 -0
- package/dist/modules/list/filter/ListFilterBar.js +246 -0
- package/dist/modules/list/filter/RecordCount.d.ts +7 -0
- package/dist/modules/list/filter/RecordCount.js +22 -0
- package/dist/modules/list/filter/RuleChips.d.ts +2 -0
- package/dist/modules/list/filter/RuleChips.js +157 -0
- package/dist/modules/list/filter/fieldIcons.d.ts +7 -0
- package/dist/modules/list/filter/fieldIcons.js +16 -0
- package/dist/modules/list/filter/filterRules.d.ts +46 -0
- package/dist/modules/list/filter/filterRules.js +166 -0
- package/dist/modules/list/filter/listFilterContext.d.ts +29 -0
- package/dist/modules/list/filter/listFilterContext.js +34 -0
- package/dist/modules/list/filter/listFilterQuery.d.ts +15 -0
- package/dist/modules/list/filter/listFilterQuery.js +21 -0
- package/dist/modules/pickers/LookupPicker.d.ts +50 -0
- package/dist/modules/pickers/LookupPicker.js +83 -0
- package/dist/modules/record-list/RecordList.d.ts +12 -0
- package/dist/modules/record-list/RecordList.js +17 -0
- package/dist/modules/record-list/RecordListProvider.d.ts +30 -0
- package/dist/modules/record-list/RecordListProvider.js +57 -0
- package/dist/modules/record-list/RecordListRoot.d.ts +28 -0
- package/dist/modules/record-list/RecordListRoot.js +124 -0
- package/dist/modules/record-list/selection.d.ts +22 -0
- package/dist/modules/record-list/selection.js +54 -0
- package/dist/theme.css +2 -0
- package/package.json +2 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { useFormat } from "../../../lib/format.js";
|
|
2
|
+
import { useMoney } from "../../../lib/money.js";
|
|
3
|
+
import { oneOf, textOf } from "../../../lib/text.js";
|
|
4
|
+
import { OPERATOR_LABELS, RelativeAmount, isRule } from "../../conditions/conditions.js";
|
|
5
|
+
import { Filter } from "../../filter/components/Filter.js";
|
|
6
|
+
import { FIELD_ICONS } from "./fieldIcons.js";
|
|
7
|
+
import { NUMBER_OPS, NUMBER_SYMBOLS, presetOf, valuesOf } from "./filterRules.js";
|
|
8
|
+
import { useFieldOptions, useListFilter } from "./listFilterContext.js";
|
|
9
|
+
import { IconAdjustmentsHorizontal } from "@tabler/icons-react";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useTranslation } from "react-i18next";
|
|
12
|
+
// src/modules/list/filter/RuleChips.tsx
|
|
13
|
+
/** A filter bar chip: what it filters, the condition (opens it), remove. */
|
|
14
|
+
const Chip = ({ name, children, onOpen, onRemove }) => {
|
|
15
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
16
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
17
|
+
className: "flex h-7 items-stretch gap-px rounded bg-muted text-sm font-medium shadow-xs",
|
|
18
|
+
children: [
|
|
19
|
+
/* @__PURE__ */ jsx(Filter.BarName, { children: name }),
|
|
20
|
+
/* @__PURE__ */ jsx(Filter.BarButton, {
|
|
21
|
+
onClick: onOpen,
|
|
22
|
+
children
|
|
23
|
+
}),
|
|
24
|
+
/* @__PURE__ */ jsx(Filter.BarClose, {
|
|
25
|
+
"aria-label": t("remove", "Remove filter"),
|
|
26
|
+
onClick: onRemove
|
|
27
|
+
})
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
/** Unknown paths (a removed property) read as text. */
|
|
32
|
+
const textField = (path) => ({
|
|
33
|
+
path,
|
|
34
|
+
label: path,
|
|
35
|
+
type: "text"
|
|
36
|
+
});
|
|
37
|
+
/** English for the `views` namespace's `filter.unit.<unit>`, by plural form. */
|
|
38
|
+
const UNIT_LABELS = {
|
|
39
|
+
days: {
|
|
40
|
+
defaultValue_one: "{{count}} day",
|
|
41
|
+
defaultValue_other: "{{count}} days"
|
|
42
|
+
},
|
|
43
|
+
weeks: {
|
|
44
|
+
defaultValue_one: "{{count}} week",
|
|
45
|
+
defaultValue_other: "{{count}} weeks"
|
|
46
|
+
},
|
|
47
|
+
months: {
|
|
48
|
+
defaultValue_one: "{{count}} month",
|
|
49
|
+
defaultValue_other: "{{count}} months"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/** A rule as words: the operator and the value. */
|
|
53
|
+
const useRuleText = (rule, field) => {
|
|
54
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
55
|
+
const { t: opT } = useTranslation("automations");
|
|
56
|
+
const { options } = useFieldOptions(field);
|
|
57
|
+
const money = useMoney();
|
|
58
|
+
const fmt = useFormat();
|
|
59
|
+
const op = opT(`op.${rule.op}`, OPERATOR_LABELS[rule.op]);
|
|
60
|
+
const labelOf = (value) => options.find((option) => option.value === value)?.label ?? value;
|
|
61
|
+
const preset = field.type === "date" ? presetOf(rule) : void 0;
|
|
62
|
+
const span = RelativeAmount.safeParse(rule.value);
|
|
63
|
+
const numberOp = field.type === "number" ? oneOf(NUMBER_OPS, rule.op) : void 0;
|
|
64
|
+
const is = t("is", "is");
|
|
65
|
+
if (preset) return {
|
|
66
|
+
op: "",
|
|
67
|
+
value: t(`date.${preset.key}`, preset.label)
|
|
68
|
+
};
|
|
69
|
+
if (rule.op === "exists" || rule.op === "not_exists") return {
|
|
70
|
+
op,
|
|
71
|
+
value: ""
|
|
72
|
+
};
|
|
73
|
+
if (span.success) {
|
|
74
|
+
const { amount, unit } = span.data;
|
|
75
|
+
return {
|
|
76
|
+
op,
|
|
77
|
+
value: t(`unit.${unit}`, {
|
|
78
|
+
count: amount,
|
|
79
|
+
...UNIT_LABELS[unit]
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (field.type === "boolean") return {
|
|
84
|
+
op: is,
|
|
85
|
+
value: textOf(rule.value) === "true" ? t("yes", "Yes") : t("no", "No")
|
|
86
|
+
};
|
|
87
|
+
if (numberOp) {
|
|
88
|
+
const n = Number(rule.value);
|
|
89
|
+
return {
|
|
90
|
+
op: NUMBER_SYMBOLS[numberOp],
|
|
91
|
+
value: field.currency ? money(n, field.currency) : fmt.number(n)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (rule.op === "contains" && field.type === "text") return {
|
|
95
|
+
op,
|
|
96
|
+
value: `“${textOf(rule.value)}”`
|
|
97
|
+
};
|
|
98
|
+
const values = valuesOf(rule).map(labelOf);
|
|
99
|
+
if (rule.op === "in" || rule.op === "eq") return {
|
|
100
|
+
op: values.length > 1 ? t("is-any-of", "is any of") : is,
|
|
101
|
+
value: values.join(", ")
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
op,
|
|
105
|
+
value: values.join(", ")
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
const RuleChip = ({ rule, index }) => {
|
|
109
|
+
const { fields, edit, setPart } = useListFilter();
|
|
110
|
+
const field = fields.find((one) => one.path === rule.path) ?? textField(rule.path);
|
|
111
|
+
const text = useRuleText(rule, field);
|
|
112
|
+
const Icon = field.icon ?? FIELD_ICONS[field.type];
|
|
113
|
+
return /* @__PURE__ */ jsxs(Chip, {
|
|
114
|
+
name: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Icon, {}), field.label] }),
|
|
115
|
+
onOpen: () => edit(index),
|
|
116
|
+
onRemove: () => setPart(index, null),
|
|
117
|
+
children: [text.op && /* @__PURE__ */ jsx("span", {
|
|
118
|
+
className: "font-normal text-muted-foreground",
|
|
119
|
+
children: text.op
|
|
120
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
121
|
+
className: "truncate",
|
|
122
|
+
children: text.value
|
|
123
|
+
})]
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
/** A group from the advanced filter: how many conditions; it opens the advanced filter. */
|
|
127
|
+
const GroupChip = ({ group, index }) => {
|
|
128
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
129
|
+
const { openAdvanced, setPart } = useListFilter();
|
|
130
|
+
const count = group.rules.length;
|
|
131
|
+
return /* @__PURE__ */ jsx(Chip, {
|
|
132
|
+
name: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(IconAdjustmentsHorizontal, {}), t("advanced", "Advanced filter")] }),
|
|
133
|
+
onOpen: openAdvanced,
|
|
134
|
+
onRemove: () => setPart(index, null),
|
|
135
|
+
children: group.match === "any" ? t("any-of", {
|
|
136
|
+
count,
|
|
137
|
+
defaultValue_one: "any of {{count}} condition",
|
|
138
|
+
defaultValue_other: "any of {{count}} conditions"
|
|
139
|
+
}) : t("conditions", {
|
|
140
|
+
count,
|
|
141
|
+
defaultValue_one: "{{count}} condition",
|
|
142
|
+
defaultValue_other: "{{count}} conditions"
|
|
143
|
+
})
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
/** Each part of the list's filter as a chip (parts are distinct, so a part is its own key). */
|
|
147
|
+
const RuleChips = () => {
|
|
148
|
+
const { parts } = useListFilter();
|
|
149
|
+
return parts.map((part, index) => isRule(part) ? /* @__PURE__ */ jsx(RuleChip, {
|
|
150
|
+
rule: part,
|
|
151
|
+
index
|
|
152
|
+
}, JSON.stringify(part)) : /* @__PURE__ */ jsx(GroupChip, {
|
|
153
|
+
group: part,
|
|
154
|
+
index
|
|
155
|
+
}, JSON.stringify(part)));
|
|
156
|
+
};
|
|
157
|
+
export { RuleChips };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TListFilterField } from "../ListFilter.js";
|
|
2
|
+
import { IconHash } from "@tabler/icons-react";
|
|
3
|
+
/**
|
|
4
|
+
* A field's icon in the filter menu and on its chips, by type, unless it brings its own:
|
|
5
|
+
* `field.icon ?? FIELD_ICONS[field.type]`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const FIELD_ICONS: Record<TListFilterField['type'], typeof IconHash>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IconCalendar, IconHash, IconLetterCase, IconSelector, IconTags, IconToggleLeft, IconUser } from "@tabler/icons-react";
|
|
2
|
+
// src/modules/list/filter/fieldIcons.ts
|
|
3
|
+
/**
|
|
4
|
+
* A field's icon in the filter menu and on its chips, by type, unless it brings its own:
|
|
5
|
+
* `field.icon ?? FIELD_ICONS[field.type]`.
|
|
6
|
+
*/
|
|
7
|
+
const FIELD_ICONS = {
|
|
8
|
+
text: IconLetterCase,
|
|
9
|
+
number: IconHash,
|
|
10
|
+
date: IconCalendar,
|
|
11
|
+
boolean: IconToggleLeft,
|
|
12
|
+
select: IconSelector,
|
|
13
|
+
member: IconUser,
|
|
14
|
+
tags: IconTags
|
|
15
|
+
};
|
|
16
|
+
export { FIELD_ICONS };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RelativeAmount, TConditionGroup, TConditionRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { TListFilterField } from "../ListFilter.js";
|
|
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;
|
|
10
|
+
/**
|
|
11
|
+
* Replaces the part at `index`, appends when `index` is null, removes when
|
|
12
|
+
* `next` is null. Parts stay distinct: a part already there isn't added twice.
|
|
13
|
+
*/
|
|
14
|
+
export declare const withPart: (parts: FilterPart[], index: number | null, next: FilterPart | null) => FilterPart[];
|
|
15
|
+
/** Comparisons of a number, as the menu writes them. */
|
|
16
|
+
export declare const NUMBER_OPS: readonly ['eq', 'neq', 'gt', 'gte', 'lt', 'lte'];
|
|
17
|
+
export declare const NUMBER_SYMBOLS: Record<(typeof NUMBER_OPS)[number], string>;
|
|
18
|
+
/** Whether the menu can show and edit this rule. */
|
|
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;
|
|
22
|
+
/**
|
|
23
|
+
* The values a rule picks: the list of "is any of", or the one of "is". A value that isn't text or
|
|
24
|
+
* numbers (a date range, a relative amount) picks nothing.
|
|
25
|
+
*/
|
|
26
|
+
export declare const valuesOf: (rule: TConditionRule | undefined) => string[];
|
|
27
|
+
/** An "is any of" rule; null when nothing is picked. */
|
|
28
|
+
export declare const anyOf: (path: string, values: string[]) => TConditionRule | null;
|
|
29
|
+
/**
|
|
30
|
+
* Date filters in one pick, on the relative operators (they stay current in a saved view);
|
|
31
|
+
* `label` is the English for the `views` namespace's `filter.date.<key>`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DATE_PRESETS: {
|
|
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 {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { z } from "zod";
|
|
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
|
+
/**
|
|
13
|
+
* Replaces the part at `index`, appends when `index` is null, removes when
|
|
14
|
+
* `next` is null. Parts stay distinct: a part already there isn't added twice.
|
|
15
|
+
*/
|
|
16
|
+
const withPart = (parts, index, next) => {
|
|
17
|
+
if (next && parts.some((part, at) => at !== index && same(part, next))) return index === null ? parts : parts.filter((_, at) => at !== index);
|
|
18
|
+
if (index === null) return next ? [...parts, next] : parts;
|
|
19
|
+
return next ? parts.map((part, at) => at === index ? next : part) : parts.filter((_, at) => at !== index);
|
|
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"]
|
|
53
|
+
};
|
|
54
|
+
/** Whether the menu can show and edit this rule. */
|
|
55
|
+
const inMenu = (rule, field) => !!field && MENU_OPS[field.type].includes(rule.op);
|
|
56
|
+
/** Fields with one value at a time (a choice, a yes/no, a date range): picking again changes it rather than adding one. */
|
|
57
|
+
const SINGLE = /* @__PURE__ */ new Set([
|
|
58
|
+
"select",
|
|
59
|
+
"member",
|
|
60
|
+
"tags",
|
|
61
|
+
"boolean",
|
|
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;
|
|
70
|
+
};
|
|
71
|
+
const Values = z.array(z.union([z.string(), z.number()]).transform(String));
|
|
72
|
+
/**
|
|
73
|
+
* The values a rule picks: the list of "is any of", or the one of "is". A value that isn't text or
|
|
74
|
+
* numbers (a date range, a relative amount) picks nothing.
|
|
75
|
+
*/
|
|
76
|
+
const valuesOf = (rule) => {
|
|
77
|
+
if (!rule || rule.value === void 0 || rule.value === null) return [];
|
|
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
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Date filters in one pick, on the relative operators (they stay current in a saved view);
|
|
96
|
+
* `label` is the English for the `views` namespace's `filter.date.<key>`.
|
|
97
|
+
*/
|
|
98
|
+
const DATE_PRESETS = [
|
|
99
|
+
{
|
|
100
|
+
key: "past-day",
|
|
101
|
+
label: "Past day",
|
|
102
|
+
op: "within_last",
|
|
103
|
+
value: days(1)
|
|
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 };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TConditionLookups } from "../../conditions/conditions.js";
|
|
2
|
+
import { TListFilterField } from "../ListFilter.js";
|
|
3
|
+
import { FilterPart } from "./filterRules.js";
|
|
4
|
+
/** What the filter menu, its chips and the advanced filter share. */
|
|
5
|
+
export interface ListFilterState {
|
|
6
|
+
fields: TListFilterField[];
|
|
7
|
+
/** Where `member` and `tags` fields pick from. */
|
|
8
|
+
lookups: TConditionLookups;
|
|
9
|
+
/** The list's filter as parts that must all hold (`partsOf`). */
|
|
10
|
+
parts: FilterPart[];
|
|
11
|
+
/** Changes the filter as `withPart` does. */
|
|
12
|
+
setPart: (index: number | null, next: FilterPart | null) => void;
|
|
13
|
+
/** The part a chip opened the menu on. */
|
|
14
|
+
editing: number | null;
|
|
15
|
+
/** Opens the menu on a chip's part, or the advanced filter when the menu can't show it. */
|
|
16
|
+
edit: (index: number) => void;
|
|
17
|
+
openAdvanced: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare const ListFilterContext: import("react").Context<ListFilterState | null>;
|
|
20
|
+
export declare const useListFilter: () => ListFilterState;
|
|
21
|
+
/** What a choice field picks from: its options, the team ("Me" first), or the list's tags. */
|
|
22
|
+
export declare const useFieldOptions: (field: TListFilterField) => {
|
|
23
|
+
options: {
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}[];
|
|
27
|
+
loading: boolean;
|
|
28
|
+
error: Error | null;
|
|
29
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { useMemberOptions, useTagOptions } from "../../pickers/LookupPicker.js";
|
|
3
|
+
import { valuesOf } from "./filterRules.js";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
import { useTranslation } from "react-i18next";
|
|
6
|
+
// src/modules/list/filter/listFilterContext.ts
|
|
7
|
+
const ListFilterContext = createContext(null);
|
|
8
|
+
const useListFilter = () => {
|
|
9
|
+
const state = useContext(ListFilterContext);
|
|
10
|
+
if (!state) throw new Error("useListFilter is only available inside <ListFilter>");
|
|
11
|
+
return state;
|
|
12
|
+
};
|
|
13
|
+
/** What a choice field picks from: its options, the team ("Me" first), or the list's tags. */
|
|
14
|
+
const useFieldOptions = (field) => {
|
|
15
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
16
|
+
const { lookups, parts } = useListFilter();
|
|
17
|
+
const picked = parts.flatMap((part) => isRule(part) && part.path === field.path ? valuesOf(part) : []);
|
|
18
|
+
const members = useMemberOptions(lookups.members, field.type === "member", picked);
|
|
19
|
+
const tags = useTagOptions(lookups.tags, field.type === "tags");
|
|
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
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export { ListFilterContext, useFieldOptions, useListFilter };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TConditionGroup } from "../../conditions/conditions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where a list's filter lives in the address, so shared links and reloads keep it: `advanced`,
|
|
4
|
+
* the condition group as JSON, and `searchValue`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const listFilterQuery: {
|
|
7
|
+
advanced: import("nuqs").SingleParserBuilder<TConditionGroup>;
|
|
8
|
+
searchValue: import("nuqs").SingleParserBuilder<string>;
|
|
9
|
+
};
|
|
10
|
+
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
11
|
+
export declare const useListConditions: () => {
|
|
12
|
+
advanced: TConditionGroup | null;
|
|
13
|
+
search: string | null;
|
|
14
|
+
setAdvanced: (next: TConditionGroup | null) => undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConditionGroup } from "../../conditions/conditions.js";
|
|
2
|
+
import { parseAsJson, parseAsString, useQueryStates } from "nuqs";
|
|
3
|
+
// src/modules/list/filter/listFilterQuery.ts
|
|
4
|
+
/**
|
|
5
|
+
* Where a list's filter lives in the address, so shared links and reloads keep it: `advanced`,
|
|
6
|
+
* the condition group as JSON, and `searchValue`.
|
|
7
|
+
*/
|
|
8
|
+
const listFilterQuery = {
|
|
9
|
+
advanced: parseAsJson((value) => ConditionGroup.safeParse(value).data ?? null),
|
|
10
|
+
searchValue: parseAsString
|
|
11
|
+
};
|
|
12
|
+
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
13
|
+
const useListConditions = () => {
|
|
14
|
+
const [{ advanced, searchValue }, setQueries] = useQueryStates(listFilterQuery, { history: "replace" });
|
|
15
|
+
return {
|
|
16
|
+
advanced: advanced?.rules.length ? advanced : null,
|
|
17
|
+
search: searchValue,
|
|
18
|
+
setAdvanced: (next) => void setQueries({ advanced: next?.rules.length ? next : null })
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { listFilterQuery, useListConditions };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MemberQueries } from "./members.js";
|
|
2
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
3
|
+
/** A tag as the pickers show one: core's `Tag` has these fields and more. */
|
|
4
|
+
export interface Tag {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The tags of one record type, as TanStack query options: in erxes, web's query for
|
|
10
|
+
* `orpc.tags.list` with the type (`{ type: 'customer' }`).
|
|
11
|
+
*/
|
|
12
|
+
export type TagsQuery = RowsQuery<Tag>;
|
|
13
|
+
type LookupOptions = {
|
|
14
|
+
options: {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
loading: boolean;
|
|
19
|
+
error: Error | null;
|
|
20
|
+
};
|
|
21
|
+
type RowsQuery<T> = UseQueryOptions<{
|
|
22
|
+
data: T[];
|
|
23
|
+
}, Error, {
|
|
24
|
+
data: T[];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* The active team as picker options, plus the `picked` members outside it (a disabled member a
|
|
28
|
+
* filter still names), so their names show; none without `members`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const useMemberOptions: (members: MemberQueries | undefined, enabled?: boolean, picked?: readonly string[]) => {
|
|
31
|
+
loading: boolean;
|
|
32
|
+
error: Error | null;
|
|
33
|
+
options: {
|
|
34
|
+
value: string;
|
|
35
|
+
label: string;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
/** A record type's tags as picker options; none without `tags`. */
|
|
39
|
+
export declare const useTagOptions: (tags: TagsQuery | undefined, enabled?: boolean) => LookupOptions;
|
|
40
|
+
/** One option, or several with `multiple`, from members or tags, on a button. */
|
|
41
|
+
export declare const LookupPicker: ({ lookup: { options, loading, error }, value, onValueChange, multiple, placeholder, disabled, className }: {
|
|
42
|
+
lookup: LookupOptions;
|
|
43
|
+
value: string[];
|
|
44
|
+
onValueChange: (values: string[]) => void;
|
|
45
|
+
multiple?: boolean;
|
|
46
|
+
placeholder: string;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
className?: string;
|
|
49
|
+
}) => import("react").JSX.Element;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Combobox } from "../../components/combobox.js";
|
|
2
|
+
import { Popover } from "../../components/popover.js";
|
|
3
|
+
import { EntityPicker } from "./EntityPicker.js";
|
|
4
|
+
import { memberName } from "./members.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { skipToken, useQuery } from "@tanstack/react-query";
|
|
8
|
+
// src/modules/pickers/LookupPicker.tsx
|
|
9
|
+
const useLookup = (query, enabled, option) => {
|
|
10
|
+
const options = query ? {
|
|
11
|
+
...query,
|
|
12
|
+
enabled
|
|
13
|
+
} : {
|
|
14
|
+
queryKey: ["erxes-ui", "no-lookup"],
|
|
15
|
+
queryFn: skipToken
|
|
16
|
+
};
|
|
17
|
+
const result = useQuery(options);
|
|
18
|
+
return {
|
|
19
|
+
options: useMemo(() => (result.data?.data ?? []).map(option), [result.data, option]),
|
|
20
|
+
loading: enabled && !!query && result.isPending,
|
|
21
|
+
error: result.error
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const memberOption = (member) => ({
|
|
25
|
+
value: member.id,
|
|
26
|
+
label: memberName(member)
|
|
27
|
+
});
|
|
28
|
+
const tagOption = (tag) => ({
|
|
29
|
+
value: tag.id,
|
|
30
|
+
label: tag.name
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* The active team as picker options, plus the `picked` members outside it (a disabled member a
|
|
34
|
+
* filter still names), so their names show; none without `members`.
|
|
35
|
+
*/
|
|
36
|
+
const useMemberOptions = (members, enabled = true, picked = []) => {
|
|
37
|
+
const team = useLookup(members?.team, enabled, memberOption);
|
|
38
|
+
const known = new Set(team.options.map((option) => option.value));
|
|
39
|
+
const missing = [...new Set(picked)].filter((id) => id !== "me" && !known.has(id)).toSorted((a, b) => a.localeCompare(b));
|
|
40
|
+
const others = useLookup(members && missing.length ? members.byIds(missing) : void 0, enabled && !team.loading && missing.length > 0, memberOption);
|
|
41
|
+
return {
|
|
42
|
+
...team,
|
|
43
|
+
options: [...team.options, ...others.options]
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** A record type's tags as picker options; none without `tags`. */
|
|
47
|
+
const useTagOptions = (tags, enabled = true) => useLookup(tags, enabled, tagOption);
|
|
48
|
+
/** One option, or several with `multiple`, from members or tags, on a button. */
|
|
49
|
+
const LookupPicker = ({ lookup: { options, loading, error }, value, onValueChange, multiple, placeholder, disabled, className }) => {
|
|
50
|
+
const [open, setOpen] = useState(false);
|
|
51
|
+
const items = [...value.filter((id) => !options.some((option) => option.value === id)).map((id) => ({
|
|
52
|
+
value: id,
|
|
53
|
+
label: id
|
|
54
|
+
})), ...options];
|
|
55
|
+
const labels = value.map((id) => items.find((option) => option.value === id)?.label ?? id);
|
|
56
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
57
|
+
open,
|
|
58
|
+
onOpenChange: setOpen,
|
|
59
|
+
children: [/* @__PURE__ */ jsx(Combobox.Trigger, {
|
|
60
|
+
disabled,
|
|
61
|
+
className,
|
|
62
|
+
children: /* @__PURE__ */ jsx(Combobox.Value, {
|
|
63
|
+
value: labels.join(", "),
|
|
64
|
+
placeholder
|
|
65
|
+
})
|
|
66
|
+
}), /* @__PURE__ */ jsx(Combobox.Content, { children: /* @__PURE__ */ jsx(EntityPicker, {
|
|
67
|
+
multiple,
|
|
68
|
+
items,
|
|
69
|
+
itemKey: (option) => ({
|
|
70
|
+
id: option.value,
|
|
71
|
+
label: option.label
|
|
72
|
+
}),
|
|
73
|
+
value,
|
|
74
|
+
onValueChange: (next) => {
|
|
75
|
+
onValueChange(next);
|
|
76
|
+
if (!multiple) setOpen(false);
|
|
77
|
+
},
|
|
78
|
+
loading,
|
|
79
|
+
error
|
|
80
|
+
}) })]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
export { LookupPicker, useMemberOptions, useTagOptions };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RecordListProvider, useRecordListSelection } from "./RecordListProvider.js";
|
|
2
|
+
import { RecordListRoot } from "./RecordListRoot.js";
|
|
3
|
+
/** Stands in for the rows while they load. */
|
|
4
|
+
declare const RecordListSkeleton: ({ rows }: {
|
|
5
|
+
rows?: number;
|
|
6
|
+
}) => import("react").JSX.Element;
|
|
7
|
+
export declare const RecordList: typeof RecordListRoot & {
|
|
8
|
+
Provider: typeof RecordListProvider;
|
|
9
|
+
Skeleton: typeof RecordListSkeleton;
|
|
10
|
+
useSelection: typeof useRecordListSelection;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Skeleton } from "../../components/skeleton.js";
|
|
2
|
+
import { RecordListProvider, useRecordListSelection } from "./RecordListProvider.js";
|
|
3
|
+
import { RecordListRoot } from "./RecordListRoot.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/modules/record-list/RecordList.tsx
|
|
6
|
+
/** Stands in for the rows while they load. */
|
|
7
|
+
const RecordListSkeleton = ({ rows = 8 }) => /* @__PURE__ */ jsx("div", {
|
|
8
|
+
className: "flex flex-col gap-2 p-3",
|
|
9
|
+
"aria-busy": true,
|
|
10
|
+
children: Array.from({ length: rows }, (_, index) => /* @__PURE__ */ jsx(Skeleton, { className: "h-8" }, `row-${String(index)}`))
|
|
11
|
+
});
|
|
12
|
+
const RecordList = Object.assign(RecordListRoot, {
|
|
13
|
+
Provider: RecordListProvider,
|
|
14
|
+
Skeleton: RecordListSkeleton,
|
|
15
|
+
useSelection: useRecordListSelection
|
|
16
|
+
});
|
|
17
|
+
export { RecordList };
|