@erxes/ui 4.0.0-v2.12 → 4.0.0-v2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CATALOG.md +3 -2
- package/README.md +1 -1
- package/dist/components/color-picker.js +2 -2
- package/dist/components/command-bar.js +3 -0
- package/dist/components/input.d.ts +1 -1
- package/dist/components/input.js +2 -2
- package/dist/components/on-demand.d.ts +9 -2
- package/dist/components/on-demand.js +15 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/modules/conditions/ConditionsEditor.d.ts +5 -3
- package/dist/modules/conditions/ConditionsEditor.js +139 -177
- package/dist/modules/conditions/DateEditors.d.ts +8 -0
- package/dist/modules/conditions/DateEditors.js +188 -0
- package/dist/modules/conditions/FieldPicker.d.ts +17 -0
- package/dist/modules/conditions/FieldPicker.js +99 -0
- package/dist/modules/conditions/RuleParts.d.ts +30 -0
- package/dist/modules/conditions/RuleParts.js +78 -0
- package/dist/modules/conditions/RuleRow.d.ts +27 -0
- package/dist/modules/conditions/RuleRow.js +156 -0
- package/dist/modules/conditions/TypedInput.d.ts +13 -0
- package/dist/modules/conditions/TypedInput.js +36 -0
- package/dist/modules/conditions/ValueEditor.d.ts +18 -0
- package/dist/modules/conditions/ValueEditor.js +164 -0
- package/dist/modules/conditions/conditions.d.ts +15 -8
- package/dist/modules/conditions/conditions.js +1 -75
- package/dist/modules/conditions/fieldIcons.d.ts +6 -0
- package/dist/modules/conditions/fieldIcons.js +19 -0
- package/dist/modules/conditions/fieldOptions.d.ts +13 -0
- package/dist/modules/conditions/fieldOptions.js +26 -0
- package/dist/modules/conditions/filterRule.d.ts +45 -0
- package/dist/modules/conditions/filterRule.js +169 -0
- package/dist/modules/conditions/filterText.d.ts +16 -0
- package/dist/modules/conditions/filterText.js +156 -0
- package/dist/modules/filter/components/Filter.d.ts +1 -1
- package/dist/modules/filter/components/Filter.js +1 -1
- package/dist/modules/filter/components/FilterBar.js +3 -0
- package/dist/modules/list/ListFilter.d.ts +20 -7
- package/dist/modules/list/ListFilter.js +50 -17
- package/dist/modules/list/ViewBar.d.ts +2 -0
- package/dist/modules/list/ViewBar.js +21 -10
- package/dist/modules/list/filter/AddFilter.d.ts +10 -0
- package/dist/modules/list/filter/AddFilter.js +140 -0
- package/dist/modules/list/filter/AdvancedPopover.d.ts +8 -0
- package/dist/modules/list/filter/AdvancedPopover.js +103 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +3 -3
- package/dist/modules/list/filter/ListFilterBar.js +104 -198
- package/dist/modules/list/filter/RuleChips.d.ts +12 -2
- package/dist/modules/list/filter/RuleChips.js +132 -138
- package/dist/modules/list/filter/SearchChip.d.ts +6 -0
- package/dist/modules/list/filter/SearchChip.js +69 -0
- package/dist/modules/list/filter/filterRules.d.ts +15 -40
- package/dist/modules/list/filter/filterRules.js +27 -156
- package/dist/modules/list/filter/listFilterContext.d.ts +25 -18
- package/dist/modules/list/filter/listFilterContext.js +8 -24
- package/dist/modules/list/filter/listFilterQuery.d.ts +4 -0
- package/dist/modules/list/filter/listFilterQuery.js +10 -2
- package/dist/theme.css +3 -2
- package/exports.txt +1 -0
- package/package.json +1 -1
- package/dist/modules/conditions/ConditionValueInput.d.ts +0 -10
- package/dist/modules/conditions/ConditionValueInput.js +0 -166
- package/dist/modules/conditions/PathPicker.d.ts +0 -8
- package/dist/modules/conditions/PathPicker.js +0 -51
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +0 -5
- package/dist/modules/list/filter/AdvancedFilterDialog.js +0 -52
- package/dist/modules/list/filter/FieldMenus.d.ts +0 -5
- package/dist/modules/list/filter/FieldMenus.js +0 -184
- package/dist/modules/list/filter/fieldIcons.d.ts +0 -7
- package/dist/modules/list/filter/fieldIcons.js +0 -16
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
import { TConditionLookups } from "../../conditions/conditions.js";
|
|
1
|
+
import { TConditionGroup, TConditionLookups } from "../../conditions/conditions.js";
|
|
2
|
+
import { TFilterRule } from "../../conditions/filterRule.js";
|
|
2
3
|
import { TListFilterField } from "../ListFilter.js";
|
|
3
4
|
import { FilterPart } from "./filterRules.js";
|
|
4
|
-
/**
|
|
5
|
+
/** Where the field picker opens: from the view bar's filter button, or the filter row's "+ Filter". */
|
|
6
|
+
export type AddFrom = 'bar' | 'row';
|
|
7
|
+
/** What the filter row, its chips, the field picker and the advanced filter share. */
|
|
5
8
|
export interface ListFilterState {
|
|
6
9
|
fields: TListFilterField[];
|
|
7
10
|
/** Where `member` and `tags` fields pick from. */
|
|
8
11
|
lookups: TConditionLookups;
|
|
9
|
-
/** The list's filter
|
|
12
|
+
/** The list's filter. */
|
|
13
|
+
advanced: TConditionGroup | null;
|
|
14
|
+
/** The filter as chips; null when it needs the advanced filter (an "or", a nested group). */
|
|
15
|
+
chips: TFilterRule[] | null;
|
|
16
|
+
/** The parts that must all hold (`partsOf`): the chips, or the advanced filter as one. */
|
|
10
17
|
parts: FilterPart[];
|
|
11
|
-
/** Changes
|
|
18
|
+
/** Changes a part as `withPart` does. */
|
|
12
19
|
setPart: (index: number | null, next: FilterPart | null) => void;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
setAdvanced: (next: TConditionGroup | null) => void;
|
|
21
|
+
/** The field picker that is open. */
|
|
22
|
+
adding: AddFrom | null;
|
|
23
|
+
setAdding: (from: AddFrom | null) => void;
|
|
24
|
+
advancedOpen: boolean;
|
|
25
|
+
setAdvancedOpen: (open: boolean) => void;
|
|
26
|
+
/** While the fields load, and why they didn't; the field picker says so. */
|
|
27
|
+
loading?: boolean;
|
|
28
|
+
error?: Error | null;
|
|
29
|
+
/** How many records match, for the advanced filter's "N match". */
|
|
30
|
+
totalCount?: number | null;
|
|
31
|
+
totalCapped?: boolean;
|
|
18
32
|
}
|
|
19
33
|
export declare const ListFilterContext: import("react").Context<ListFilterState | null>;
|
|
20
34
|
export declare const useListFilter: () => ListFilterState;
|
|
21
|
-
/**
|
|
22
|
-
export declare const
|
|
23
|
-
options: {
|
|
24
|
-
value: string;
|
|
25
|
-
label: string;
|
|
26
|
-
}[];
|
|
27
|
-
loading: boolean;
|
|
28
|
-
error: Error | null;
|
|
29
|
-
};
|
|
35
|
+
/** A field by its path; one no list field has (a removed property) reads as text. */
|
|
36
|
+
export declare const useFieldAt: (path: string) => TListFilterField;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
-
import { useMemberOptions, useTagOptions } from "../../pickers/LookupPicker.js";
|
|
3
|
-
import { valuesOf } from "./filterRules.js";
|
|
4
1
|
import { createContext, useContext } from "react";
|
|
5
|
-
import { useTranslation } from "react-i18next";
|
|
6
2
|
// src/modules/list/filter/listFilterContext.ts
|
|
7
3
|
const ListFilterContext = createContext(null);
|
|
8
4
|
const useListFilter = () => {
|
|
@@ -10,25 +6,13 @@ const useListFilter = () => {
|
|
|
10
6
|
if (!state) throw new Error("useListFilter is only available inside <ListFilter>");
|
|
11
7
|
return state;
|
|
12
8
|
};
|
|
13
|
-
/**
|
|
14
|
-
const
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (field.type === "member") return {
|
|
21
|
-
...members,
|
|
22
|
-
options: [{
|
|
23
|
-
value: "me",
|
|
24
|
-
label: t("me", "Me")
|
|
25
|
-
}, ...members.options]
|
|
26
|
-
};
|
|
27
|
-
if (field.type === "tags") return tags;
|
|
28
|
-
return {
|
|
29
|
-
options: field.options ?? [],
|
|
30
|
-
loading: false,
|
|
31
|
-
error: null
|
|
9
|
+
/** A field by its path; one no list field has (a removed property) reads as text. */
|
|
10
|
+
const useFieldAt = (path) => {
|
|
11
|
+
const { fields } = useListFilter();
|
|
12
|
+
return fields.find((field) => field.path === path) ?? {
|
|
13
|
+
path,
|
|
14
|
+
label: path,
|
|
15
|
+
type: "text"
|
|
32
16
|
};
|
|
33
17
|
};
|
|
34
|
-
export { ListFilterContext,
|
|
18
|
+
export { ListFilterContext, useFieldAt, useListFilter };
|
|
@@ -12,5 +12,9 @@ export declare const listFilterQuery: {
|
|
|
12
12
|
export declare const useListConditions: () => {
|
|
13
13
|
advanced: TConditionGroup | null;
|
|
14
14
|
search: string | null;
|
|
15
|
+
/** Whether the list is filtered or searched. */
|
|
16
|
+
active: boolean;
|
|
15
17
|
setAdvanced: (next: TConditionGroup | null) => undefined;
|
|
18
|
+
setSearch: (next: string | null) => undefined;
|
|
19
|
+
clear: () => undefined;
|
|
16
20
|
};
|
|
@@ -13,10 +13,18 @@ const listFilterQuery = {
|
|
|
13
13
|
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
14
14
|
const useListConditions = () => {
|
|
15
15
|
const [{ advanced, searchValue }, setQueries] = useQueryStates(listFilterQuery, { history: "replace" });
|
|
16
|
+
const filter = advanced?.rules.length ? advanced : null;
|
|
16
17
|
return {
|
|
17
|
-
advanced:
|
|
18
|
+
advanced: filter,
|
|
18
19
|
search: searchValue,
|
|
19
|
-
|
|
20
|
+
/** Whether the list is filtered or searched. */
|
|
21
|
+
active: filter !== null || Boolean(searchValue),
|
|
22
|
+
setAdvanced: (next) => void setQueries({ advanced: next?.rules.length ? next : null }),
|
|
23
|
+
setSearch: (next) => void setQueries({ searchValue: next || null }),
|
|
24
|
+
clear: () => void setQueries({
|
|
25
|
+
advanced: null,
|
|
26
|
+
searchValue: null
|
|
27
|
+
})
|
|
20
28
|
};
|
|
21
29
|
};
|
|
22
30
|
export { listFilterQuery, useListConditions };
|
package/dist/theme.css
CHANGED
|
@@ -126,8 +126,9 @@
|
|
|
126
126
|
--grid-template-columns-field: 6.5rem minmax(0, 1fr);
|
|
127
127
|
/* A side column of 18 to 24rem beside the content. */
|
|
128
128
|
--grid-template-columns-aside: minmax(18rem, 24rem) minmax(0, 1fr);
|
|
129
|
-
/* A condition row: field
|
|
130
|
-
|
|
129
|
+
/* A condition row: "Where", "And" or "Or", the field, the operator, the value, then remove. */
|
|
130
|
+
/* 5.5rem holds the And/Or picker in Mongolian ("Эсвэл"). */
|
|
131
|
+
--grid-template-columns-condition: 5.5rem minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 1.2fr) auto;
|
|
131
132
|
|
|
132
133
|
/* Panels and sidebars sliding open or shut. */
|
|
133
134
|
--ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
|
package/exports.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TConditionField, TConditionLookups, TConditionRule } from "./conditions.js";
|
|
2
|
-
type ValueProps = TConditionLookups & {
|
|
3
|
-
rule: TConditionRule;
|
|
4
|
-
field?: TConditionField;
|
|
5
|
-
onChange: (value: unknown) => void;
|
|
6
|
-
disabled?: boolean;
|
|
7
|
-
};
|
|
8
|
-
/** The value side of a rule, shaped by the operator and the field's type. */
|
|
9
|
-
export declare const ConditionValueInput: (props: ValueProps) => import("react").JSX.Element;
|
|
10
|
-
export {};
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { Input } from "../../components/input.js";
|
|
2
|
-
import { Select } from "../../components/select.js";
|
|
3
|
-
import { amountStep, fromAmountInput, toAmountInput } from "../../lib/money.js";
|
|
4
|
-
import { oneOf, textOf } from "../../lib/text.js";
|
|
5
|
-
import { LookupPicker, useMemberOptions, useTagOptions } from "../pickers/LookupPicker.js";
|
|
6
|
-
import { LIST_VALUE, RELATIVE, RELATIVE_UNITS } from "./conditions.js";
|
|
7
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { useState } from "react";
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import { useTranslation } from "react-i18next";
|
|
11
|
-
// src/modules/conditions/ConditionValueInput.tsx
|
|
12
|
-
/** What the rule holds so far: a half-typed amount is still shown. */
|
|
13
|
-
const RelativeValue = z.object({
|
|
14
|
-
amount: z.number().optional(),
|
|
15
|
-
unit: z.enum(RELATIVE_UNITS).optional()
|
|
16
|
-
});
|
|
17
|
-
const RelativeInput = ({ rule, onChange, disabled }) => {
|
|
18
|
-
const { t } = useTranslation("automations");
|
|
19
|
-
const current = RelativeValue.safeParse(rule.value).data ?? {};
|
|
20
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
21
|
-
className: "flex w-full items-center gap-1",
|
|
22
|
-
children: [/* @__PURE__ */ jsx(Input, {
|
|
23
|
-
className: "h-8 w-20",
|
|
24
|
-
type: "number",
|
|
25
|
-
min: 0,
|
|
26
|
-
disabled,
|
|
27
|
-
value: current.amount ?? "",
|
|
28
|
-
onChange: (event) => onChange({
|
|
29
|
-
unit: "days",
|
|
30
|
-
...current,
|
|
31
|
-
amount: Math.max(0, Number(event.target.value) || 0)
|
|
32
|
-
})
|
|
33
|
-
}), rule.op === "anniversary_within" ? /* @__PURE__ */ jsx("span", {
|
|
34
|
-
className: "text-sm text-muted-foreground",
|
|
35
|
-
children: t("days", "days")
|
|
36
|
-
}) : /* @__PURE__ */ jsxs(Select, {
|
|
37
|
-
value: current.unit ?? "days",
|
|
38
|
-
disabled,
|
|
39
|
-
onValueChange: (next) => {
|
|
40
|
-
const unit = oneOf(RELATIVE_UNITS, next);
|
|
41
|
-
if (unit) onChange({
|
|
42
|
-
amount: 0,
|
|
43
|
-
...current,
|
|
44
|
-
unit
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
48
|
-
className: "h-8 w-28 shrink-0",
|
|
49
|
-
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
50
|
-
}), /* @__PURE__ */ jsx(Select.Content, { children: RELATIVE_UNITS.map((unit) => /* @__PURE__ */ jsx(Select.Item, {
|
|
51
|
-
value: unit,
|
|
52
|
-
children: t(unit, unit)
|
|
53
|
-
}, unit)) })]
|
|
54
|
-
})]
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
/** A team member ("me" first) or a tag of the subject. */
|
|
58
|
-
const LookupInput = ({ rule, field, onChange, disabled, ...lookups }) => {
|
|
59
|
-
const { t } = useTranslation("automations");
|
|
60
|
-
const isMember = field?.type === "member";
|
|
61
|
-
const value = textOf(rule.value);
|
|
62
|
-
const members = useMemberOptions(lookups.members, isMember, value ? [value] : []);
|
|
63
|
-
const tags = useTagOptions(lookups.tags, !isMember);
|
|
64
|
-
const lookup = isMember ? members : tags;
|
|
65
|
-
return /* @__PURE__ */ jsx(LookupPicker, {
|
|
66
|
-
lookup: isMember ? {
|
|
67
|
-
...lookup,
|
|
68
|
-
options: [{
|
|
69
|
-
value: "me",
|
|
70
|
-
label: t("me", "Me")
|
|
71
|
-
}, ...lookup.options]
|
|
72
|
-
} : lookup,
|
|
73
|
-
value: value ? [value] : [],
|
|
74
|
-
onValueChange: ([next]) => onChange(next ?? ""),
|
|
75
|
-
disabled,
|
|
76
|
-
placeholder: t("choose", "Choose…"),
|
|
77
|
-
className: "h-8 w-full min-w-0"
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
const ListInput = ({ rule, onChange, disabled }) => {
|
|
81
|
-
const { t } = useTranslation("automations");
|
|
82
|
-
return /* @__PURE__ */ jsx(Input, {
|
|
83
|
-
className: "h-8 w-full min-w-0",
|
|
84
|
-
disabled,
|
|
85
|
-
placeholder: t("list-placeholder", "a, b, c"),
|
|
86
|
-
value: Array.isArray(rule.value) ? rule.value.join(", ") : textOf(rule.value),
|
|
87
|
-
onChange: (event) => onChange(event.target.value.split(",").map((item) => item.trim()).filter(Boolean))
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
const BooleanInput = ({ rule, onChange, disabled }) => {
|
|
91
|
-
const { t } = useTranslation("automations");
|
|
92
|
-
return /* @__PURE__ */ jsxs(Select, {
|
|
93
|
-
value: textOf(rule.value ?? "true"),
|
|
94
|
-
onValueChange: (value) => onChange(value === "true"),
|
|
95
|
-
disabled,
|
|
96
|
-
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
97
|
-
className: "h-8 w-28 shrink-0",
|
|
98
|
-
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
99
|
-
}), /* @__PURE__ */ jsxs(Select.Content, { children: [/* @__PURE__ */ jsx(Select.Item, {
|
|
100
|
-
value: "true",
|
|
101
|
-
children: t("yes", "yes")
|
|
102
|
-
}), /* @__PURE__ */ jsx(Select.Item, {
|
|
103
|
-
value: "false",
|
|
104
|
-
children: t("no", "no")
|
|
105
|
-
})] })]
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
const OptionInput = ({ rule, options, onChange, disabled }) => /* @__PURE__ */ jsxs(Select, {
|
|
109
|
-
value: textOf(rule.value),
|
|
110
|
-
onValueChange: onChange,
|
|
111
|
-
disabled,
|
|
112
|
-
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
113
|
-
className: "h-8 w-full min-w-0",
|
|
114
|
-
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
115
|
-
}), /* @__PURE__ */ jsx(Select.Content, { children: options.map((option) => /* @__PURE__ */ jsx(Select.Item, {
|
|
116
|
-
value: option,
|
|
117
|
-
children: option
|
|
118
|
-
}, option)) })]
|
|
119
|
-
});
|
|
120
|
-
const TextInput = ({ rule, field, onChange, disabled }) => {
|
|
121
|
-
const { t } = useTranslation("automations");
|
|
122
|
-
return /* @__PURE__ */ jsx(Input, {
|
|
123
|
-
className: "h-8 w-full min-w-0",
|
|
124
|
-
type: field?.type === "date" ? "date" : field?.type === "number" ? "number" : "text",
|
|
125
|
-
disabled,
|
|
126
|
-
placeholder: t("value-placeholder", "value"),
|
|
127
|
-
value: textOf(rule.value),
|
|
128
|
-
onChange: (event) => onChange(field?.type === "number" ? Number(event.target.value) : event.target.value)
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
/** An amount typed in the currency's major unit (12.50), kept in its smallest (1250); the text is kept while typing. */
|
|
132
|
-
const MoneyInput = ({ rule, onChange, disabled, currency }) => {
|
|
133
|
-
const { t } = useTranslation("automations");
|
|
134
|
-
const stored = Number(rule.value);
|
|
135
|
-
const [text, setText] = useState(rule.value === void 0 || !Number.isFinite(stored) ? "" : toAmountInput(stored, currency));
|
|
136
|
-
return /* @__PURE__ */ jsx(Input, {
|
|
137
|
-
className: "h-8 w-full min-w-0",
|
|
138
|
-
type: "number",
|
|
139
|
-
step: amountStep(currency),
|
|
140
|
-
disabled,
|
|
141
|
-
placeholder: t("value-placeholder", "value"),
|
|
142
|
-
value: text,
|
|
143
|
-
onChange: (event) => {
|
|
144
|
-
setText(event.target.value);
|
|
145
|
-
onChange(fromAmountInput(event.target.value, currency));
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
/** The value side of a rule, shaped by the operator and the field's type. */
|
|
150
|
-
const ConditionValueInput = (props) => {
|
|
151
|
-
const { rule, field } = props;
|
|
152
|
-
if (RELATIVE.has(rule.op)) return /* @__PURE__ */ jsx(RelativeInput, { ...props });
|
|
153
|
-
if (field?.currency && field.type === "number" && !LIST_VALUE.has(rule.op)) return /* @__PURE__ */ jsx(MoneyInput, {
|
|
154
|
-
...props,
|
|
155
|
-
currency: field.currency
|
|
156
|
-
});
|
|
157
|
-
if (LIST_VALUE.has(rule.op)) return /* @__PURE__ */ jsx(ListInput, { ...props });
|
|
158
|
-
if (field?.type === "member" || field?.type === "tags") return /* @__PURE__ */ jsx(LookupInput, { ...props });
|
|
159
|
-
if (field?.type === "boolean") return /* @__PURE__ */ jsx(BooleanInput, { ...props });
|
|
160
|
-
if (field?.options?.length) return /* @__PURE__ */ jsx(OptionInput, {
|
|
161
|
-
...props,
|
|
162
|
-
options: field.options
|
|
163
|
-
});
|
|
164
|
-
return /* @__PURE__ */ jsx(TextInput, { ...props });
|
|
165
|
-
};
|
|
166
|
-
export { ConditionValueInput };
|
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
|
@@ -1,51 +0,0 @@
|
|
|
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 };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Button } from "../../../components/button.js";
|
|
2
|
-
import { Dialog } from "../../../components/dialog.js";
|
|
3
|
-
import { ConditionsEditor } from "../../conditions/ConditionsEditor.js";
|
|
4
|
-
import { useListFilter } from "./listFilterContext.js";
|
|
5
|
-
import { useListConditions } from "./listFilterQuery.js";
|
|
6
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { useState } from "react";
|
|
8
|
-
import { useTranslation } from "react-i18next";
|
|
9
|
-
// src/modules/list/filter/AdvancedFilterDialog.tsx
|
|
10
|
-
/** Mounted each time the dialog opens, so the draft starts from the list's filter. */
|
|
11
|
-
const AdvancedFilterForm = ({ onDone }) => {
|
|
12
|
-
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
13
|
-
const { fields, lookups } = useListFilter();
|
|
14
|
-
const { advanced, setAdvanced } = useListConditions();
|
|
15
|
-
const [draft, setDraft] = useState(advanced);
|
|
16
|
-
const apply = (next) => {
|
|
17
|
-
setAdvanced(next);
|
|
18
|
-
onDone();
|
|
19
|
-
};
|
|
20
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ConditionsEditor, {
|
|
21
|
-
fields: fields.map(({ options, ...field }) => ({
|
|
22
|
-
...field,
|
|
23
|
-
options: options?.map((option) => option.value)
|
|
24
|
-
})),
|
|
25
|
-
...lookups,
|
|
26
|
-
value: draft ?? void 0,
|
|
27
|
-
onChange: (next) => setDraft(next ?? null)
|
|
28
|
-
}), /* @__PURE__ */ jsxs(Dialog.Footer, { children: [/* @__PURE__ */ jsx(Button, {
|
|
29
|
-
variant: "ghost",
|
|
30
|
-
onClick: () => apply(null),
|
|
31
|
-
children: t("clear", "Clear")
|
|
32
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
33
|
-
onClick: () => apply(draft),
|
|
34
|
-
children: t("apply", "Apply")
|
|
35
|
-
})] })] });
|
|
36
|
-
};
|
|
37
|
-
/** The full builder (every field, and/or groups), for what the filter menu can't say. */
|
|
38
|
-
const AdvancedFilterDialog = ({ open, onOpenChange }) => {
|
|
39
|
-
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
40
|
-
return /* @__PURE__ */ jsx(Dialog, {
|
|
41
|
-
open,
|
|
42
|
-
onOpenChange,
|
|
43
|
-
children: /* @__PURE__ */ jsxs(Dialog.Content, {
|
|
44
|
-
className: "sm:max-w-3xl",
|
|
45
|
-
children: [/* @__PURE__ */ jsx(Dialog.HeaderCombined, {
|
|
46
|
-
title: t("advanced", "Advanced filter"),
|
|
47
|
-
description: t("advanced-title", "Show records where")
|
|
48
|
-
}), /* @__PURE__ */ jsx(AdvancedFilterForm, { onDone: () => onOpenChange(false) })]
|
|
49
|
-
})
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
export { AdvancedFilterDialog };
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Button } from "../../../components/button.js";
|
|
2
|
-
import { Combobox } from "../../../components/combobox.js";
|
|
3
|
-
import { Command } from "../../../components/command.js";
|
|
4
|
-
import { Input } from "../../../components/input.js";
|
|
5
|
-
import { Select } from "../../../components/select.js";
|
|
6
|
-
import { amountStep, fromAmountInput, toAmountInput } from "../../../lib/money.js";
|
|
7
|
-
import { oneOf, textOf } from "../../../lib/text.js";
|
|
8
|
-
import { isRule } from "../../conditions/conditions.js";
|
|
9
|
-
import { useFilterContext } from "../../filter/hooks/useFilterContext.js";
|
|
10
|
-
import { EntityPicker } from "../../pickers/EntityPicker.js";
|
|
11
|
-
import { DATE_PRESETS, NUMBER_OPS, NUMBER_SYMBOLS, anyOf, presetOf, targetOf, valuesOf } from "./filterRules.js";
|
|
12
|
-
import { useFieldOptions, useListFilter } from "./listFilterContext.js";
|
|
13
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { useEffect, useRef, useState } from "react";
|
|
15
|
-
import { useTranslation } from "react-i18next";
|
|
16
|
-
// src/modules/list/filter/FieldMenus.tsx
|
|
17
|
-
/** The part this field's menu changes, and that part when it is a rule of the field. */
|
|
18
|
-
const useTarget = (field) => {
|
|
19
|
-
const { parts, setPart, editing } = useListFilter();
|
|
20
|
-
const { resetFilterState } = useFilterContext();
|
|
21
|
-
const index = targetOf(parts, field, editing);
|
|
22
|
-
const part = index === null ? void 0 : parts[index];
|
|
23
|
-
return {
|
|
24
|
-
rule: part && isRule(part) && part.path === field.path ? part : void 0,
|
|
25
|
-
set: (next) => setPart(index, next),
|
|
26
|
-
/** Sets the rule and closes the menu. */
|
|
27
|
-
apply: (next) => {
|
|
28
|
-
setPart(index, next);
|
|
29
|
-
resetFilterState();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
/** A submenu's box takes the keyboard as the submenu opens. */
|
|
34
|
-
const useFocusOnMount = () => {
|
|
35
|
-
const input = useRef(null);
|
|
36
|
-
useEffect(() => input.current?.focus(), []);
|
|
37
|
-
return input;
|
|
38
|
-
};
|
|
39
|
-
/** Options (a choice, members, tags): each pick adds to or takes from one "is any of" rule; the menu stays open. */
|
|
40
|
-
const OptionsMenu = ({ field }) => {
|
|
41
|
-
const { options, loading, error } = useFieldOptions(field);
|
|
42
|
-
const { rule, set } = useTarget(field);
|
|
43
|
-
return /* @__PURE__ */ jsx(EntityPicker, {
|
|
44
|
-
multiple: true,
|
|
45
|
-
items: options,
|
|
46
|
-
itemKey: (option) => ({
|
|
47
|
-
id: option.value,
|
|
48
|
-
label: option.label
|
|
49
|
-
}),
|
|
50
|
-
value: valuesOf(rule),
|
|
51
|
-
onValueChange: (values) => set(anyOf(field.path, values)),
|
|
52
|
-
loading,
|
|
53
|
-
error,
|
|
54
|
-
searchPlaceholder: field.label
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
const DateMenu = ({ field }) => {
|
|
58
|
-
const { t } = useTranslation("views", { keyPrefix: "filter.date" });
|
|
59
|
-
const { rule, apply } = useTarget(field);
|
|
60
|
-
const current = presetOf(rule);
|
|
61
|
-
return /* @__PURE__ */ jsx(Command, { children: /* @__PURE__ */ jsx(Command.List, { children: DATE_PRESETS.map((preset) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
62
|
-
value: preset.key,
|
|
63
|
-
onSelect: () => apply({
|
|
64
|
-
path: field.path,
|
|
65
|
-
op: preset.op,
|
|
66
|
-
value: preset.value
|
|
67
|
-
}),
|
|
68
|
-
children: [t(preset.key, preset.label), /* @__PURE__ */ jsx(Combobox.Check, { checked: current?.key === preset.key })]
|
|
69
|
-
}, preset.key)) }) });
|
|
70
|
-
};
|
|
71
|
-
const BooleanMenu = ({ field }) => {
|
|
72
|
-
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
73
|
-
const { rule, apply } = useTarget(field);
|
|
74
|
-
const value = rule ? textOf(rule.value) : null;
|
|
75
|
-
return /* @__PURE__ */ jsx(Command, { children: /* @__PURE__ */ jsx(Command.List, { children: ["true", "false"].map((option) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
76
|
-
value: option,
|
|
77
|
-
onSelect: () => apply({
|
|
78
|
-
path: field.path,
|
|
79
|
-
op: "eq",
|
|
80
|
-
value: option === "true"
|
|
81
|
-
}),
|
|
82
|
-
children: [option === "true" ? t("yes", "Yes") : t("no", "No"), /* @__PURE__ */ jsx(Combobox.Check, { checked: value === option })]
|
|
83
|
-
}, option)) }) });
|
|
84
|
-
};
|
|
85
|
-
/** A number as typed: money in the currency's major unit. */
|
|
86
|
-
const numberText = (value, currency) => {
|
|
87
|
-
const n = Number(value);
|
|
88
|
-
if (value === void 0 || value === null || !Number.isFinite(n)) return "";
|
|
89
|
-
return currency ? toAmountInput(n, currency) : String(n);
|
|
90
|
-
};
|
|
91
|
-
/** An operator and a value; Enter or Apply adds the rule (or changes the one being edited). */
|
|
92
|
-
const NumberMenu = ({ field }) => {
|
|
93
|
-
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
94
|
-
const { rule, apply } = useTarget(field);
|
|
95
|
-
const [op, setOp] = useState(() => oneOf(NUMBER_OPS, rule?.op ?? null) ?? "gte");
|
|
96
|
-
const [text, setText] = useState(() => numberText(rule?.value, field.currency));
|
|
97
|
-
const valid = text.trim() !== "" && Number.isFinite(Number(text));
|
|
98
|
-
const input = useFocusOnMount();
|
|
99
|
-
return /* @__PURE__ */ jsxs("form", {
|
|
100
|
-
className: "flex items-center gap-1.5 p-2",
|
|
101
|
-
onSubmit: (event) => {
|
|
102
|
-
event.preventDefault();
|
|
103
|
-
if (!valid) return;
|
|
104
|
-
const value = field.currency ? fromAmountInput(text, field.currency) : Number(text);
|
|
105
|
-
apply({
|
|
106
|
-
path: field.path,
|
|
107
|
-
op,
|
|
108
|
-
value
|
|
109
|
-
});
|
|
110
|
-
},
|
|
111
|
-
children: [
|
|
112
|
-
/* @__PURE__ */ jsxs(Select, {
|
|
113
|
-
value: op,
|
|
114
|
-
onValueChange: (next) => setOp(oneOf(NUMBER_OPS, next) ?? op),
|
|
115
|
-
children: [/* @__PURE__ */ jsx(Select.Trigger, {
|
|
116
|
-
className: "h-8 w-16 shrink-0",
|
|
117
|
-
children: /* @__PURE__ */ jsx(Select.Value, {})
|
|
118
|
-
}), /* @__PURE__ */ jsx(Select.Content, { children: NUMBER_OPS.map((option) => /* @__PURE__ */ jsx(Select.Item, {
|
|
119
|
-
value: option,
|
|
120
|
-
children: NUMBER_SYMBOLS[option]
|
|
121
|
-
}, option)) })]
|
|
122
|
-
}),
|
|
123
|
-
/* @__PURE__ */ jsx(Input, {
|
|
124
|
-
ref: input,
|
|
125
|
-
type: "number",
|
|
126
|
-
className: "h-8 min-w-0 flex-1",
|
|
127
|
-
step: field.currency ? amountStep(field.currency) : "any",
|
|
128
|
-
placeholder: field.currency ?? t("value", "Value"),
|
|
129
|
-
value: text,
|
|
130
|
-
onChange: (event) => setText(event.target.value)
|
|
131
|
-
}),
|
|
132
|
-
/* @__PURE__ */ jsx(Button, {
|
|
133
|
-
type: "submit",
|
|
134
|
-
size: "sm",
|
|
135
|
-
className: "h-8",
|
|
136
|
-
disabled: !valid,
|
|
137
|
-
children: t("apply", "Apply")
|
|
138
|
-
})
|
|
139
|
-
]
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
/** "Contains" text; an empty box removes the rule being edited. */
|
|
143
|
-
const TextMenu = ({ field }) => {
|
|
144
|
-
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
145
|
-
const { rule, apply } = useTarget(field);
|
|
146
|
-
const [text, setText] = useState(() => textOf(rule?.value));
|
|
147
|
-
const input = useFocusOnMount();
|
|
148
|
-
return /* @__PURE__ */ jsxs("form", {
|
|
149
|
-
className: "flex items-center gap-1.5 p-2",
|
|
150
|
-
onSubmit: (event) => {
|
|
151
|
-
event.preventDefault();
|
|
152
|
-
apply(text.trim() ? {
|
|
153
|
-
path: field.path,
|
|
154
|
-
op: "contains",
|
|
155
|
-
value: text.trim()
|
|
156
|
-
} : null);
|
|
157
|
-
},
|
|
158
|
-
children: [/* @__PURE__ */ jsx(Input, {
|
|
159
|
-
ref: input,
|
|
160
|
-
className: "h-8 min-w-0 flex-1",
|
|
161
|
-
placeholder: t("contains", "Contains…"),
|
|
162
|
-
value: text,
|
|
163
|
-
onChange: (event) => setText(event.target.value)
|
|
164
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
165
|
-
type: "submit",
|
|
166
|
-
size: "sm",
|
|
167
|
-
className: "h-8",
|
|
168
|
-
children: t("apply", "Apply")
|
|
169
|
-
})]
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
/** A field's submenu, by its type. */
|
|
173
|
-
const FieldMenu = ({ field }) => {
|
|
174
|
-
switch (field.type) {
|
|
175
|
-
case "select":
|
|
176
|
-
case "member":
|
|
177
|
-
case "tags": return /* @__PURE__ */ jsx(OptionsMenu, { field });
|
|
178
|
-
case "date": return /* @__PURE__ */ jsx(DateMenu, { field });
|
|
179
|
-
case "boolean": return /* @__PURE__ */ jsx(BooleanMenu, { field });
|
|
180
|
-
case "number": return /* @__PURE__ */ jsx(NumberMenu, { field });
|
|
181
|
-
case "text": return /* @__PURE__ */ jsx(TextMenu, { field });
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
export { FieldMenu };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { TListFilterField } from "../ListFilter.js";
|
|
2
|
-
import { IconHash } from "@tabler/icons-react";
|
|
3
|
-
/**
|
|
4
|
-
* A field's icon in the filter menu and on its chips, by type, unless it brings its own:
|
|
5
|
-
* `field.icon ?? FIELD_ICONS[field.type]`.
|
|
6
|
-
*/
|
|
7
|
-
export declare const FIELD_ICONS: Record<TListFilterField['type'], typeof IconHash>;
|