@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.
Files changed (63) hide show
  1. package/CATALOG.md +3 -2
  2. package/README.md +1 -1
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +2 -2
  5. package/dist/modules/conditions/ConditionsEditor.d.ts +5 -3
  6. package/dist/modules/conditions/ConditionsEditor.js +139 -177
  7. package/dist/modules/conditions/DateEditors.d.ts +8 -0
  8. package/dist/modules/conditions/DateEditors.js +188 -0
  9. package/dist/modules/conditions/FieldPicker.d.ts +17 -0
  10. package/dist/modules/conditions/FieldPicker.js +99 -0
  11. package/dist/modules/conditions/RuleParts.d.ts +30 -0
  12. package/dist/modules/conditions/RuleParts.js +78 -0
  13. package/dist/modules/conditions/RuleRow.d.ts +27 -0
  14. package/dist/modules/conditions/RuleRow.js +156 -0
  15. package/dist/modules/conditions/TypedInput.d.ts +13 -0
  16. package/dist/modules/conditions/TypedInput.js +36 -0
  17. package/dist/modules/conditions/ValueEditor.d.ts +18 -0
  18. package/dist/modules/conditions/ValueEditor.js +164 -0
  19. package/dist/modules/conditions/conditions.d.ts +14 -9
  20. package/dist/modules/conditions/conditions.js +1 -75
  21. package/dist/modules/conditions/fieldIcons.d.ts +6 -0
  22. package/dist/modules/conditions/fieldIcons.js +19 -0
  23. package/dist/modules/conditions/fieldOptions.d.ts +13 -0
  24. package/dist/modules/conditions/fieldOptions.js +26 -0
  25. package/dist/modules/conditions/filterRule.d.ts +45 -0
  26. package/dist/modules/conditions/filterRule.js +169 -0
  27. package/dist/modules/conditions/filterText.d.ts +16 -0
  28. package/dist/modules/conditions/filterText.js +156 -0
  29. package/dist/modules/filter/components/Filter.d.ts +1 -1
  30. package/dist/modules/filter/components/Filter.js +1 -1
  31. package/dist/modules/list/ListFilter.d.ts +16 -5
  32. package/dist/modules/list/ListFilter.js +50 -17
  33. package/dist/modules/list/ViewBar.d.ts +2 -0
  34. package/dist/modules/list/ViewBar.js +21 -10
  35. package/dist/modules/list/filter/AddFilter.d.ts +10 -0
  36. package/dist/modules/list/filter/AddFilter.js +140 -0
  37. package/dist/modules/list/filter/AdvancedPopover.d.ts +8 -0
  38. package/dist/modules/list/filter/AdvancedPopover.js +103 -0
  39. package/dist/modules/list/filter/ListFilterBar.d.ts +3 -3
  40. package/dist/modules/list/filter/ListFilterBar.js +104 -205
  41. package/dist/modules/list/filter/RuleChips.d.ts +12 -2
  42. package/dist/modules/list/filter/RuleChips.js +132 -134
  43. package/dist/modules/list/filter/SearchChip.d.ts +6 -0
  44. package/dist/modules/list/filter/SearchChip.js +69 -0
  45. package/dist/modules/list/filter/filterRules.d.ts +15 -40
  46. package/dist/modules/list/filter/filterRules.js +27 -156
  47. package/dist/modules/list/filter/listFilterContext.d.ts +25 -18
  48. package/dist/modules/list/filter/listFilterContext.js +8 -24
  49. package/dist/modules/list/filter/listFilterQuery.d.ts +4 -0
  50. package/dist/modules/list/filter/listFilterQuery.js +10 -2
  51. package/dist/theme.css +3 -2
  52. package/exports.txt +1 -0
  53. package/package.json +1 -1
  54. package/dist/modules/conditions/ConditionValueInput.d.ts +0 -10
  55. package/dist/modules/conditions/ConditionValueInput.js +0 -166
  56. package/dist/modules/conditions/PathPicker.d.ts +0 -8
  57. package/dist/modules/conditions/PathPicker.js +0 -56
  58. package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +0 -5
  59. package/dist/modules/list/filter/AdvancedFilterDialog.js +0 -52
  60. package/dist/modules/list/filter/FieldMenus.d.ts +0 -5
  61. package/dist/modules/list/filter/FieldMenus.js +0 -184
  62. package/dist/modules/list/filter/fieldIcons.d.ts +0 -7
  63. package/dist/modules/list/filter/fieldIcons.js +0 -16
