@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
@@ -0,0 +1,156 @@
1
+ import { useFormat } from "../../lib/format.js";
2
+ import { useMoney } from "../../lib/money.js";
3
+ import { textOf } from "../../lib/text.js";
4
+ import { LIST_VALUE, NO_VALUE, RelativeAmount, isRule } from "./conditions.js";
5
+ import { valuesBetween } from "./filterRule.js";
6
+ import { useFieldOptions } from "./fieldOptions.js";
7
+ import { z } from "zod";
8
+ import { useTranslation } from "react-i18next";
9
+ // src/modules/conditions/filterText.ts
10
+ /** English for the `views` namespace's `filter.op.<op>`. */
11
+ const OPERATORS = {
12
+ eq: "is",
13
+ neq: "is not",
14
+ gt: "is greater than",
15
+ gte: "is at least",
16
+ lt: "is less than",
17
+ lte: "is at most",
18
+ contains: "contains",
19
+ not_contains: "doesn't contain",
20
+ starts_with: "starts with",
21
+ in: "is any of",
22
+ not_in: "is none of",
23
+ exists: "is set",
24
+ not_exists: "is empty",
25
+ within_last: "is in the last",
26
+ more_than_ago: "is more than … ago",
27
+ within_next: "is in the next",
28
+ anniversary_within: "anniversary in the next",
29
+ between: "is between"
30
+ };
31
+ /** Dates compare as days: `filter.op-date.<op>`. */
32
+ const DATE_OPERATORS = {
33
+ eq: "is on",
34
+ neq: "is not on",
35
+ gt: "is after",
36
+ gte: "is on or after",
37
+ lt: "is before",
38
+ lte: "is on or before"
39
+ };
40
+ /** Numbers read as symbols on a chip. */
41
+ const SYMBOLS = {
42
+ eq: "=",
43
+ neq: "≠",
44
+ gt: ">",
45
+ gte: "≥",
46
+ lt: "<",
47
+ lte: "≤"
48
+ };
49
+ /** English for `filter.unit.<unit>`, by plural form. */
50
+ const UNITS = {
51
+ days: {
52
+ defaultValue_one: "{{count}} day",
53
+ defaultValue_other: "{{count}} days"
54
+ },
55
+ weeks: {
56
+ defaultValue_one: "{{count}} week",
57
+ defaultValue_other: "{{count}} weeks"
58
+ },
59
+ months: {
60
+ defaultValue_one: "{{count}} month",
61
+ defaultValue_other: "{{count}} months"
62
+ }
63
+ };
64
+ /** An operator in words, for a field's type ("is before" on a date). */
65
+ const useOperatorLabel = () => {
66
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
67
+ return (op, type) => {
68
+ const dated = type === "date" ? DATE_OPERATORS[op] : void 0;
69
+ return dated ? t(`op-date.${op}`, dated) : t(`op.${op}`, OPERATORS[op]);
70
+ };
71
+ };
72
+ /** A relative amount in words: "30 days". */
73
+ const useSpanText = () => {
74
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
75
+ return ({ amount, unit }) => t(`unit.${unit}`, {
76
+ count: amount,
77
+ ...UNITS[unit]
78
+ });
79
+ };
80
+ const Values = z.array(z.union([
81
+ z.string(),
82
+ z.number(),
83
+ z.boolean()
84
+ ]).transform(String));
85
+ /**
86
+ * The values a rule picks: the list of "is any of", or the one of "is". A value that isn't text,
87
+ * a number or yes/no (a date range, a relative amount) picks nothing.
88
+ */
89
+ const valuesOf = (rule) => {
90
+ if (!rule || rule.value === void 0 || rule.value === null) return [];
91
+ return Values.safeParse(Array.isArray(rule.value) ? rule.value : [rule.value]).data ?? [];
92
+ };
93
+ /** A rule in words, as a chip shows it: the operator and the value (empty when it needs none). */
94
+ const useRuleText = (rule, field, lookups) => {
95
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
96
+ const operator = useOperatorLabel();
97
+ const spanText = useSpanText();
98
+ const money = useMoney();
99
+ const fmt = useFormat();
100
+ const type = field?.type;
101
+ const picked = isRule(rule) ? valuesOf(rule) : [];
102
+ const { options } = useFieldOptions(field, lookups, picked);
103
+ const one = (value) => {
104
+ if (value === void 0 || value === null || value === "") return "…";
105
+ if (type === "date") {
106
+ const day = textOf(value);
107
+ return /^\d{4}-\d{2}-\d{2}/.test(day) ? fmt.date(day.slice(0, 10)) : day;
108
+ }
109
+ if (type === "number") {
110
+ const n = Number(value);
111
+ return field?.currency ? money(n, field.currency) : fmt.number(n);
112
+ }
113
+ return textOf(value);
114
+ };
115
+ if (!isRule(rule)) {
116
+ const [from, to] = valuesBetween(rule);
117
+ return {
118
+ op: operator("between", type),
119
+ value: `${one(from)} – ${one(to)}`
120
+ };
121
+ }
122
+ const op = operator(rule.op, type);
123
+ if (NO_VALUE.has(rule.op)) return {
124
+ op,
125
+ value: ""
126
+ };
127
+ const span = RelativeAmount.safeParse(rule.value);
128
+ if (span.success) return {
129
+ op,
130
+ value: spanText(span.data)
131
+ };
132
+ if (type === "boolean") return {
133
+ op: t("op.eq", "is"),
134
+ value: textOf(rule.value) === "true" ? t("yes", "Yes") : t("no", "No")
135
+ };
136
+ if (type === "number" && SYMBOLS[rule.op]) return {
137
+ op: SYMBOLS[rule.op] ?? op,
138
+ value: one(rule.value)
139
+ };
140
+ if (options.length || LIST_VALUE.has(rule.op)) {
141
+ const labels = picked.map((value) => options.find((option) => option.value === value)?.label ?? value);
142
+ return {
143
+ op: labels.length === 1 && LIST_VALUE.has(rule.op) ? operator(rule.op === "in" ? "eq" : "neq", type) : op,
144
+ value: labels.join(", ") || "…"
145
+ };
146
+ }
147
+ if (type === "date" || type === "number") return {
148
+ op,
149
+ value: one(rule.value)
150
+ };
151
+ return {
152
+ op,
153
+ value: rule.value === void 0 ? "…" : `“${textOf(rule.value)}”`
154
+ };
155
+ };
156
+ export { useOperatorLabel, useRuleText, useSpanText, valuesOf };
@@ -3,7 +3,7 @@ import { FilterDialog, FilterDialogStringView } from "./FilterDialog.js";
3
3
  import { FilterCommandInput, FilterCommandItem, FilterItem, FilterPopover, FilterSearchValueTrigger, FilterTrigger, FilterView } from "./FilterPopover.js";
