@erxes/ui 4.0.0-v2.13 → 4.0.0-v2.15

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 (78) hide show
  1. package/CATALOG.md +15 -8
  2. package/README.md +1 -1
  3. package/dist/index.d.ts +6 -6
  4. package/dist/index.js +4 -3
  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 +169 -0
  19. package/dist/modules/conditions/conditions.d.ts +21 -12
  20. package/dist/modules/conditions/conditions.js +8 -75
  21. package/dist/modules/conditions/fieldIcons.d.ts +6 -0
  22. package/dist/modules/conditions/fieldIcons.js +21 -0
  23. package/dist/modules/conditions/fieldOptions.d.ts +15 -0
  24. package/dist/modules/conditions/fieldOptions.js +38 -0
  25. package/dist/modules/conditions/filterRule.d.ts +45 -0
  26. package/dist/modules/conditions/filterRule.js +171 -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 +22 -10
  32. package/dist/modules/list/ListFilter.js +53 -20
  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 +109 -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/modules/pickers/LookupPicker.d.ts +6 -0
  52. package/dist/modules/pickers/LookupPicker.js +32 -1
  53. package/dist/modules/record-list/RecordList.d.ts +2 -1
  54. package/dist/modules/record-list/RecordList.js +2 -1
  55. package/dist/modules/record-list/RecordListRoot.d.ts +3 -1
  56. package/dist/modules/record-list/RecordListRoot.js +53 -37
  57. package/dist/modules/record-table/components/RecordTableHead.d.ts +7 -2
  58. package/dist/modules/record-table/components/RecordTableHead.js +73 -6
  59. package/dist/modules/record-table/components/RecordTableProvider.d.ts +22 -1
  60. package/dist/modules/record-table/components/RecordTableProvider.js +12 -1
  61. package/dist/modules/records/contacts.d.ts +18 -0
  62. package/dist/modules/records/openRecord.d.ts +35 -1
  63. package/dist/modules/records/openRecord.js +27 -4
  64. package/dist/theme.css +3 -2
  65. package/dist/types/UIConfig.d.ts +47 -100
  66. package/dist/types/UIConfig.js +14 -0
  67. package/exports.txt +10 -3
  68. package/package.json +1 -1
  69. package/dist/modules/conditions/ConditionValueInput.d.ts +0 -10
  70. package/dist/modules/conditions/ConditionValueInput.js +0 -166
  71. package/dist/modules/conditions/PathPicker.d.ts +0 -8
  72. package/dist/modules/conditions/PathPicker.js +0 -56
  73. package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +0 -5
  74. package/dist/modules/list/filter/AdvancedFilterDialog.js +0 -52
  75. package/dist/modules/list/filter/FieldMenus.d.ts +0 -5
  76. package/dist/modules/list/filter/FieldMenus.js +0 -184
  77. package/dist/modules/list/filter/fieldIcons.d.ts +0 -7
  78. 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
- /** What the filter menu, its chips and the advanced filter share. */
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 as parts that must all hold (`partsOf`). */
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 the filter as `withPart` does. */
18
+ /** Changes a part as `withPart` does. */
12
19
  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;
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
- /** 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
- };
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
- /** 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
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, useFieldOptions, useListFilter };
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: advanced?.rules.length ? advanced : null,
18
+ advanced: filter,
18
19
  search: searchValue,
19
- setAdvanced: (next) => void setQueries({ advanced: next?.rules.length ? next : null })
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 };
@@ -1,3 +1,4 @@
1
+ import { ContactSearchQueries } from "../records/contacts.js";
1
2
  import { MemberQueries } from "./members.js";
2
3
  import { UseQueryOptions } from "@tanstack/react-query";
3
4
  /** A tag as the pickers show one: core's `Tag` has these fields and more. */
@@ -36,6 +37,11 @@ export declare const useMemberOptions: (members: MemberQueries | undefined, enab
36
37
  label: string;
37
38
  }[];
38
39
  };
