@erxes/ui 4.0.0-v2.12 → 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/components/color-picker.js +2 -2
- package/dist/components/command-bar.js +3 -0
- package/dist/components/input.d.ts +1 -1
- package/dist/components/input.js +2 -2
- package/dist/components/on-demand.d.ts +9 -2
- package/dist/components/on-demand.js +15 -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 +15 -8
- 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/filter/components/FilterBar.js +3 -0
- package/dist/modules/list/ListFilter.d.ts +20 -7
- 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 -198
- package/dist/modules/list/filter/RuleChips.d.ts +12 -2
- package/dist/modules/list/filter/RuleChips.js +132 -138
- 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 -51
- 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,156 @@
|
|
|
1
|
+
import { useFormat } from "../../lib/format.js";
|
|
2
|
+
import { useMoney } from "../../lib/money.js";
|
|
3
|
+
import { textOf } from "../../lib/text.js";
|
|
4
|
+
import { LIST_VALUE, NO_VALUE, RelativeAmount, isRule } from "./conditions.js";
|
|
5
|
+
import { valuesBetween } from "./filterRule.js";
|
|
6
|
+
import { useFieldOptions } from "./fieldOptions.js";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { useTranslation } from "react-i18next";
|
|
9
|
+
// src/modules/conditions/filterText.ts
|
|
10
|
+
/** English for the `views` namespace's `filter.op.<op>`. */
|
|
11
|
+
const OPERATORS = {
|
|
12
|
+
eq: "is",
|
|
13
|
+
neq: "is not",
|
|
14
|
+
gt: "is greater than",
|
|
15
|
+
gte: "is at least",
|
|
16
|
+
lt: "is less than",
|
|
17
|
+
lte: "is at most",
|
|
18
|
+
contains: "contains",
|
|
19
|
+
not_contains: "doesn't contain",
|
|
20
|
+
starts_with: "starts with",
|
|
21
|
+
in: "is any of",
|
|
22
|
+
not_in: "is none of",
|
|
23
|
+
exists: "is set",
|
|
24
|
+
not_exists: "is empty",
|
|
25
|
+
within_last: "is in the last",
|
|
26
|
+
more_than_ago: "is more than … ago",
|
|
27
|
+
within_next: "is in the next",
|
|
28
|
+
anniversary_within: "anniversary in the next",
|
|
29
|
+
between: "is between"
|
|
30
|
+
};
|
|
31
|
+
/** Dates compare as days: `filter.op-date.<op>`. */
|
|
32
|
+
const DATE_OPERATORS = {
|
|
33
|
+
eq: "is on",
|
|
34
|
+
neq: "is not on",
|
|
35
|
+
gt: "is after",
|
|
36
|
+
gte: "is on or after",
|
|
37
|
+
lt: "is before",
|
|
38
|
+
lte: "is on or before"
|
|
39
|
+
};
|
|
40
|
+
/** Numbers read as symbols on a chip. */
|
|
41
|
+
const SYMBOLS = {
|
|
42
|
+
eq: "=",
|
|
43
|
+
neq: "≠",
|
|
44
|
+
gt: ">",
|
|
45
|
+
gte: "≥",
|
|
46
|
+
lt: "<",
|
|
47
|
+
lte: "≤"
|
|
48
|
+
};
|
|
49
|
+
/** English for `filter.unit.<unit>`, by plural form. */
|
|
50
|
+
const UNITS = {
|
|
51
|
+
days: {
|
|
52
|
+
defaultValue_one: "{{count}} day",
|
|
53
|
+
defaultValue_other: "{{count}} days"
|
|
54
|
+
},
|
|
55
|
+
weeks: {
|
|
56
|
+
defaultValue_one: "{{count}} week",
|
|
57
|
+
defaultValue_other: "{{count}} weeks"
|
|
58
|
+
},
|
|
59
|
+
months: {
|
|
60
|
+
defaultValue_one: "{{count}} month",
|
|
61
|
+
defaultValue_other: "{{count}} months"
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/** An operator in words, for a field's type ("is before" on a date). */
|
|
65
|
+
const useOperatorLabel = () => {
|
|
66
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
67
|
+
return (op, type) => {
|
|
68
|
+
const dated = type === "date" ? DATE_OPERATORS[op] : void 0;
|
|
69
|
+
return dated ? t(`op-date.${op}`, dated) : t(`op.${op}`, OPERATORS[op]);
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/** A relative amount in words: "30 days". */
|
|
73
|
+
const useSpanText = () => {
|
|
74
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
75
|
+
return ({ amount, unit }) => t(`unit.${unit}`, {
|
|
76
|
+
count: amount,
|
|
77
|
+
...UNITS[unit]
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const Values = z.array(z.union([
|
|
81
|
+
z.string(),
|
|
82
|
+
z.number(),
|
|
83
|
+
z.boolean()
|
|
84
|
+
]).transform(String));
|
|
85
|
+
/**
|
|
86
|
+
* The values a rule picks: the list of "is any of", or the one of "is". A value that isn't text,
|
|
87
|
+
* a number or yes/no (a date range, a relative amount) picks nothing.
|
|
88
|
+
*/
|
|
89
|
+
const valuesOf = (rule) => {
|
|
90
|
+
if (!rule || rule.value === void 0 || rule.value === null) return [];
|
|
91
|
+
return Values.safeParse(Array.isArray(rule.value) ? rule.value : [rule.value]).data ?? [];
|
|
92
|
+
};
|
|
93
|
+
/** A rule in words, as a chip shows it: the operator and the value (empty when it needs none). */
|
|
94
|
+
const useRuleText = (rule, field, lookups) => {
|
|
95
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
96
|
+
const operator = useOperatorLabel();
|
|
97
|
+
const spanText = useSpanText();
|
|
98
|
+
const money = useMoney();
|
|
99
|
+
const fmt = useFormat();
|
|
100
|
+
const type = field?.type;
|
|
101
|
+
const picked = isRule(rule) ? valuesOf(rule) : [];
|
|
102
|
+
const { options } = useFieldOptions(field, lookups, picked);
|
|
103
|
+
const one = (value) => {
|
|
104
|
+
if (value === void 0 || value === null || value === "") return "…";
|
|
105
|
+
if (type === "date") {
|
|
106
|
+
const day = textOf(value);
|
|
107
|
+
return /^\d{4}-\d{2}-\d{2}/.test(day) ? fmt.date(day.slice(0, 10)) : day;
|
|
108
|
+
}
|
|
109
|
+
if (type === "number") {
|
|
110
|
+
const n = Number(value);
|
|
111
|
+
return field?.currency ? money(n, field.currency) : fmt.number(n);
|
|
112
|
+
}
|
|
113
|
+
return textOf(value);
|
|
114
|
+
};
|
|
115
|
+
if (!isRule(rule)) {
|
|
116
|
+
const [from, to] = valuesBetween(rule);
|
|
117
|
+
return {
|
|
118
|
+
op: operator("between", type),
|
|
119
|
+
value: `${one(from)} – ${one(to)}`
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const op = operator(rule.op, type);
|
|
123
|
+
if (NO_VALUE.has(rule.op)) return {
|
|
124
|
+
op,
|
|
125
|
+
value: ""
|
|
126
|
+
};
|
|
127
|
+
const span = RelativeAmount.safeParse(rule.value);
|
|
128
|
+
if (span.success) return {
|
|
129
|
+
op,
|
|
130
|
+
value: spanText(span.data)
|
|
131
|
+
};
|
|
132
|
+
if (type === "boolean") return {
|
|
133
|
+
op: t("op.eq", "is"),
|
|
134
|
+
value: textOf(rule.value) === "true" ? t("yes", "Yes") : t("no", "No")
|
|
135
|
+
};
|
|
136
|
+
if (type === "number" && SYMBOLS[rule.op]) return {
|
|
137
|
+
op: SYMBOLS[rule.op] ?? op,
|
|
138
|
+
value: one(rule.value)
|
|
139
|
+
};
|
|
140
|
+
if (options.length || LIST_VALUE.has(rule.op)) {
|
|
141
|
+
const labels = picked.map((value) => options.find((option) => option.value === value)?.label ?? value);
|
|
142
|
+
return {
|
|
143
|
+
op: labels.length === 1 && LIST_VALUE.has(rule.op) ? operator(rule.op === "in" ? "eq" : "neq", type) : op,
|
|
144
|
+
value: labels.join(", ") || "…"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (type === "date" || type === "number") return {
|
|
148
|
+
op,
|
|
149
|
+
value: one(rule.value)
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
op,
|
|
153
|
+
value: rule.value === void 0 ? "…" : `“${textOf(rule.value)}”`
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
export { useOperatorLabel, useRuleText, useSpanText, valuesOf };
|
|
@@ -3,7 +3,7 @@ import { FilterDialog, FilterDialogStringView } from "./FilterDialog.js";
|
|
|
3
3
|
import { FilterCommandInput, FilterCommandItem, FilterItem, FilterPopover, FilterSearchValueTrigger, FilterTrigger, FilterView } from "./FilterPopover.js";
|
|
4
4
|
import { FilterProvider } from "./FilterProvider.js";
|
|
5
5
|
/**
|
|
6
|
-
* Parts of a filter popover and bar,
|
|
6
|
+
* Parts of a filter popover and bar, for a page without saved views.
|
|
7
7
|
* A list page uses `ListFilter`; reach for these parts only for a filter it can't draw.
|
|
8
8
|
*/
|
|
9
9
|
export declare const Filter: typeof FilterProvider & {
|
|
@@ -4,7 +4,7 @@ import { FilterCommandInput, FilterCommandItem, FilterItem, FilterPopover, Filte
|
|
|
4
4
|
import { FilterProvider } from "./FilterProvider.js";
|
|
5
5
|
// src/modules/filter/components/Filter.tsx
|
|
6
6
|
/**
|
|
7
|
-
* Parts of a filter popover and bar,
|
|
7
|
+
* Parts of a filter popover and bar, for a page without saved views.
|
|
8
8
|
* A list page uses `ListFilter`; reach for these parts only for a filter it can't draw.
|
|
9
9
|
*/
|
|
10
10
|
const Filter = Object.assign(FilterProvider, {
|
|
@@ -4,6 +4,7 @@ import { useFilterContext } from "../hooks/useFilterContext.js";
|
|
|
4
4
|
import { IconSearch, IconX } from "@tabler/icons-react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import "react";
|
|
7
|
+
import { useTranslation } from "react-i18next";
|
|
7
8
|
import { useQueryState } from "nuqs";
|
|
8
9
|
// src/modules/filter/components/FilterBar.tsx
|
|
9
10
|
const FilterBar = ({ ref, className, ...props }) => {
|
|
@@ -15,11 +16,13 @@ const FilterBar = ({ ref, className, ...props }) => {
|
|
|
15
16
|
};
|
|
16
17
|
const FilterBarCloseButton = ({ ref, className, filterKey, ...props }) => {
|
|
17
18
|
const [, setQuery] = useQueryState(filterKey ?? "");
|
|
19
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
18
20
|
return /* @__PURE__ */ jsx(Button, {
|
|
19
21
|
ref,
|
|
20
22
|
variant: "segment",
|
|
21
23
|
size: "icon",
|
|
22
24
|
className,
|
|
25
|
+
"aria-label": t("remove", "Remove filter"),
|
|
23
26
|
onClick: () => void setQuery(null),
|
|
24
27
|
...props,
|
|
25
28
|
children: /* @__PURE__ */ jsx(IconX, {})
|
|
@@ -21,8 +21,10 @@ export type TListFilterField = {
|
|
|
21
21
|
}[];
|
|
22
22
|
/** Instead of the type's icon. */
|
|
23
23
|
icon?: ElementType;
|
|
24
|
-
/** The menu's heading it lists under; `fields` by default. */
|
|
25
|
-
group?: 'fields' | 'lead' | 'company' | 'activity' | 'custom';
|
|
24
|
+
/** The menu's heading it lists under; `fields` by default. `plugin`: under `groupLabel`. */
|
|
25
|
+
group?: 'fields' | 'lead' | 'company' | 'activity' | 'custom' | 'plugin';
|
|
26
|
+
/** The heading instead of the group's own: a plugin's title, for the fields it keeps. */
|
|
27
|
+
groupLabel?: string;
|
|
26
28
|
/** A `number` that is money: stored in this currency's smallest unit, typed in its major one. */
|
|
27
29
|
currency?: string;
|
|
28
30
|
};
|
|
@@ -49,10 +51,11 @@ export type TListFilterProps = TConditionLookups & {
|
|
|
49
51
|
recordType?: TPluginListType;
|
|
50
52
|
};
|
|
51
53
|
/**
|
|
52
|
-
* A list's filter bar,
|
|
53
|
-
* The
|
|
54
|
-
*
|
|
55
|
-
*
|
|
54
|
+
* A list's filter: a view bar button, and a chip row while it filters.
|
|
55
|
+
* The field picker opens on `F` and holds search and the advanced filter, a popover of
|
|
56
|
+
* "Where / And / Or" rows. Each chip is one condition whose field, operator and value open in
|
|
57
|
+
* place. The conditions and search live in the address (shared links and reloads keep them);
|
|
58
|
+
* `useListFilterParams()` reads them for the list's query. `member` fields pick
|
|
56
59
|
* from `members` and `tags` fields from `tags`: in erxes `memberQueries` from
|
|
57
60
|
* `@erxes/core-contract/client` and the tags query of the record type; outside erxes, the
|
|
58
61
|
* plugin's own.
|
|
@@ -66,4 +69,14 @@ export declare const ListFilter: ({ recordType, ...props }: TListFilterProps) =>
|
|
|
66
69
|
export declare const useListFilterParams: () => {
|
|
67
70
|
filter: string | undefined;
|
|
68
71
|
search: string | undefined;
|
|
69
|
-
};
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A list's empty state while `ListFilter` filters it, with Clear filters.
|
|
75
|
+
* "No customers match these filters" and a button that clears them; `fallback`, the list's own
|
|
76
|
+
* empty state, when it isn't filtered.
|
|
77
|
+
* `records` names them ("customers"); "records" by default.
|
|
78
|
+
*/
|
|
79
|
+
export declare const ListFilterEmpty: ({ records, fallback }: {
|
|
80
|
+
records?: string;
|
|
81
|
+
fallback?: ReactNode;
|
|
82
|
+
}) => string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null;
|
|
@@ -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 };
|