4
4
  import { FilterProvider } from "./FilterProvider.js";
5
5
  /**
6
- * Parts of a filter popover and bar, which `ListFilter` is built from.
6
+ * Parts of a filter popover and bar, for a page without saved views.
7
7
  * A list page uses `ListFilter`; reach for these parts only for a filter it can't draw.
8
8
  */
9
9
  export declare const Filter: typeof FilterProvider & {
@@ -4,7 +4,7 @@ import { FilterCommandInput, FilterCommandItem, FilterItem, FilterPopover, Filte
4
4
  import { FilterProvider } from "./FilterProvider.js";
5
5
  // src/modules/filter/components/Filter.tsx
6
6
  /**
7
- * Parts of a filter popover and bar, which `ListFilter` is built from.
7
+ * Parts of a filter popover and bar, for a page without saved views.
8
8
  * A list page uses `ListFilter`; reach for these parts only for a filter it can't draw.
9
9
  */
10
10
  const Filter = Object.assign(FilterProvider, {
@@ -11,9 +11,10 @@ export type TListFilterField = {
11
11
  label: string;
12
12
  /**
13
13
  * How it compares: contains (text), ranges (number), relative dates, yes/no, a pick from
14
- * `options`, a team member (from `members`), a tag (from `tags`).
14
+ * `options`, a team member (from `members`), a tag (from `tags`), a customer or company
15
+ * (searched in `contacts`). The rule's value is the picked ids.
15
16
  */
16
- type: 'text' | 'number' | 'date' | 'boolean' | 'select' | 'member' | 'tags';
17
+ type: 'text' | 'number' | 'date' | 'boolean' | 'select' | 'member' | 'tags' | 'customer' | 'company';
17
18
  /** A `select`'s choices. */
18
19
  options?: {
19
20
  value: string;
@@ -51,13 +52,14 @@ export type TListFilterProps = TConditionLookups & {
51
52
  recordType?: TPluginListType;
52
53
  };
53
54
  /**
54
- * A list's filter bar, with a field menu, search and conditions as chips.
55
- * The menu of `fields` opens on `F` and holds search and the advanced filter. The conditions
56
- * and search live in the address (shared links and reloads keep them); `useListFilterParams()`
57
- * reads them for the list's query. `member` fields pick
58
- * from `members` and `tags` fields from `tags`: in erxes `memberQueries` from
59
- * `@erxes/core-contract/client` and the tags query of the record type; outside erxes, the
60
- * plugin's own.
55
+ * A list's filter: a view bar button, and a chip row while it filters.
56
+ * The field picker opens on `F` and holds search and the advanced filter, a popover of
57
+ * "Where / And / Or" rows. Each chip is one condition whose field, operator and value open in
58
+ * place. The conditions and search live in the address (shared links and reloads keep them);
59
+ * `useListFilterParams()` reads them for the list's query. `member` fields pick
60
+ * from `members`, `tags` fields from `tags`, `customer` and `company` fields from `contacts`: in
61
+ * erxes `memberQueries` and `contactSearchQueries` from `@erxes/core-contract/client` and the
62
+ * tags query of the record type; outside erxes, the plugin's own.
61
63
  */
62
64
  export declare const ListFilter: ({ recordType, ...props }: TListFilterProps) => import("react").JSX.Element;
63
65
  /**
@@ -68,4 +70,14 @@ export declare const ListFilter: ({ recordType, ...props }: TListFilterProps) =>
68
70
  export declare const useListFilterParams: () => {
69
71
  filter: string | undefined;
70
72
  search: string | undefined;
71
- };
73
+ };
74
+ /**
75
+ * A list's empty state while `ListFilter` filters it, with Clear filters.
76
+ * "No customers match these filters" and a button that clears them; `fallback`, the list's own
77
+ * empty state, when it isn't filtered.
78
+ * `records` names them ("customers"); "records" by default.
79
+ */
80
+ export declare const ListFilterEmpty: ({ records, fallback }: {
81
+ records?: string;
82
+ fallback?: ReactNode;
83
+ }) => string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null;
@@ -1,8 +1,11 @@
1
- import { Filter } from "../filter/components/Filter.js";
1
+ import { Button } from "../../components/button.js";
2
+ import { Empty } from "../../components/empty.js";
2
3
  import { useListConditions } from "./filter/listFilterQuery.js";
3
4
  import { useListViews } from "./ViewBar.js";
4
- import { jsx } from "react/jsx-runtime";
5
+ import { IconFilterOff } from "@tabler/icons-react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
5
7
  import { Suspense, lazy } from "react";
8
+ import { useTranslation } from "react-i18next";
6
9
  import { useAutoAnimate } from "@formkit/auto-animate/react";
7
10
  // src/modules/list/ListFilter.tsx
8
11
  /**
@@ -11,28 +14,26 @@ import { useAutoAnimate } from "@formkit/auto-animate/react";
11
14
  */
12
15
  const ListFilterBar = lazy(async () => ({ default: (await import("./filter/ListFilterBar.js")).ListFilterBar }));
13
16
  /**
14
- * A list's filter bar, with a field menu, search and conditions as chips.
15
- * The menu of `fields` opens on `F` and holds search and the advanced filter. The conditions
16
- * and search live in the address (shared links and reloads keep them); `useListFilterParams()`
17
- * reads them for the list's query. `member` fields pick
18
- * from `members` and `tags` fields from `tags`: in erxes `memberQueries` from
19
- * `@erxes/core-contract/client` and the tags query of the record type; outside erxes, the
20
- * plugin's own.
17
+ * A list's filter: a view bar button, and a chip row while it filters.
18
+ * The field picker opens on `F` and holds search and the advanced filter, a popover of
19
+ * "Where / And / Or" rows. Each chip is one condition whose field, operator and value open in
20
+ * place. The conditions and search live in the address (shared links and reloads keep them);
21
+ * `useListFilterParams()` reads them for the list's query. `member` fields pick
22
+ * from `members`, `tags` fields from `tags`, `customer` and `company` fields from `contacts`: in
23
+ * erxes `memberQueries` and `contactSearchQueries` from `@erxes/core-contract/client` and the
24
+ * tags query of the record type; outside erxes, the plugin's own.
21
25
  */
22
26
  const ListFilter = ({ recordType, ...props }) => {
23
27
  const [barRef] = useAutoAnimate({ duration: 150 });
24
28
  const host = useListViews();
25
29
  const status = props.status ?? (recordType && host && /* @__PURE__ */ jsx(host.Changes, { recordType }));
26
- return /* @__PURE__ */ jsx(Filter, {
27
- id: `${props.id}-list-filter`,
28
- children: /* @__PURE__ */ jsx(Filter.Bar, {
29
- ref: barRef,
30
- className: "min-w-0 flex-nowrap justify-end",
31
- children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(ListFilterBar, {
32
- ...props,
33
- status
34
- }) })
35
- })
30
+ return /* @__PURE__ */ jsx("div", {
31
+ ref: barRef,
32
+ className: "flex min-w-0 flex-1 items-center justify-end gap-1",
33
+ children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(ListFilterBar, {
34
+ ...props,
35
+ status
36
+ }) })
36
37
  });
37
38
  };
38
39
  /**
@@ -47,4 +48,36 @@ const useListFilterParams = () => {
47
48
  search: search || void 0
48
49
  };
49
50
  };
50
- export { ListFilter, useListFilterParams };
51
+ /**
52
+ * A list's empty state while `ListFilter` filters it, with Clear filters.
53
+ * "No customers match these filters" and a button that clears them; `fallback`, the list's own
54
+ * empty state, when it isn't filtered.
55
+ * `records` names them ("customers"); "records" by default.
56
+ */
57
+ const ListFilterEmpty = ({ records, fallback = null }) => {
58
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
59
+ const { active, clear } = useListConditions();
60
+ if (!active) return fallback;
61
+ return /* @__PURE__ */ jsxs(Empty, {
62
+ className: "pointer-events-none absolute inset-x-0 top-2/5",
63
+ children: [/* @__PURE__ */ jsxs(Empty.Header, { children: [
64
+ /* @__PURE__ */ jsx(Empty.Media, {
65
+ variant: "icon",
66
+ children: /* @__PURE__ */ jsx(IconFilterOff, {})
67
+ }),
68
+ /* @__PURE__ */ jsx(Empty.Title, { children: t("no-records", {
69
+ records: records ?? t("records", "records"),
70
+ defaultValue: "No {{records}} match these filters"
71
+ }) }),
72
+ /* @__PURE__ */ jsx(Empty.Description, { children: t("no-records-hint", "Change a condition or clear them to see every record.") })
73
+ ] }), /* @__PURE__ */ jsx(Empty.Content, {
74
+ className: "pointer-events-auto",
75
+ children: /* @__PURE__ */ jsx(Button, {
76
+ variant: "outline",
77
+ onClick: clear,
78
+ children: t("clear-filters", "Clear filters")
79
+ })
80
+ })]
81
+ });
82
+ };
83
+ export { ListFilter, ListFilterEmpty, useListFilterParams };
@@ -18,6 +18,8 @@ export type TListViews = {
18
18
  };
19
19
  /** The host's saved views, for `ViewBar` and `ListFilter`. Null outside erxes. */
20
20
  export declare const useListViews: () => TListViews | null;
21
+ /** Where `ListFilter` puts its row of chips: under the `ViewBar` it sits in; null outside one. */
22
+ export declare const useFilterRowSlot: () => HTMLElement | null;
21
23
  /**
22
24
  * Gives every list with a `recordType` saved views, as core's lists have.
23
25
  * Web provides its tabs (save, rename, share, copy a link) and the filter's save, once, around
@@ -1,12 +1,16 @@
1
1
  import { TabButton } from "../../components/tabs.js";
2
2
  import { IconLayoutList } from "@tabler/icons-react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
- import { Suspense, createContext, use } from "react";
4
+ import { Suspense, createContext, use, useState } from "react";
5
5
  import { useAutoAnimate } from "@formkit/auto-animate/react";
6
6
  // src/modules/list/ViewBar.tsx
7
7
  const ListViewsContext = createContext(null);
8
8
  /** The host's saved views, for `ViewBar` and `ListFilter`. Null outside erxes. */
9
9
  const useListViews = () => use(ListViewsContext);
10
+ const FilterRowContext = createContext(null);
11
+ const FilterRowSlot = FilterRowContext.Provider;
12
+ /** Where `ListFilter` puts its row of chips: under the `ViewBar` it sits in; null outside one. */
13
+ const useFilterRowSlot = () => use(FilterRowContext);
10
14
  /**
11
15
  * Gives every list with a `recordType` saved views, as core's lists have.
12
16
  * Web provides its tabs (save, rename, share, copy a link) and the filter's save, once, around
@@ -26,6 +30,7 @@ const ListViewsProvider = ({ views, children }) => /* @__PURE__ */ jsx(ListViews
26
30
  const ViewBar = ({ allLabel, recordType, tabs, children }) => {
27
31
  const [tabsRef] = useAutoAnimate({ duration: 150 });
28
32
  const host = useListViews();
33
+ const [slot, setSlot] = useState(null);
29
34
  const all = /* @__PURE__ */ jsxs(TabButton, {
30
35
  type: "button",
31
36
  "aria-current": "page",
@@ -39,16 +44,22 @@ const ViewBar = ({ allLabel, recordType, tabs, children }) => {
39
44
  allLabel
40
45
  })
41
46
  });
42
- return /* @__PURE__ */ jsxs("div", {
43
- className: "flex h-10 shrink-0 items-center gap-3 border-b bg-background pr-3",
44
- children: [/* @__PURE__ */ jsx("div", {
45
- ref: tabsRef,
46
- className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto p-1 hide-scroll",
47
- children: tabs ?? saved ?? all
47
+ return /* @__PURE__ */ jsxs(FilterRowSlot, {
48
+ value: slot,
49
+ children: [/* @__PURE__ */ jsxs("div", {
50
+ className: "flex h-10 shrink-0 items-center gap-3 border-b bg-background pr-3",
51
+ children: [/* @__PURE__ */ jsx("div", {
52
+ ref: tabsRef,
53
+ className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto p-1 hide-scroll",
54
+ children: tabs ?? saved ?? all
55
+ }), /* @__PURE__ */ jsx("div", {
56
+ className: "flex min-w-0 max-w-13/20 shrink-0 items-center justify-end",
57
+ children
58
+ })]
48
59
  }), /* @__PURE__ */ jsx("div", {
49
- className: "flex min-w-0 max-w-13/20 shrink-0 items-center justify-end",
50
- children
60
+ ref: setSlot,
61
+ className: "contents"
51
62
  })]
52
63
  });
53
64
  };
54
- export { ListViewsProvider, ViewBar, useListViews };
65
+ export { ListViewsProvider, ViewBar, useFilterRowSlot, useListViews };
@@ -0,0 +1,10 @@
1
+ import { AddFrom } from "./listFilterContext.js";
2
+ import { ReactElement } from "react";
3
+ /**
4
+ * "Add a filter": the fields to pick from, then the picked field's operator and value. It opens
5
+ * from the view bar's filter button (`F`) or the filter row's "+ Filter".
6
+ */
7
+ export declare const AddFilter: ({ from, trigger }: {
8
+ from: AddFrom;
9
+ trigger: ReactElement;
10
+ }) => import("react").JSX.Element;
@@ -0,0 +1,140 @@
1
+ import { Command } from "../../../components/command.js";
2
+ import { Popover } from "../../../components/popover.js";
3
+ import { Select } from "../../../components/select.js";
4
+ import { CONDITION_OPERATORS, NO_VALUE } from "../../conditions/conditions.js";
5
+ import { isFilled, opOf, operatorsFor, ruleFor, withOperator } from "../../conditions/filterRule.js";
6
+ import { FieldPicker } from "../../conditions/FieldPicker.js";
7
+ import { FieldIcon } from "../../conditions/fieldIcons.js";
8
+ import { useOperatorLabel } from "../../conditions/filterText.js";
9
+ import { ValueEditor } from "../../conditions/ValueEditor.js";
10
+ import { useListFilter } from "./listFilterContext.js";
11
+ import { SearchBox } from "./SearchChip.js";
12
+ import { IconAdjustmentsHorizontal, IconSearch } from "@tabler/icons-react";
13
+ import { jsx, jsxs } from "react/jsx-runtime";
14
+ import { useRef, useState } from "react";
15
+ import { useTranslation } from "react-i18next";
16
+ // src/modules/list/filter/AddFilter.tsx
17
+ const asOperator = (value) => value === "between" ? "between" : CONDITION_OPERATORS.find((op) => op === value);
18
+ /**
19
+ * A new rule on `field`: its operator, then its value. The rule joins the filter once it says
20
+ * enough (a pick, a typed value) and changes in place as editing goes on.
21
+ */
22
+ const NewRule = ({ field, onDone }) => {
23
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
24
+ const { lookups, parts, setPart } = useListFilter();
25
+ const label = useOperatorLabel();
26
+ const [rule, setRule] = useState(() => ruleFor(field));
27
+ const index = useRef(null);
28
+ const ops = operatorsFor(field.type);
29
+ const change = (next) => {
30
+ setRule(next);
31
+ if (isFilled(next)) {
32
+ setPart(index.current, next);
33
+ index.current ??= parts.length;
34
+ } else if (index.current !== null) {
35
+ setPart(index.current, null);
36
+ index.current = null;
37
+ }
38
+ };
39
+ const op = opOf(rule);
40
+ return /* @__PURE__ */ jsxs("div", {
41
+ className: "flex flex-col",
42
+ children: [/* @__PURE__ */ jsxs("div", {
43
+ className: "flex h-10 items-center gap-2 border-b px-3 text-sm",
44
+ children: [
45
+ /* @__PURE__ */ jsx(FieldIcon, {
46
+ field,
47
+ className: "size-4 shrink-0 text-muted-foreground"
48
+ }),
49
+ /* @__PURE__ */ jsx("span", {
50
+ className: "min-w-0 flex-1 truncate font-medium",
51
+ children: field.label
52
+ }),
53
+ ops.length > 1 && /* @__PURE__ */ jsxs(Select, {
54
+ value: op,
55
+ onValueChange: (next) => {
56
+ const picked = asOperator(next);
57
+ if (!picked) return;
58
+ change(withOperator(rule, picked));
59
+ if (NO_VALUE.has(picked)) onDone();
60
+ },
61
+ children: [/* @__PURE__ */ jsx(Select.Trigger, {
62
+ className: "h-7 w-auto max-w-40",
63
+ "aria-label": t("operator", "Operator"),
64
+ children: /* @__PURE__ */ jsx(Select.Value, { children: label(op, field.type) })
65
+ }), /* @__PURE__ */ jsx(Select.Content, { children: ops.map((one) => /* @__PURE__ */ jsx(Select.Item, {
66
+ value: one,
67
+ children: label(one, field.type)
68
+ }, one)) })]
69
+ })
70
+ ]
71
+ }), /* @__PURE__ */ jsx("div", {
72
+ className: field.type === "number" || field.type === "text" ? "p-2" : void 0,
73
+ children: /* @__PURE__ */ jsx(ValueEditor, {
74
+ rule,
75
+ field,
76
+ lookups,
77
+ onChange: change,
78
+ onDone
79
+ }, op)
80
+ })]
81
+ });
82
+ };
83
+ /** The picker's pages: the fields (with search and the advanced filter), then the chosen one. */
84
+ const AddFilterContent = ({ onDone }) => {
85
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
86
+ const { fields, loading, error, setAdvancedOpen, setAdding } = useListFilter();
87
+ const [view, setView] = useState({ kind: "fields" });
88
+ const search = t("search", "Search");
89
+ const advanced = t("advanced", "Advanced filter");
90
+ if (view.kind === "search") return /* @__PURE__ */ jsx(SearchBox, { onDone });
91
+ if (view.kind === "rule") return /* @__PURE__ */ jsx(NewRule, {
92
+ field: view.field,
93
+ onDone
94
+ });
95
+ return /* @__PURE__ */ jsx(FieldPicker, {
96
+ fields,
97
+ loading,
98
+ error,
99
+ onSelect: (field) => {
100
+ const found = fields.find((one) => one.path === field.path);
101
+ if (found) setView({
102
+ kind: "rule",
103
+ field: found
104
+ });
105
+ },
106
+ children: /* @__PURE__ */ jsxs(Command.Group, { children: [/* @__PURE__ */ jsxs(Command.Item, {
107
+ value: "search",
108
+ keywords: [search],
109
+ onSelect: () => setView({ kind: "search" }),
110
+ children: [/* @__PURE__ */ jsx(IconSearch, {}), search]
111
+ }), /* @__PURE__ */ jsxs(Command.Item, {
112
+ value: "advanced",
113
+ keywords: [advanced],
114
+ onSelect: () => {
115
+ setAdding(null);
116
+ setAdvancedOpen(true);
117
+ },
118
+ children: [/* @__PURE__ */ jsx(IconAdjustmentsHorizontal, {}), advanced]
119
+ })] })
120
+ });
121
+ };
122
+ /**
123
+ * "Add a filter": the fields to pick from, then the picked field's operator and value. It opens
124
+ * from the view bar's filter button (`F`) or the filter row's "+ Filter".
125
+ */
126
+ const AddFilter = ({ from, trigger }) => {
127
+ const { adding, setAdding } = useListFilter();
128
+ const open = adding === from;
129
+ return /* @__PURE__ */ jsxs(Popover, {
130
+ open,
131
+ onOpenChange: (next) => setAdding(next ? from : null),
132
+ children: [/* @__PURE__ */ jsx(Popover.Trigger, { render: trigger }), /* @__PURE__ */ jsx(Popover.Content, {
133
+ variant: "flush",
134
+ align: from === "bar" ? "end" : "start",
135
+ className: "w-72",
136
+ children: open && /* @__PURE__ */ jsx(AddFilterContent, { onDone: () => setAdding(null) })
137
+ })]
138
+ });
139
+ };
140
+ export { AddFilter };
@@ -0,0 +1,8 @@
1
+ import { RefObject } from "react";
2
+ /**
3
+ * The advanced filter: rows "Where / And / Or" with nested groups, in a popover anchored to the
4
+ * filter row. It doesn't block the page: the list updates behind it as the rules change.
5
+ */
6
+ export declare const AdvancedPopover: ({ anchor }: {
7
+ anchor: RefObject<HTMLElement | null>;
8
+ }) => import("react").JSX.Element;
@@ -0,0 +1,103 @@
1
+ import { Button } from "../../../components/button.js";
2
+ import { Popover } from "../../../components/popover.js";
3
+ import { Skeleton } from "../../../components/skeleton.js";
4
+ import { useFormat } from "../../../lib/format.js";
5
+ import { isUndefinedOrNull } from "../../../utils/IsUndefinedOrNull.js";
6
+ import { completeOf } from "../../conditions/filterRule.js";
7
+ import { ConditionsEditor } from "../../conditions/ConditionsEditor.js";
8
+ import { useListFilter } from "./listFilterContext.js";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { useEffect, useState } from "react";
11
+ import { useTranslation } from "react-i18next";
12
+ import { useDebouncedCallback } from "use-debounce";
13
+ // src/modules/list/filter/AdvancedPopover.tsx
14
+ /** How long the list waits after an edit before it follows. */
15
+ const APPLY_MS = 300;
16
+ /** "1,204 match", from the list's own count as it follows the edits. */
17
+ const MatchCount = () => {
18
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
19
+ const { totalCount, totalCapped } = useListFilter();
20
+ const fmt = useFormat();
21
+ if (isUndefinedOrNull(totalCount)) return /* @__PURE__ */ jsx(Skeleton, { className: "h-3.5 w-16" });
22
+ return /* @__PURE__ */ jsx("output", {
23
+ "aria-live": "polite",
24
+ className: "text-xs tabular-nums text-muted-foreground",
25
+ children: t("match", {
26
+ count: totalCapped ? 2 : totalCount,
27
+ formatted: fmt.count(totalCount, totalCapped),
28
+ defaultValue_one: "{{formatted}} match",
29
+ defaultValue_other: "{{formatted}} match"
30
+ })
31
+ });
32
+ };
33
+ /**
34
+ * Mounted while open, so the draft starts from the list's filter. Unfinished rules stay in the
35
+ * draft; the finished ones reach the list as editing pauses, and the table behind follows.
36
+ */
37
+ const AdvancedEditor = ({ onDone }) => {
38
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
39
+ const { fields, lookups, advanced, setAdvanced } = useListFilter();
40
+ const [draft, setDraft] = useState(advanced ?? void 0);
41
+ const apply = useDebouncedCallback((next) => setAdvanced(next ? completeOf(next) : null), APPLY_MS);
42
+ useEffect(() => () => apply.flush(), [apply]);
43
+ return /* @__PURE__ */ jsxs("div", {
44
+ className: "flex flex-col",
45
+ children: [/* @__PURE__ */ jsx("div", {
46
+ className: "max-h-popup overflow-y-auto p-3",
47
+ children: /* @__PURE__ */ jsx(ConditionsEditor, {
48
+ fields,
49
+ ...lookups,
50
+ value: draft,
51
+ onChange: (next) => {
52
+ setDraft(next);
53
+ apply(next);
54
+ }
55
+ })
56
+ }), /* @__PURE__ */ jsxs("div", {
57
+ className: "flex h-10 items-center gap-2 border-t px-3",
58
+ children: [
59
+ /* @__PURE__ */ jsx(MatchCount, {}),
60
+ /* @__PURE__ */ jsx(Button, {
61
+ size: "sm",
62
+ variant: "ghost",
63
+ tone: "muted",
64
+ className: "ml-auto",
65
+ disabled: !draft,
66
+ onClick: () => {
67
+ setDraft(void 0);
68
+ apply(void 0);
69
+ },
70
+ children: t("clear-all", "Clear all")
71
+ }),
72
+ /* @__PURE__ */ jsx(Button, {
73
+ size: "sm",
74
+ variant: "secondary",
75
+ onClick: onDone,
76
+ children: t("done", "Done")
77
+ })
78
+ ]
79
+ })]
80
+ });
81
+ };
82
+ /**
83
+ * The advanced filter: rows "Where / And / Or" with nested groups, in a popover anchored to the
84
+ * filter row. It doesn't block the page: the list updates behind it as the rules change.
85
+ */
86
+ const AdvancedPopover = ({ anchor }) => {
87
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
88
+ const { advancedOpen, setAdvancedOpen } = useListFilter();
89
+ return /* @__PURE__ */ jsx(Popover, {
90
+ open: advancedOpen,
91
+ onOpenChange: setAdvancedOpen,
92
+ children: /* @__PURE__ */ jsx(Popover.Content, {
93
+ anchor,
94
+ align: "start",
95
+ variant: "flush",
96
+ collisionPadding: 16,
97
+ "aria-label": t("advanced", "Advanced filter"),
98
+ className: "w-3xl max-w-full",
99
+ children: advancedOpen && /* @__PURE__ */ jsx(AdvancedEditor, { onDone: () => setAdvancedOpen(false) })
100
+ })
101
+ });
102
+ };
103
+ export { AdvancedPopover };