40
+ /**
41
+ * Customers or companies matching `search` as picker options, the `picked` ones first so their
42
+ * names show whatever is searched; none without `contacts` or a `type`.
43
+ */
44
+ export declare const useContactOptions: (contacts: ContactSearchQueries | undefined, type: 'customer' | 'company' | null, picked?: readonly string[], search?: string) => LookupOptions;
39
45
  /** A record type's tags as picker options; none without `tags`. */
40
46
  export declare const useTagOptions: (tags: TagsQuery | undefined, enabled?: boolean) => LookupOptions;
41
47
  /** A button that picks members or tags, one or several with `multiple`. */
@@ -1,6 +1,7 @@
1
1
  import { Combobox } from "../../components/combobox.js";
2
2
  import { Popover } from "../../components/popover.js";
3
3
  import { EntityPicker } from "./EntityPicker.js";
4
+ import { companyTitle, customerTitle } from "../records/contacts.js";
4
5
  import { memberName } from "./members.js";
5
6
  import { jsx, jsxs } from "react/jsx-runtime";
6
7
  import { useMemo, useState } from "react";
@@ -44,6 +45,36 @@ const useMemberOptions = (members, enabled = true, picked = []) => {
44
45
  options: [...team.options, ...others.options]
45
46
  };
46
47
  };
48
+ const customerOption = (customer) => ({
49
+ value: customer.id,
50
+ label: customerTitle(customer) || customer.id
51
+ });
52
+ const companyOption = (company) => ({
53
+ value: company.id,
54
+ label: companyTitle(company) || company.id
55
+ });
56
+ /**
57
+ * Customers or companies matching `search` as picker options, the `picked` ones first so their
58
+ * names show whatever is searched; none without `contacts` or a `type`.
59
+ */
60
+ const useContactOptions = (contacts, type, picked = [], search = "") => {
61
+ const ids = [...new Set(picked)].toSorted((a, b) => a.localeCompare(b));
62
+ const input = { search: search.trim() || void 0 };
63
+ const customers = type === "customer" ? contacts?.customers : void 0;
64
+ const companies = type === "company" ? contacts?.companies : void 0;
65
+ const byIds = ids.length > 0;
66
+ const lookups = [
67
+ useLookup(customers && byIds ? customers({ ids }) : void 0, byIds, customerOption),
68
+ useLookup(companies && byIds ? companies({ ids }) : void 0, byIds, companyOption),
69
+ useLookup(customers?.(input), true, customerOption),
70
+ useLookup(companies?.(input), true, companyOption)
71
+ ];
72
+ return {
73
+ options: [...new Map(lookups.flatMap((lookup) => lookup.options).map((row) => [row.value, row])).values()],
74
+ loading: lookups.some((lookup) => lookup.loading),
75
+ error: lookups.find((lookup) => lookup.error)?.error ?? null
76
+ };
77
+ };
47
78
  /** A record type's tags as picker options; none without `tags`. */
48
79
  const useTagOptions = (tags, enabled = true) => useLookup(tags, enabled, tagOption);
49
80
  /** A button that picks members or tags, one or several with `multiple`. */
@@ -81,4 +112,4 @@ const LookupPicker = ({ lookup: { options, loading, error }, value, onValueChang
81
112
  }) })]
82
113
  });
83
114
  };
84
- export { LookupPicker, useMemberOptions, useTagOptions };
115
+ export { LookupPicker, useContactOptions, useMemberOptions, useTagOptions };
@@ -6,7 +6,8 @@ declare const RecordListSkeleton: ({ rows }: {
6
6
  }) => import("react").JSX.Element;
7
7
  /**
8
8
  * Rows grouped under headers that fold away, such as tasks by status.
9
- * Each group's sticky header picks all its rows, and folded groups are kept in this browser.
9
+ * Each group's sticky header picks all its rows (unless `selectable={false}`), and folded groups
10
+ * are kept in this browser.
10
11
  * Wrap it in `RecordList.Provider`, which holds the selection `RecordList.useSelection` reads
11
12
  * for a bulk command bar.
12
13
  */
@@ -11,7 +11,8 @@ const RecordListSkeleton = ({ rows = 8 }) => /* @__PURE__ */ jsx("div", {
11
11
  });