package/CATALOG.md CHANGED
@@ -32,8 +32,9 @@ core's, in the erxes repo on branch `postgre`. The `ui-patterns` skill has the r
32
32
 
33
33
  - `<DisplayMenu list displays>` The Display menu in a list's filter bar: table, board or grouped list.
34
34
  - `EnumCursorDirection` Which way a cursor-paged table loads more rows: forward or backward.
35
- - `Filter.{Trigger, Popover, Item, CommandItem, View, …}` Parts of a filter popover and bar, which `ListFilter` is built from.
36
- - `<ListFilter recordType>` A list's filter bar, with a field menu, search and conditions as chips.
35
+ - `Filter.{Trigger, Popover, Item, CommandItem, View, …}` Parts of a filter popover and bar, for a page without saved views.
36
+ - `<ListFilter recordType>` A list's filter: a view bar button, and a chip row while it filters.
37
+ - `<ListFilterEmpty records fallback>` A list's empty state while `ListFilter` filters it, with Clear filters.
37
38
  - `listFilterQuery` The URL params holding a list's filter, as nuqs parsers.
38
39
  - `<ListViewsProvider views>` Gives every list with a `recordType` saved views, as core's lists have.
39
40
  - `RecordList.{Provider, Skeleton, useSelection}` Rows grouped under headers that fold away, such as tasks by status.
package/README.md CHANGED
@@ -41,7 +41,7 @@ Only what something uses:
41
41
  `PanelField`, `PanelFormRow`, `PanelFormLayout`, `PanelLabel`, the description field and
42
42
  editor, and `usePanelExpanded`. The panel itself (header, tabs, resize) is web's.
43
43
  - a list's bar in `src/modules/list`: `ViewBar`, `DisplayMenu` with `useListDisplay`, and
44
- `ListFilter` with `useListFilterParams`. `ListFilter` draws core's filter bar itself, with or
44
+ `ListFilter` with `useListFilterParams` and its empty state `ListFilterEmpty`. `ListFilter` draws core's filter bar itself, with or
45
45
  without web: its `member` fields pick from `members` (`memberQueries` from
46
46
  `@erxes/core-contract/client`) and its `tags` fields from `tags` (a tags query of the record
47
47
  type); a plugin outside erxes passes its own. Web's lists and the automation builder use the
package/dist/index.d.ts CHANGED
@@ -103,7 +103,7 @@ import { RecordTableColumnDef } from "./modules/record-table/components/RecordTa
103
103
  import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
104
104
  import { EnumCursorDirection } from "./modules/record-table/types/RecordTableCursorTypes.js";
105
105
  import { DisplayMenu, TListDisplay, useListDisplay } from "./modules/list/DisplayMenu.js";
106
- import { ListFilter, TListFilterField, TListFilterProps, useListFilterParams } from "./modules/list/ListFilter.js";
106
+ import { ListFilter, ListFilterEmpty, TListFilterField, TListFilterProps, useListFilterParams } from "./modules/list/ListFilter.js";
107
107
  import { listFilterQuery } from "./modules/list/filter/listFilterQuery.js";
108
108
  import { TConditionField, TConditionGroup, TConditionLookups, TConditionRule, isRule } from "./modules/conditions/conditions.js";
109
109
  import { ConditionsEditor } from "./modules/conditions/LazyConditionsEditor.js";
