@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TConditionField } from "./conditions.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* The searchable list of fields, grouped under headings with each field's icon; what every
|
|
5
|
+
* filter and condition editor picks a field from. `children` are rows above the fields (search,
|
|
6
|
+
* the advanced filter). With `customPath`, a typed path (`event.payload.amount`) is a choice too.
|
|
7
|
+
*/
|
|
8
|
+
export declare const FieldPicker: ({ fields, value, onSelect, children, customPath, loading, error }: {
|
|
9
|
+
fields: TConditionField[];
|
|
10
|
+
/** The path picked now; it shows a check. */
|
|
11
|
+
value?: string;
|
|
12
|
+
onSelect: (field: TConditionField) => void;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
customPath?: boolean;
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
error?: Error | null;
|
|
17
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Combobox } from "../../components/combobox.js";
|
|
2
|
+
import { Command } from "../../components/command.js";
|
|
3
|
+
import { FieldIcon } from "./fieldIcons.js";
|
|
4
|
+
import { IconCode } from "@tabler/icons-react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { useTranslation } from "react-i18next";
|
|
8
|
+
// src/modules/conditions/FieldPicker.tsx
|
|
9
|
+
/** Core's own groups, in the order the picker lists them; any other (a plugin's) follows. */
|
|
10
|
+
const GROUPS = {
|
|
11
|
+
fields: "Fields",
|
|
12
|
+
lead: "Lead",
|
|
13
|
+
company: "Company",
|
|
14
|
+
activity: "Activity",
|
|
15
|
+
custom: "Properties"
|
|
16
|
+
};
|
|
17
|
+
const ORDER = Object.keys(GROUPS);
|
|
18
|
+
/** A heading per group, and one per `groupLabel` (each plugin's fields under its title). */
|
|
19
|
+
const groupOf = (field) => field.groupLabel ? `label:${field.groupLabel}` : field.group ?? "fields";
|
|
20
|
+
const rank = (group) => {
|
|
21
|
+
const at = ORDER.indexOf(group);
|
|
22
|
+
return at < 0 ? ORDER.length : at;
|
|
23
|
+
};
|
|
24
|
+
/** The groups in the picker's order, each with its heading: the fields' `groupLabel`, else its name. */
|
|
25
|
+
const useGroups = (fields) => {
|
|
26
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
27
|
+
return [...new Set(fields.map(groupOf))].toSorted((a, b) => rank(a) - rank(b)).map((group) => {
|
|
28
|
+
const inGroup = fields.filter((field) => groupOf(field) === group);
|
|
29
|
+
return {
|
|
30
|
+
group,
|
|
31
|
+
heading: inGroup[0]?.groupLabel ?? t(`group.${group}`, GROUPS[group] ?? group),
|
|
32
|
+
fields: inGroup
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
/** A path typed by hand: automations reach event payloads and step outputs the catalog lacks. */
|
|
37
|
+
const PATH = /^(event|subject|steps|run)(\.[A-Za-z0-9_-]+)+$/;
|
|
38
|
+
/**
|
|
39
|
+
* The searchable list of fields, grouped under headings with each field's icon; what every
|
|
40
|
+
* filter and condition editor picks a field from. `children` are rows above the fields (search,
|
|
41
|
+
* the advanced filter). With `customPath`, a typed path (`event.payload.amount`) is a choice too.
|
|
42
|
+
*/
|
|
43
|
+
const FieldPicker = ({ fields, value, onSelect, children, customPath, loading, error }) => {
|
|
44
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
45
|
+
const [search, setSearch] = useState("");
|
|
46
|
+
const groups = useGroups(fields);
|
|
47
|
+
const typed = search.trim();
|
|
48
|
+
return /* @__PURE__ */ jsxs(Command, { children: [/* @__PURE__ */ jsx(Command.Input, {
|
|
49
|
+
value: search,
|
|
50
|
+
onValueChange: setSearch,
|
|
51
|
+
placeholder: customPath ? t("field-or-path", "Field or path…") : t("add", "Add filter…"),
|
|
52
|
+
focusOnMount: true
|
|
53
|
+
}), /* @__PURE__ */ jsxs(Command.List, {
|
|
54
|
+
className: "max-h-popup",
|
|
55
|
+
children: [
|
|
56
|
+
/* @__PURE__ */ jsx(Command.Empty, { children: t("no-match", "No field matches") }),
|
|
57
|
+
children,
|
|
58
|
+
loading && /* @__PURE__ */ jsx("p", {
|
|
59
|
+
className: "px-2 py-1.5 text-xs text-muted-foreground",
|
|
60
|
+
children: t("loading", "Loading fields…")
|
|
61
|
+
}),
|
|
62
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
63
|
+
role: "alert",
|
|
64
|
+
className: "px-2 py-1.5 text-xs text-destructive",
|
|
65
|
+
children: error.message
|
|
66
|
+
}),
|
|
67
|
+
customPath && PATH.test(typed) && !fields.some((field) => field.path === typed) && /* @__PURE__ */ jsxs(Command.Item, {
|
|
68
|
+
value: `path:${typed}`,
|
|
69
|
+
keywords: [typed],
|
|
70
|
+
onSelect: () => onSelect({
|
|
71
|
+
path: typed,
|
|
72
|
+
label: typed,
|
|
73
|
+
type: "text"
|
|
74
|
+
}),
|
|
75
|
+
children: [/* @__PURE__ */ jsx(IconCode, {}), /* @__PURE__ */ jsx("span", {
|
|
76
|
+
className: "truncate font-mono text-xs",
|
|
77
|
+
children: typed
|
|
78
|
+
})]
|
|
79
|
+
}),
|
|
80
|
+
groups.map((group) => /* @__PURE__ */ jsx(Command.Group, {
|
|
81
|
+
heading: group.heading,
|
|
82
|
+
children: group.fields.map((field) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
83
|
+
value: field.path,
|
|
84
|
+
keywords: [field.label, group.heading],
|
|
85
|
+
onSelect: () => onSelect(field),
|
|
86
|
+
children: [
|
|
87
|
+
/* @__PURE__ */ jsx(FieldIcon, { field }),
|
|
88
|
+
/* @__PURE__ */ jsx("span", {
|
|
89
|
+
className: "truncate",
|
|
90
|
+
children: field.label
|
|
91
|
+
}),
|
|
92
|
+
/* @__PURE__ */ jsx(Combobox.Check, { checked: field.path === value })
|
|
93
|
+
]
|
|
94
|
+
}, field.path))
|
|
95
|
+
}, group.group))
|
|
96
|
+
]
|
|
97
|
+
})] });
|
|
98
|
+
};
|
|
99
|
+
export { FieldPicker };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TConditionField, TConditionLookups } from "./conditions.js";
|
|
2
|
+
import { TFilterOperator, TFilterRule } from "./filterRule.js";
|
|
3
|
+
import { ReactElement } from "react";
|
|
4
|
+
type PartProps = {
|
|
5
|
+
/** The button the part shows; it opens the editor. */
|
|
6
|
+
button: ReactElement;
|
|
7
|
+
open: boolean;
|
|
8
|
+
onOpenChange: (open: boolean) => void;
|
|
9
|
+
};
|
|
10
|
+
/** The rule's field: the grouped, searchable field list. */
|
|
11
|
+
export declare const FieldPart: ({ fields, field, customPath, onSelect, ...part }: PartProps & {
|
|
12
|
+
fields: TConditionField[];
|
|
13
|
+
field: TConditionField;
|
|
14
|
+
customPath?: boolean;
|
|
15
|
+
onSelect: (field: TConditionField) => void;
|
|
16
|
+
}) => import("react").JSX.Element;
|
|
17
|
+
/** The rule's operator: those of the field's type. */
|
|
18
|
+
export declare const OperatorPart: ({ rule, field, onSelect, ...part }: PartProps & {
|
|
19
|
+
rule: TFilterRule;
|
|
20
|
+
field: TConditionField;
|
|
21
|
+
onSelect: (op: TFilterOperator) => void;
|
|
22
|
+
}) => import("react").JSX.Element;
|
|
23
|
+
/** The rule's value, in the editor its operator and type need; a final pick closes it. */
|
|
24
|
+
export declare const ValuePart: ({ rule, field, lookups, onChange, ...part }: PartProps & {
|
|
25
|
+
rule: TFilterRule;
|
|
26
|
+
field: TConditionField;
|
|
27
|
+
lookups: TConditionLookups;
|
|
28
|
+
onChange: (next: TFilterRule) => void;
|
|
29
|
+
}) => import("react").JSX.Element;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Combobox } from "../../components/combobox.js";
|
|
2
|
+
import { Command } from "../../components/command.js";
|
|
3
|
+
import { Popover } from "../../components/popover.js";
|
|
4
|
+
import { cn } from "../../lib/utils.js";
|
|
5
|
+
import { RELATIVE } from "./conditions.js";
|
|
6
|
+
import { opOf, operatorsFor, pathOf } from "./filterRule.js";
|
|
7
|
+
import { FieldPicker } from "./FieldPicker.js";
|
|
8
|
+
import { useOperatorLabel } from "./filterText.js";
|
|
9
|
+
import { ValueEditor } from "./ValueEditor.js";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
// src/modules/conditions/RuleParts.tsx
|
|
12
|
+
/** The operators of the field's type (and the rule's own, should it be another); a pick changes it. */
|
|
13
|
+
const OperatorMenu = ({ rule, field, onSelect }) => {
|
|
14
|
+
const label = useOperatorLabel();
|
|
15
|
+
const current = opOf(rule);
|
|
16
|
+
const ops = operatorsFor(field.type);
|
|
17
|
+
return /* @__PURE__ */ jsx(Command, { children: /* @__PURE__ */ jsx(Command.List, { children: (ops.includes(current) ? ops : [current, ...ops]).map((op) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
18
|
+
value: op,
|
|
19
|
+
onSelect: () => onSelect(op),
|
|
20
|
+
children: [label(op, field.type), /* @__PURE__ */ jsx(Combobox.Check, { checked: op === current })]
|
|
21
|
+
}, op)) }) });
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* One part of a rule (its field, operator or value) as a button that opens its editor in a
|
|
25
|
+
* popover: a chip's segments and the advanced filter's rows both use it.
|
|
26
|
+
*/
|
|
27
|
+
const RulePart = ({ button, open, onOpenChange, className, children }) => /* @__PURE__ */ jsxs(Popover, {
|
|
28
|
+
open,
|
|
29
|
+
onOpenChange,
|
|
30
|
+
children: [/* @__PURE__ */ jsx(Popover.Trigger, { render: button }), /* @__PURE__ */ jsx(Popover.Content, {
|
|
31
|
+
variant: "flush",
|
|
32
|
+
align: "start",
|
|
33
|
+
className,
|
|
34
|
+
children
|
|
35
|
+
})]
|
|
36
|
+
});
|
|
37
|
+
/** The rule's field: the grouped, searchable field list. */
|
|
38
|
+
const FieldPart = ({ fields, field, customPath, onSelect, ...part }) => /* @__PURE__ */ jsx(RulePart, {
|
|
39
|
+
...part,
|
|
40
|
+
className: "w-72",
|
|
41
|
+
children: /* @__PURE__ */ jsx(FieldPicker, {
|
|
42
|
+
fields,
|
|
43
|
+
value: field.path,
|
|
44
|
+
customPath,
|
|
45
|
+
onSelect
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
/** The rule's operator: those of the field's type. */
|
|
49
|
+
const OperatorPart = ({ rule, field, onSelect, ...part }) => /* @__PURE__ */ jsx(RulePart, {
|
|
50
|
+
...part,
|
|
51
|
+
className: "w-56",
|
|
52
|
+
children: /* @__PURE__ */ jsx(OperatorMenu, {
|
|
53
|
+
rule,
|
|
54
|
+
field,
|
|
55
|
+
onSelect
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
/** The rule's value, in the editor its operator and type need; a final pick closes it. */
|
|
59
|
+
const ValuePart = ({ rule, field, lookups, onChange, ...part }) => {
|
|
60
|
+
const op = opOf(rule);
|
|
61
|
+
const calendar = field.type === "date" && !RELATIVE.has(op);
|
|
62
|
+
const typed = field.type === "number" || field.type === "text";
|
|
63
|
+
return /* @__PURE__ */ jsx(RulePart, {
|
|
64
|
+
...part,
|
|
65
|
+
className: calendar ? "w-auto" : "w-72",
|
|
66
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
67
|
+
className: cn(typed && "p-2"),
|
|
68
|
+
children: /* @__PURE__ */ jsx(ValueEditor, {
|
|
69
|
+
rule,
|
|
70
|
+
field,
|
|
71
|
+
lookups,
|
|
72
|
+
onChange,
|
|
73
|
+
onDone: () => part.onOpenChange(false)
|
|
74
|
+
}, `${pathOf(rule)}:${op}`)
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
export { FieldPart, OperatorPart, ValuePart };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TConditionField, TConditionLookups } from "./conditions.js";
|
|
2
|
+
import { TFilterRule } from "./filterRule.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
export type RowShared = {
|
|
5
|
+
fields: TConditionField[];
|
|
6
|
+
lookups: TConditionLookups;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
customPath?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** The row's (or a group's) last cell: an X named for what it removes. */
|
|
11
|
+
export declare const RemoveButton: ({ label, disabled, onRemove }: {
|
|
12
|
+
label: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
onRemove: () => void;
|
|
15
|
+
}) => import("react").JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* A row of the advanced filter (and an automation's conditions): `lead` ("Where", "And", "Or"),
|
|
18
|
+
* then the field, the operator and the value, each opening its editor, then remove. `fresh`
|
|
19
|
+
* opens the value at once, for a row just added.
|
|
20
|
+
*/
|
|
21
|
+
export declare const RuleRow: ({ rule, fields, lookups, disabled, customPath, lead, fresh, onChange, onRemove }: RowShared & {
|
|
22
|
+
rule: TFilterRule;
|
|
23
|
+
lead: ReactNode;
|
|
24
|
+
fresh: boolean;
|
|
25
|
+
onChange: (next: TFilterRule) => void;
|
|
26
|
+
onRemove: () => void;
|
|
27
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Button } from "../../components/button.js";
|
|
2
|
+
import { cn } from "../../lib/utils.js";
|
|
3
|
+
import { NO_VALUE } from "./conditions.js";
|
|
4
|
+
import { opOf, pathOf, withField, withOperator } from "./filterRule.js";
|
|
5
|
+
import { FieldIcon } from "./fieldIcons.js";
|
|
6
|
+
import { useRuleText } from "./filterText.js";
|
|
7
|
+
import { FieldPart, OperatorPart, ValuePart } from "./RuleParts.js";
|
|
8
|
+
import { ValueEditor, isTypedValue } from "./ValueEditor.js";
|
|
9
|
+
import { IconChevronDown, IconX } from "@tabler/icons-react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import { useTranslation } from "react-i18next";
|
|
13
|
+
// src/modules/conditions/RuleRow.tsx
|
|
14
|
+
/** A path no field has (an automation's typed path, a removed property) reads as text. */
|
|
15
|
+
const fieldAt = (fields, path) => fields.find((field) => field.path === path) ?? {
|
|
16
|
+
path,
|
|
17
|
+
label: path,
|
|
18
|
+
type: "text"
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A row's part as a button, named "Field: Name" (the part, then the text it shows); the popover
|
|
22
|
+
* it opens adds its handlers and state.
|
|
23
|
+
*/
|
|
24
|
+
const RowButton = ({ part, shows, className, ...props }) => /* @__PURE__ */ jsx(Button, {
|
|
25
|
+
variant: "outline",
|
|
26
|
+
"aria-label": `${part}: ${shows}`,
|
|
27
|
+
className: cn("h-8 w-full min-w-0 justify-start font-normal", className),
|
|
28
|
+
...props
|
|
29
|
+
});
|
|
30
|
+
/** The operator's button: its words and a chevron. Props pass through to the popover trigger. */
|
|
31
|
+
const OperatorButton = ({ shows, ...props }) => {
|
|
32
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
33
|
+
return /* @__PURE__ */ jsxs(RowButton, {
|
|
34
|
+
className: "justify-between",
|
|
35
|
+
part: t("operator", "Operator"),
|
|
36
|
+
shows,
|
|
37
|
+
...props,
|
|
38
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
39
|
+
className: "truncate",
|
|
40
|
+
children: shows
|
|
41
|
+
}), /* @__PURE__ */ jsx(IconChevronDown, { className: "text-muted-foreground" })]
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
/** The row's (or a group's) last cell: an X named for what it removes. */
|
|
45
|
+
const RemoveButton = ({ label, disabled, onRemove }) => /* @__PURE__ */ jsx(Button, {
|
|
46
|
+
size: "icon",
|
|
47
|
+
variant: "ghost",
|
|
48
|
+
tone: "muted",
|
|
49
|
+
disabled,
|
|
50
|
+
onClick: onRemove,
|
|
51
|
+
"aria-label": label,
|
|
52
|
+
children: /* @__PURE__ */ jsx(IconX, {})
|
|
53
|
+
});
|
|
54
|
+
/** A typed value sits in the row; a picked one (a list, a calendar) opens from a button. */
|
|
55
|
+
const RowValue = ({ rule, field, lookups, disabled, onChange, open, onOpenChange }) => {
|
|
56
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
57
|
+
const text = useRuleText(rule, field, lookups);
|
|
58
|
+
const op = opOf(rule);
|
|
59
|
+
if (NO_VALUE.has(op)) return /* @__PURE__ */ jsx("span", {});
|
|
60
|
+
if (isTypedValue(rule, field) && !disabled) return /* @__PURE__ */ jsx(ValueEditor, {
|
|
61
|
+
rule,
|
|
62
|
+
field,
|
|
63
|
+
lookups,
|
|
64
|
+
onChange
|
|
65
|
+
}, `${pathOf(rule)}:${op}`);
|
|
66
|
+
const empty = text.value === "…";
|
|
67
|
+
const shows = empty ? t("choose", "Choose…") : text.value;
|
|
68
|
+
return /* @__PURE__ */ jsx(ValuePart, {
|
|
69
|
+
rule,
|
|
70
|
+
field,
|
|
71
|
+
lookups,
|
|
72
|
+
onChange,
|
|
73
|
+
open,
|
|
74
|
+
onOpenChange,
|
|
75
|
+
button: /* @__PURE__ */ jsx(RowButton, {
|
|
76
|
+
disabled,
|
|
77
|
+
part: t("value", "Value"),
|
|
78
|
+
shows,
|
|
79
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
80
|
+
className: cn("truncate", empty && "text-muted-foreground"),
|
|
81
|
+
children: shows
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* A row of the advanced filter (and an automation's conditions): `lead` ("Where", "And", "Or"),
|
|
88
|
+
* then the field, the operator and the value, each opening its editor, then remove. `fresh`
|
|
89
|
+
* opens the value at once, for a row just added.
|
|
90
|
+
*/
|
|
91
|
+
const RuleRow = ({ rule, fields, lookups, disabled, customPath, lead, fresh, onChange, onRemove }) => {
|
|
92
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
93
|
+
const field = fieldAt(fields, pathOf(rule));
|
|
94
|
+
const text = useRuleText(rule, field, lookups);
|
|
95
|
+
const [open, setOpen] = useState(fresh ? "value" : null);
|
|
96
|
+
const toggle = (part) => (next) => setOpen(next ? part : null);
|
|
97
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
98
|
+
className: "grid grid-cols-condition items-center gap-1.5",
|
|
99
|
+
children: [
|
|
100
|
+
lead,
|
|
101
|
+
/* @__PURE__ */ jsx(FieldPart, {
|
|
102
|
+
fields,
|
|
103
|
+
field,
|
|
104
|
+
customPath,
|
|
105
|
+
open: open === "field",
|
|
106
|
+
onOpenChange: toggle("field"),
|
|
107
|
+
onSelect: (next) => {
|
|
108
|
+
onChange(withField(rule, field, next));
|
|
109
|
+
setOpen(null);
|
|
110
|
+
},
|
|
111
|
+
button: /* @__PURE__ */ jsxs(RowButton, {
|
|
112
|
+
disabled,
|
|
113
|
+
part: t("field", "Field"),
|
|
114
|
+
shows: field.label,
|
|
115
|
+
children: [/* @__PURE__ */ jsx(FieldIcon, {
|
|
116
|
+
field,
|
|
117
|
+
className: "text-muted-foreground"
|
|
118
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
119
|
+
className: "truncate",
|
|
120
|
+
children: field.label
|
|
121
|
+
})]
|
|
122
|
+
})
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ jsx(OperatorPart, {
|
|
125
|
+
rule,
|
|
126
|
+
field,
|
|
127
|
+
open: open === "op",
|
|
128
|
+
onOpenChange: toggle("op"),
|
|
129
|
+
onSelect: (op) => {
|
|
130
|
+
const next = withOperator(rule, op);
|
|
131
|
+
onChange(next);
|
|
132
|
+
setOpen(NO_VALUE.has(op) || isTypedValue(next, field) ? null : "value");
|
|
133
|
+
},
|
|
134
|
+
button: /* @__PURE__ */ jsx(OperatorButton, {
|
|
135
|
+
shows: text.op,
|
|
136
|
+
disabled
|
|
137
|
+
})
|
|
138
|
+
}),
|
|
139
|
+
/* @__PURE__ */ jsx(RowValue, {
|
|
140
|
+
rule,
|
|
141
|
+
field,
|
|
142
|
+
lookups,
|
|
143
|
+
disabled,
|
|
144
|
+
onChange,
|
|
145
|
+
open: open === "value",
|
|
146
|
+
onOpenChange: toggle("value")
|
|
147
|
+
}),
|
|
148
|
+
/* @__PURE__ */ jsx(RemoveButton, {
|
|
149
|
+
label: t("remove-rule", "Remove rule"),
|
|
150
|
+
disabled,
|
|
151
|
+
onRemove
|
|
152
|
+
})
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
export { RemoveButton, RuleRow };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Input } from "../../components/input.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* A box whose text reaches `onCommit` once typing pauses (no request per keystroke), at once on
|
|
5
|
+
* Enter (then `onEnter`), and when it closes mid-word. `initial` is its first text. With
|
|
6
|
+
* `focusOnMount` it takes the keyboard as it shows, being the editor a menu just opened.
|
|
7
|
+
*/
|
|
8
|
+
export declare const TypedInput: ({ initial, onCommit, onEnter, focusOnMount, ...props }: Omit<ComponentProps<typeof Input>, 'value' | 'onChange' | 'onKeyDown' | 'defaultValue' | 'ref'> & {
|
|
9
|
+
initial: string;
|
|
10
|
+
onCommit: (text: string) => void;
|
|
11
|
+
onEnter?: () => void;
|
|
12
|
+
focusOnMount?: boolean;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Input } from "../../components/input.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
5
|
+
// src/modules/conditions/TypedInput.tsx
|
|
6
|
+
/** How long typing waits before the filter follows it. */
|
|
7
|
+
const TYPING_MS = 250;
|
|
8
|
+
/**
|
|
9
|
+
* A box whose text reaches `onCommit` once typing pauses (no request per keystroke), at once on
|
|
10
|
+
* Enter (then `onEnter`), and when it closes mid-word. `initial` is its first text. With
|
|
11
|
+
* `focusOnMount` it takes the keyboard as it shows, being the editor a menu just opened.
|
|
12
|
+
*/
|
|
13
|
+
const TypedInput = ({ initial, onCommit, onEnter, focusOnMount, ...props }) => {
|
|
14
|
+
const [text, setText] = useState(initial);
|
|
15
|
+
const input = useRef(null);
|
|
16
|
+
const debounced = useDebouncedCallback(onCommit, TYPING_MS);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (focusOnMount) input.current?.focus();
|
|
19
|
+
}, [focusOnMount]);
|
|
20
|
+
useEffect(() => () => debounced.flush(), [debounced]);
|
|
21
|
+
return /* @__PURE__ */ jsx(Input, {
|
|
22
|
+
...props,
|
|
23
|
+
ref: input,
|
|
24
|
+
value: text,
|
|
25
|
+
onChange: (event) => {
|
|
26
|
+
setText(event.target.value);
|
|
27
|
+
debounced(event.target.value);
|
|
28
|
+
},
|
|
29
|
+
onKeyDown: (event) => {
|
|
30
|
+
if (event.key !== "Enter") return;
|
|
31
|
+
debounced.flush();
|
|
32
|
+
onEnter?.();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export { TypedInput };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TConditionField, TConditionLookups } from "./conditions.js";
|
|
2
|
+
import { TFilterRule } from "./filterRule.js";
|
|
3
|
+
export type ValueEditorProps = {
|
|
4
|
+
rule: TFilterRule;
|
|
5
|
+
field: TConditionField | undefined;
|
|
6
|
+
lookups: TConditionLookups;
|
|
7
|
+
onChange: (next: TFilterRule) => void;
|
|
8
|
+
/** A pick that finishes the rule (a day, yes or no, Enter): a popover around the editor closes. */
|
|
9
|
+
onDone?: () => void;
|
|
10
|
+
};
|
|
11
|
+
/** Whether the value is typed into a box (it fits in a row), rather than picked from a list. */
|
|
12
|
+
export declare const isTypedValue: (rule: TFilterRule, field: TConditionField | undefined) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The editor for a rule's value, by its operator and its field's type: labelled options with
|
|
15
|
+
* search, text and numbers that apply as typing pauses, relative dates and days on a calendar,
|
|
16
|
+
* yes or no. None when the operator needs no value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ValueEditor: (props: ValueEditorProps) => import("react").JSX.Element | null;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Combobox } from "../../components/combobox.js";
|
|
2
|
+
import { Command } from "../../components/command.js";
|
|
3
|
+
import { amountStep, fromAmountInput, toAmountInput } from "../../lib/money.js";
|
|
4
|
+
import { textOf } from "../../lib/text.js";
|
|
5
|
+
import { EntityPicker } from "../pickers/EntityPicker.js";
|
|
6
|
+
import { LIST_VALUE, NO_VALUE, RELATIVE, isRule } from "./conditions.js";
|
|
7
|
+
import { between, valuesBetween } from "./filterRule.js";
|
|
8
|
+
import { DayEditor, RelativeEditor } from "./DateEditors.js";
|
|
9
|
+
import { useFieldOptions } from "./fieldOptions.js";
|
|
10
|
+
import { valuesOf } from "./filterText.js";
|
|
11
|
+
import { TypedInput } from "./TypedInput.js";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useTranslation } from "react-i18next";
|
|
14
|
+
// src/modules/conditions/ValueEditor.tsx
|
|
15
|
+
/** Options (a choice, members, tags) by their labels: "is any of" picks several, others one. */
|
|
16
|
+
const OptionsEditor = ({ rule, field, lookups, onChange, onDone }) => {
|
|
17
|
+
const picked = valuesOf(rule);
|
|
18
|
+
const { options, loading, error } = useFieldOptions(field, lookups, picked);
|
|
19
|
+
const multiple = LIST_VALUE.has(rule.op);
|
|
20
|
+
return /* @__PURE__ */ jsx(EntityPicker, {
|
|
21
|
+
multiple,
|
|
22
|
+
items: options,
|
|
23
|
+
itemKey: (option) => ({
|
|
24
|
+
id: option.value,
|
|
25
|
+
label: option.label
|
|
26
|
+
}),
|
|
27
|
+
value: picked,
|
|
28
|
+
onValueChange: (values) => {
|
|
29
|
+
onChange({
|
|
30
|
+
...rule,
|
|
31
|
+
value: multiple ? values : values[0]
|
|
32
|
+
});
|
|
33
|
+
if (!multiple) onDone?.();
|
|
34
|
+
},
|
|
35
|
+
loading,
|
|
36
|
+
error,
|
|
37
|
+
searchPlaceholder: field?.label
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const BooleanEditor = ({ rule, onChange, onDone }) => {
|
|
41
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
42
|
+
const value = textOf(rule.value);
|
|
43
|
+
return /* @__PURE__ */ jsx(Command, { children: /* @__PURE__ */ jsx(Command.List, { children: ["true", "false"].map((option) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
44
|
+
value: option,
|
|
45
|
+
onSelect: () => {
|
|
46
|
+
onChange({
|
|
47
|
+
...rule,
|
|
48
|
+
value: option === "true"
|
|
49
|
+
});
|
|
50
|
+
onDone?.();
|
|
51
|
+
},
|
|
52
|
+
children: [option === "true" ? t("yes", "Yes") : t("no", "No"), /* @__PURE__ */ jsx(Combobox.Check, { checked: value === option })]
|
|
53
|
+
}, option)) }) });
|
|
54
|
+
};
|
|
55
|
+
/** Text, or a list typed as "a, b, c" (an automation's "is any of" on text). */
|
|
56
|
+
const TextEditor = ({ rule, onChange, onDone }) => {
|
|
57
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
58
|
+
const list = LIST_VALUE.has(rule.op);
|
|
59
|
+
return /* @__PURE__ */ jsx(TypedInput, {
|
|
60
|
+
focusOnMount: !!onDone,
|
|
61
|
+
className: "h-8",
|
|
62
|
+
"aria-label": t("value", "Value"),
|
|
63
|
+
placeholder: list ? t("list-placeholder", "a, b, c") : t("value", "Value"),
|
|
64
|
+
initial: list ? valuesOf(rule).join(", ") : textOf(rule.value),
|
|
65
|
+
onCommit: (text) => onChange({
|
|
66
|
+
...rule,
|
|
67
|
+
value: list ? text.split(",").map((item) => item.trim()).filter(Boolean) : text.trim()
|
|
68
|
+
}),
|
|
69
|
+
onEnter: onDone
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/** A number as typed: money in the currency's major unit. */
|
|
73
|
+
const numberText = (value, currency) => {
|
|
74
|
+
const n = Number(value);
|
|
75
|
+
if (value === void 0 || value === null || value === "" || !Number.isFinite(n)) return "";
|
|
76
|
+
return currency ? toAmountInput(n, currency) : String(n);
|
|
77
|
+
};
|
|
78
|
+
const numberOf = (text, currency) => {
|
|
79
|
+
if (!text.trim() || !Number.isFinite(Number(text))) return void 0;
|
|
80
|
+
return currency ? fromAmountInput(text, currency) : Number(text);
|
|
81
|
+
};
|
|
82
|
+
/** One number box; an amount of money is typed in the currency's major unit. */
|
|
83
|
+
const NumberInput = ({ value, currency, label, onChange, onEnter, focusOnMount }) => /* @__PURE__ */ jsx(TypedInput, {
|
|
84
|
+
focusOnMount,
|
|
85
|
+
type: "number",
|
|
86
|
+
className: "h-8 min-w-0 flex-1",
|
|
87
|
+
"aria-label": label,
|
|
88
|
+
placeholder: currency ?? label,
|
|
89
|
+
step: currency ? amountStep(currency) : "any",
|
|
90
|
+
initial: numberText(value, currency),
|
|
91
|
+
onCommit: (text) => onChange(numberOf(text, currency)),
|
|
92
|
+
onEnter
|
|
93
|
+
});
|
|
94
|
+
/** A number, or both ends of "between". */
|
|
95
|
+
const NumberEditor = ({ rule, field, onChange, onDone }) => {
|
|
96
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
97
|
+
const currency = field?.currency;
|
|
98
|
+
if (isRule(rule)) return /* @__PURE__ */ jsx(NumberInput, {
|
|
99
|
+
focusOnMount: !!onDone,
|
|
100
|
+
value: rule.value,
|
|
101
|
+
currency,
|
|
102
|
+
label: t("value", "Value"),
|
|
103
|
+
onChange: (value) => onChange({
|
|
104
|
+
...rule,
|
|
105
|
+
value
|
|
106
|
+
}),
|
|
107
|
+
onEnter: onDone
|
|
108
|
+
});
|
|
109
|
+
const [from, to] = valuesBetween(rule);
|
|
110
|
+
const path = rule.rules[0].path;
|
|
111
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
112
|
+
className: "flex items-center gap-1.5",
|
|
113
|
+
children: [
|
|
114
|
+
/* @__PURE__ */ jsx(NumberInput, {
|
|
115
|
+
focusOnMount: !!onDone,
|
|
116
|
+
value: from,
|
|
117
|
+
currency,
|
|
118
|
+
label: t("from", "From"),
|
|
119
|
+
onChange: (value) => onChange(between(path, value, to))
|
|
120
|
+
}),
|
|
121
|
+
/* @__PURE__ */ jsx("span", {
|
|
122
|
+
className: "text-muted-foreground",
|
|
123
|
+
children: "–"
|
|
124
|
+
}),
|
|
125
|
+
/* @__PURE__ */ jsx(NumberInput, {
|
|
126
|
+
value: to,
|
|
127
|
+
currency,
|
|
128
|
+
label: t("to", "To"),
|
|
129
|
+
onChange: (value) => onChange(between(path, from, value)),
|
|
130
|
+
onEnter: onDone
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
/** Whether the value is typed into a box (it fits in a row), rather than picked from a list. */
|
|
136
|
+
const isTypedValue = (rule, field) => {
|
|
137
|
+
if (!isRule(rule)) return field?.type !== "date";
|
|
138
|
+
if (NO_VALUE.has(rule.op) || RELATIVE.has(rule.op)) return false;
|
|
139
|
+
const type = field?.type;
|
|
140
|
+
if (type === "date" || type === "boolean" || type === "member" || type === "tags") return false;
|
|
141
|
+
return !field?.options?.length;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* The editor for a rule's value, by its operator and its field's type: labelled options with
|
|
145
|
+
* search, text and numbers that apply as typing pauses, relative dates and days on a calendar,
|
|
146
|
+
* yes or no. None when the operator needs no value.
|
|
147
|
+
*/
|
|
148
|
+
const ValueEditor = (props) => {
|
|
149
|
+
const { rule, field } = props;
|
|
150
|
+
const type = field?.type;
|
|
151
|
+
if (!isRule(rule)) return type === "date" ? /* @__PURE__ */ jsx(DayEditor, { ...props }) : /* @__PURE__ */ jsx(NumberEditor, { ...props });
|
|
152
|
+
const ruleProps = {
|
|
153
|
+
...props,
|
|
154
|
+
rule
|
|
155
|
+
};
|
|
156
|
+
if (NO_VALUE.has(rule.op)) return null;
|
|
157
|
+
if (RELATIVE.has(rule.op)) return /* @__PURE__ */ jsx(RelativeEditor, { ...ruleProps });
|
|
158
|
+
if (type === "date") return /* @__PURE__ */ jsx(DayEditor, { ...props });
|
|
159
|
+
if (type === "number") return /* @__PURE__ */ jsx(NumberEditor, { ...props });
|
|
160
|
+
if (type === "boolean") return /* @__PURE__ */ jsx(BooleanEditor, { ...ruleProps });
|
|
161
|
+
if (type === "member" || type === "tags" || field?.options?.length) return /* @__PURE__ */ jsx(OptionsEditor, { ...ruleProps });
|
|
162
|
+
return /* @__PURE__ */ jsx(TextEditor, { ...ruleProps });
|
|
163
|
+
};
|
|
164
|
+
export { ValueEditor, isTypedValue };
|