@erxes/ui 4.0.0-v2.13 → 4.0.0-v2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CATALOG.md +3 -2
- package/README.md +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/modules/conditions/ConditionsEditor.d.ts +5 -3
- package/dist/modules/conditions/ConditionsEditor.js +139 -177
- package/dist/modules/conditions/DateEditors.d.ts +8 -0
- package/dist/modules/conditions/DateEditors.js +188 -0
- package/dist/modules/conditions/FieldPicker.d.ts +17 -0
- package/dist/modules/conditions/FieldPicker.js +99 -0
- package/dist/modules/conditions/RuleParts.d.ts +30 -0
- package/dist/modules/conditions/RuleParts.js +78 -0
- package/dist/modules/conditions/RuleRow.d.ts +27 -0
- package/dist/modules/conditions/RuleRow.js +156 -0
- package/dist/modules/conditions/TypedInput.d.ts +13 -0
- package/dist/modules/conditions/TypedInput.js +36 -0
- package/dist/modules/conditions/ValueEditor.d.ts +18 -0
- package/dist/modules/conditions/ValueEditor.js +164 -0
- package/dist/modules/conditions/conditions.d.ts +14 -9
- package/dist/modules/conditions/conditions.js +1 -75
- package/dist/modules/conditions/fieldIcons.d.ts +6 -0
- package/dist/modules/conditions/fieldIcons.js +19 -0
- package/dist/modules/conditions/fieldOptions.d.ts +13 -0
- package/dist/modules/conditions/fieldOptions.js +26 -0
- package/dist/modules/conditions/filterRule.d.ts +45 -0
- package/dist/modules/conditions/filterRule.js +169 -0
- package/dist/modules/conditions/filterText.d.ts +16 -0
- package/dist/modules/conditions/filterText.js +156 -0
- package/dist/modules/filter/components/Filter.d.ts +1 -1
- package/dist/modules/filter/components/Filter.js +1 -1
- package/dist/modules/list/ListFilter.d.ts +16 -5
- package/dist/modules/list/ListFilter.js +50 -17
- package/dist/modules/list/ViewBar.d.ts +2 -0
- package/dist/modules/list/ViewBar.js +21 -10
- package/dist/modules/list/filter/AddFilter.d.ts +10 -0
- package/dist/modules/list/filter/AddFilter.js +140 -0
- package/dist/modules/list/filter/AdvancedPopover.d.ts +8 -0
- package/dist/modules/list/filter/AdvancedPopover.js +103 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +3 -3
- package/dist/modules/list/filter/ListFilterBar.js +104 -205
- package/dist/modules/list/filter/RuleChips.d.ts +12 -2
- package/dist/modules/list/filter/RuleChips.js +132 -134
- package/dist/modules/list/filter/SearchChip.d.ts +6 -0
- package/dist/modules/list/filter/SearchChip.js +69 -0
- package/dist/modules/list/filter/filterRules.d.ts +15 -40
- package/dist/modules/list/filter/filterRules.js +27 -156
- package/dist/modules/list/filter/listFilterContext.d.ts +25 -18
- package/dist/modules/list/filter/listFilterContext.js +8 -24
- package/dist/modules/list/filter/listFilterQuery.d.ts +4 -0
- package/dist/modules/list/filter/listFilterQuery.js +10 -2
- package/dist/theme.css +3 -2
- package/exports.txt +1 -0
- package/package.json +1 -1
- package/dist/modules/conditions/ConditionValueInput.d.ts +0 -10
- package/dist/modules/conditions/ConditionValueInput.js +0 -166
- package/dist/modules/conditions/PathPicker.d.ts +0 -8
- package/dist/modules/conditions/PathPicker.js +0 -56
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +0 -5
- package/dist/modules/list/filter/AdvancedFilterDialog.js +0 -52
- package/dist/modules/list/filter/FieldMenus.d.ts +0 -5
- package/dist/modules/list/filter/FieldMenus.js +0 -184
- package/dist/modules/list/filter/fieldIcons.d.ts +0 -7
- package/dist/modules/list/filter/fieldIcons.js +0 -16
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TagsQuery } from "../pickers/LookupPicker.js";
|
|
2
2
|
import { MemberQueries } from "../pickers/members.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
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
6
|
export type TConditionOperator = (typeof CONDITION_OPERATORS)[number];
|
|
@@ -31,18 +32,27 @@ export declare const RelativeAmount: z.ZodObject<{
|
|
|
31
32
|
}>>;
|
|
32
33
|
}, z.core.$strip>;
|
|
33
34
|
export type RelativeAmount = z.infer<typeof RelativeAmount>;
|
|
35
|
+
/** A choice of a `select` field: what the rule holds, and what the picker shows. */
|
|
36
|
+
export type TFieldOption = {
|
|
37
|
+
value: string;
|
|
38
|
+
label: string;
|
|
39
|
+
};
|
|
34
40
|
/**
|
|
35
|
-
* A field conditions can use: a record's, or an earlier step's output.
|
|
36
|
-
*
|
|
41
|
+
* A field conditions can use: a record's, or an earlier step's output. The picker lists fields
|
|
42
|
+
* under their `group`'s heading: `groupLabel` when the field brings one (a plugin's name), else
|
|
43
|
+
* the group's own name.
|
|
37
44
|
*/
|
|
38
45
|
export type TConditionField = {
|
|
39
46
|
path: string;
|
|
40
47
|
label: string;
|
|
41
48
|
type: string;
|
|
42
|
-
|
|
49
|
+
/** A `select`'s choices. */
|
|
50
|
+
options?: TFieldOption[];
|
|
43
51
|
group?: string;
|
|
44
|
-
/** The heading
|
|
52
|
+
/** The heading of the field's group, instead of the group's own name. */
|
|
45
53
|
groupLabel?: string;
|
|
54
|
+
/** Instead of the type's icon. */
|
|
55
|
+
icon?: ElementType;
|
|
46
56
|
/** A money amount, stored in this currency's smallest unit and typed in its major unit. */
|
|
47
57
|
currency?: string;
|
|
48
58
|
};
|
|
@@ -55,14 +65,9 @@ export type TConditionLookups = {
|
|
|
55
65
|
members?: MemberQueries;
|
|
56
66
|
tags?: TagsQuery;
|
|
57
67
|
};
|
|
58
|
-
export declare const OPERATOR_LABELS: Record<TConditionOperator, string>;
|
|
59
|
-
/** Operators that make sense for a field's type. */
|
|
60
|
-
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"];
|
|
61
68
|
export declare const NO_VALUE: Set<string>;
|
|
62
69
|
export declare const RELATIVE: Set<string>;
|
|
63
70
|
export declare const LIST_VALUE: Set<string>;
|
|
64
71
|
/** Whether a condition entry is a rule rather than a nested group. */
|
|
65
72
|
export declare const isRule: (rule: TConditionRule | TConditionGroup) => rule is TConditionRule;
|
|
66
|
-
/** A relative date takes `{ amount, unit }`; switching to or from one resets the value. */
|
|
67
|
-
export declare const withOperator: (rule: TConditionRule, op: TConditionOperator) => TConditionRule;
|
|
68
73
|
export {};
|
|
@@ -49,65 +49,6 @@ const RelativeAmount = z.object({
|
|
|
49
49
|
amount: z.int().min(0).max(MAX_AMOUNT),
|
|
50
50
|
unit: z.enum(RELATIVE_UNITS).default("days")
|
|
51
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
52
|
const NO_VALUE = /* @__PURE__ */ new Set(["exists", "not_exists"]);
|
|
112
53
|
const RELATIVE = /* @__PURE__ */ new Set([
|
|
113
54
|
"within_last",
|
|
@@ -118,19 +59,4 @@ const RELATIVE = /* @__PURE__ */ new Set([
|
|
|
118
59
|
const LIST_VALUE = /* @__PURE__ */ new Set(["in", "not_in"]);
|
|
119
60
|
/** Whether a condition entry is a rule rather than a nested group. */
|
|
120
61
|
const isRule = (rule) => !("match" in rule);
|
|
121
|
-
|
|
122
|
-
const withOperator = (rule, op) => {
|
|
123
|
-
if (RELATIVE.has(op) === RELATIVE.has(rule.op)) return {
|
|
124
|
-
...rule,
|
|
125
|
-
op
|
|
126
|
-
};
|
|
127
|
-
return {
|
|
128
|
-
...rule,
|
|
129
|
-
op,
|
|
130
|
-
value: RELATIVE.has(op) ? {
|
|
131
|
-
amount: 30,
|
|
132
|
-
unit: "days"
|
|
133
|
-
} : void 0
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
export { CONDITION_OPERATORS, ConditionGroup, LIST_VALUE, NO_VALUE, OPERATOR_LABELS, RELATIVE, RELATIVE_UNITS, RelativeAmount, isRule, operatorsFor, withOperator };
|
|
62
|
+
export { CONDITION_OPERATORS, ConditionGroup, LIST_VALUE, NO_VALUE, RELATIVE, RELATIVE_UNITS, RelativeAmount, isRule };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TConditionField } from "./conditions.js";
|
|
2
|
+
/** A field's icon in the pickers and on its chips: its own, else its type's. */
|
|
3
|
+
export declare const FieldIcon: ({ field, className }: {
|
|
4
|
+
field: Pick<TConditionField, 'type' | 'icon'>;
|
|
5
|
+
className?: string;
|
|
6
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IconCalendar, IconHash, IconLetterCase, IconList, IconSelector, IconTags, IconToggleLeft, IconUser } from "@tabler/icons-react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/modules/conditions/fieldIcons.tsx
|
|
4
|
+
const FIELD_ICONS = {
|
|
5
|
+
text: IconLetterCase,
|
|
6
|
+
number: IconHash,
|
|
7
|
+
date: IconCalendar,
|
|
8
|
+
boolean: IconToggleLeft,
|
|
9
|
+
select: IconSelector,
|
|
10
|
+
member: IconUser,
|
|
11
|
+
tags: IconTags,
|
|
12
|
+
list: IconList
|
|
13
|
+
};
|
|
14
|
+
/** A field's icon in the pickers and on its chips: its own, else its type's. */
|
|
15
|
+
const FieldIcon = ({ field, className }) => {
|
|
16
|
+
const Icon = field.icon ?? FIELD_ICONS[field.type] ?? IconLetterCase;
|
|
17
|
+
return /* @__PURE__ */ jsx(Icon, { className });
|
|
18
|
+
};
|
|
19
|
+
export { FieldIcon };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TConditionField, TConditionLookups } from "./conditions.js";
|
|
2
|
+
/**
|
|
3
|
+
* What a choice field picks from, with labels: its `options`, the team ("Me" first), or the
|
|
4
|
+
* record type's tags. `picked` are the ids a rule holds, so a member who left still has a name.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useFieldOptions: (field: TConditionField | undefined, lookups: TConditionLookups, picked?: readonly string[]) => {
|
|
7
|
+
options: {
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
}[];
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useMemberOptions, useTagOptions } from "../pickers/LookupPicker.js";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
// src/modules/conditions/fieldOptions.ts
|
|
4
|
+
/**
|
|
5
|
+
* What a choice field picks from, with labels: its `options`, the team ("Me" first), or the
|
|
6
|
+
* record type's tags. `picked` are the ids a rule holds, so a member who left still has a name.
|
|
7
|
+
*/
|
|
8
|
+
const useFieldOptions = (field, lookups, picked = []) => {
|
|
9
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
10
|
+
const members = useMemberOptions(lookups.members, field?.type === "member", picked);
|
|
11
|
+
const tags = useTagOptions(lookups.tags, field?.type === "tags");
|
|
12
|
+
if (field?.type === "member") return {
|
|
13
|
+
...members,
|
|
14
|
+
options: [{
|
|
15
|
+
value: "me",
|
|
16
|
+
label: t("me", "Me")
|
|
17
|
+
}, ...members.options]
|
|
18
|
+
};
|
|
19
|
+
if (field?.type === "tags") return tags;
|
|
20
|
+
return {
|
|
21
|
+
options: field?.options ?? [],
|
|
22
|
+
loading: false,
|
|
23
|
+
error: null
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export { useFieldOptions };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TConditionField, TConditionGroup, TConditionOperator, TConditionRule } from "./conditions.js";
|
|
2
|
+
/**
|
|
3
|
+
* "Between" isn't an operator of core's: it is a group of "at least" and "at most" on one field,
|
|
4
|
+
* which every reader of conditions (core's lists, automations, a plugin's API) already takes.
|
|
5
|
+
* The editors show such a group as one rule.
|
|
6
|
+
*/
|
|
7
|
+
export type TBetween = TConditionGroup & {
|
|
8
|
+
match: 'all';
|
|
9
|
+
rules: [TConditionRule & {
|
|
10
|
+
op: 'gte';
|
|
11
|
+
}, TConditionRule & {
|
|
12
|
+
op: 'lte';
|
|
13
|
+
}];
|
|
14
|
+
};
|
|
15
|
+
/** A rule as the editors show one: a rule, or a "between" group. */
|
|
16
|
+
export type TFilterRule = TConditionRule | TBetween;
|
|
17
|
+
/** The operators the editors offer: core's, and "between". */
|
|
18
|
+
export type TFilterOperator = TConditionOperator | 'between';
|
|
19
|
+
export declare const isFilterRule: (node: TConditionRule | TConditionGroup) => node is TFilterRule;
|
|
20
|
+
export declare const pathOf: (rule: TFilterRule) => string;
|
|
21
|
+
export declare const opOf: (rule: TFilterRule) => TFilterOperator;
|
|
22
|
+
export declare const between: (path: string, from: unknown, to: unknown) => TBetween;
|
|
23
|
+
/** The operators that fit a field's type, in the order the menus list them. */
|
|
24
|
+
export declare const operatorsFor: (type: string | undefined) => readonly TFilterOperator[];
|
|
25
|
+
/** A new rule on `field`: its type's first operator, no value yet. */
|
|
26
|
+
export declare const ruleFor: (field: Pick<TConditionField, 'path' | 'type'>) => TFilterRule;
|
|
27
|
+
/** "Between"'s two values. */
|
|
28
|
+
export declare const valuesBetween: (rule: TBetween) => [unknown, unknown];
|
|
29
|
+
/** The same rule on another field: kept when the field reads the same way, else started anew. */
|
|
30
|
+
export declare const withField: (rule: TFilterRule, from: TConditionField | undefined, to: TConditionField) => TFilterRule;
|
|
31
|
+
/**
|
|
32
|
+
* The rule with another operator. The value stays while it still means the same (a list for
|
|
33
|
+
* "is any of" and "is none of", a number for the comparisons); otherwise it starts empty.
|
|
34
|
+
*/
|
|
35
|
+
export declare const withOperator: (rule: TFilterRule, op: TFilterOperator) => TFilterRule;
|
|
36
|
+
/** Whether an editor's rule says enough: a "between" needs both ends. */
|
|
37
|
+
export declare const isFilled: (rule: TFilterRule) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The conditions without the rules still being written: a group drops its unfinished rules,
|
|
40
|
+
* an empty group goes, and a group left with one rule is that rule (one side of a "between").
|
|
41
|
+
* Null when nothing is left.
|
|
42
|
+
*/
|
|
43
|
+
export declare const completeOf: (group: TConditionGroup) => TConditionGroup | null;
|
|
44
|
+
/** How many rules a group holds, a "between" counting as one. */
|
|
45
|
+
export declare const ruleCount: (group: TConditionGroup) => number;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { LIST_VALUE, NO_VALUE, RELATIVE, RelativeAmount, isRule } from "./conditions.js";
|
|
2
|
+
// src/modules/conditions/filterRule.ts
|
|
3
|
+
const isBetween = (node) => {
|
|
4
|
+
if (isRule(node) || node.match !== "all" || node.rules.length !== 2) return false;
|
|
5
|
+
const [from, to] = node.rules;
|
|
6
|
+
return !!from && !!to && isRule(from) && isRule(to) && from.op === "gte" && to.op === "lte" && from.path === to.path;
|
|
7
|
+
};
|
|
8
|
+
const isFilterRule = (node) => isRule(node) || isBetween(node);
|
|
9
|
+
const pathOf = (rule) => isRule(rule) ? rule.path : rule.rules[0].path;
|
|
10
|
+
const opOf = (rule) => isRule(rule) ? rule.op : "between";
|
|
11
|
+
const between = (path, from, to) => ({
|
|
12
|
+
match: "all",
|
|
13
|
+
rules: [{
|
|
14
|
+
path,
|
|
15
|
+
op: "gte",
|
|
16
|
+
value: from
|
|
17
|
+
}, {
|
|
18
|
+
path,
|
|
19
|
+
op: "lte",
|
|
20
|
+
value: to
|
|
21
|
+
}]
|
|
22
|
+
});
|
|
23
|
+
/** The operators that fit a field's type, in the order the menus list them. */
|
|
24
|
+
const operatorsFor = (type) => {
|
|
25
|
+
switch (type) {
|
|
26
|
+
case "date": return [
|
|
27
|
+
"within_last",
|
|
28
|
+
"within_next",
|
|
29
|
+
"more_than_ago",
|
|
30
|
+
"eq",
|
|
31
|
+
"lt",
|
|
32
|
+
"gt",
|
|
33
|
+
"between",
|
|
34
|
+
"anniversary_within",
|
|
35
|
+
"exists",
|
|
36
|
+
"not_exists"
|
|
37
|
+
];
|
|
38
|
+
case "number": return [
|
|
39
|
+
"eq",
|
|
40
|
+
"neq",
|
|
41
|
+
"gt",
|
|
42
|
+
"gte",
|
|
43
|
+
"lt",
|
|
44
|
+
"lte",
|
|
45
|
+
"between",
|
|
46
|
+
"exists",
|
|
47
|
+
"not_exists"
|
|
48
|
+
];
|
|
49
|
+
case "select":
|
|
50
|
+
case "member":
|
|
51
|
+
case "tags": return [
|
|
52
|
+
"in",
|
|
53
|
+
"not_in",
|
|
54
|
+
"exists",
|
|
55
|
+
"not_exists"
|
|
56
|
+
];
|
|
57
|
+
case "list": return [
|
|
58
|
+
"contains",
|
|
59
|
+
"not_contains",
|
|
60
|
+
"exists",
|
|
61
|
+
"not_exists"
|
|
62
|
+
];
|
|
63
|
+
case "boolean": return ["eq"];
|
|
64
|
+
default: return [
|
|
65
|
+
"contains",
|
|
66
|
+
"not_contains",
|
|
67
|
+
"eq",
|
|
68
|
+
"neq",
|
|
69
|
+
"starts_with",
|
|
70
|
+
"exists",
|
|
71
|
+
"not_exists"
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/** A new rule on `field`: its type's first operator, no value yet. */
|
|
76
|
+
const ruleFor = (field) => {
|
|
77
|
+
const op = operatorsFor(field.type)[0] ?? "eq";
|
|
78
|
+
if (op === "between") return between(field.path, void 0, void 0);
|
|
79
|
+
if (op === "within_last") return {
|
|
80
|
+
path: field.path,
|
|
81
|
+
op,
|
|
82
|
+
value: {
|
|
83
|
+
amount: 30,
|
|
84
|
+
unit: "days"
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
path: field.path,
|
|
89
|
+
op,
|
|
90
|
+
value: field.type === "boolean" ? true : void 0
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/** "Between"'s two values. */
|
|
94
|
+
const valuesBetween = (rule) => [rule.rules[0].value, rule.rules[1].value];
|
|
95
|
+
/** The same rule on another field: kept when the field reads the same way, else started anew. */
|
|
96
|
+
const withField = (rule, from, to) => {
|
|
97
|
+
if (from?.type !== to.type) return ruleFor(to);
|
|
98
|
+
return isRule(rule) ? {
|
|
99
|
+
...rule,
|
|
100
|
+
path: to.path
|
|
101
|
+
} : between(to.path, ...valuesBetween(rule));
|
|
102
|
+
};
|
|
103
|
+
const kindOf = (op) => NO_VALUE.has(op) ? "none" : RELATIVE.has(op) ? "relative" : LIST_VALUE.has(op) ? "list" : "one";
|
|
104
|
+
/**
|
|
105
|
+
* The rule with another operator. The value stays while it still means the same (a list for
|
|
106
|
+
* "is any of" and "is none of", a number for the comparisons); otherwise it starts empty.
|
|
107
|
+
*/
|
|
108
|
+
const withOperator = (rule, op) => {
|
|
109
|
+
const path = pathOf(rule);
|
|
110
|
+
const current = opOf(rule);
|
|
111
|
+
if (op === "between") return isRule(rule) && kindOf(current) === "one" ? between(path, rule.value, void 0) : between(path, void 0, void 0);
|
|
112
|
+
if (!isRule(rule)) return {
|
|
113
|
+
path,
|
|
114
|
+
op,
|
|
115
|
+
value: NO_VALUE.has(op) ? void 0 : rule.rules[0].value
|
|
116
|
+
};
|
|
117
|
+
if (kindOf(op) === kindOf(current)) return {
|
|
118
|
+
...rule,
|
|
119
|
+
op
|
|
120
|
+
};
|
|
121
|
+
if (kindOf(op) === "relative") return {
|
|
122
|
+
path,
|
|
123
|
+
op,
|
|
124
|
+
value: {
|
|
125
|
+
amount: 30,
|
|
126
|
+
unit: "days"
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
if (kindOf(op) === "list" && rule.value !== void 0 && kindOf(current) === "one") return {
|
|
130
|
+
path,
|
|
131
|
+
op,
|
|
132
|
+
value: [rule.value]
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
path,
|
|
136
|
+
op
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const filled = (value) => value !== void 0 && value !== null && value !== "" && !(typeof value === "number" && !Number.isFinite(value));
|
|
140
|
+
/** Whether a rule says enough to filter by: its value is there, or it needs none. */
|
|
141
|
+
const isComplete = (rule) => {
|
|
142
|
+
if (NO_VALUE.has(rule.op)) return true;
|
|
143
|
+
if (RELATIVE.has(rule.op)) return RelativeAmount.safeParse(rule.value).success;
|
|
144
|
+
if (LIST_VALUE.has(rule.op)) return Array.isArray(rule.value) && rule.value.some(filled);
|
|
145
|
+
return filled(rule.value);
|
|
146
|
+
};
|
|
147
|
+
/** Whether an editor's rule says enough: a "between" needs both ends. */
|
|
148
|
+
const isFilled = (rule) => isRule(rule) ? isComplete(rule) : rule.rules.every(isComplete);
|
|
149
|
+
/**
|
|
150
|
+
* The conditions without the rules still being written: a group drops its unfinished rules,
|
|
151
|
+
* an empty group goes, and a group left with one rule is that rule (one side of a "between").
|
|
152
|
+
* Null when nothing is left.
|
|
153
|
+
*/
|
|
154
|
+
const completeOf = (group) => {
|
|
155
|
+
const rules = group.rules.flatMap((node) => {
|
|
156
|
+
if (isRule(node)) return isComplete(node) ? [node] : [];
|
|
157
|
+
const inner = completeOf(node);
|
|
158
|
+
if (!inner) return [];
|
|
159
|
+
const [only] = inner.rules;
|
|
160
|
+
return inner.rules.length === 1 && only ? [only] : [inner];
|
|
161
|
+
});
|
|
162
|
+
return rules.length ? {
|
|
163
|
+
...group,
|
|
164
|
+
rules
|
|
165
|
+
} : null;
|
|
166
|
+
};
|
|
167
|
+
/** How many rules a group holds, a "between" counting as one. */
|
|
168
|
+
const ruleCount = (group) => group.rules.reduce((count, node) => count + (isFilterRule(node) ? 1 : ruleCount(node)), 0);
|
|
169
|
+
export { between, completeOf, isFilled, isFilterRule, opOf, operatorsFor, pathOf, ruleCount, ruleFor, valuesBetween, withField, withOperator };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RelativeAmount, TConditionField, TConditionLookups, TConditionRule } from "./conditions.js";
|
|
2
|
+
import { TFilterOperator, TFilterRule } from "./filterRule.js";
|
|
3
|
+
/** An operator in words, for a field's type ("is before" on a date). */
|
|
4
|
+
export declare const useOperatorLabel: () => (op: TFilterOperator, type: string | undefined) => string;
|
|
5
|
+
/** A relative amount in words: "30 days". */
|
|
6
|
+
export declare const useSpanText: () => ({ amount, unit }: RelativeAmount) => string;
|
|
7
|
+
/**
|
|
8
|
+
* The values a rule picks: the list of "is any of", or the one of "is". A value that isn't text,
|
|
9
|
+
* a number or yes/no (a date range, a relative amount) picks nothing.
|
|
10
|
+
*/
|
|
11
|
+
export declare const valuesOf: (rule: TConditionRule | undefined) => string[];
|
|
12
|
+
/** A rule in words, as a chip shows it: the operator and the value (empty when it needs none). */
|
|
13
|
+
export declare const useRuleText: (rule: TFilterRule, field: TConditionField | undefined, lookups: TConditionLookups) => {
|
|
14
|
+
op: string;
|
|
15
|
+
value: string;
|
|
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, {
|
|
@@ -51,10 +51,11 @@ export type TListFilterProps = TConditionLookups & {
|
|
|
51
51
|
recordType?: TPluginListType;
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
|
-
* A list's filter bar,
|
|
55
|
-
* The
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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
|
|
58
59
|
* from `members` and `tags` fields from `tags`: in erxes `memberQueries` from
|
|
59
60
|
* `@erxes/core-contract/client` and the tags query of the record type; outside erxes, the
|
|
60
61
|
* plugin's own.
|
|
@@ -68,4 +69,14 @@ export declare const ListFilter: ({ recordType, ...props }: TListFilterProps) =>
|
|
|
68
69
|
export declare const useListFilterParams: () => {
|
|
69
70
|
filter: string | undefined;
|
|
70
71
|
search: string | undefined;
|
|
71
|
-
};
|
|
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;
|