@erxes/ui 4.0.0-v2.1 → 4.0.0-v2.10
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/AGENTS.md +58 -0
- package/CATALOG.md +251 -0
- package/README.md +25 -2
- package/dist/components/accordion.d.ts +1 -0
- package/dist/components/accordion.js +1 -0
- package/dist/components/alert-dialog.d.ts +4 -0
- package/dist/components/alert-dialog.js +4 -0
- package/dist/components/alert.d.ts +1 -0
- package/dist/components/alert.js +1 -0
- package/dist/components/avatar.d.ts +2 -0
- package/dist/components/avatar.js +1 -0
- package/dist/components/background-gradient-animation.d.ts +4 -1
- package/dist/components/background-gradient-animation.js +4 -1
- package/dist/components/badge.d.ts +3 -0
- package/dist/components/badge.js +2 -0
- package/dist/components/breadcrumb.d.ts +1 -0
- package/dist/components/breadcrumb.js +1 -0
- package/dist/components/button.d.ts +6 -1
- package/dist/components/button.js +5 -1
- package/dist/components/calendar.d.ts +5 -0
- package/dist/components/calendar.js +4 -0
- package/dist/components/card.d.ts +1 -0
- package/dist/components/card.js +1 -0
- package/dist/components/chart-config.d.ts +4 -1
- package/dist/components/charts.d.ts +6 -0
- package/dist/components/charts.js +12 -3
- package/dist/components/checkbox.d.ts +1 -0
- package/dist/components/checkbox.js +1 -0
- package/dist/components/choicebox-group.d.ts +1 -0
- package/dist/components/choicebox-group.js +1 -0
- package/dist/components/collapsible.d.ts +1 -0
- package/dist/components/collapsible.js +1 -0
- package/dist/components/color-picker.d.ts +1 -0
- package/dist/components/color-picker.js +13 -6
- package/dist/components/combobox.d.ts +6 -1
- package/dist/components/combobox.js +9 -1
- package/dist/components/command-bar.d.ts +4 -0
- package/dist/components/command-bar.js +4 -0
- package/dist/components/command.d.ts +4 -0
- package/dist/components/command.js +4 -0
- package/dist/components/context-menu.d.ts +1 -0
- package/dist/components/context-menu.js +1 -0
- package/dist/components/copy-text.d.ts +1 -0
- package/dist/components/copy-text.js +1 -0
- package/dist/components/date-picker-value.d.ts +5 -9
- package/dist/components/date-picker-value.js +15 -34
- package/dist/components/date-picker.d.ts +4 -4
- package/dist/components/date-picker.js +9 -7
- package/dist/components/date-text-input.d.ts +2 -4
- package/dist/components/date-text-input.js +11 -9
- package/dist/components/dialog.d.ts +4 -0
- package/dist/components/dialog.js +5 -1
- package/dist/components/drag-handle.d.ts +1 -0
- package/dist/components/drag-handle.js +1 -0
- package/dist/components/dropdown-menu.d.ts +1 -0
- package/dist/components/dropdown-menu.js +1 -0
- package/dist/components/empty.d.ts +6 -1
- package/dist/components/empty.js +25 -2
- package/dist/components/form.d.ts +6 -2
- package/dist/components/form.js +8 -2
- package/dist/components/hover-card.d.ts +1 -0
- package/dist/components/hover-card.js +1 -0
- package/dist/components/icon-tip.d.ts +7 -0
- package/dist/components/icon-tip.js +16 -0
- package/dist/components/info-card.d.ts +4 -0
- package/dist/components/info-card.js +4 -0
- package/dist/components/input-group.d.ts +5 -4
- package/dist/components/input-group.js +5 -4
- package/dist/components/input.d.ts +1 -0
- package/dist/components/input.js +1 -0
- package/dist/components/kbd.d.ts +2 -1
- package/dist/components/kbd.js +2 -1
- package/dist/components/label.d.ts +1 -1
- package/dist/components/label.js +1 -1
- package/dist/components/multiselect.d.ts +1 -0
- package/dist/components/multiselect.js +3 -2
- package/dist/components/on-demand.d.ts +6 -0
- package/dist/components/on-demand.js +6 -0
- package/dist/components/popover.d.ts +4 -0
- package/dist/components/popover.js +4 -0
- package/dist/components/radio-group.d.ts +1 -0
- package/dist/components/radio-group.js +1 -0
- package/dist/components/scroll-area.d.ts +1 -0
- package/dist/components/scroll-area.js +1 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.js +7 -1
- package/dist/components/separator.d.ts +4 -0
- package/dist/components/separator.js +4 -0
- package/dist/components/sheet.d.ts +4 -0
- package/dist/components/sheet.js +8 -4
- package/dist/components/sidebar/panel.js +29 -7
- package/dist/components/sidebar.d.ts +1 -0
- package/dist/components/sidebar.js +1 -0
- package/dist/components/skeleton.d.ts +1 -0
- package/dist/components/skeleton.js +1 -0
- package/dist/components/spinner.d.ts +1 -0
- package/dist/components/spinner.js +1 -0
- package/dist/components/string-array.js +1 -0
- package/dist/components/switch.d.ts +1 -0
- package/dist/components/switch.js +1 -0
- package/dist/components/table.d.ts +4 -0
- package/dist/components/table.js +4 -0
- package/dist/components/tabs.d.ts +8 -1
- package/dist/components/tabs.js +8 -1
- package/dist/components/text-overflow.d.ts +4 -1
- package/dist/components/text-overflow.js +4 -1
- package/dist/components/textarea.d.ts +1 -0
- package/dist/components/textarea.js +1 -0
- package/dist/components/toaster.d.ts +4 -1
- package/dist/components/toaster.js +5 -2
- package/dist/components/toggle-group.d.ts +5 -0
- package/dist/components/toggle-group.js +19 -11
- package/dist/components/toggle.d.ts +1 -0
- package/dist/components/toggle.js +1 -0
- package/dist/components/tooltip.d.ts +4 -0
- package/dist/components/tooltip.js +4 -0
- package/dist/components/upload.d.ts +4 -0
- package/dist/components/upload.js +20 -11
- package/dist/federation.d.ts +8 -1
- package/dist/federation.js +12 -2
- package/dist/hooks/use-item-keys.d.ts +11 -0
- package/dist/hooks/use-item-keys.js +24 -0
- package/dist/hooks/use-page-hotkey.d.ts +12 -0
- package/dist/hooks/use-page-hotkey.js +22 -0
- package/dist/hooks/use-toast.d.ts +5 -0
- package/dist/hooks/use-toast.js +5 -0
- package/dist/index.d.ts +33 -6
- package/dist/index.js +31 -4
- package/dist/lib/format.d.ts +60 -0
- package/dist/lib/format.js +86 -0
- package/dist/lib/money.d.ts +13 -0
- package/dist/lib/money.js +21 -0
- package/dist/lib/stored.d.ts +13 -0
- package/dist/lib/stored.js +41 -0
- package/dist/lib/text.d.ts +11 -0
- package/dist/lib/text.js +18 -0
- package/dist/modules/attachments/use-carousel.js +5 -10
- package/dist/modules/blocks/hooks/useBarcodeSizeForm.d.ts +1 -1
- package/dist/modules/blocks/utils/parseBlocks.d.ts +1 -1
- package/dist/modules/blocks/utils/parseBlocks.js +1 -1
- package/dist/modules/conditions/ConditionValueInput.d.ts +10 -0
- package/dist/modules/conditions/ConditionValueInput.js +166 -0
- package/dist/modules/conditions/ConditionsEditor.d.ts +11 -0
- package/dist/modules/conditions/ConditionsEditor.js +209 -0
- package/dist/modules/conditions/LazyConditionsEditor.d.ts +10 -0
- package/dist/modules/conditions/LazyConditionsEditor.js +11 -0
- package/dist/modules/conditions/PathPicker.d.ts +8 -0
- package/dist/modules/conditions/PathPicker.js +51 -0
- package/dist/modules/conditions/conditions.d.ts +66 -0
- package/dist/modules/conditions/conditions.js +136 -0
- package/dist/modules/display/components/EmailDisplay.d.ts +4 -0
- package/dist/modules/display/components/EmailDisplay.js +6 -3
- package/dist/modules/display/components/PhoneDisplay.d.ts +4 -0
- package/dist/modules/display/components/PhoneDisplay.js +4 -0
- package/dist/modules/display/components/RelativeDateDisplay.d.ts +7 -5
- package/dist/modules/display/components/RelativeDateDisplay.js +10 -8
- package/dist/modules/display/components/SexDisplay.d.ts +1 -0
- package/dist/modules/display/components/SexDisplay.js +1 -0
- package/dist/modules/filter/components/Filter.d.ts +4 -0
- package/dist/modules/filter/components/Filter.js +4 -0
- package/dist/modules/filter/components/FilterBar.js +5 -7
- package/dist/modules/filter/components/FilterDialog.js +4 -5
- package/dist/modules/filter/components/FilterPopover.js +1 -1
- package/dist/modules/filter/components/FilterProvider.d.ts +1 -2
- package/dist/modules/filter/components/FilterProvider.js +22 -16
- package/dist/modules/filter/hooks/useFilterContext.d.ts +1 -0
- package/dist/modules/filter/hooks/useFilterContext.js +1 -0
- package/dist/modules/filter/types/filter.d.ts +0 -1
- package/dist/modules/hotkey/components/PopoverScoped.d.ts +5 -0
- package/dist/modules/hotkey/components/PopoverScoped.js +5 -0
- package/dist/modules/hotkey/hooks/usePreviousHotkeyScope.d.ts +1 -0
- package/dist/modules/hotkey/hooks/usePreviousHotkeyScope.js +1 -0
- package/dist/modules/hotkey/hooks/useScopedHotkeys.d.ts +5 -1
- package/dist/modules/hotkey/hooks/useScopedHotkeys.js +5 -1
- package/dist/modules/icons/components/IconComponent.d.ts +4 -0
- package/dist/modules/icons/components/IconComponent.js +4 -0
- package/dist/modules/icons/components/IconPicker.d.ts +4 -0
- package/dist/modules/icons/components/IconPicker.js +7 -5
- package/dist/modules/icons/providers/IconsProvider.d.ts +1 -0
- package/dist/modules/icons/providers/IconsProvider.js +1 -0
- package/dist/modules/inputs/components/EmailField.d.ts +4 -1
- package/dist/modules/inputs/components/EmailField.js +4 -1
- package/dist/modules/inputs/components/FullNameField.d.ts +6 -0
- package/dist/modules/inputs/components/FullNameField.js +20 -8
- package/dist/modules/inputs/components/PhoneField.d.ts +4 -1
- package/dist/modules/inputs/components/PhoneField.js +4 -1
- package/dist/modules/inputs/components/SexField.d.ts +1 -0
- package/dist/modules/inputs/components/SexField.js +1 -0
- package/dist/modules/layout/components/AppLayout.d.ts +6 -6
- package/dist/modules/layout/components/AppLayout.js +12 -13
- package/dist/modules/layout/components/AppLayoutResizeHandle.d.ts +5 -12
- package/dist/modules/layout/components/AppLayoutResizeHandle.js +15 -18
- package/dist/modules/layout/components/Page.d.ts +5 -0
- package/dist/modules/layout/components/Page.js +5 -0
- package/dist/modules/layout/components/PageHeader.d.ts +4 -1
- package/dist/modules/layout/components/PageHeader.js +9 -3
- package/dist/modules/list/DisplayMenu.d.ts +24 -0
- package/dist/modules/list/DisplayMenu.js +87 -0
- package/dist/modules/list/ListFilter.d.ts +63 -0
- package/dist/modules/list/ListFilter.js +44 -0
- package/dist/modules/list/ViewBar.d.ts +13 -0
- package/dist/modules/list/ViewBar.js +30 -0
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +5 -0
- package/dist/modules/list/filter/AdvancedFilterDialog.js +52 -0
- package/dist/modules/list/filter/FieldMenus.d.ts +5 -0
- package/dist/modules/list/filter/FieldMenus.js +184 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +6 -0
- package/dist/modules/list/filter/ListFilterBar.js +246 -0
- package/dist/modules/list/filter/RecordCount.d.ts +7 -0
- package/dist/modules/list/filter/RecordCount.js +22 -0
- package/dist/modules/list/filter/RuleChips.d.ts +2 -0
- package/dist/modules/list/filter/RuleChips.js +157 -0
- package/dist/modules/list/filter/fieldIcons.d.ts +7 -0
- package/dist/modules/list/filter/fieldIcons.js +16 -0
- package/dist/modules/list/filter/filterRules.d.ts +46 -0
- package/dist/modules/list/filter/filterRules.js +166 -0
- package/dist/modules/list/filter/listFilterContext.d.ts +29 -0
- package/dist/modules/list/filter/listFilterContext.js +34 -0
- package/dist/modules/list/filter/listFilterQuery.d.ts +16 -0
- package/dist/modules/list/filter/listFilterQuery.js +22 -0
- package/dist/modules/navigation-menu/components/NavigationMenu.d.ts +4 -3
- package/dist/modules/navigation-menu/components/NavigationMenu.js +7 -7
- package/dist/modules/pickers/EntityPicker.d.ts +37 -0
- package/dist/modules/pickers/EntityPicker.js +67 -0
- package/dist/modules/pickers/LookupPicker.d.ts +51 -0
- package/dist/modules/pickers/LookupPicker.js +84 -0
- package/dist/modules/pickers/SelectMember.d.ts +41 -0
- package/dist/modules/pickers/SelectMember.js +122 -0
- package/dist/modules/pickers/members.d.ts +30 -0
- package/dist/modules/pickers/members.js +18 -0
- package/dist/modules/record-field/components/NumberField.d.ts +5 -0
- package/dist/modules/record-field/components/NumberField.js +14 -7
- package/dist/modules/record-field/components/TextField.d.ts +4 -0
- package/dist/modules/record-field/components/TextField.js +14 -3
- package/dist/modules/record-field/meta-inputs/components/PhoneInput.d.ts +5 -0
- package/dist/modules/record-field/meta-inputs/components/PhoneInput.js +5 -0
- package/dist/modules/record-list/RecordList.d.ts +18 -0
- package/dist/modules/record-list/RecordList.js +23 -0
- package/dist/modules/record-list/RecordListProvider.d.ts +30 -0
- package/dist/modules/record-list/RecordListProvider.js +57 -0
- package/dist/modules/record-list/RecordListRoot.d.ts +28 -0
- package/dist/modules/record-list/RecordListRoot.js +124 -0
- package/dist/modules/record-list/selection.d.ts +22 -0
- package/dist/modules/record-list/selection.js +54 -0
- package/dist/modules/record-panel/PanelDescriptionEditor.d.ts +9 -0
- package/dist/modules/record-panel/PanelDescriptionEditor.js +39 -0
- package/dist/modules/record-panel/PanelDescriptionField.d.ts +13 -0
- package/dist/modules/record-panel/PanelDescriptionField.js +39 -0
- package/dist/modules/record-panel/PanelField.d.ts +17 -0
- package/dist/modules/record-panel/PanelField.js +47 -0
- package/dist/modules/record-panel/PanelForm.d.ts +22 -0
- package/dist/modules/record-panel/PanelForm.js +81 -0
- package/dist/modules/record-panel/PanelLabel.d.ts +10 -0
- package/dist/modules/record-panel/PanelLabel.js +55 -0
- package/dist/modules/record-panel/PanelSection.d.ts +12 -0
- package/dist/modules/record-panel/PanelSection.js +24 -0
- package/dist/modules/record-panel/panelExpansion.d.ts +10 -0
- package/dist/modules/record-panel/panelExpansion.js +7 -0
- package/dist/modules/record-panel/useSaveOnLeave.d.ts +14 -0
- package/dist/modules/record-panel/useSaveOnLeave.js +42 -0
- package/dist/modules/record-table/components/RecordTable.d.ts +6 -0
- package/dist/modules/record-table/components/RecordTable.js +6 -0
- package/dist/modules/record-table/components/RecordTableCell.d.ts +9 -0
- package/dist/modules/record-table/components/RecordTableCell.js +16 -2
- package/dist/modules/record-table/components/RecordTableCellInline.d.ts +5 -0
- package/dist/modules/record-table/components/RecordTableCellInline.js +8 -7
- package/dist/modules/record-table/components/RecordTableCursor.js +30 -28
- package/dist/modules/record-table/components/RecordTableProvider.js +12 -7
- package/dist/modules/record-table/hooks/useTablePreferences.d.ts +1 -1
- package/dist/modules/record-table/hooks/useTablePreferences.js +18 -31
- package/dist/modules/record-table/states/RecordTableCursorState.d.ts +21 -1
- package/dist/modules/record-table/states/RecordTableCursorState.js +21 -3
- package/dist/modules/record-table/types/RecordTableCursorTypes.d.ts +1 -0
- package/dist/modules/record-table/types/RecordTableCursorTypes.js +1 -0
- package/dist/modules/records/ContactLink.d.ts +13 -0
- package/dist/modules/records/ContactLink.js +77 -0
- package/dist/modules/records/contacts.d.ts +35 -0
- package/dist/modules/records/contacts.js +10 -0
- package/dist/modules/records/openRecord.d.ts +44 -0
- package/dist/modules/records/openRecord.js +48 -0
- package/dist/state/sidebarPanelState.d.ts +5 -1
- package/dist/state/sidebarPanelState.js +11 -3
- package/dist/state/themeState.d.ts +13 -2
- package/dist/state/themeState.js +18 -4
- package/dist/theme.css +5 -2
- package/dist/types/SexCode.d.ts +1 -0
- package/dist/types/SexCode.js +1 -0
- package/dist/types/UIConfig.d.ts +131 -3
- package/dist/utils/IsUndefinedOrNull.d.ts +1 -0
- package/dist/utils/IsUndefinedOrNull.js +1 -0
- package/dist/utils/file-storage.d.ts +1 -0
- package/dist/utils/file-storage.js +1 -0
- package/dist/utils/format/formatPhoneNumber.d.ts +4 -0
- package/dist/utils/format/formatPhoneNumber.js +4 -0
- package/dist/utils/getPluginAssetsUrl.d.ts +5 -0
- package/dist/utils/getPluginAssetsUrl.js +5 -0
- package/dist/utils/host-component.d.ts +10 -0
- package/dist/utils/host-component.js +34 -0
- package/dist/utils/json.d.ts +3 -2
- package/dist/utils/json.js +3 -2
- package/dist/utils/plugin-runtime.d.ts +21 -17
- package/dist/utils/plugin-runtime.js +59 -12
- package/dist/utils/plugin-styles.d.ts +7 -0
- package/dist/utils/plugin-styles.js +54 -0
- package/dist/utils/record-timeline.d.ts +10 -9
- package/dist/utils/record-timeline.js +12 -17
- package/exports.txt +226 -0
- package/package.json +13 -3
- package/dist/constants/IntlLanguages.d.ts +0 -74
- package/dist/constants/IntlLanguages.js +0 -76
- package/dist/hooks/use-query-state.d.ts +0 -16
- package/dist/hooks/use-query-state.js +0 -122
- package/dist/modules/filter/hooks/useFilterQueryState.d.ts +0 -4
- package/dist/modules/filter/hooks/useFilterQueryState.js +0 -14
- package/dist/types/Theme.d.ts +0 -1
- package/dist/types/Theme.js +0 -0
- package/dist/utils/localization/formatDateISOStringToRelativeDate.d.ts +0 -2
- package/dist/utils/localization/formatDateISOStringToRelativeDate.js +0 -16
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RelativeAmount, TConditionGroup, TConditionRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { TListFilterField } from "../ListFilter.js";
|
|
3
|
+
/** One thing the list's filter requires: a rule, or a group of rules (from the advanced filter). */
|
|
4
|
+
export type FilterPart = TConditionRule | TConditionGroup;
|
|
5
|
+
type Operator = TConditionRule['op'];
|
|
6
|
+
/** The list's filter as parts that must all hold; an "any" group of several rules is one part. */
|
|
7
|
+
export declare const partsOf: (group: TConditionGroup | null) => FilterPart[];
|
|
8
|
+
/** Parts back to the list's filter: null when there are none. */
|
|
9
|
+
export declare const groupOf: (parts: FilterPart[]) => TConditionGroup | null;
|
|
10
|
+
/**
|
|
11
|
+
* Replaces the part at `index`, appends when `index` is null, removes when
|
|
12
|
+
* `next` is null. Parts stay distinct: a part already there isn't added twice.
|
|
13
|
+
*/
|
|
14
|
+
export declare const withPart: (parts: FilterPart[], index: number | null, next: FilterPart | null) => FilterPart[];
|
|
15
|
+
/** Comparisons of a number, as the menu writes them. */
|
|
16
|
+
export declare const NUMBER_OPS: readonly ['eq', 'neq', 'gt', 'gte', 'lt', 'lte'];
|
|
17
|
+
export declare const NUMBER_SYMBOLS: Record<(typeof NUMBER_OPS)[number], string>;
|
|
18
|
+
/** Whether the menu can show and edit this rule. */
|
|
19
|
+
export declare const inMenu: (rule: TConditionRule, field: TListFilterField | undefined) => boolean;
|
|
20
|
+
/** Which part the menu of `field` changes: the one being edited, else its existing single rule, else a new one. */
|
|
21
|
+
export declare const targetOf: (parts: FilterPart[], field: TListFilterField, editing: number | null) => number | null;
|
|
22
|
+
/**
|
|
23
|
+
* The values a rule picks: the list of "is any of", or the one of "is". A value that isn't text or
|
|
24
|
+
* numbers (a date range, a relative amount) picks nothing.
|
|
25
|
+
*/
|
|
26
|
+
export declare const valuesOf: (rule: TConditionRule | undefined) => string[];
|
|
27
|
+
/** An "is any of" rule; null when nothing is picked. */
|
|
28
|
+
export declare const anyOf: (path: string, values: string[]) => TConditionRule | null;
|
|
29
|
+
/**
|
|
30
|
+
* Date filters in one pick, on the relative operators (they stay current in a saved view);
|
|
31
|
+
* `label` is the English for the `views` namespace's `filter.date.<key>`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DATE_PRESETS: {
|
|
34
|
+
key: string;
|
|
35
|
+
label: string;
|
|
36
|
+
op: Operator;
|
|
37
|
+
value?: RelativeAmount;
|
|
38
|
+
}[];
|
|
39
|
+
/** The preset a rule is, if any. */
|
|
40
|
+
export declare const presetOf: (rule: TConditionRule | undefined) => {
|
|
41
|
+
key: string;
|
|
42
|
+
label: string;
|
|
43
|
+
op: Operator;
|
|
44
|
+
value?: RelativeAmount;
|
|
45
|
+
} | undefined;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/modules/list/filter/filterRules.ts
|
|
4
|
+
/** The list's filter as parts that must all hold; an "any" group of several rules is one part. */
|
|
5
|
+
const partsOf = (group) => !group ? [] : group.match === "all" || group.rules.length < 2 ? group.rules : [group];
|
|
6
|
+
/** Parts back to the list's filter: null when there are none. */
|
|
7
|
+
const groupOf = (parts) => parts.length ? {
|
|
8
|
+
match: "all",
|
|
9
|
+
rules: parts
|
|
10
|
+
} : null;
|
|
11
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
12
|
+
/**
|
|
13
|
+
* Replaces the part at `index`, appends when `index` is null, removes when
|
|
14
|
+
* `next` is null. Parts stay distinct: a part already there isn't added twice.
|
|
15
|
+
*/
|
|
16
|
+
const withPart = (parts, index, next) => {
|
|
17
|
+
if (next && parts.some((part, at) => at !== index && same(part, next))) return index === null ? parts : parts.filter((_, at) => at !== index);
|
|
18
|
+
if (index === null) return next ? [...parts, next] : parts;
|
|
19
|
+
return next ? parts.map((part, at) => at === index ? next : part) : parts.filter((_, at) => at !== index);
|
|
20
|
+
};
|
|
21
|
+
/** Comparisons of a number, as the menu writes them. */
|
|
22
|
+
const NUMBER_OPS = [
|
|
23
|
+
"eq",
|
|
24
|
+
"neq",
|
|
25
|
+
"gt",
|
|
26
|
+
"gte",
|
|
27
|
+
"lt",
|
|
28
|
+
"lte"
|
|
29
|
+
];
|
|
30
|
+
const NUMBER_SYMBOLS = {
|
|
31
|
+
eq: "=",
|
|
32
|
+
neq: "≠",
|
|
33
|
+
gt: ">",
|
|
34
|
+
gte: "≥",
|
|
35
|
+
lt: "<",
|
|
36
|
+
lte: "≤"
|
|
37
|
+
};
|
|
38
|
+
/** The operators the filter menu shows and edits for each kind of field; other rules open the advanced filter. */
|
|
39
|
+
const MENU_OPS = {
|
|
40
|
+
select: ["in", "eq"],
|
|
41
|
+
member: ["in", "eq"],
|
|
42
|
+
tags: ["in", "eq"],
|
|
43
|
+
boolean: ["eq"],
|
|
44
|
+
date: [
|
|
45
|
+
"within_last",
|
|
46
|
+
"more_than_ago",
|
|
47
|
+
"within_next",
|
|
48
|
+
"exists",
|
|
49
|
+
"not_exists"
|
|
50
|
+
],
|
|
51
|
+
number: NUMBER_OPS,
|
|
52
|
+
text: ["contains"]
|
|
53
|
+
};
|
|
54
|
+
/** Whether the menu can show and edit this rule. */
|
|
55
|
+
const inMenu = (rule, field) => !!field && MENU_OPS[field.type].includes(rule.op);
|
|
56
|
+
/** Fields with one value at a time (a choice, a yes/no, a date range): picking again changes it rather than adding one. */
|
|
57
|
+
const SINGLE = /* @__PURE__ */ new Set([
|
|
58
|
+
"select",
|
|
59
|
+
"member",
|
|
60
|
+
"tags",
|
|
61
|
+
"boolean",
|
|
62
|
+
"date"
|
|
63
|
+
]);
|
|
64
|
+
/** Which part the menu of `field` changes: the one being edited, else its existing single rule, else a new one. */
|
|
65
|
+
const targetOf = (parts, field, editing) => {
|
|
66
|
+
if (editing !== null) return editing;
|
|
67
|
+
if (!SINGLE.has(field.type)) return null;
|
|
68
|
+
const index = parts.findIndex((part) => isRule(part) && part.path === field.path && inMenu(part, field));
|
|
69
|
+
return index < 0 ? null : index;
|
|
70
|
+
};
|
|
71
|
+
const Values = z.array(z.union([z.string(), z.number()]).transform(String));
|
|
72
|
+
/**
|
|
73
|
+
* The values a rule picks: the list of "is any of", or the one of "is". A value that isn't text or
|
|
74
|
+
* numbers (a date range, a relative amount) picks nothing.
|
|
75
|
+
*/
|
|
76
|
+
const valuesOf = (rule) => {
|
|
77
|
+
if (!rule || rule.value === void 0 || rule.value === null) return [];
|
|
78
|
+
return Values.safeParse(rule.op === "in" ? rule.value : [rule.value]).data ?? [];
|
|
79
|
+
};
|
|
80
|
+
/** An "is any of" rule; null when nothing is picked. */
|
|
81
|
+
const anyOf = (path, values) => values.length ? {
|
|
82
|
+
path,
|
|
83
|
+
op: "in",
|
|
84
|
+
value: values
|
|
85
|
+
} : null;
|
|
86
|
+
const days = (amount) => ({
|
|
87
|
+
amount,
|
|
88
|
+
unit: "days"
|
|
89
|
+
});
|
|
90
|
+
const months = (amount) => ({
|
|
91
|
+
amount,
|
|
92
|
+
unit: "months"
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Date filters in one pick, on the relative operators (they stay current in a saved view);
|
|
96
|
+
* `label` is the English for the `views` namespace's `filter.date.<key>`.
|
|
97
|
+
*/
|
|
98
|
+
const DATE_PRESETS = [
|
|
99
|
+
{
|
|
100
|
+
key: "past-day",
|
|
101
|
+
label: "Past day",
|
|
102
|
+
op: "within_last",
|
|
103
|
+
value: days(1)
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: "past-week",
|
|
107
|
+
label: "Past 7 days",
|
|
108
|
+
op: "within_last",
|
|
109
|
+
value: days(7)
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: "past-month",
|
|
113
|
+
label: "Past 30 days",
|
|
114
|
+
op: "within_last",
|
|
115
|
+
value: days(30)
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: "past-quarter",
|
|
119
|
+
label: "Past 3 months",
|
|
120
|
+
op: "within_last",
|
|
121
|
+
value: months(3)
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: "past-year",
|
|
125
|
+
label: "Past year",
|
|
126
|
+
op: "within_last",
|
|
127
|
+
value: months(12)
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
key: "older-month",
|
|
131
|
+
label: "More than 30 days ago",
|
|
132
|
+
op: "more_than_ago",
|
|
133
|
+
value: days(30)
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
key: "older-year",
|
|
137
|
+
label: "More than a year ago",
|
|
138
|
+
op: "more_than_ago",
|
|
139
|
+
value: months(12)
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
key: "next-week",
|
|
143
|
+
label: "Next 7 days",
|
|
144
|
+
op: "within_next",
|
|
145
|
+
value: days(7)
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
key: "next-month",
|
|
149
|
+
label: "Next 30 days",
|
|
150
|
+
op: "within_next",
|
|
151
|
+
value: days(30)
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
key: "set",
|
|
155
|
+
label: "Is set",
|
|
156
|
+
op: "exists"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
key: "empty",
|
|
160
|
+
label: "Is empty",
|
|
161
|
+
op: "not_exists"
|
|
162
|
+
}
|
|
163
|
+
];
|
|
164
|
+
/** The preset a rule is, if any. */
|
|
165
|
+
const presetOf = (rule) => rule && DATE_PRESETS.find((preset) => preset.op === rule.op && JSON.stringify(preset.value) === JSON.stringify(rule.value));
|
|
166
|
+
export { DATE_PRESETS, NUMBER_OPS, NUMBER_SYMBOLS, anyOf, groupOf, inMenu, partsOf, presetOf, targetOf, valuesOf, withPart };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TConditionLookups } from "../../conditions/conditions.js";
|
|
2
|
+
import { TListFilterField } from "../ListFilter.js";
|
|
3
|
+
import { FilterPart } from "./filterRules.js";
|
|
4
|
+
/** What the filter menu, its chips and the advanced filter share. */
|
|
5
|
+
export interface ListFilterState {
|
|
6
|
+
fields: TListFilterField[];
|
|
7
|
+
/** Where `member` and `tags` fields pick from. */
|
|
8
|
+
lookups: TConditionLookups;
|
|
9
|
+
/** The list's filter as parts that must all hold (`partsOf`). */
|
|
10
|
+
parts: FilterPart[];
|
|
11
|
+
/** Changes the filter as `withPart` does. */
|
|
12
|
+
setPart: (index: number | null, next: FilterPart | null) => void;
|
|
13
|
+
/** The part a chip opened the menu on. */
|
|
14
|
+
editing: number | null;
|
|
15
|
+
/** Opens the menu on a chip's part, or the advanced filter when the menu can't show it. */
|
|
16
|
+
edit: (index: number) => void;
|
|
17
|
+
openAdvanced: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare const ListFilterContext: import("react").Context<ListFilterState | null>;
|
|
20
|
+
export declare const useListFilter: () => ListFilterState;
|
|
21
|
+
/** What a choice field picks from: its options, the team ("Me" first), or the list's tags. */
|
|
22
|
+
export declare const useFieldOptions: (field: TListFilterField) => {
|
|
23
|
+
options: {
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}[];
|
|
27
|
+
loading: boolean;
|
|
28
|
+
error: Error | null;
|
|
29
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { useMemberOptions, useTagOptions } from "../../pickers/LookupPicker.js";
|
|
3
|
+
import { valuesOf } from "./filterRules.js";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
import { useTranslation } from "react-i18next";
|
|
6
|
+
// src/modules/list/filter/listFilterContext.ts
|
|
7
|
+
const ListFilterContext = createContext(null);
|
|
8
|
+
const useListFilter = () => {
|
|
9
|
+
const state = useContext(ListFilterContext);
|
|
10
|
+
if (!state) throw new Error("useListFilter is only available inside <ListFilter>");
|
|
11
|
+
return state;
|
|
12
|
+
};
|
|
13
|
+
/** What a choice field picks from: its options, the team ("Me" first), or the list's tags. */
|
|
14
|
+
const useFieldOptions = (field) => {
|
|
15
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
16
|
+
const { lookups, parts } = useListFilter();
|
|
17
|
+
const picked = parts.flatMap((part) => isRule(part) && part.path === field.path ? valuesOf(part) : []);
|
|
18
|
+
const members = useMemberOptions(lookups.members, field.type === "member", picked);
|
|
19
|
+
const tags = useTagOptions(lookups.tags, field.type === "tags");
|
|
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
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export { ListFilterContext, useFieldOptions, useListFilter };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TConditionGroup } from "../../conditions/conditions.js";
|
|
2
|
+
/**
|
|
3
|
+
* The URL params holding a list's filter, as nuqs parsers.
|
|
4
|
+
* Shared links and reloads keep the filter: `advanced` is the condition group as JSON, and
|
|
5
|
+
* `searchValue` the search.
|
|
6
|
+
*/
|
|
7
|
+
export declare const listFilterQuery: {
|
|
8
|
+
advanced: import("nuqs").SingleParserBuilder<TConditionGroup>;
|
|
9
|
+
searchValue: import("nuqs").SingleParserBuilder<string>;
|
|
10
|
+
};
|
|
11
|
+
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
12
|
+
export declare const useListConditions: () => {
|
|
13
|
+
advanced: TConditionGroup | null;
|
|
14
|
+
search: string | null;
|
|
15
|
+
setAdvanced: (next: TConditionGroup | null) => undefined;
|
|
16
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ConditionGroup } from "../../conditions/conditions.js";
|
|
2
|
+
import { parseAsJson, parseAsString, useQueryStates } from "nuqs";
|
|
3
|
+
// src/modules/list/filter/listFilterQuery.ts
|
|
4
|
+
/**
|
|
5
|
+
* The URL params holding a list's filter, as nuqs parsers.
|
|
6
|
+
* Shared links and reloads keep the filter: `advanced` is the condition group as JSON, and
|
|
7
|
+
* `searchValue` the search.
|
|
8
|
+
*/
|
|
9
|
+
const listFilterQuery = {
|
|
10
|
+
advanced: parseAsJson((value) => ConditionGroup.safeParse(value).data ?? null),
|
|
11
|
+
searchValue: parseAsString
|
|
12
|
+
};
|
|
13
|
+
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
14
|
+
const useListConditions = () => {
|
|
15
|
+
const [{ advanced, searchValue }, setQueries] = useQueryStates(listFilterQuery, { history: "replace" });
|
|
16
|
+
return {
|
|
17
|
+
advanced: advanced?.rules.length ? advanced : null,
|
|
18
|
+
search: searchValue,
|
|
19
|
+
setAdvanced: (next) => void setQueries({ advanced: next?.rules.length ? next : null })
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export { listFilterQuery, useListConditions };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Sidebar } from "../../../components/sidebar.js";
|
|
2
|
-
|
|
2
|
+
/** A sidebar link that lights up while the address is under its `to`. */
|
|
3
|
+
export declare const NavigationMenuLinkItem: ({ ref, name, icon: IconComponent, to, children, className, isActive: isActiveProp, label, action, itemClassName, ...props }: React.ComponentProps<typeof Sidebar.MenuButton> & {
|
|
3
4
|
name: string;
|
|
4
5
|
icon?: React.ElementType;
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/** The address, from the app's paths. */
|
|
7
|
+
to: string;
|
|
7
8
|
isActive?: boolean;
|
|
8
9
|
label?: React.ReactNode;
|
|
9
10
|
action?: React.ReactNode;
|
|
@@ -4,15 +4,15 @@ import { useNavigationMenuItemControls } from "./NavigationMenuItemControls.js";
|
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { Link, useLocation } from "react-router-dom";
|
|
6
6
|
// src/modules/navigation-menu/components/NavigationMenu.tsx
|
|
7
|
-
|
|
7
|
+
/** A sidebar link that lights up while the address is under its `to`. */
|
|
8
|
+
const NavigationMenuLinkItem = ({ ref, name, icon: IconComponent, to, children, className, isActive: isActiveProp, label, action, itemClassName, ...props }) => {
|
|
8
9
|
const { pathname } = useLocation();
|
|
9
|
-
const
|
|
10
|
-
const isActive = pathname.startsWith(fullPath);
|
|
10
|
+
const isActive = pathname.startsWith(to);
|
|
11
11
|
const controls = useNavigationMenuItemControls();
|
|
12
|
-
const order = controls?.getOrder(
|
|
12
|
+
const order = controls?.getOrder(to);
|
|
13
13
|
return /* @__PURE__ */ jsxs(Sidebar.MenuItem, {
|
|
14
14
|
className: cn(itemClassName, order !== void 0 && "order-(--order)"),
|
|
15
|
-
"data-nav-path": controls ?
|
|
15
|
+
"data-nav-path": controls ? to : void 0,
|
|
16
16
|
style: { "--order": order },
|
|
17
17
|
children: [
|
|
18
18
|
/* @__PURE__ */ jsxs(Sidebar.MenuButton, {
|
|
@@ -20,7 +20,7 @@ const NavigationMenuLinkItem = ({ ref, name, icon: IconComponent, path, pathPref
|
|
|
20
20
|
ref,
|
|
21
21
|
className,
|
|
22
22
|
...props,
|
|
23
|
-
render: /* @__PURE__ */ jsx(Link, { to
|
|
23
|
+
render: /* @__PURE__ */ jsx(Link, { to }),
|
|
24
24
|
children: [
|
|
25
25
|
IconComponent && /* @__PURE__ */ jsx(IconComponent, { className: cn("text-accent-foreground", isActive && "text-primary-text") }),
|
|
26
26
|
label || /* @__PURE__ */ jsx("span", {
|
|
@@ -33,7 +33,7 @@ const NavigationMenuLinkItem = ({ ref, name, icon: IconComponent, path, pathPref
|
|
|
33
33
|
action,
|
|
34
34
|
controls?.renderActions({
|
|
35
35
|
name,
|
|
36
|
-
path:
|
|
36
|
+
path: to,
|
|
37
37
|
icon: IconComponent
|
|
38
38
|
})
|
|
39
39
|
]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
interface EntityPickerProps<T, K extends string> {
|
|
3
|
+
items: T[];
|
|
4
|
+
/** The id and the text a search matches. */
|
|
5
|
+
itemKey: (item: T) => {
|
|
6
|
+
id: K;
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
9
|
+
/** How an item reads in the list; its label by default. */
|
|
10
|
+
renderItem?: (item: T) => ReactNode;
|
|
11
|
+
value: K[];
|
|
12
|
+
/** The picked ids. One pick replaces the value unless `multiple`, where it toggles. */
|
|
13
|
+
onValueChange: (ids: K[]) => void;
|
|
14
|
+
multiple?: boolean;
|
|
15
|
+
/** Items keep their order (a tree reads top down); otherwise the picked ones come first. */
|
|
16
|
+
keepOrder?: boolean;
|
|
17
|
+
loading?: boolean;
|
|
18
|
+
error?: Error | null;
|
|
19
|
+
/** Searching on the server: `items` are already the matches, so they are not filtered here. */
|
|
20
|
+
onSearchChange?: (search: string) => void;
|
|
21
|
+
searchPlaceholder?: string;
|
|
22
|
+
/** A first row that picks nothing. */
|
|
23
|
+
noneLabel?: string;
|
|
24
|
+
/** Above the list, e.g. the picked tags as badges. */
|
|
25
|
+
header?: ReactNode;
|
|
26
|
+
/** A row for what was searched, e.g. "Add tag: VIP"; `clear` empties the search. */
|
|
27
|
+
renderCreate?: (search: string, clear: () => void) => ReactNode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The searchable list behind every record picker; build a picker on it.
|
|
31
|
+
* It serves members, contacts, tags and a plugin's own records: search, the picked ones first, a
|
|
32
|
+
* check on each, and optional "none" and "create" rows. Each picker brings its own trigger (a
|
|
33
|
+
* table cell, a form control, a button) and its items, usually from
|
|
34
|
+
* `useQuery(orpc.<group>.list.queryOptions(...))`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const EntityPicker: <T, K extends string = string>({ items, itemKey, renderItem, value, onValueChange, multiple, keepOrder, loading, error, onSearchChange, searchPlaceholder, noneLabel, header, renderCreate }: EntityPickerProps<T, K>) => import("react").JSX.Element;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Combobox } from "../../components/combobox.js";
|
|
2
|
+
import { Command } from "../../components/command.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
// src/modules/pickers/EntityPicker.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The searchable list behind every record picker; build a picker on it.
|
|
8
|
+
* It serves members, contacts, tags and a plugin's own records: search, the picked ones first, a
|
|
9
|
+
* check on each, and optional "none" and "create" rows. Each picker brings its own trigger (a
|
|
10
|
+
* table cell, a form control, a button) and its items, usually from
|
|
11
|
+
* `useQuery(orpc.<group>.list.queryOptions(...))`.
|
|
12
|
+
*/
|
|
13
|
+
const EntityPicker = ({ items, itemKey, renderItem, value, onValueChange, multiple, keepOrder, loading, error, onSearchChange, searchPlaceholder, noneLabel, header, renderCreate }) => {
|
|
14
|
+
const [search, setSearch] = useState("");
|
|
15
|
+
const [pickedAtOpen] = useState(value);
|
|
16
|
+
const term = search.trim().toLowerCase();
|
|
17
|
+
const matches = items.map((item) => ({
|
|
18
|
+
item,
|
|
19
|
+
...itemKey(item)
|
|
20
|
+
})).filter((row) => onSearchChange !== void 0 || row.label.toLowerCase().includes(term));
|
|
21
|
+
const rows = keepOrder ? matches : matches.toSorted((a, b) => Number(pickedAtOpen.includes(b.id)) - Number(pickedAtOpen.includes(a.id)));
|
|
22
|
+
const pick = (id) => onValueChange(!multiple ? [id] : value.includes(id) ? value.filter((item) => item !== id) : [...value, id]);
|
|
23
|
+
const changeSearch = (next) => {
|
|
24
|
+
setSearch(next);
|
|
25
|
+
onSearchChange?.(next);
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ jsxs(Command, {
|
|
28
|
+
shouldFilter: false,
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ jsx(Command.Input, {
|
|
31
|
+
value: search,
|
|
32
|
+
onValueChange: changeSearch,
|
|
33
|
+
placeholder: searchPlaceholder,
|
|
34
|
+
variant: "secondary",
|
|
35
|
+
wrapperClassName: "flex-auto",
|
|
36
|
+
focusOnMount: true
|
|
37
|
+
}),
|
|
38
|
+
header,
|
|
39
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
40
|
+
role: "alert",
|
|
41
|
+
className: "text-destructive px-3 py-2 text-sm",
|
|
42
|
+
children: error.message
|
|
43
|
+
}),
|
|
44
|
+
/* @__PURE__ */ jsxs(Command.List, {
|
|
45
|
+
className: "max-h-75 overflow-y-auto",
|
|
46
|
+
children: [
|
|
47
|
+
noneLabel && !term && /* @__PURE__ */ jsxs(Command.Item, {
|
|
48
|
+
value: "__none__",
|
|
49
|
+
onSelect: () => onValueChange([]),
|
|
50
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
51
|
+
className: "text-muted-foreground",
|
|
52
|
+
children: noneLabel
|
|
53
|
+
}), /* @__PURE__ */ jsx(Combobox.Check, { checked: value.length === 0 })]
|
|
54
|
+
}),
|
|
55
|
+
renderCreate?.(search.trim(), () => changeSearch("")),
|
|
56
|
+
!error && /* @__PURE__ */ jsx(Combobox.Empty, { loading }),
|
|
57
|
+
rows.map(({ item, id, label }) => /* @__PURE__ */ jsxs(Command.Item, {
|
|
58
|
+
value: id,
|
|
59
|
+
onSelect: () => pick(id),
|
|
60
|
+
children: [renderItem ? renderItem(item) : label, /* @__PURE__ */ jsx(Combobox.Check, { checked: value.includes(id) })]
|
|
61
|
+
}, id))
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
export { EntityPicker };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MemberQueries } from "./members.js";
|
|
2
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
3
|
+
/** A tag as the pickers show one: core's `Tag` has these fields and more. */
|
|
4
|
+
export interface Tag {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* TanStack query options for the tags of one record type.
|
|
10
|
+
* In erxes, web's query for `orpc.tags.list` with the type (`{ type: 'customer' }`).
|
|
11
|
+
*/
|
|
12
|
+
export type TagsQuery = RowsQuery<Tag>;
|
|
13
|
+
type LookupOptions = {
|
|
14
|
+
options: {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
loading: boolean;
|
|
19
|
+
error: Error | null;
|
|
20
|
+
};
|
|
21
|
+
type RowsQuery<T> = UseQueryOptions<{
|
|
22
|
+
data: T[];
|
|
23
|
+
}, Error, {
|
|
24
|
+
data: T[];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* The active team members as picker options.
|
|
28
|
+
* It adds the `picked` members outside it (a disabled member a filter still names), so their
|
|
29
|
+
* names show; none without `members`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const useMemberOptions: (members: MemberQueries | undefined, enabled?: boolean, picked?: readonly string[]) => {
|
|
32
|
+
loading: boolean;
|
|
33
|
+
error: Error | null;
|
|
34
|
+
options: {
|
|
35
|
+
value: string;
|
|
36
|
+
label: string;
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
39
|
+
/** A record type's tags as picker options; none without `tags`. */
|
|
40
|
+
export declare const useTagOptions: (tags: TagsQuery | undefined, enabled?: boolean) => LookupOptions;
|
|
41
|
+
/** A button that picks members or tags, one or several with `multiple`. */
|
|
42
|
+
export declare const LookupPicker: ({ lookup: { options, loading, error }, value, onValueChange, multiple, placeholder, disabled, className }: {
|
|
43
|
+
lookup: LookupOptions;
|
|
44
|
+
value: string[];
|
|
45
|
+
onValueChange: (values: string[]) => void;
|
|
46
|
+
multiple?: boolean;
|
|
47
|
+
placeholder: string;
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
className?: string;
|
|
50
|
+
}) => import("react").JSX.Element;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Combobox } from "../../components/combobox.js";
|
|
2
|
+
import { Popover } from "../../components/popover.js";
|
|
3
|
+
import { EntityPicker } from "./EntityPicker.js";
|
|
4
|
+
import { memberName } from "./members.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { skipToken, useQuery } from "@tanstack/react-query";
|
|
8
|
+
// src/modules/pickers/LookupPicker.tsx
|
|
9
|
+
const useLookup = (query, enabled, option) => {
|
|
10
|
+
const options = query ? {
|
|
11
|
+
...query,
|
|
12
|
+
enabled
|
|
13
|
+
} : {
|
|
14
|
+
queryKey: ["erxes-ui", "no-lookup"],
|
|
15
|
+
queryFn: skipToken
|
|
16
|
+
};
|
|
17
|
+
const result = useQuery(options);
|
|
18
|
+
return {
|
|
19
|
+
options: useMemo(() => (result.data?.data ?? []).map(option), [result.data, option]),
|
|
20
|
+
loading: enabled && !!query && result.isPending,
|
|
21
|
+
error: result.error
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const memberOption = (member) => ({
|
|
25
|
+
value: member.id,
|
|
26
|
+
label: memberName(member)
|
|
27
|
+
});
|
|
28
|
+
const tagOption = (tag) => ({
|
|
29
|
+
value: tag.id,
|
|
30
|
+
label: tag.name
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* The active team members as picker options.
|
|
34
|
+
* It adds the `picked` members outside it (a disabled member a filter still names), so their
|
|
35
|
+
* names show; none without `members`.
|
|
36
|
+
*/
|
|
37
|
+
const useMemberOptions = (members, enabled = true, picked = []) => {
|
|
38
|
+
const team = useLookup(members?.team, enabled, memberOption);
|
|
39
|
+
const known = new Set(team.options.map((option) => option.value));
|
|
40
|
+
const missing = [...new Set(picked)].filter((id) => id !== "me" && !known.has(id)).toSorted((a, b) => a.localeCompare(b));
|
|
41
|
+
const others = useLookup(members && missing.length ? members.byIds(missing) : void 0, enabled && !team.loading && missing.length > 0, memberOption);
|
|
42
|
+
return {
|
|
43
|
+
...team,
|
|
44
|
+
options: [...team.options, ...others.options]
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/** A record type's tags as picker options; none without `tags`. */
|
|
48
|
+
const useTagOptions = (tags, enabled = true) => useLookup(tags, enabled, tagOption);
|
|
49
|
+
/** A button that picks members or tags, one or several with `multiple`. */
|
|
50
|
+
const LookupPicker = ({ lookup: { options, loading, error }, value, onValueChange, multiple, placeholder, disabled, className }) => {
|
|
51
|
+
const [open, setOpen] = useState(false);
|
|
52
|
+
const items = [...value.filter((id) => !options.some((option) => option.value === id)).map((id) => ({
|
|
53
|
+
value: id,
|
|
54
|
+
label: id
|
|
55
|
+
})), ...options];
|
|
56
|
+
const labels = value.map((id) => items.find((option) => option.value === id)?.label ?? id);
|
|
57
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
58
|
+
open,
|
|
59
|
+
onOpenChange: setOpen,
|
|
60
|
+
children: [/* @__PURE__ */ jsx(Combobox.Trigger, {
|
|
61
|
+
disabled,
|
|
62
|
+
className,
|
|
63
|
+
children: /* @__PURE__ */ jsx(Combobox.Value, {
|
|
64
|
+
value: labels.join(", "),
|
|
65
|
+
placeholder
|
|
66
|
+
})
|
|
67
|
+
}), /* @__PURE__ */ jsx(Combobox.Content, { children: /* @__PURE__ */ jsx(EntityPicker, {
|
|
68
|
+
multiple,
|
|
69
|
+
items,
|
|
70
|
+
itemKey: (option) => ({
|
|
71
|
+
id: option.value,
|
|
72
|
+
label: option.label
|
|
73
|
+
}),
|
|
74
|
+
value,
|
|
75
|
+
onValueChange: (next) => {
|
|
76
|
+
onValueChange(next);
|
|
77
|
+
if (!multiple) setOpen(false);
|
|
78
|
+
},
|
|
79
|
+
loading,
|
|
80
|
+
error
|
|
81
|
+
}) })]
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export { LookupPicker, useMemberOptions, useTagOptions };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AvatarProps } from "../../components/avatar.js";
|
|
2
|
+
import { Combobox } from "../../components/combobox.js";
|
|
3
|
+
import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
|
|
4
|
+
import { MemberQueries } from "./members.js";
|
|
5
|
+
import { ComponentProps, ComponentRef, RefAttributes } from "react";
|
|
6
|
+
/** A member's avatar and name by id, or a placeholder without one. */
|
|
7
|
+
export declare const MemberInline: ({ memberId, members, placeholder, size, className }: {
|
|
8
|
+
memberId: string | null | undefined;
|
|
9
|
+
members: MemberQueries;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
size?: AvatarProps['size'];
|
|
12
|
+
className?: string;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
14
|
+
interface SelectMemberProps {
|
|
15
|
+
value: string | null | undefined;
|
|
16
|
+
onValueChange: (id: string | null) => void;
|
|
17
|
+
/** Where the members come from: `memberQueries` from `@erxes/core-contract/client`. */
|
|
18
|
+
members: MemberQueries;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
/** A first row that picks no member, e.g. "Anyone" on a filter. */
|
|
21
|
+
noneLabel?: string;
|
|
22
|
+
}
|
|
23
|
+
/** The member as a record table cell; click to pick another. */
|
|
24
|
+
declare const SelectMemberInlineCell: ({ ref, value, onValueChange, members, noneLabel, scope, placeholder, size, className, variant, id, 'aria-label': ariaLabel }: SelectMemberProps & {
|
|
25
|
+
scope?: string;
|
|
26
|
+
size?: AvatarProps['size'];
|
|
27
|
+
className?: string;
|
|
28
|
+
/** `field` beside its label in a side panel; a table cell by default. */
|
|
29
|
+
variant?: ComponentProps<typeof RecordTableInlineCell.Trigger>['variant'];
|
|
30
|
+
id?: string;
|
|
31
|
+
/** Names the picker while it shows no member. */
|
|
32
|
+
'aria-label'?: string;
|
|
33
|
+
} & RefAttributes<ComponentRef<typeof RecordTableInlineCell.Trigger>>) => import("react").JSX.Element;
|
|
34
|
+
/** A member picker button; its other props (an id, `Form.Control`'s aria wiring) go to the button. */
|
|
35
|
+
declare const SelectMemberField: ({ value, onValueChange, members, noneLabel, placeholder, className, ...trigger }: SelectMemberProps & Omit<ComponentProps<typeof Combobox.Trigger>, 'value' | 'children' | 'placeholder'>) => import("react").JSX.Element;
|
|
36
|
+
/** The member picker as a table cell and as a field. */
|
|
37
|
+
export declare const SelectMember: {
|
|
38
|
+
InlineCell: typeof SelectMemberInlineCell;
|
|
39
|
+
Field: typeof SelectMemberField;
|
|
40
|
+
};
|
|
41
|
+
export {};
|