12
12
  /**
13
13
  * Rows grouped under headers that fold away, such as tasks by status.
14
- * Each group's sticky header picks all its rows, and folded groups are kept in this browser.
14
+ * Each group's sticky header picks all its rows (unless `selectable={false}`), and folded groups
15
+ * are kept in this browser.
15
16
  * Wrap it in `RecordList.Provider`, which holds the selection `RecordList.useSelection` reads
16
17
  * for a bulk command bar.
17
18
  */
@@ -17,6 +17,8 @@ interface RecordListProps<TRow> {
17
17
  renderRow: (row: TRow) => ReactNode;
18
18
  /** False: one list with no headers, such as rows sorted by date. */
19
19
  grouped?: boolean;
20
+ /** False: rows without checkboxes, for a list with no bulk actions. */
21
+ selectable?: boolean;
20
22
  className?: string;
21
23
  }
22
24
  /**
@@ -24,5 +26,5 @@ interface RecordListProps<TRow> {
24
26
  * folded groups are kept in this browser. Shift-click picks every row between two clicks, as
25
27
  * shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
26
28
  */
27
- export declare const RecordListRoot: <TRow>({ groups, rowId, rowLabel, renderRow, grouped, className }: RecordListProps<TRow>) => import("react").JSX.Element;
29
+ export declare const RecordListRoot: <TRow>({ groups, rowId, rowLabel, renderRow, grouped, selectable, className }: RecordListProps<TRow>) => import("react").JSX.Element;
28
30
  export {};
@@ -15,45 +15,57 @@ import { useAtom } from "jotai";
15
15
  */
16
16
  const revealed = "opacity-0 group-hover/list-row:opacity-100 group-focus-within/list-row:opacity-100";
17
17
  const useHover = () => useMediaQuery("(hover: hover) and (not (any-pointer: coarse))");