@@ -130,4 +130,4 @@ import { jsonOf } from "./utils/json.js";
130
130
  import { PluginLiveMessage, PluginRuntime, PluginSession, getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
131
131
  import { addPluginStyles } from "./utils/plugin-styles.js";
132
132
  import { RecordTimeline, RecordTimelineProps, setRecordTimeline } from "./utils/record-timeline.js";
133
- export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, type CompanyContact, ConditionsEditor, ContactLink, type ContactQueries, ContextMenu, CopyText, type CustomerContact, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListViewsProvider, LookupPicker, type Member, MemberInline, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordList, type RecordListGroup, RecordOpenerProvider, RecordPage, type RecordRef, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TActivityRowProps, type TConditionField, type TConditionGroup, type TConditionLookups, type TConditionRule, type TContactContentType, type TDashboardWidgetPreview, type TListDisplay, type TListFilterField, type TListFilterProps, type TListViews, type TPanelRecordType, type TPluginListType, type TPropertyInputMeta, type TPropertyInputProps, type TRecordContacts, type TRecordDraftProps, type TRecordSection, type TRecordSectionProps, type TRecordSlotProps, type TRecordTab, type TRelationTab, type TRelationTabProps, type TViewTabsProps, TabButton, Table, Tabs, type Tag, type TagsQuery, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
133
+ export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, type CompanyContact, ConditionsEditor, ContactLink, type ContactQueries, ContextMenu, CopyText, type CustomerContact, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListFilterEmpty, ListViewsProvider, LookupPicker, type Member, MemberInline, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordList, type RecordListGroup, RecordOpenerProvider, RecordPage, type RecordRef, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TActivityRowProps, type TConditionField, type TConditionGroup, type TConditionLookups, type TConditionRule, type TContactContentType, type TDashboardWidgetPreview, type TListDisplay, type TListFilterField, type TListFilterProps, type TListViews, type TPanelRecordType, type TPluginListType, type TPropertyInputMeta, type TPropertyInputProps, type TRecordContacts, type TRecordDraftProps, type TRecordSection, type TRecordSectionProps, type TRecordSlotProps, type TRecordTab, type TRelationTab, type TRelationTabProps, type TViewTabsProps, TabButton, Table, Tabs, type Tag, type TagsQuery, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
package/dist/index.js CHANGED
@@ -99,7 +99,7 @@ import { RecordTable } from "./modules/record-table/components/RecordTable.js";
99
99
  import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
100
100
  import { EnumCursorDirection } from "./modules/record-table/types/RecordTableCursorTypes.js";
101
101
  import { DisplayMenu, useListDisplay } from "./modules/list/DisplayMenu.js";
102
- import { ListFilter, useListFilterParams } from "./modules/list/ListFilter.js";
102
+ import { ListFilter, ListFilterEmpty, useListFilterParams } from "./modules/list/ListFilter.js";
103
103
  import { listFilterQuery } from "./modules/list/filter/listFilterQuery.js";
104
104
  import { isRule } from "./modules/conditions/conditions.js";
105
105
  import { ConditionsEditor } from "./modules/conditions/LazyConditionsEditor.js";
@@ -125,4 +125,4 @@ import { jsonOf } from "./utils/json.js";
125
125
  import { getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
126
126
  import { addPluginStyles } from "./utils/plugin-styles.js";
127
127
  import { RecordTimeline, setRecordTimeline } from "./utils/record-timeline.js";
128
- export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ConditionsEditor, ContactLink, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListViewsProvider, LookupPicker, MemberInline, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordList, RecordOpenerProvider, RecordPage, RecordTable, RecordTableInlineCell, RecordTimeline, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
128
+ export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ConditionsEditor, ContactLink, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListFilterEmpty, ListViewsProvider, LookupPicker, MemberInline, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordList, RecordOpenerProvider, RecordPage, RecordTable, RecordTableInlineCell, RecordTimeline, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
@@ -1,11 +1,13 @@
1
1
  import { TConditionField, TConditionGroup, TConditionLookups } from "./conditions.js";
2
2
  /**
3
- * Conditions: rows "<field> <operator> <value>", all or any, with nested groups, on `fields`
4
- * (grouped in the picker when they have a `group`); `members` and `tags` feed their pickers.
3
+ * Conditions as rows "Where <field> <operator> <value>", joined by "and" or "or", with nested
4
+ * groups, on `fields`; `members` and `tags` feed their pickers. Fields and values pick from the
5
+ * same menus as a list's filter chips. With `customPath`, a typed path is a field too.
5
6
  */
6
- export declare const ConditionsEditor: ({ value, onChange, disabled, fields, ...lookups }: TConditionLookups & {
7
+ export declare const ConditionsEditor: ({ value, onChange, disabled, fields, customPath, ...lookups }: TConditionLookups & {
7
8
  value: TConditionGroup | undefined;
8
9
  onChange: (next: TConditionGroup | undefined) => void;
9
10
  disabled?: boolean;
10
11
  fields: TConditionField[];
12
+ customPath?: boolean;
11
13
  }) => import("react").JSX.Element;
@@ -1,139 +1,98 @@
1
1
  import { Button } from "../../components/button.js";
2
+ import { Popover } from "../../components/popover.js";
2
3
  import { Select } from "../../components/select.js";
3
4
  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";
5
+ import { NO_VALUE, isRule } from "./conditions.js";
6
+ import { isFilterRule, ruleFor } from "./filterRule.js";
7
+ import { FieldPicker } from "./FieldPicker.js";
8
+ import { RemoveButton, RuleRow } from "./RuleRow.js";
9
+ import { IconBraces, IconPlus } from "@tabler/icons-react";
10
10
  import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { useState } from "react";
11
12
  import { useTranslation } from "react-i18next";
12
13
  // 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
- ]
14
+ /** "Where" first; the second row picks "and" or "or" for the group; the rest repeat it. */
15
+ const Conjunction = ({ index, group, disabled, onChange }) => {
16
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
17
+ const word = group.match === "all" ? t("and", "And") : t("or", "Or");
18
+ if (index === 0) return /* @__PURE__ */ jsx("span", {
19
+ className: "px-2 text-sm text-muted-foreground",
20
+ children: t("where", "Where")
73
21
  });
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
- ]
22
+ if (index > 1 || disabled) return /* @__PURE__ */ jsx("span", {
23
+ className: "px-2 text-sm text-muted-foreground",
24
+ children: word
25
+ });
26
+ return /* @__PURE__ */ jsxs(Select, {
27
+ value: group.match,
28
+ onValueChange: (match) => onChange({
29
+ ...group,
30
+ match: match === "any" ? "any" : "all"
31
+ }),
32
+ children: [/* @__PURE__ */ jsx(Select.Trigger, {
33
+ className: "h-8 w-full",
34
+ "aria-label": t("conjunction", "And or or"),
35
+ children: /* @__PURE__ */ jsx(Select.Value, { children: word })
36
+ }), /* @__PURE__ */ jsxs(Select.Content, { children: [/* @__PURE__ */ jsx(Select.Item, {
37
+ value: "all",
38
+ children: t("and", "And")
39
+ }), /* @__PURE__ */ jsx(Select.Item, {
40
+ value: "any",
41
+ children: t("or", "Or")
42
+ })] })]
110
43
  });
111
44
  };
112
- const AddButtons = ({ newRule, newGroup, disabled, onAdd }) => {
113
- const { t } = useTranslation("automations");
45
+ /** "Add filter rule" opens the field picker; "Add filter group", while groups may still nest. */
46
+ const AddButtons = ({ fields, disabled, customPath, canGroup, onAdd }) => {
47
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
48
+ const [open, setOpen] = useState(false);
114
49
  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, {
50
+ className: "flex gap-1",
51
+ children: [/* @__PURE__ */ jsxs(Popover, {
52
+ open,
53
+ onOpenChange: setOpen,
54
+ children: [/* @__PURE__ */ jsxs(Popover.Trigger, {
55
+ render: /* @__PURE__ */ jsx(Button, {
56
+ size: "sm",
57
+ variant: "ghost",
58
+ tone: "muted",
59
+ disabled
60
+ }),
61
+ children: [/* @__PURE__ */ jsx(IconPlus, {}), t("add-rule", "Add filter rule")]
62
+ }), /* @__PURE__ */ jsx(Popover.Content, {
63
+ variant: "flush",
64
+ align: "start",
65
+ className: "w-72",
66
+ children: /* @__PURE__ */ jsx(FieldPicker, {
67
+ fields,
68
+ customPath,
69
+ onSelect: (field) => {
70
+ setOpen(false);
71
+ onAdd(ruleFor(field));
72
+ }
73
+ })
74
+ })]
75
+ }), canGroup && /* @__PURE__ */ jsxs(Button, {
123
76
  size: "sm",
124
77
  variant: "ghost",
78
+ tone: "muted",
125
79
  disabled,
126
- onClick: () => onAdd(newGroup),
127
- children: [/* @__PURE__ */ jsx(IconBraces, {}), t("add-group", "Add group")]
80
+ onClick: () => onAdd({
81
+ match: "all",
82
+ rules: []
83
+ }),
84
+ children: [/* @__PURE__ */ jsx(IconBraces, {}), t("add-group", "Add filter group")]
128
85
  })]
129
86
  });
130
87
  };
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 }) => {
88
+ /** One group: its rows and nested groups (three levels in all), then the add buttons. */
89
+ const GroupEditor = ({ group, onChange, depth, ...shared }) => {
90
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
133
91
  const keys = useItemKeys(group.rules.length);
134
- const update = (index, rule) => onChange({
92
+ const [fresh, setFresh] = useState(null);
93
+ const update = (index, node) => onChange({
135
94
  ...group,
136
- rules: group.rules.map((item, at) => at === index ? rule : item)
95
+ rules: group.rules.map((item, at) => at === index ? node : item)
137
96
  });
138
97
  const remove = (index) => {
139
98
  keys.removed(index);
@@ -142,68 +101,71 @@ const GroupEditor = ({ group, onChange, onRemove, fields, disabled, depth, looku
142
101
  rules: group.rules.filter((_, at) => at !== index)
143
102
  });
144
103
  };
145
- const add = (rule) => {
146
- keys.added();
147
- onChange({
148
- ...group,
149
- rules: [...group.rules, rule]
150
- });
151
- };
104
+ const lead = (index) => /* @__PURE__ */ jsx(Conjunction, {
105
+ index,
106
+ group,
107
+ disabled: shared.disabled,
108
+ onChange
109
+ });
152
110
  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
- ]
111
+ className: "flex flex-col gap-1.5",
112
+ children: [group.rules.map((node, index) => isFilterRule(node) ? /* @__PURE__ */ jsx(RuleRow, {
113
+ ...shared,
114
+ rule: node,
115
+ lead: lead(index),
116
+ fresh: fresh === index,
117
+ onChange: (next) => update(index, next),
118
+ onRemove: () => remove(index)
119
+ }, keys.keyAt(index)) : /* @__PURE__ */ jsxs("div", {
120
+ className: "grid grid-cols-condition items-start gap-1.5",
121
+ children: [
122
+ lead(index),
123
+ /* @__PURE__ */ jsx("div", {
124
+ className: "col-span-3 rounded-md border bg-muted/40 p-2",
125
+ children: /* @__PURE__ */ jsx(GroupEditor, {
126
+ ...shared,
127
+ group: node,
128
+ depth: depth + 1,
129
+ onChange: (next) => update(index, next)
130
+ })
131
+ }),
132
+ /* @__PURE__ */ jsx(RemoveButton, {
133
+ label: t("remove-group", "Remove group"),
134
+ disabled: shared.disabled,
135
+ onRemove: () => remove(index)
136
+ })
137
+ ]
138
+ }, keys.keyAt(index))), /* @__PURE__ */ jsx(AddButtons, {
139
+ fields: shared.fields,
140
+ disabled: shared.disabled,
141
+ customPath: shared.customPath,
142
+ canGroup: depth < 2,
143
+ onAdd: (node) => {
144
+ keys.added();
145
+ setFresh(isRule(node) && !NO_VALUE.has(node.op) ? group.rules.length : null);
146
+ onChange({
147
+ ...group,
148
+ rules: [...group.rules, node]
149
+ });
150
+ }
151
+ })]
190
152
  });
191
153
  };
