@erxes/ui 4.0.0-v2.8 → 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 +8 -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 +9 -2
- package/dist/index.js +9 -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/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/theme.css +2 -0
- package/package.json +2 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, lazy } from "react";
|
|
3
|
+
// src/modules/conditions/LazyConditionsEditor.tsx
|
|
4
|
+
const Editor = lazy(async () => ({ default: (await import("./ConditionsEditor.js")).ConditionsEditor }));
|
|
5
|
+
/**
|
|
6
|
+
* The condition editor, fetched the first time one renders: erxes-ui is one shared chunk every
|
|
7
|
+
* route loads, and only automations and a list's advanced filter edit conditions.
|
|
8
|
+
*/
|
|
9
|
+
const ConditionsEditor = (props) => /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Editor, { ...props }) });
|
|
10
|
+
export { ConditionsEditor };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TConditionField } from "./conditions.js";
|
|
2
|
+
/** A field from the catalog, or any path typed by hand (`event.payload.amount`, `steps.x.output.y`). */
|
|
3
|
+
export declare const PathPicker: ({ value, fields, onChange, disabled }: {
|
|
4
|
+
value: string;
|
|
5
|
+
fields: TConditionField[];
|
|
6
|
+
onChange: (path: string) => void;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Input } from "../../components/input.js";
|
|
2
|
+
import { Select } from "../../components/select.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
// src/modules/conditions/PathPicker.tsx
|
|
6
|
+
const GROUP_LABELS = {
|
|
7
|
+
fields: "Fields",
|
|
8
|
+
lead: "Lead",
|
|
9
|
+
custom: "Properties",
|
|
10
|
+
company: "Company",
|
|
11
|
+
activity: "Activity"
|
|
12
|
+
};
|
|
13
|
+
const CUSTOM_PATH = "__custom__";
|
|
14
|
+
const groupOf = (field) => field.group ?? "fields";
|
|
15
|
+
const FieldItems = ({ fields }) => fields.map((field) => /* @__PURE__ */ jsx(Select.Item, {
|
|
16
|
+
value: field.path,
|
|
17
|
+
children: field.label
|
|
18
|
+
}, field.path));
|
|
19
|
+
const GroupedFieldItems = ({ fields }) => {
|
|
20
|
+
const { t } = useTranslation("automations");
|
|
21
|
+
return [...new Set(fields.map(groupOf))].map((group) => /* @__PURE__ */ jsxs(Select.Group, { children: [/* @__PURE__ */ jsx(Select.Label, { children: t(`field-group.${group}`, GROUP_LABELS[group] ?? group) }), /* @__PURE__ */ jsx(FieldItems, { fields: fields.filter((field) => groupOf(field) === group) })] }, group));
|
|
22
|
+
};
|
|
23
|
+
/** A field from the catalog, or any path typed by hand (`event.payload.amount`, `steps.x.output.y`). */
|
|
24
|
+
const PathPicker = ({ value, fields, onChange, disabled }) => {
|
|
25
|
+
const { t } = useTranslation("automations");
|
|
26
|
+
const known = fields.some((field) => field.path === value);
|
|
27
|
+
const grouped = fields.some((field) => field.group);
|
|
28
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
29
|
+
className: "flex min-w-0 gap-1",
|
|
30
|
+
children: [/* @__PURE__ */ jsxs(Select, {
|
|
31
|
+
value: known ? value : CUSTOM_PATH,
|
|
32
|
+
onValueChange: (path) => onChange(path === CUSTOM_PATH ? "" : path),
|
|
33
|
+
disabled,
|
|
34
|
+
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
35
|
+
className: "h-8 w-full min-w-0",
|
|
36
|
+
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
37
|
+
}), /* @__PURE__ */ jsxs(Select.Content, { children: [grouped ? /* @__PURE__ */ jsx(GroupedFieldItems, { fields }) : /* @__PURE__ */ jsx(FieldItems, { fields }), !grouped && /* @__PURE__ */ jsx(Select.Item, {
|
|
38
|
+
value: CUSTOM_PATH,
|
|
39
|
+
children: t("custom-path", "Another value…")
|
|
40
|
+
})] })]
|
|
41
|
+
}), !known && /* @__PURE__ */ jsx(Input, {
|
|
42
|
+
text: "code",
|
|
43
|
+
className: "h-8 w-full min-w-0",
|
|
44
|
+
placeholder: "event.payload.amount",
|
|
45
|
+
value,
|
|
46
|
+
disabled,
|
|
47
|
+
onChange: (event) => onChange(event.target.value)
|
|
48
|
+
})]
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export { PathPicker };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TagsQuery } from "../pickers/LookupPicker.js";
|
|
2
|
+
import { MemberQueries } from "../pickers/members.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
export declare const CONDITION_OPERATORS: readonly ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'contains', 'not_contains', 'starts_with', 'in', 'not_in', 'exists', 'not_exists', 'within_last', 'more_than_ago', 'within_next', 'anniversary_within'];
|
|
5
|
+
export type TConditionOperator = (typeof CONDITION_OPERATORS)[number];
|
|
6
|
+
/** `all`: every condition holds; `any`: one does. */
|
|
7
|
+
declare const CONDITION_MATCHES: readonly ['all', 'any'];
|
|
8
|
+
/** The units of a relative date's `{ amount, unit }`. */
|
|
9
|
+
export declare const RELATIVE_UNITS: readonly ['days', 'weeks', 'months'];
|
|
10
|
+
export type TConditionRule = {
|
|
11
|
+
/** `subject.primaryEmail`, `event.payload.amount`, `steps.s2.output.id`. */
|
|
12
|
+
path: string;
|
|
13
|
+
op: TConditionOperator;
|
|
14
|
+
value?: unknown;
|
|
15
|
+
};
|
|
16
|
+
/** Rules (or nested groups) that must all, or any, hold. */
|
|
17
|
+
export type TConditionGroup = {
|
|
18
|
+
match: (typeof CONDITION_MATCHES)[number];
|
|
19
|
+
rules: (TConditionRule | TConditionGroup)[];
|
|
20
|
+
};
|
|
21
|
+
/** Parses a condition group from outside (the address); core checks the rest. */
|
|
22
|
+
export declare const ConditionGroup: z.ZodType<TConditionGroup, unknown, z.core.$ZodTypeInternals<TConditionGroup, unknown>>;
|
|
23
|
+
/** The value of a relative-date rule: "within the last 30 days". */
|
|
24
|
+
export declare const RelativeAmount: z.ZodObject<{
|
|
25
|
+
amount: z.ZodInt;
|
|
26
|
+
unit: z.ZodDefault<z.ZodEnum<{
|
|
27
|
+
days: "days";
|
|
28
|
+
months: "months";
|
|
29
|
+
weeks: "weeks";
|
|
30
|
+
}>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type RelativeAmount = z.infer<typeof RelativeAmount>;
|
|
33
|
+
/**
|
|
34
|
+
* A field conditions can use: a record's, or an earlier step's output. `group`: where it comes
|
|
35
|
+
* from, for grouping in the picker (a list's advanced filter).
|
|
36
|
+
*/
|
|
37
|
+
export type TConditionField = {
|
|
38
|
+
path: string;
|
|
39
|
+
label: string;
|
|
40
|
+
type: string;
|
|
41
|
+
options?: string[];
|
|
42
|
+
group?: string;
|
|
43
|
+
/** A money amount, stored in this currency's smallest unit and typed in its major unit. */
|
|
44
|
+
currency?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Where `member` and `tags` values pick from. In erxes: `memberQueries` from
|
|
48
|
+
* `@erxes/core-contract/client`, and web's tags query for the record type. Without one, the
|
|
49
|
+
* picker has nothing to offer.
|
|
50
|
+
*/
|
|
51
|
+
export type TConditionLookups = {
|
|
52
|
+
members?: MemberQueries;
|
|
53
|
+
tags?: TagsQuery;
|
|
54
|
+
};
|
|
55
|
+
export declare const OPERATOR_LABELS: Record<TConditionOperator, string>;
|
|
56
|
+
/** Operators that make sense for a field's type. */
|
|
57
|
+
export declare const operatorsFor: (type: string | undefined) => readonly ["eq", "neq"] | readonly ["contains", "not_contains", "exists", "not_exists"] | readonly ["eq", "neq", "in", "not_in", "exists", "not_exists"] | readonly ["eq", "neq", "gt", "gte", "lt", "lte", "exists", "not_exists"] | readonly ["within_last", "more_than_ago", "within_next", "anniversary_within", "eq", "gt", "lt", "exists", "not_exists"] | readonly ["eq", "neq", "gt", "gte", "lt", "lte", "contains", "not_contains", "starts_with", "in", "not_in", "exists", "not_exists", "within_last", "more_than_ago", "within_next", "anniversary_within"];
|
|
58
|
+
export declare const NO_VALUE: Set<string>;
|
|
59
|
+
export declare const RELATIVE: Set<string>;
|
|
60
|
+
export declare const LIST_VALUE: Set<string>;
|
|
61
|
+
export declare const isRule: (rule: TConditionRule | TConditionGroup) => rule is TConditionRule;
|
|
62
|
+
/** A relative date takes `{ amount, unit }`; switching to or from one resets the value. */
|
|
63
|
+
export declare const withOperator: (rule: TConditionRule, op: TConditionOperator) => TConditionRule;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// src/modules/conditions/conditions.ts
|
|
3
|
+
const CONDITION_OPERATORS = [
|
|
4
|
+
"eq",
|
|
5
|
+
"neq",
|
|
6
|
+
"gt",
|
|
7
|
+
"gte",
|
|
8
|
+
"lt",
|
|
9
|
+
"lte",
|
|
10
|
+
"contains",
|
|
11
|
+
"not_contains",
|
|
12
|
+
"starts_with",
|
|
13
|
+
"in",
|
|
14
|
+
"not_in",
|
|
15
|
+
"exists",
|
|
16
|
+
"not_exists",
|
|
17
|
+
"within_last",
|
|
18
|
+
"more_than_ago",
|
|
19
|
+
"within_next",
|
|
20
|
+
"anniversary_within"
|
|
21
|
+
];
|
|
22
|
+
/** `all`: every condition holds; `any`: one does. */
|
|
23
|
+
const CONDITION_MATCHES = ["all", "any"];
|
|
24
|
+
/** The units of a relative date's `{ amount, unit }`. */
|
|
25
|
+
const RELATIVE_UNITS = [
|
|
26
|
+
"days",
|
|
27
|
+
"weeks",
|
|
28
|
+
"months"
|
|
29
|
+
];
|
|
30
|
+
/** Core's limits, so a filter the UI accepts is one core's API accepts too. */
|
|
31
|
+
const MAX_RULES = 50;
|
|
32
|
+
const MAX_AMOUNT = 3650;
|
|
33
|
+
/** Groups nest as deep as the editor builds them: a group, and two levels inside it. */
|
|
34
|
+
const MAX_DEPTH = 3;
|
|
35
|
+
const ConditionRule = z.object({
|
|
36
|
+
path: z.string().trim().regex(/^(event|subject|steps|run)(\.[A-Za-z0-9_-]+)*$/),
|
|
37
|
+
op: z.enum(CONDITION_OPERATORS),
|
|
38
|
+
value: z.unknown().optional()
|
|
39
|
+
});
|
|
40
|
+
/** A group whose groups nest at most `depth` levels, so a crafted address can't recurse on. */
|
|
41
|
+
const groupOf = (depth) => z.object({
|
|
42
|
+
match: z.enum(CONDITION_MATCHES),
|
|
43
|
+
rules: z.array(depth > 1 ? z.union([ConditionRule, groupOf(depth - 1)]) : ConditionRule).max(MAX_RULES)
|
|
44
|
+
});
|
|
45
|
+
/** Parses a condition group from outside (the address); core checks the rest. */
|
|
46
|
+
const ConditionGroup = groupOf(MAX_DEPTH);
|
|
47
|
+
/** The value of a relative-date rule: "within the last 30 days". */
|
|
48
|
+
const RelativeAmount = z.object({
|
|
49
|
+
amount: z.int().min(0).max(MAX_AMOUNT),
|
|
50
|
+
unit: z.enum(RELATIVE_UNITS).default("days")
|
|
51
|
+
});
|
|
52
|
+
const OPERATOR_LABELS = {
|
|
53
|
+
eq: "is",
|
|
54
|
+
neq: "is not",
|
|
55
|
+
gt: "is greater than",
|
|
56
|
+
gte: "is at least",
|
|
57
|
+
lt: "is less than",
|
|
58
|
+
lte: "is at most",
|
|
59
|
+
contains: "contains",
|
|
60
|
+
not_contains: "doesn't contain",
|
|
61
|
+
starts_with: "starts with",
|
|
62
|
+
in: "is one of",
|
|
63
|
+
not_in: "is none of",
|
|
64
|
+
exists: "is set",
|
|
65
|
+
not_exists: "is empty",
|
|
66
|
+
within_last: "in the last",
|
|
67
|
+
more_than_ago: "more than … ago",
|
|
68
|
+
within_next: "in the next",
|
|
69
|
+
anniversary_within: "anniversary in the next"
|
|
70
|
+
};
|
|
71
|
+
/** Operators that make sense for a field's type. */
|
|
72
|
+
const operatorsFor = (type) => {
|
|
73
|
+
if (type === "date") return [
|
|
74
|
+
"within_last",
|
|
75
|
+
"more_than_ago",
|
|
76
|
+
"within_next",
|
|
77
|
+
"anniversary_within",
|
|
78
|
+
"eq",
|
|
79
|
+
"gt",
|
|
80
|
+
"lt",
|
|
81
|
+
"exists",
|
|
82
|
+
"not_exists"
|
|
83
|
+
];
|
|
84
|
+
if (type === "number") return [
|
|
85
|
+
"eq",
|
|
86
|
+
"neq",
|
|
87
|
+
"gt",
|
|
88
|
+
"gte",
|
|
89
|
+
"lt",
|
|
90
|
+
"lte",
|
|
91
|
+
"exists",
|
|
92
|
+
"not_exists"
|
|
93
|
+
];
|
|
94
|
+
if (type === "tags" || type === "list") return [
|
|
95
|
+
"contains",
|
|
96
|
+
"not_contains",
|
|
97
|
+
"exists",
|
|
98
|
+
"not_exists"
|
|
99
|
+
];
|
|
100
|
+
if (type === "boolean") return ["eq", "neq"];
|
|
101
|
+
if (type === "select" || type === "member") return [
|
|
102
|
+
"eq",
|
|
103
|
+
"neq",
|
|
104
|
+
"in",
|
|
105
|
+
"not_in",
|
|
106
|
+
"exists",
|
|
107
|
+
"not_exists"
|
|
108
|
+
];
|
|
109
|
+
return CONDITION_OPERATORS;
|
|
110
|
+
};
|
|
111
|
+
const NO_VALUE = /* @__PURE__ */ new Set(["exists", "not_exists"]);
|
|
112
|
+
const RELATIVE = /* @__PURE__ */ new Set([
|
|
113
|
+
"within_last",
|
|
114
|
+
"more_than_ago",
|
|
115
|
+
"within_next",
|
|
116
|
+
"anniversary_within"
|
|
117
|
+
]);
|
|
118
|
+
const LIST_VALUE = /* @__PURE__ */ new Set(["in", "not_in"]);
|
|
119
|
+
const isRule = (rule) => !("match" in rule);
|
|
120
|
+
/** A relative date takes `{ amount, unit }`; switching to or from one resets the value. */
|
|
121
|
+
const withOperator = (rule, op) => {
|
|
122
|
+
if (RELATIVE.has(op) === RELATIVE.has(rule.op)) return {
|
|
123
|
+
...rule,
|
|
124
|
+
op
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
...rule,
|
|
128
|
+
op,
|
|
129
|
+
value: RELATIVE.has(op) ? {
|
|
130
|
+
amount: 30,
|
|
131
|
+
unit: "days"
|
|
132
|
+
} : void 0
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
export { CONDITION_OPERATORS, ConditionGroup, LIST_VALUE, NO_VALUE, OPERATOR_LABELS, RELATIVE, RELATIVE_UNITS, RelativeAmount, isRule, operatorsFor, withOperator };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { TConditionLookups } from "../conditions/conditions.js";
|
|
1
2
|
import { ElementType, ReactNode } from "react";
|
|
2
|
-
/** A field a
|
|
3
|
+
/** A field a list filters by, as its menu, chip and the advanced filter show it. */
|
|
3
4
|
export type TListFilterField = {
|
|
4
5
|
/** The rules' `path` in the filter the list's API gets: `subject.<column>`, e.g. `subject.stageId`. */
|
|
5
|
-
path:
|
|
6
|
+
path: string;
|
|
6
7
|
label: string;
|
|
7
|
-
/**
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* How it compares: contains (text), ranges (number), relative dates, yes/no, a pick from
|
|
10
|
+
* `options`, a team member (from `members`), a tag (from `tags`).
|
|
11
|
+
*/
|
|
12
|
+
type: 'text' | 'number' | 'date' | 'boolean' | 'select' | 'member' | 'tags';
|
|
9
13
|
/** A `select`'s choices. */
|
|
10
14
|
options?: {
|
|
11
15
|
value: string;
|
|
@@ -13,8 +17,12 @@ export type TListFilterField = {
|
|
|
13
17
|
}[];
|
|
14
18
|
/** Instead of the type's icon. */
|
|
15
19
|
icon?: ElementType;
|
|
20
|
+
/** The menu's heading it lists under; `fields` by default. */
|
|
21
|
+
group?: 'fields' | 'lead' | 'company' | 'activity' | 'custom';
|
|
22
|
+
/** A `number` that is money: stored in this currency's smallest unit, typed in its major one. */
|
|
23
|
+
currency?: string;
|
|
16
24
|
};
|
|
17
|
-
export type TListFilterProps = {
|
|
25
|
+
export type TListFilterProps = TConditionLookups & {
|
|
18
26
|
/** Unique per list, e.g. `sales-deals`: its menu's hotkey scope. */
|
|
19
27
|
id: string;
|
|
20
28
|
fields: TListFilterField[];
|
|
@@ -24,15 +32,21 @@ export type TListFilterProps = {
|
|
|
24
32
|
totalCapped?: boolean;
|
|
25
33
|
/** The list's own controls, before the menu: `DisplayMenu`, an Archived toggle. */
|
|
26
34
|
children?: ReactNode;
|
|
35
|
+
/** While `fields` load, and why they didn't; the menu says so. */
|
|
36
|
+
loading?: boolean;
|
|
37
|
+
error?: Error | null;
|
|
38
|
+
/** Beside the chips, before the count: what a saved view changed. */
|
|
39
|
+
status?: ReactNode;
|
|
27
40
|
};
|
|
28
|
-
/** Web registers core's filter bar. */
|
|
29
|
-
export declare const setListFilter: (component: import("react").ComponentType<TListFilterProps> | null) => void;
|
|
30
41
|
/**
|
|
31
|
-
* A
|
|
32
|
-
*
|
|
33
|
-
*
|
|
42
|
+
* A list's filter bar: the menu of `fields` (`F`), search, the advanced filter, and each
|
|
43
|
+
* condition as a chip. The conditions and search live in the address (shared links and reloads
|
|
44
|
+
* keep them); `useListFilterParams()` reads them for the list's query. `member` fields pick
|
|
45
|
+
* from `members` and `tags` fields from `tags`: in erxes `memberQueries` from
|
|
46
|
+
* `@erxes/core-contract/client` and the tags query of the record type; outside erxes, the
|
|
47
|
+
* plugin's own.
|
|
34
48
|
*/
|
|
35
|
-
export declare const ListFilter: (props: TListFilterProps) => import("react").JSX.Element
|
|
49
|
+
export declare const ListFilter: (props: TListFilterProps) => import("react").JSX.Element;
|
|
36
50
|
/**
|
|
37
51
|
* What `ListFilter` holds, for the list's API: `filter`, core's condition group
|
|
38
52
|
* (`ConditionGroup` from `@erxes/core-contract`) as JSON, its rules on the fields' paths,
|
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Filter } from "../filter/components/Filter.js";
|
|
2
|
+
import { useListConditions } from "./filter/listFilterQuery.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Suspense, lazy } from "react";
|
|
5
|
+
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
|
4
6
|
// src/modules/list/ListFilter.tsx
|
|
5
|
-
const listFilter = hostComponent();
|
|
6
|
-
/** Web registers core's filter bar. */
|
|
7
|
-
const setListFilter = listFilter.set;
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* links and reloads keep them); `useListFilterParams()` reads them for the list's query.
|
|
8
|
+
* The bar, fetched the first time a list renders one: erxes-ui is one shared chunk every route
|
|
9
|
+
* loads, and the bar with its condition editor is too much of it for pages without a list.
|
|
12
10
|
*/
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
const ListFilterBar = lazy(async () => ({ default: (await import("./filter/ListFilterBar.js")).ListFilterBar }));
|
|
12
|
+
/**
|
|
13
|
+
* A list's filter bar: the menu of `fields` (`F`), search, the advanced filter, and each
|
|
14
|
+
* condition as a chip. The conditions and search live in the address (shared links and reloads
|
|
15
|
+
* keep them); `useListFilterParams()` reads them for the list's query. `member` fields pick
|
|
16
|
+
* from `members` and `tags` fields from `tags`: in erxes `memberQueries` from
|
|
17
|
+
* `@erxes/core-contract/client` and the tags query of the record type; outside erxes, the
|
|
18
|
+
* plugin's own.
|
|
19
|
+
*/
|
|
20
|
+
const ListFilter = (props) => {
|
|
21
|
+
const [barRef] = useAutoAnimate({ duration: 150 });
|
|
22
|
+
return /* @__PURE__ */ jsx(Filter, {
|
|
23
|
+
id: `${props.id}-list-filter`,
|
|
24
|
+
children: /* @__PURE__ */ jsx(Filter.Bar, {
|
|
25
|
+
ref: barRef,
|
|
26
|
+
className: "min-w-0 flex-nowrap justify-end",
|
|
27
|
+
children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(ListFilterBar, { ...props }) })
|
|
28
|
+
})
|
|
29
|
+
});
|
|
23
30
|
};
|
|
24
31
|
/**
|
|
25
32
|
* What `ListFilter` holds, for the list's API: `filter`, core's condition group
|
|
@@ -27,13 +34,10 @@ const filterText = (text) => {
|
|
|
27
34
|
* and `search`. Both are undefined when unset.
|
|
28
35
|
*/
|
|
29
36
|
const useListFilterParams = () => {
|
|
30
|
-
const
|
|
31
|
-
advanced: parseAsString,
|
|
32
|
-
searchValue: parseAsString
|
|
33
|
-
});
|
|
37
|
+
const { advanced, search } = useListConditions();
|
|
34
38
|
return {
|
|
35
|
-
filter:
|
|
36
|
-
search:
|
|
39
|
+
filter: advanced ? JSON.stringify(advanced) : void 0,
|
|
40
|
+
search: search || void 0
|
|
37
41
|
};
|
|
38
42
|
};
|
|
39
|
-
export { ListFilter,
|
|
43
|
+
export { ListFilter, useListFilterParams };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Button } from "../../../components/button.js";
|
|
2
|
+
import { Dialog } from "../../../components/dialog.js";
|
|
3
|
+
import { ConditionsEditor } from "../../conditions/ConditionsEditor.js";
|
|
4
|
+
import { useListFilter } from "./listFilterContext.js";
|
|
5
|
+
import { useListConditions } from "./listFilterQuery.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { useTranslation } from "react-i18next";
|
|
9
|
+
// src/modules/list/filter/AdvancedFilterDialog.tsx
|
|
10
|
+
/** Mounted each time the dialog opens, so the draft starts from the list's filter. */
|
|
11
|
+
const AdvancedFilterForm = ({ onDone }) => {
|
|
12
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
13
|
+
const { fields, lookups } = useListFilter();
|
|
14
|
+
const { advanced, setAdvanced } = useListConditions();
|
|
15
|
+
const [draft, setDraft] = useState(advanced);
|
|
16
|
+
const apply = (next) => {
|
|
17
|
+
setAdvanced(next);
|
|
18
|
+
onDone();
|
|
19
|
+
};
|
|
20
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ConditionsEditor, {
|
|
21
|
+
fields: fields.map(({ options, ...field }) => ({
|
|
22
|
+
...field,
|
|
23
|
+
options: options?.map((option) => option.value)
|
|
24
|
+
})),
|
|
25
|
+
...lookups,
|
|
26
|
+
value: draft ?? void 0,
|
|
27
|
+
onChange: (next) => setDraft(next ?? null)
|
|
28
|
+
}), /* @__PURE__ */ jsxs(Dialog.Footer, { children: [/* @__PURE__ */ jsx(Button, {
|
|
29
|
+
variant: "ghost",
|
|
30
|
+
onClick: () => apply(null),
|
|
31
|
+
children: t("clear", "Clear")
|
|
32
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
33
|
+
onClick: () => apply(draft),
|
|
34
|
+
children: t("apply", "Apply")
|
|
35
|
+
})] })] });
|
|
36
|
+
};
|
|
37
|
+
/** The full builder (every field, and/or groups), for what the filter menu can't say. */
|
|
38
|
+
const AdvancedFilterDialog = ({ open, onOpenChange }) => {
|
|
39
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
40
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
41
|
+
open,
|
|
42
|
+
onOpenChange,
|
|
43
|
+
children: /* @__PURE__ */ jsxs(Dialog.Content, {
|
|
44
|
+
className: "sm:max-w-3xl",
|
|
45
|
+
children: [/* @__PURE__ */ jsx(Dialog.HeaderCombined, {
|
|
46
|
+
title: t("advanced", "Advanced filter"),
|
|
47
|
+
description: t("advanced-title", "Show records where")
|
|
48
|
+
}), /* @__PURE__ */ jsx(AdvancedFilterForm, { onDone: () => onOpenChange(false) })]
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export { AdvancedFilterDialog };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Button } from "../../../components/button.js";
|
|
2
|
+
import { Combobox } from "../../../components/combobox.js";
|
|
3
|
+
import { Command } from "../../../components/command.js";
|
|
4
|
+
import { Input } from "../../../components/input.js";
|
|
5
|
+
import { Select } from "../../../components/select.js";
|
|
6
|
+
import { amountStep, fromAmountInput, toAmountInput } from "../../../lib/money.js";
|
|
7
|
+
import { oneOf, textOf } from "../../../lib/text.js";
|
|
8
|
+
import { isRule } from "../../conditions/conditions.js";
|
|
9
|
+
import { useFilterContext } from "../../filter/hooks/useFilterContext.js";
|
|
10
|
+
import { EntityPicker } from "../../pickers/EntityPicker.js";
|
|
11
|
+
import { DATE_PRESETS, NUMBER_OPS, NUMBER_SYMBOLS, anyOf, presetOf, targetOf, valuesOf } from "./filterRules.js";
|
|
12
|
+
import { useFieldOptions, useListFilter } from "./listFilterContext.js";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { useEffect, useRef, useState } from "react";
|
|
15
|
+
import { useTranslation } from "react-i18next";
|
|
16
|
+
// src/modules/list/filter/FieldMenus.tsx
|
|
17
|
+
/** The part this field's menu changes, and that part when it is a rule of the field. */
|
|
18
|
+
const useTarget = (field) => {
|
|
19
|
+
const { parts, setPart, editing } = useListFilter();
|
|
20
|
+
const { resetFilterState } = useFilterContext();
|
|
21
|
+
const index = targetOf(parts, field, editing);
|
|
22
|
+
const part = index === null ? void 0 : parts[index];
|
|
23
|
+
return {
|
|
24
|
+
rule: part && isRule(part) && part.path === field.path ? part : void 0,
|
|
25
|
+
set: (next) => setPart(index, next),
|
|
26
|
+
/** Sets the rule and closes the menu. */
|
|
27
|
+
apply: (next) => {
|
|
28
|
+
setPart(index, next);
|
|
29
|
+
resetFilterState();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** A submenu's box takes the keyboard as the submenu opens. */
|
|
34
|
+
const useFocusOnMount = () => {
|
|
35
|
+
const input = useRef(null);
|
|
36
|
+
useEffect(() => input.current?.focus(), []);
|
|
37
|
+
return input;
|
|
38
|
+
};
|
|
39
|
+
/** Options (a choice, members, tags): each pick adds to or takes from one "is any of" rule; the menu stays open. */
|
|
40
|
+
const OptionsMenu = ({ field }) => {
|
|
41
|
+
const { options, loading, error } = useFieldOptions(field);
|
|
42
|
+
const { rule, set } = useTarget(field);
|
|
43
|
+
return /* @__PURE__ */ jsx(EntityPicker, {
|
|
44
|
+
multiple: true,
|
|
45
|
+
items: options,
|
|
46
|
+
itemKey: (option) => ({
|
|
47
|
+
id: option.value,
|
|
48
|
+
label: option.label
|
|
49
|
+
}),
|
|
50
|
+
value: valuesOf(rule),
|
|
51
|
+
onValueChange: (values) => set(anyOf(field.path, values)),
|
|
52
|
+
loading,
|
|
53
|
+
error,
|
|
54
|
+
searchPlaceholder: field.label
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const DateMenu = ({ field }) => {
|
|
58
|
+
const { t } = useTranslation("views", { keyPrefix: "filter.date" });
|
|
59
|
+
const { rule, apply } = useTarget(field);
|
|
60
|
+
const current = presetOf(rule);
|
|
61
|
+
return /* @__PURE__ */ jsx(Command, { children: /* @__PURE__ */ jsx(Command.List, { children: DATE_PRESETS.map((preset) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
62
|
+
value: preset.key,
|
|
63
|
+
onSelect: () => apply({
|
|
64
|
+
path: field.path,
|
|
65
|
+
op: preset.op,
|
|
66
|
+
value: preset.value
|
|
67
|
+
}),
|
|
68
|
+
children: [t(preset.key, preset.label), /* @__PURE__ */ jsx(Combobox.Check, { checked: current?.key === preset.key })]
|
|
69
|
+
}, preset.key)) }) });
|
|
70
|
+
};
|
|
71
|
+
const BooleanMenu = ({ field }) => {
|
|
72
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
73
|
+
const { rule, apply } = useTarget(field);
|
|
74
|
+
const value = rule ? textOf(rule.value) : null;
|
|
75
|
+
return /* @__PURE__ */ jsx(Command, { children: /* @__PURE__ */ jsx(Command.List, { children: ["true", "false"].map((option) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
76
|
+
value: option,
|
|
77
|
+
onSelect: () => apply({
|
|
78
|
+
path: field.path,
|
|
79
|
+
op: "eq",
|
|
80
|
+
value: option === "true"
|
|
81
|
+
}),
|
|
82
|
+
children: [option === "true" ? t("yes", "Yes") : t("no", "No"), /* @__PURE__ */ jsx(Combobox.Check, { checked: value === option })]
|
|
83
|
+
}, option)) }) });
|
|
84
|
+
};
|
|
85
|
+
/** A number as typed: money in the currency's major unit. */
|
|
86
|
+
const numberText = (value, currency) => {
|
|
87
|
+
const n = Number(value);
|
|
88
|
+
if (value === void 0 || value === null || !Number.isFinite(n)) return "";
|
|
89
|
+
return currency ? toAmountInput(n, currency) : String(n);
|
|
90
|
+
};
|
|
91
|
+
/** An operator and a value; Enter or Apply adds the rule (or changes the one being edited). */
|
|
92
|
+
const NumberMenu = ({ field }) => {
|
|
93
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
94
|
+
const { rule, apply } = useTarget(field);
|
|
95
|
+
const [op, setOp] = useState(() => oneOf(NUMBER_OPS, rule?.op ?? null) ?? "gte");
|
|
96
|
+
const [text, setText] = useState(() => numberText(rule?.value, field.currency));
|
|
97
|
+
const valid = text.trim() !== "" && Number.isFinite(Number(text));
|
|
98
|
+
const input = useFocusOnMount();
|
|
99
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
100
|
+
className: "flex items-center gap-1.5 p-2",
|
|
101
|
+
onSubmit: (event) => {
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
if (!valid) return;
|
|
104
|
+
const value = field.currency ? fromAmountInput(text, field.currency) : Number(text);
|
|
105
|
+
apply({
|
|
106
|
+
path: field.path,
|
|
107
|
+
op,
|
|
108
|
+
value
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
children: [
|
|
112
|
+
/* @__PURE__ */ jsxs(Select, {
|
|
113
|
+
value: op,
|
|
114
|
+
onValueChange: (next) => setOp(oneOf(NUMBER_OPS, next) ?? op),
|
|
115
|
+
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
116
|
+
className: "h-8 w-16 shrink-0",
|
|
117
|
+
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
118
|
+
}), /* @__PURE__ */ jsx(Select.Content, { children: NUMBER_OPS.map((option) => /* @__PURE__ */ jsx(Select.Item, {
|
|
119
|
+
value: option,
|
|
120
|
+
children: NUMBER_SYMBOLS[option]
|
|
121
|
+
}, option)) })]
|
|
122
|
+
}),
|
|
123
|
+
/* @__PURE__ */ jsx(Input, {
|
|
124
|
+
ref: input,
|
|
125
|
+
type: "number",
|
|
126
|
+
className: "h-8 min-w-0 flex-1",
|
|
127
|
+
step: field.currency ? amountStep(field.currency) : "any",
|
|
128
|
+
placeholder: field.currency ?? t("value", "Value"),
|
|
129
|
+
value: text,
|
|
130
|
+
onChange: (event) => setText(event.target.value)
|
|
131
|
+
}),
|
|
132
|
+
/* @__PURE__ */ jsx(Button, {
|
|
133
|
+
type: "submit",
|
|
134
|
+
size: "sm",
|
|
135
|
+
className: "h-8",
|
|
136
|
+
disabled: !valid,
|
|
137
|
+
children: t("apply", "Apply")
|
|
138
|
+
})
|
|
139
|
+
]
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
/** "Contains" text; an empty box removes the rule being edited. */
|
|
143
|
+
const TextMenu = ({ field }) => {
|
|
144
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
145
|
+
const { rule, apply } = useTarget(field);
|
|
146
|
+
const [text, setText] = useState(() => textOf(rule?.value));
|
|
147
|
+
const input = useFocusOnMount();
|
|
148
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
149
|
+
className: "flex items-center gap-1.5 p-2",
|
|
150
|
+
onSubmit: (event) => {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
apply(text.trim() ? {
|
|
153
|
+
path: field.path,
|
|
154
|
+
op: "contains",
|
|
155
|
+
value: text.trim()
|
|
156
|
+
} : null);
|
|
157
|
+
},
|
|
158
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
159
|
+
ref: input,
|
|
160
|
+
className: "h-8 min-w-0 flex-1",
|
|
161
|
+
placeholder: t("contains", "Contains…"),
|
|
162
|
+
value: text,
|
|
163
|
+
onChange: (event) => setText(event.target.value)
|
|
164
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
165
|
+
type: "submit",
|
|
166
|
+
size: "sm",
|
|
167
|
+
className: "h-8",
|
|
168
|
+
children: t("apply", "Apply")
|
|
169
|
+
})]
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
/** A field's submenu, by its type. */
|
|
173
|
+
const FieldMenu = ({ field }) => {
|
|
174
|
+
switch (field.type) {
|
|
175
|
+
case "select":
|
|
176
|
+
case "member":
|
|
177
|
+
case "tags": return /* @__PURE__ */ jsx(OptionsMenu, { field });
|
|
178
|
+
case "date": return /* @__PURE__ */ jsx(DateMenu, { field });
|
|
179
|
+
case "boolean": return /* @__PURE__ */ jsx(BooleanMenu, { field });
|
|
180
|
+
case "number": return /* @__PURE__ */ jsx(NumberMenu, { field });
|
|
181
|
+
case "text": return /* @__PURE__ */ jsx(TextMenu, { field });
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
export { FieldMenu };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TListFilterProps } from "../ListFilter.js";
|
|
2
|
+
/**
|
|
3
|
+
* Inside `<Filter>`: its chips, the list's status and the count, then the list's controls
|
|
4
|
+
* and the menu (`F`).
|
|
5
|
+
*/
|
|
6
|
+
export declare const ListFilterBar: ({ id, fields, loading, error, status, totalCount, totalCapped, children, members, tags }: TListFilterProps) => import("react").JSX.Element;
|