@erxes/ui 4.0.0-v2.7 → 4.0.0-v2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/dist/hooks/use-item-keys.d.ts +10 -0
- package/dist/hooks/use-item-keys.js +23 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +10 -2
- package/dist/lib/format.d.ts +2 -0
- package/dist/lib/format.js +6 -1
- package/dist/lib/money.d.ts +10 -0
- package/dist/lib/money.js +18 -0
- package/dist/lib/text.d.ts +7 -0
- package/dist/lib/text.js +14 -0
- package/dist/modules/conditions/ConditionValueInput.d.ts +10 -0
- package/dist/modules/conditions/ConditionValueInput.js +166 -0
- package/dist/modules/conditions/ConditionsEditor.d.ts +11 -0
- package/dist/modules/conditions/ConditionsEditor.js +209 -0
- package/dist/modules/conditions/LazyConditionsEditor.d.ts +9 -0
- package/dist/modules/conditions/LazyConditionsEditor.js +10 -0
- package/dist/modules/conditions/PathPicker.d.ts +8 -0
- package/dist/modules/conditions/PathPicker.js +51 -0
- package/dist/modules/conditions/conditions.d.ts +64 -0
- package/dist/modules/conditions/conditions.js +135 -0
- package/dist/modules/list/DisplayMenu.d.ts +14 -7
- package/dist/modules/list/DisplayMenu.js +48 -28
- package/dist/modules/list/ListFilter.d.ts +25 -11
- package/dist/modules/list/ListFilter.js +30 -26
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +5 -0
- package/dist/modules/list/filter/AdvancedFilterDialog.js +52 -0
- package/dist/modules/list/filter/FieldMenus.d.ts +5 -0
- package/dist/modules/list/filter/FieldMenus.js +184 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +6 -0
- package/dist/modules/list/filter/ListFilterBar.js +246 -0
- package/dist/modules/list/filter/RecordCount.d.ts +7 -0
- package/dist/modules/list/filter/RecordCount.js +22 -0
- package/dist/modules/list/filter/RuleChips.d.ts +2 -0
- package/dist/modules/list/filter/RuleChips.js +157 -0
- package/dist/modules/list/filter/fieldIcons.d.ts +7 -0
- package/dist/modules/list/filter/fieldIcons.js +16 -0
- package/dist/modules/list/filter/filterRules.d.ts +46 -0
- package/dist/modules/list/filter/filterRules.js +166 -0
- package/dist/modules/list/filter/listFilterContext.d.ts +29 -0
- package/dist/modules/list/filter/listFilterContext.js +34 -0
- package/dist/modules/list/filter/listFilterQuery.d.ts +15 -0
- package/dist/modules/list/filter/listFilterQuery.js +21 -0
- package/dist/modules/pickers/LookupPicker.d.ts +50 -0
- package/dist/modules/pickers/LookupPicker.js +83 -0
- package/dist/modules/record-list/RecordList.d.ts +12 -0
- package/dist/modules/record-list/RecordList.js +17 -0
- package/dist/modules/record-list/RecordListProvider.d.ts +30 -0
- package/dist/modules/record-list/RecordListProvider.js +57 -0
- package/dist/modules/record-list/RecordListRoot.d.ts +28 -0
- package/dist/modules/record-list/RecordListRoot.js +124 -0
- package/dist/modules/record-list/selection.d.ts +22 -0
- package/dist/modules/record-list/selection.js +54 -0
- package/dist/theme.css +2 -0
- package/package.json +2 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Button } from "../../components/button.js";
|
|
2
|
+
import { Select } from "../../components/select.js";
|
|
3
|
+
import { useItemKeys } from "../../hooks/use-item-keys.js";
|
|
4
|
+
import { oneOf } from "../../lib/text.js";
|
|
5
|
+
import { cn } from "../../lib/utils.js";
|
|
6
|
+
import { CONDITION_OPERATORS, NO_VALUE, OPERATOR_LABELS, isRule, operatorsFor, withOperator } from "./conditions.js";
|
|
7
|
+
import { ConditionValueInput } from "./ConditionValueInput.js";
|
|
8
|
+
import { PathPicker } from "./PathPicker.js";
|
|
9
|
+
import { IconBraces, IconPlus, IconX } from "@tabler/icons-react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useTranslation } from "react-i18next";
|
|
12
|
+
// src/modules/conditions/ConditionsEditor.tsx
|
|
13
|
+
/** Field and operator side by side, remove at the end; the value takes its own full line. */
|
|
14
|
+
const RuleRow = ({ rule, fields, disabled, lookups, onChange, onRemove }) => {
|
|
15
|
+
const { t } = useTranslation("automations");
|
|
16
|
+
const field = fields.find((one) => one.path === rule.path);
|
|
17
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
18
|
+
className: "grid grid-cols-condition items-center gap-2",
|
|
19
|
+
children: [
|
|
20
|
+
/* @__PURE__ */ jsx(PathPicker, {
|
|
21
|
+
value: rule.path,
|
|
22
|
+
fields,
|
|
23
|
+
disabled,
|
|
24
|
+
onChange: (path) => onChange(fields.find((one) => one.path === path)?.type === field?.type ? {
|
|
25
|
+
...rule,
|
|
26
|
+
path
|
|
27
|
+
} : {
|
|
28
|
+
...rule,
|
|
29
|
+
path,
|
|
30
|
+
value: void 0
|
|
31
|
+
})
|
|
32
|
+
}),
|
|
33
|
+
/* @__PURE__ */ jsxs(Select, {
|
|
34
|
+
value: rule.op,
|
|
35
|
+
onValueChange: (next) => {
|
|
36
|
+
const op = oneOf(CONDITION_OPERATORS, next);
|
|
37
|
+
if (op) onChange(withOperator(rule, op));
|
|
38
|
+
},
|
|
39
|
+
disabled,
|
|
40
|
+
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
41
|
+
className: "h-8 w-full min-w-0",
|
|
42
|
+
"aria-label": t("operator", "Operator"),
|
|
43
|
+
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
44
|
+
}), /* @__PURE__ */ jsx(Select.Content, { children: operatorsFor(field?.type).map((op) => /* @__PURE__ */ jsx(Select.Item, {
|
|
45
|
+
value: op,
|
|
46
|
+
children: t(`op.${op}`, OPERATOR_LABELS[op])
|
|
47
|
+
}, op)) })]
|
|
48
|
+
}),
|
|
49
|
+
/* @__PURE__ */ jsx(Button, {
|
|
50
|
+
size: "icon",
|
|
51
|
+
variant: "ghost",
|
|
52
|
+
tone: "muted",
|
|
53
|
+
className: "size-8",
|
|
54
|
+
disabled,
|
|
55
|
+
onClick: onRemove,
|
|
56
|
+
"aria-label": t("remove", "Remove"),
|
|
57
|
+
children: /* @__PURE__ */ jsx(IconX, { className: "size-4" })
|
|
58
|
+
}),
|
|
59
|
+
!NO_VALUE.has(rule.op) && /* @__PURE__ */ jsx("div", {
|
|
60
|
+
className: "col-span-2 flex min-w-0",
|
|
61
|
+
children: /* @__PURE__ */ jsx(ConditionValueInput, {
|
|
62
|
+
rule,
|
|
63
|
+
field,
|
|
64
|
+
disabled,
|
|
65
|
+
...lookups,
|
|
66
|
+
onChange: (value) => onChange({
|
|
67
|
+
...rule,
|
|
68
|
+
value
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const MatchSelect = ({ group, onChange, onRemove, disabled }) => {
|
|
76
|
+
const { t } = useTranslation("automations");
|
|
77
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
78
|
+
className: "flex items-center gap-2 text-sm",
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ jsx("span", { children: t("match-prefix", "Match") }),
|
|
81
|
+
/* @__PURE__ */ jsxs(Select, {
|
|
82
|
+
value: group.match,
|
|
83
|
+
onValueChange: (match) => onChange({
|
|
84
|
+
...group,
|
|
85
|
+
match: match === "any" ? "any" : "all"
|
|
86
|
+
}),
|
|
87
|
+
disabled,
|
|
88
|
+
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
89
|
+
className: "h-8 w-24",
|
|
90
|
+
"aria-label": t("match-prefix", "Match"),
|
|
91
|
+
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
92
|
+
}), /* @__PURE__ */ jsxs(Select.Content, { children: [/* @__PURE__ */ jsx(Select.Item, {
|
|
93
|
+
value: "all",
|
|
94
|
+
children: t("match-all", "all")
|
|
95
|
+
}), /* @__PURE__ */ jsx(Select.Item, {
|
|
96
|
+
value: "any",
|
|
97
|
+
children: t("match-any", "any")
|
|
98
|
+
})] })]
|
|
99
|
+
}),
|
|
100
|
+
/* @__PURE__ */ jsx("span", { children: t("match-suffix", "of these") }),
|
|
101
|
+
onRemove && /* @__PURE__ */ jsx(Button, {
|
|
102
|
+
size: "sm",
|
|
103
|
+
variant: "ghost",
|
|
104
|
+
className: "ml-auto",
|
|
105
|
+
disabled,
|
|
106
|
+
onClick: onRemove,
|
|
107
|
+
children: /* @__PURE__ */ jsx(IconX, {})
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const AddButtons = ({ newRule, newGroup, disabled, onAdd }) => {
|
|
113
|
+
const { t } = useTranslation("automations");
|
|
114
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
115
|
+
className: "flex gap-2",
|
|
116
|
+
children: [/* @__PURE__ */ jsxs(Button, {
|
|
117
|
+
size: "sm",
|
|
118
|
+
variant: "outline",
|
|
119
|
+
disabled,
|
|
120
|
+
onClick: () => onAdd(newRule),
|
|
121
|
+
children: [/* @__PURE__ */ jsx(IconPlus, {}), t("add-condition", "Add condition")]
|
|
122
|
+
}), newGroup && /* @__PURE__ */ jsxs(Button, {
|
|
123
|
+
size: "sm",
|
|
124
|
+
variant: "ghost",
|
|
125
|
+
disabled,
|
|
126
|
+
onClick: () => onAdd(newGroup),
|
|
127
|
+
children: [/* @__PURE__ */ jsx(IconBraces, {}), t("add-group", "Add group")]
|
|
128
|
+
})]
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
/** One group: "all"/"any" of its rules and nested groups (up to three levels). */
|
|
132
|
+
const GroupEditor = ({ group, onChange, onRemove, fields, disabled, depth, lookups }) => {
|
|
133
|
+
const keys = useItemKeys(group.rules.length);
|
|
134
|
+
const update = (index, rule) => onChange({
|
|
135
|
+
...group,
|
|
136
|
+
rules: group.rules.map((item, at) => at === index ? rule : item)
|
|
137
|
+
});
|
|
138
|
+
const remove = (index) => {
|
|
139
|
+
keys.removed(index);
|
|
140
|
+
onChange({
|
|
141
|
+
...group,
|
|
142
|
+
rules: group.rules.filter((_, at) => at !== index)
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const add = (rule) => {
|
|
146
|
+
keys.added();
|
|
147
|
+
onChange({
|
|
148
|
+
...group,
|
|
149
|
+
rules: [...group.rules, rule]
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
153
|
+
className: cn("space-y-2", depth > 0 && "rounded-md border border-dashed p-2"),
|
|
154
|
+
children: [
|
|
155
|
+
/* @__PURE__ */ jsx(MatchSelect, {
|
|
156
|
+
group,
|
|
157
|
+
onChange,
|
|
158
|
+
onRemove,
|
|
159
|
+
disabled
|
|
160
|
+
}),
|
|
161
|
+
group.rules.map((rule, index) => isRule(rule) ? /* @__PURE__ */ jsx(RuleRow, {
|
|
162
|
+
rule,
|
|
163
|
+
fields,
|
|
164
|
+
disabled,
|
|
165
|
+
lookups,
|
|
166
|
+
onChange: (next) => update(index, next),
|
|
167
|
+
onRemove: () => remove(index)
|
|
168
|
+
}, keys.keyAt(index)) : /* @__PURE__ */ jsx(GroupEditor, {
|
|
169
|
+
group: rule,
|
|
170
|
+
fields,
|
|
171
|
+
disabled,
|
|
172
|
+
lookups,
|
|
173
|
+
depth: depth + 1,
|
|
174
|
+
onChange: (next) => update(index, next),
|
|
175
|
+
onRemove: () => remove(index)
|
|
176
|
+
}, keys.keyAt(index))),
|
|
177
|
+
/* @__PURE__ */ jsx(AddButtons, {
|
|
178
|
+
newRule: {
|
|
179
|
+
path: fields[3]?.path ?? "subject.primaryEmail",
|
|
180
|
+
op: "exists"
|
|
181
|
+
},
|
|
182
|
+
newGroup: depth < 2 ? {
|
|
183
|
+
match: group.match === "all" ? "any" : "all",
|
|
184
|
+
rules: []
|
|
185
|
+
} : null,
|
|
186
|
+
disabled,
|
|
187
|
+
onAdd: add
|
|
188
|
+
})
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Conditions: rows "<field> <operator> <value>", all or any, with nested groups, on `fields`
|
|
194
|
+
* (grouped in the picker when they have a `group`); `members` and `tags` feed their pickers.
|
|
195
|
+
*/
|
|
196
|
+
const ConditionsEditor = ({ value, onChange, disabled, fields, ...lookups }) => {
|
|
197
|
+
return /* @__PURE__ */ jsx(GroupEditor, {
|
|
198
|
+
group: value ?? {
|
|
199
|
+
match: "all",
|
|
200
|
+
rules: []
|
|
201
|
+
},
|
|
202
|
+
fields,
|
|
203
|
+
disabled,
|
|
204
|
+
lookups,
|
|
205
|
+
depth: 0,
|
|
206
|
+
onChange: (next) => onChange(next.rules.length ? next : void 0)
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
export { ConditionsEditor };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConditionsEditor as ConditionsEditor$1 } from "./ConditionsEditor.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
declare const Editor: import("react").LazyExoticComponent<typeof ConditionsEditor$1>;
|
|
4
|
+
/**
|
|
5
|
+
* The condition editor, fetched the first time one renders: erxes-ui is one shared chunk every
|
|
6
|
+
* route loads, and only automations and a list's advanced filter edit conditions.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ConditionsEditor: (props: ComponentProps<typeof Editor>) => import("react").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -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,13 +1,20 @@
|
|
|
1
|
-
declare const LIST_DISPLAYS: readonly ['table', 'board'];
|
|
2
|
-
/** How a list shows its records: rows
|
|
1
|
+
declare const LIST_DISPLAYS: readonly ['list', 'table', 'board'];
|
|
2
|
+
/** How a list shows its records: grouped rows (`RecordList`), a table, or cards on a board. */
|
|
3
3
|
export type TListDisplay = (typeof LIST_DISPLAYS)[number];
|
|
4
|
+
/** The displays a list offers, in the menu's order; the first shows until one is chosen. */
|
|
5
|
+
type ListDisplays = readonly [TListDisplay, ...TListDisplay[]];
|
|
4
6
|
/**
|
|
5
|
-
* `const [display] = useListDisplay('sales-deals')`: the
|
|
6
|
-
*
|
|
7
|
+
* `const [display] = useListDisplay('sales-deals')`: the display a list shows, chosen under its
|
|
8
|
+
* Display menu and remembered in this browser, one choice per list. Give it the same `displays`
|
|
9
|
+
* as the list's `DisplayMenu`.
|
|
7
10
|
*/
|
|
8
|
-
export declare const useListDisplay: (list: string) => ["board" | "table", (args_0: "board" | "table" | typeof import("jotai/utils").RESET | ((prev: "board" | "table") => "board" | "table" | typeof import("jotai/utils").RESET)) => void];
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
+
export declare const useListDisplay: (list: string, displays?: ListDisplays) => readonly ["board" | "list" | "table", (args_0: "board" | "list" | "table" | typeof import("jotai/utils").RESET | ((prev: "board" | "list" | "table" | null) => "board" | "list" | "table" | typeof import("jotai/utils").RESET | null) | null) => void];
|
|
12
|
+
/**
|
|
13
|
+
* "Display" in a list's filter bar: table or board, or the `displays` the list offers, such as
|
|
14
|
+
* `['list', 'board', 'table']` (`useListDisplay(list, displays)` reads the choice).
|
|
15
|
+
*/
|
|
16
|
+
export declare const DisplayMenu: ({ list, displays }: {
|
|
11
17
|
list: string;
|
|
18
|
+
displays?: ListDisplays;
|
|
12
19
|
}) => import("react").JSX.Element;
|
|
13
20
|
export {};
|
|
@@ -3,36 +3,53 @@ import { IconTip } from "../../components/icon-tip.js";
|
|
|
3
3
|
import { Popover } from "../../components/popover.js";
|
|
4
4
|
import { storedFamily } from "../../lib/stored.js";
|
|
5
5
|
import { cn } from "../../lib/utils.js";
|
|
6
|
-
import { IconAdjustmentsHorizontal, IconLayoutKanban, IconTable } from "@tabler/icons-react";
|
|
6
|
+
import { IconAdjustmentsHorizontal, IconLayoutKanban, IconList, IconTable } from "@tabler/icons-react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { useAtom } from "jotai";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { useTranslation } from "react-i18next";
|
|
11
11
|
// src/modules/list/DisplayMenu.tsx
|
|
12
|
+
const LIST_DISPLAYS = [
|
|
13
|
+
"list",
|
|
14
|
+
"table",
|
|
15
|
+
"board"
|
|
16
|
+
];
|
|
17
|
+
const TABLE_AND_BOARD = ["table", "board"];
|
|
18
|
+
/** Null until the member picks one. */
|
|
12
19
|
const listDisplayFamily = storedFamily({
|
|
13
20
|
key: "erxes:list-display",
|
|
14
|
-
schema: z.enum(
|
|
15
|
-
initial:
|
|
21
|
+
schema: z.enum(LIST_DISPLAYS).nullable(),
|
|
22
|
+
initial: null
|
|
16
23
|
});
|
|
17
24
|
/**
|
|
18
|
-
* `const [display] = useListDisplay('sales-deals')`: the
|
|
19
|
-
*
|
|
25
|
+
* `const [display] = useListDisplay('sales-deals')`: the display a list shows, chosen under its
|
|
26
|
+
* Display menu and remembered in this browser, one choice per list. Give it the same `displays`
|
|
27
|
+
* as the list's `DisplayMenu`.
|
|
20
28
|
*/
|
|
21
|
-
const useListDisplay = (list) =>
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const useListDisplay = (list, displays = TABLE_AND_BOARD) => {
|
|
30
|
+
const [chosen, setDisplay] = useAtom(listDisplayFamily(list));
|
|
31
|
+
return [chosen && displays.includes(chosen) ? chosen : displays[0], setDisplay];
|
|
32
|
+
};
|
|
33
|
+
const DISPLAYS = {
|
|
34
|
+
list: {
|
|
35
|
+
fallback: "List",
|
|
36
|
+
icon: IconList
|
|
37
|
+
},
|
|
38
|
+
table: {
|
|
39
|
+
fallback: "Table",
|
|
40
|
+
icon: IconTable
|
|
41
|
+
},
|
|
42
|
+
board: {
|
|
43
|
+
fallback: "Board",
|
|
44
|
+
icon: IconLayoutKanban
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* "Display" in a list's filter bar: table or board, or the `displays` the list offers, such as
|
|
49
|
+
* `['list', 'board', 'table']` (`useListDisplay(list, displays)` reads the choice).
|
|
50
|
+
*/
|
|
51
|
+
const DisplayMenu = ({ list, displays = TABLE_AND_BOARD }) => {
|
|
52
|
+
const [current, setDisplay] = useListDisplay(list, displays);
|
|
36
53
|
const { t } = useTranslation("views", { keyPrefix: "display" });
|
|
37
54
|
return /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsx(IconTip, {
|
|
38
55
|
label: t("label", "Display"),
|
|
@@ -52,14 +69,17 @@ const DisplayMenu = ({ list }) => {
|
|
|
52
69
|
className: "mb-2 text-xs font-medium text-muted-foreground",
|
|
53
70
|
children: t("view", "View")
|
|
54
71
|
}), /* @__PURE__ */ jsx("div", {
|
|
55
|
-
className: "grid grid-cols-
|
|
56
|
-
children:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
className: cn("grid gap-2", displays.length > 2 ? "grid-cols-3" : "grid-cols-2"),
|
|
73
|
+
children: displays.map((value) => {
|
|
74
|
+
const { fallback, icon: Icon } = DISPLAYS[value];
|
|
75
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
76
|
+
type: "button",
|
|
77
|
+
"aria-pressed": current === value,
|
|
78
|
+
onClick: () => setDisplay(value),
|
|
79
|
+
className: cn("flex flex-col items-center gap-1.5 rounded-lg border p-3 text-sm text-muted-foreground transition-colors hover:bg-accent", current === value && "border-primary bg-primary/5 font-medium text-foreground"),
|
|
80
|
+
children: [/* @__PURE__ */ jsx(Icon, { className: "size-5" }), t(value, fallback)]
|
|
81
|
+
}, value);
|
|
82
|
+
})
|
|
63
83
|
})]
|
|
64
84
|
})] });
|
|
65
85
|
};
|