18
- const GroupHeader = ({ group, ids, panelId, collapsed, onCollapse }) => {
18
+ const GroupHeader = ({ group, ids, panelId, collapsed, onCollapse, selectable }) => /* @__PURE__ */ jsxs("div", {
19
+ className: "group/list-row sticky top-0 z-10 flex h-9 items-center gap-1 border-b bg-muted px-2 text-xs font-medium",
20
+ children: [
21
+ selectable && /* @__PURE__ */ jsx(GroupCheckbox, {
22
+ label: group.label,
23
+ ids
24
+ }),
25
+ /* @__PURE__ */ jsxs(Button, {
26
+ variant: "ghost",
27
+ size: "sm",
28
+ "aria-expanded": !collapsed,
29
+ "aria-controls": collapsed ? void 0 : panelId,
30
+ onClick: () => onCollapse(!collapsed),
31
+ children: [
32
+ collapsed ? /* @__PURE__ */ jsx(IconChevronRight, { "aria-hidden": true }) : /* @__PURE__ */ jsx(IconChevronDown, { "aria-hidden": true }),
33
+ group.icon,
34
+ group.label,
35
+ /* @__PURE__ */ jsx("span", {
36
+ className: "text-muted-foreground tabular-nums",
37
+ children: ids.length
38
+ })
39
+ ]
40
+ }),
41
+ group.action && /* @__PURE__ */ jsx("span", {
42
+ className: "ml-auto flex items-center",
43
+ children: group.action
44
+ })
45
+ ]
46
+ });
47
+ /** Picks or drops every row of a group. */
48
+ const GroupCheckbox = ({ label, ids }) => {
19
49
  const { selection } = useRecordListContext();
20
50
  const hover = useHover();
21
51
  const picked = useSelectionState((current) => ids.filter((id) => current.has(id)).length);
22
- return /* @__PURE__ */ jsxs("div", {
23
- className: "group/list-row sticky top-0 z-10 flex h-9 items-center gap-1 border-b bg-muted px-2 text-xs font-medium",
24
- children: [
25
- /* @__PURE__ */ jsx("span", {
26
- className: cn("flex h-9 w-8 shrink-0 items-center justify-center", hover && !picked && revealed),
27
- children: /* @__PURE__ */ jsx(Checkbox, {
28
- checked: picked > 0 && picked === ids.length,
29
- indeterminate: picked > 0 && picked < ids.length,
30
- "aria-label": `Select all in ${group.label}`,
31
- onCheckedChange: () => selection.toggleAll(ids)
32
- })
33
- }),
34
- /* @__PURE__ */ jsxs(Button, {
35
- variant: "ghost",
36
- size: "sm",
37
- "aria-expanded": !collapsed,
38
- "aria-controls": collapsed ? void 0 : panelId,
39
- onClick: () => onCollapse(!collapsed),
40
- children: [
41
- collapsed ? /* @__PURE__ */ jsx(IconChevronRight, { "aria-hidden": true }) : /* @__PURE__ */ jsx(IconChevronDown, { "aria-hidden": true }),
42
- group.icon,
43
- group.label,
44
- /* @__PURE__ */ jsx("span", {
45
- className: "text-muted-foreground tabular-nums",
46
- children: ids.length
47
- })
48
- ]
49
- }),
50
- group.action && /* @__PURE__ */ jsx("span", {
51
- className: "ml-auto flex items-center",
52
- children: group.action
53
- })
54
- ]
52
+ return /* @__PURE__ */ jsx("span", {
53
+ className: cn("flex h-9 w-8 shrink-0 items-center justify-center", hover && !picked && revealed),
54
+ children: /* @__PURE__ */ jsx(Checkbox, {
55
+ checked: picked > 0 && picked === ids.length,
56
+ indeterminate: picked > 0 && picked < ids.length,
57
+ "aria-label": `Select all in ${label}`,
58
+ onCheckedChange: () => selection.toggleAll(ids)
59
+ })
55
60
  });
56
61
  };
62
+ const rowClass = "group/list-row flex h-11 items-center gap-1 border-b px-2 text-sm hover:bg-muted data-selected:bg-primary/10";
63
+ /** A row with no checkbox, in a list without selection. */
64
+ const PlainRow = ({ id, children }) => /* @__PURE__ */ jsx("li", {
65
+ "data-record-row": id,
66
+ className: rowClass,
67
+ children
68
+ });
57
69
  const Row = ({ id, label, order, children }) => {
58
70
  const { selection } = useRecordListContext();
59
71
  const hover = useHover();
@@ -62,7 +74,7 @@ const Row = ({ id, label, order, children }) => {
62
74
  return /* @__PURE__ */ jsxs("li", {
63
75
  "data-record-row": id,
64
76
  "data-selected": checked || void 0,
65
- className: "group/list-row flex h-11 items-center gap-1 border-b px-2 text-sm hover:bg-muted data-selected:bg-primary/10",
77
+ className: rowClass,
66
78
  children: [/* @__PURE__ */ jsx("span", {
67
79
  className: cn("flex h-11 w-8 shrink-0 items-center justify-center", hover && !selecting && revealed),
68
80
  children: /* @__PURE__ */ jsx(Checkbox, {
@@ -83,17 +95,20 @@ const Row = ({ id, label, order, children }) => {
83
95
  * folded groups are kept in this browser. Shift-click picks every row between two clicks, as
84
96
  * shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
85
97
  */
86
- const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, className }) => {
98
+ const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, selectable = true, className }) => {
87
99
  const { listId } = useRecordListContext();
88
100
  const [collapsed, setCollapsed] = useAtom(collapsedGroups(listId));
89
101
  const prefix = useId();
90
102
  const folded = (group) => grouped && collapsed.includes(group.id);
91
103
  const order = groups.filter((group) => !folded(group)).flatMap((group) => group.rows.map(rowId));
92
- const rows = (list) => list.map((row) => /* @__PURE__ */ jsx(Row, {
104
+ const rows = (list) => list.map((row) => selectable ? /* @__PURE__ */ jsx(Row, {
93
105
  id: rowId(row),
94
106
  label: rowLabel(row),
95
107
  order,
96
108
  children: renderRow(row)
109
+ }, rowId(row)) : /* @__PURE__ */ jsx(PlainRow, {
110
+ id: rowId(row),
111
+ children: renderRow(row)
97
112
  }, rowId(row)));
98
113
  if (!grouped) return /* @__PURE__ */ jsx("div", {
99
114
  "data-record-list": listId,
@@ -112,6 +127,7 @@ const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, cl
112
127
  ids: group.rows.map(rowId),
113
128
  panelId,
114
129
  collapsed: folded(group),
130
+ selectable,
115
131
  onCollapse: (fold) => setCollapsed((current) => fold ? [...current, group.id] : current.filter((id) => id !== group.id))
116
132
  }), !folded(group) && /* @__PURE__ */ jsx("ul", {
117
133
  id: panelId,
@@ -1,8 +1,13 @@
1
- import { RecordTableFeatures } from "./RecordTableProvider.js";
1
+ import { RecordTableFeatures, TRecordTableSort } from "./RecordTableProvider.js";
2
2
  import React from "react";
3
3
  import { Header, RowData } from "@tanstack/react-table";
4
4
  type RecordTableHeader = Header<RecordTableFeatures, RowData>;
5
- /** A header cell: drag it to reorder its column, drag its right edge to resize it. */
5
+ /** Off → ascending → descending → off. */
6
+ export declare const nextSort: (sort: TRecordTableSort | null, by: string) => TRecordTableSort | null;
7
+ /**
8
+ * A header cell: drag it to reorder its column, drag its right edge to resize it, click it to
9
+ * sort by it when the table sorts (`RecordTable.Provider`'s `sortable`).
10
+ */
6
11
  export declare const RecordTableHead: ({ header, pinned, children, className, ...props }: React.ComponentProps<'th'> & {
7
12
  header: RecordTableHeader;
8
13
  pinned: boolean;
@@ -2,8 +2,9 @@ import { Table } from "../../../components/table.js";
2
2
  import { cn } from "../../../lib/utils.js";
3
3
  import { isStructuralColumn } from "../utils/columnUtils.js";
4
4
  import { useRecordTable, useRecordTableState } from "./RecordTableProvider.js";
5
+ import { IconArrowDown, IconArrowUp, IconArrowsSort } from "@tabler/icons-react";
5
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import "react";
7
+ import { useRef } from "react";
7
8
  import { cva } from "class-variance-authority";
8
9
  import { useDndContext } from "@dnd-kit/core";
9
10
  import { useSortable } from "@dnd-kit/sortable";
@@ -13,10 +14,65 @@ const recordTableHeadVariants = cva("sticky z-2 top-0 w-(--head-width) transitio
13
14
  isDragging: { true: "z-3" },
14
15
  pinned: { true: "z-3 left-(--head-start)" }
15
16
  } });
16
- /** A header cell: drag it to reorder its column, drag its right edge to resize it. */
17
+ const SORT_BUTTON = {
18
+ none: {
19
+ Icon: IconArrowsSort,
20
+ label: "Sort ascending"
21
+ },
22
+ asc: {
23
+ Icon: IconArrowUp,
24
+ label: "Sort descending"
25
+ },
26
+ desc: {
27
+ Icon: IconArrowDown,
28
+ label: "Clear sort"
29
+ }
30
+ };
31
+ const ARIA_SORT = {
32
+ asc: "ascending",
33
+ desc: "descending",
34
+ none: "none"
35
+ };
36
+ const CLICK_MS = 300;
37
+ /** Off → ascending → descending → off. */
38
+ const nextSort = (sort, by) => {
39
+ if (sort?.by !== by) return {
40
+ by,
41
+ direction: "asc"
42
+ };
43
+ return sort.direction === "asc" ? {
44
+ by,
45
+ direction: "desc"
46
+ } : null;
47
+ };
48
+ /** The header's sort control: the order shown, and a button for the keyboard. */
49
+ const SortButton = ({ direction, onSort }) => {
50
+ const { Icon, label } = SORT_BUTTON[direction ?? "none"];
51
+ return /* @__PURE__ */ jsx("button", {
52
+ type: "button",
53
+ "aria-label": label,
54
+ className: cn("relative z-1 ml-1 inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-ring", !direction && "opacity-0 group-hover/head:opacity-100"),
55
+ onClick: (event) => {
56
+ event.stopPropagation();
57
+ onSort();
58
+ },
59
+ children: /* @__PURE__ */ jsx(Icon, {
60
+ className: "size-3.5",
61
+ "aria-hidden": true
62
+ })
63
+ });
64
+ };
65
+ /**
66
+ * A header cell: drag it to reorder its column, drag its right edge to resize it, click it to
67
+ * sort by it when the table sorts (`RecordTable.Provider`'s `sortable`).
68
+ */
17
69
  const RecordTableHead = ({ header, pinned, children, className, ...props }) => {
18
70
  const { id } = header.column;
19
- const { headId } = useRecordTable();
71
+ const { headId, sorting } = useRecordTable();
72
+ const pressedAt = useRef(0);
73
+ const sortable = Boolean(sorting?.columns.includes(id));
74
+ const direction = sorting?.sort?.by === id ? sorting.sort.direction : void 0;
75
+ const sort = () => sorting?.onChange(nextSort(sorting.sort, id));
20
76
  const { isDragging, listeners, setNodeRef, transform } = useSortable({
21
77
  id,
22
78
  disabled: pinned
@@ -27,13 +83,24 @@ const RecordTableHead = ({ header, pinned, children, className, ...props }) => {
27
83
  className: cn(recordTableHeadVariants({
28
84
  isDragging,
29
85
  pinned
30
- }), className),
86
+ }), sortable && "group/head cursor-pointer", className),
31
87
  style: {
32
88
  "--head-width": `var(--header-${header.id}-width)`,
33
89
  "--head-start": pinned ? `var(--col-${id}-start)` : void 0
34
90
  },
91
+ "aria-sort": sortable ? ARIA_SORT[direction ?? "none"] : void 0,
92
+ onPointerDown: sortable ? () => pressedAt.current = Date.now() : void 0,
93
+ onClick: sortable ? () => {
94
+ if (Date.now() - pressedAt.current < CLICK_MS) sort();
95
+ } : void 0,
35
96
  ...props,
36
- children: [children, !isStructuralColumn(id) && /* @__PURE__ */ jsxs(Fragment, { children: [
97
+ children: [sortable ? /* @__PURE__ */ jsxs("div", {
98
+ className: "flex items-center",
99
+ children: [children, /* @__PURE__ */ jsx(SortButton, {
100
+ direction,
101
+ onSort: sort
102
+ })]
103
+ }) : children, !isStructuralColumn(id) && /* @__PURE__ */ jsxs(Fragment, { children: [
37
104
  /* @__PURE__ */ jsx("span", {
38
105
  ...listeners,
39
106
  "aria-hidden": true,
@@ -75,4 +142,4 @@ const RecordTableHeadSize = ({ header }) => {
75
142
  onTouchStart: startResize
76
143
  });
77
144
  };
78
- export { RecordTableHead };
145
+ export { RecordTableHead, nextSort };
@@ -16,8 +16,21 @@ export type RecordTableFeatures = typeof recordTableFeatures;
16
16
  export type RecordTableColumnDef<TData extends RowData> = ColumnDef<RecordTableFeatures, TData>;
17
17
  /** Rows are typed `RowData` here: every table shares this context, whatever its data. */
18
18
  export type RecordTableInstance = Table<RecordTableFeatures, RowData>;
19
+ /** The order a list's rows come in: by a column, either way. The page sorts (usually its query). */
20
+ export interface TRecordTableSort {
21
+ by: string;
22
+ direction: 'asc' | 'desc';
23
+ }
24
+ interface IRecordTableSorting {
25
+ sort: TRecordTableSort | null;
26
+ /** The columns a click on their header sorts by. */
27
+ columns: readonly string[];
28
+ onChange: (sort: TRecordTableSort | null) => void;
29
+ }
19
30
  interface IRecordTableContext {
20
31
  table: RecordTableInstance;
32
+ /** Null: the table doesn't sort from its headers. */
33
+ sorting: IRecordTableSorting | null;
21
34
  columnSelectorOpen: boolean;
22
35
  setColumnSelectorOpen: (open: boolean) => void;
23
36
  /** The id of a column's header cell, unique per table: cells are named by their column. */
@@ -37,6 +50,14 @@ export interface RecordTableProviderProps<TData extends RowData> extends HTMLAtt
37
50
  data: TData[];
38
51
  stickyColumns?: string[];
39
52
  tableId?: string;
53
+ /**
54
+ * Sorting by a click on a column's header: off, then ascending, then descending, then off.
55
+ * `sortable` lists the columns that sort; the page orders the rows by `sort` (its query does)
56
+ * and keeps it, e.g. in the URL. Without `onSortChange` no header sorts.
57
+ */
58
+ sort?: TRecordTableSort | null;
59
+ sortable?: readonly string[];
60
+ onSortChange?: (sort: TRecordTableSort | null) => void;
40
61
  }
41
- export declare const RecordTableProvider: <TData extends RowData>({ children, columns, data, stickyColumns, tableId, ...containerProps }: RecordTableProviderProps<TData>) => import("react").JSX.Element;
62
+ export declare const RecordTableProvider: <TData extends RowData>({ children, columns, data, stickyColumns, tableId, sort, sortable, onSortChange, ...containerProps }: RecordTableProviderProps<TData>) => import("react").JSX.Element;
42
63
  export {};
@@ -34,7 +34,7 @@ const useRecordTableState = (select) => {
34
34
  };
35
35
  /** A row's `_id` or `id`, else tanstack's default (its index under its parent). */
36
36
  const getRowId = (row, index, parent) => readRow(row).id ?? (parent ? `${parent.id}.${index}` : String(index));
37
- const RecordTableProvider = ({ children, columns, data, stickyColumns, tableId, ...containerProps }) => {
37
+ const RecordTableProvider = ({ children, columns, data, stickyColumns, tableId, sort = null, sortable, onSortChange, ...containerProps }) => {
38
38
  const [columnSelectorOpen, setColumnSelectorOpen] = useState(false);
39
39
  const { state, setColumnOrder, ...layoutHandlers } = useColumnLayout({
40
40
  columnIds: columns.map((column) => column.id ?? ""),
@@ -53,13 +53,24 @@ const RecordTableProvider = ({ children, columns, data, stickyColumns, tableId,
53
53
  getRowId
54
54
  }, () => null);
55
55
  const headPrefix = useId();
56
+ const sorting = useMemo(() => onSortChange ? {
57
+ sort,
58
+ columns: sortable ?? [],
59
+ onChange: onSortChange
60
+ } : null, [
61
+ sort,
62
+ sortable,
63
+ onSortChange
64
+ ]);
56
65
  const context = useMemo(() => ({
57
66
  table: shared,
67
+ sorting,
58
68
  columnSelectorOpen,
59
69
  setColumnSelectorOpen,
60
70
  headId: (columnId) => `${headPrefix}-head-${columnId}`
61
71
  }), [
62
72
  shared,
73
+ sorting,
63
74
  columnSelectorOpen,
64
75
  headPrefix
65
76
  ]);
@@ -26,6 +26,24 @@ export interface ContactQueries {
26
26
  customer: (id: string) => ContactQuery<CustomerContact>;
27
27
  company: (id: string) => ContactQuery<CompanyContact>;
28
28
  }
29
+ type ContactRows<T> = UseQueryOptions<{
30
+ data: T[];
31
+ }, Error, {
32
+ data: T[];
33
+ }>;
34
+ /** What a contact search asks for: matches, or the contacts with these ids. */
35
+ export interface ContactSearch {
36
+ search?: string;
37
+ ids?: string[];
38
+ }
39
+ /**
40
+ * Where a filter's `customer` and `company` fields search contacts.
41
+ * TanStack query options; in erxes, `contactSearchQueries` from `@erxes/core-contract/client`.
42
+ */
43
+ export interface ContactSearchQueries {
44
+ customers: (input: ContactSearch) => ContactRows<CustomerContact>;
45
+ companies: (input: ContactSearch) => ContactRows<CompanyContact>;
46
+ }
29
47
  /** The customer or company types `ContactLink` shows. */
30
48
  export type TContactContentType = 'core:customer' | 'core:company';
31
49
  /** A customer's name, else its email or phone. */
@@ -16,9 +16,11 @@ type OpenNewRecord = (contentType: string, defaults?: Record<string, unknown>) =
16
16
  * record so Back returns to it. erxes-ui is a Module Federation singleton, so every plugin
17
17
  * reads the host's.
18
18
  */
19
- export declare const RecordOpenerProvider: ({ open, openNew, children }: PropsWithChildren<{
19
+ export declare const RecordOpenerProvider: ({ open, openNew, current, dismiss, children }: PropsWithChildren<{
20
20
  open: OpenRecord;
21
21
  openNew?: OpenNewRecord;
22
+ current?: RecordRef | null;
23
+ dismiss?: OpenRecord;
22
24
  }>) => import("react").JSX.Element;
23
25
  /**
24
26
  * Opens a record, or a new draft, in core's side panel.
@@ -27,12 +29,44 @@ export declare const RecordOpenerProvider: ({ open, openNew, children }: PropsWi
27
29
  * `openNew('sales:deal', { stageId })` opens a draft that becomes the record on Save. Any
28
30
  * type core or an installed plugin registers opens (`IUIConfig.recordTypes`). `canOpen` is
29
31
  * false outside erxes (a plugin page rendered on its own), where both do nothing.
32
+ *
33
+ * `current` is the record the panel shows now (null when it shows none or a draft), for a list
34
+ * that marks it or steps to the next (j/k). `dismiss(record)` takes a record out of the panel,
35
+ * shown or behind Back, e.g. one the list just deleted. Inside a record, `useRecordPanel`.
30
36
  */
31
37
  export declare const useOpenRecord: () => {
32
38
  open: OpenRecord;
33
39
  openNew: OpenNewRecord;
40
+ current: RecordRef | null;
41
+ dismiss: OpenRecord;
34
42
  canOpen: boolean;
35
43
  };
44
+ /**
45
+ * What a record shown in core's panel, or on its own page, can do to it. Core's own tabs are
46
+ * `detail` and `activity`; a type's `tabs` use their `value`.
47
+ */
48
+ export interface RecordPanelControls {
49
+ record: RecordRef;
50
+ /** The tab shown; empty is the record's default. */
51
+ tab: string;
52
+ /** Shows a tab: an Actions menu item whose form opens on Detail picks `detail` first. */
53
+ setTab: (tab: string) => void;
54
+ /** Closes the panel; on a record's own page, goes back to its list. */
55
+ close: () => void;
56
+ /** Takes this record out, e.g. after deleting it: back to the record under it, else closed. */
57
+ dismiss: () => void;
58
+ /** Puts another record in this one's place, Back unchanged: a request accepted as a task. */
59
+ replace: (next: RecordRef) => void;
60
+ }
61
+ /** Web gives each record it shows its controls. */
62
+ export declare const RecordPanelProvider: import("react").Context<RecordPanelControls | null>;
63
+ /**
64
+ * The record a slot is in, and what the slot can do to it.
65
+ * Any slot (`Title`, `Actions`, `Detail`, a tab, a relation tab): `const panel = useRecordPanel()`, then `panel?.dismiss()` after a delete,
66
+ * `panel?.replace({ contentType: 'tasks:task', contentId })`, `panel?.setTab('detail')`.
67
+ * Null outside a record (a plugin page on its own).
68
+ */
69
+ export declare const useRecordPanel: () => RecordPanelControls | null;
36
70
  /** Web registers how a record draws on its own page. */
37
71
  export declare const setRecordPage: (component: import("react").ComponentType<RecordRef> | null) => void;
38
72
  /**