192
154
  /**
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.
155
+ * Conditions as rows "Where <field> <operator> <value>", joined by "and" or "or", with nested
156
+ * groups, on `fields`; `members` and `tags` feed their pickers. Fields and values pick from the
157
+ * same menus as a list's filter chips. With `customPath`, a typed path is a field too.
195
158
  */
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
- };
159
+ const ConditionsEditor = ({ value, onChange, disabled, fields, customPath, ...lookups }) => /* @__PURE__ */ jsx(GroupEditor, {
160
+ group: value ?? {
161
+ match: "all",
162
+ rules: []
163
+ },
164
+ fields,
165
+ lookups,
166
+ disabled,
167
+ customPath,
168
+ depth: 0,
169
+ onChange: (next) => onChange(next.rules.length ? next : void 0)
170
+ });
209
171
  export { ConditionsEditor };
@@ -0,0 +1,8 @@
1
+ import { TConditionRule } from "./conditions.js";
2
+ import { ValueEditorProps } from "./ValueEditor.js";
3
+ /** "In the last 30 days": the usual spans in one pick, or any amount and unit. */
4
+ export declare const RelativeEditor: (props: Omit<ValueEditorProps, 'rule' | 'field' | 'lookups'> & {
5
+ rule: TConditionRule;
6
+ }) => import("react").JSX.Element;
7
+ /** A day (before, on, after) or a range of days, on erxes-ui's date picker. */
8
+ export declare const DayEditor: ({ rule, onChange, onDone }: ValueEditorProps) => import("react").JSX.Element;
@@ -0,0 +1,188 @@
1
+ import { Combobox } from "../../components/combobox.js";
2
+ import { Command } from "../../components/command.js";
3
+ import { DatePicker } from "../../components/date-picker.js";
4
+ import { Select } from "../../components/select.js";
5
+ import { toIsoDay } from "../../lib/format.js";
6
+ import { oneOf, textOf } from "../../lib/text.js";
7
+ import { RELATIVE_UNITS, isRule } from "./conditions.js";
8
+ import { between, valuesBetween } from "./filterRule.js";
9
+ import { useSpanText } from "./filterText.js";
10
+ import { TypedInput } from "./TypedInput.js";
11
+ import { jsx, jsxs } from "react/jsx-runtime";
12
+ import { z } from "zod";
13
+ import { useTranslation } from "react-i18next";
14
+ // src/modules/conditions/DateEditors.tsx
15
+ const Span = z.object({
16
+ amount: z.number().optional(),
17
+ unit: z.enum(RELATIVE_UNITS).optional()
18
+ });
19
+ /** Relative dates in one pick, by operator; they stay current in a saved view. */
20
+ const PRESETS = {
21
+ within_last: [
22
+ {
23
+ amount: 1,
24
+ unit: "days"
25
+ },
26
+ {
27
+ amount: 7,
28
+ unit: "days"
29
+ },
30
+ {
31
+ amount: 30,
32
+ unit: "days"
33
+ },
34
+ {
35
+ amount: 90,
36
+ unit: "days"
37
+ },
38
+ {
39
+ amount: 12,
40
+ unit: "months"
41
+ }
42
+ ],
43
+ within_next: [
44
+ {
45
+ amount: 7,
46
+ unit: "days"
47
+ },
48
+ {
49
+ amount: 30,
50
+ unit: "days"
51
+ },
52
+ {
53
+ amount: 90,
54
+ unit: "days"
55
+ }
56
+ ],
57
+ more_than_ago: [
58
+ {
59
+ amount: 30,
60
+ unit: "days"
61
+ },
62
+ {
63
+ amount: 90,
64
+ unit: "days"
65
+ },
66
+ {
67
+ amount: 12,
68
+ unit: "months"
69
+ }
70
+ ],
71
+ anniversary_within: [{
72
+ amount: 7,
73
+ unit: "days"
74
+ }, {
75
+ amount: 30,
76
+ unit: "days"
77
+ }]
78
+ };
79
+ /** The amount and unit of a span, typed. */
80
+ const SpanInput = ({ rule, onChange, onDone }) => {
81
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
82
+ const current = Span.safeParse(rule.value).data ?? {};
83
+ return /* @__PURE__ */ jsxs("div", {
84
+ className: "flex items-center gap-1.5 border-t p-2",
85
+ children: [/* @__PURE__ */ jsx(TypedInput, {
86
+ type: "number",
87
+ min: 0,
88
+ className: "h-8 w-20",
89
+ "aria-label": t("amount", "Amount"),
90
+ initial: textOf(current.amount),
91
+ onCommit: (text) => onChange({
92
+ ...rule,
93
+ value: {
94
+ unit: current.unit ?? "days",
95
+ amount: Math.max(0, Math.round(Number(text) || 0))
96
+ }
97
+ }),
98
+ onEnter: onDone
99
+ }), rule.op === "anniversary_within" ? /* @__PURE__ */ jsx("span", {
100
+ className: "text-sm text-muted-foreground",
101
+ children: t("units.days", "days")
102
+ }) : /* @__PURE__ */ jsxs(Select, {
103
+ value: current.unit ?? "days",
104
+ onValueChange: (next) => {
105
+ const unit = oneOf(RELATIVE_UNITS, next);
106
+ if (unit) onChange({
107
+ ...rule,
108
+ value: {
109
+ amount: current.amount ?? 0,
110
+ unit
111
+ }
112
+ });
113
+ },
114
+ children: [/* @__PURE__ */ jsx(Select.Trigger, {
115
+ className: "h-8 flex-1",
116
+ "aria-label": t("unit-label", "Unit"),
117
+ children: /* @__PURE__ */ jsx(Select.Value, { children: t(`units.${current.unit ?? "days"}`, current.unit ?? "days") })
118
+ }), /* @__PURE__ */ jsx(Select.Content, { children: RELATIVE_UNITS.map((unit) => /* @__PURE__ */ jsx(Select.Item, {
119
+ value: unit,
120
+ children: t(`units.${unit}`, unit)
121
+ }, unit)) })]
122
+ })]
123
+ });
124
+ };
125
+ /** "In the last 30 days": the usual spans in one pick, or any amount and unit. */
126
+ const RelativeEditor = (props) => {
127
+ const { rule, onChange, onDone } = props;
128
+ const spanText = useSpanText();
129
+ const current = Span.safeParse(rule.value).data ?? {};
130
+ return /* @__PURE__ */ jsxs("div", {
131
+ className: "flex flex-col",
132
+ children: [/* @__PURE__ */ jsx(Command, {
133
+ className: "h-auto",
134
+ children: /* @__PURE__ */ jsx(Command.List, { children: (PRESETS[rule.op] ?? []).map((span) => /* @__PURE__ */ jsxs(Command.Item, {
135
+ value: `${span.amount}-${span.unit}`,
136
+ onSelect: () => {
137
+ onChange({
138
+ ...rule,
139
+ value: span
140
+ });
141
+ onDone?.();
142
+ },
143
+ children: [spanText(span), /* @__PURE__ */ jsx(Combobox.Check, { checked: current.amount === span.amount && current.unit === span.unit })]
144
+ }, `${span.amount}-${span.unit}`)) })
145
+ }), /* @__PURE__ */ jsx(SpanInput, { ...props })]
146
+ });
147
+ };
148
+ const dayOf = (value) => {
149
+ const text = textOf(value);
150
+ return /^\d{4}-\d{2}-\d{2}/.test(text) ? text.slice(0, 10) : void 0;
151
+ };
152
+ /** A day (before, on, after) or a range of days, on erxes-ui's date picker. */
153
+ const DayEditor = ({ rule, onChange, onDone }) => {
154
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
155
+ if (isRule(rule)) return /* @__PURE__ */ jsx(DatePicker, {
156
+ inline: true,
157
+ mode: "single",
158
+ value: dayOf(rule.value),
159
+ placeholder: t("pick-day", "Pick a day"),
160
+ clearable: false,
161
+ onChange: (date) => {
162
+ if (!(date instanceof Date)) return;
163
+ onChange({
164
+ ...rule,
165
+ value: toIsoDay(date)
166
+ });
167
+ onDone?.();
168
+ }
169
+ });
170
+ const [from, to] = valuesBetween(rule).map(dayOf);
171
+ const path = rule.rules[0].path;
172
+ return /* @__PURE__ */ jsx(DatePicker, {
173
+ inline: true,
174
+ mode: "range",
175
+ value: {
176
+ from,
177
+ to
178
+ },
179
+ clearable: false,
180
+ onChange: (range) => {
181
+ if (!range || range instanceof Date || Array.isArray(range)) return;
182
+ const { from: start, to: end } = range;
183
+ onChange(between(path, start && toIsoDay(start), end && toIsoDay(end)));
184
+ if (start && end) onDone?.();
185
+ }
186
+ });
187
+ };
188
+ export { DayEditor, RelativeEditor };