@salesforce/ui-bundle-template-app-react-template-b2x 11.18.0 → 11.19.0

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 (77) hide show
  1. package/dist/CHANGELOG.md +8 -0
  2. package/dist/force-app/main/default/uiBundles/reactexternalapp/package.json +4 -4
  3. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/{features/object-search/components → components}/ObjectBreadcrumb.tsx +7 -2
  4. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/api/distinctValuesService.ts +84 -0
  5. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/api/searchService.ts +71 -0
  6. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/MergedSearchResults.tsx +263 -0
  7. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/Search.tsx +185 -0
  8. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/SearchResults.tsx +77 -0
  9. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/SourceSection.tsx +166 -0
  10. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/controls/PaginationControls.tsx +185 -0
  11. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/controls/ScopeSelector.tsx +55 -0
  12. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/controls/SearchBar.tsx +55 -0
  13. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/controls/SortControl.tsx +62 -0
  14. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/ActiveFilters.tsx +61 -0
  15. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/DefaultFilterPanel.tsx +125 -0
  16. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/{object-search/components → search/components/filters}/FilterContext.tsx +7 -20
  17. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/inputs/BooleanFilter.tsx +50 -0
  18. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/inputs/DateRangeFilter.tsx +160 -0
  19. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/inputs/FilterFieldWrapper.tsx +26 -0
  20. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/inputs/MultiSelectFilter.tsx +88 -0
  21. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/inputs/NumericRangeFilter.tsx +78 -0
  22. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/inputs/SelectFilter.tsx +46 -0
  23. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/filters/inputs/TextFilter.tsx +52 -0
  24. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/components/results/DefaultResultRow.tsx +109 -0
  25. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/config.json +83 -0
  26. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/{object-search → search}/hooks/useAsyncData.ts +3 -10
  27. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/hooks/useDistinctValues.ts +59 -0
  28. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/hooks/useSearch.ts +703 -0
  29. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/index.ts +90 -0
  30. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/loadConfig.ts +14 -0
  31. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/queryBuilder.ts +156 -0
  32. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/types.ts +307 -0
  33. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/utils/debounce.ts +17 -0
  34. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/utils/fieldUtils.ts +14 -0
  35. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/utils/filterUtils.ts +285 -0
  36. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/search/utils/sortUtils.ts +34 -0
  37. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/pages/AccountObjectDetailPage.tsx +49 -16
  38. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/pages/AccountSearch.tsx +21 -293
  39. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/pages/Home.tsx +22 -7
  40. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/routes.tsx +1 -1
  41. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/{features/object-search/utils/fieldUtils.ts → utils/accountFields.ts} +9 -0
  42. package/dist/force-app/main/default/uiBundles/reactexternalapp/tsconfig.tsbuildinfo +1 -1
  43. package/dist/package-lock.json +2 -2
  44. package/dist/package.json +1 -1
  45. package/package.json +1 -1
  46. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/api/account/accountSearchService.ts +0 -46
  47. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/api/account/query/distinctAccountIndustries.graphql +0 -19
  48. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/api/account/query/distinctAccountTypes.graphql +0 -19
  49. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/api/account/query/searchAccounts.graphql +0 -51
  50. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/api/graphql-operations-types.ts +0 -11260
  51. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/api/accountSearchService.ts +0 -46
  52. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/api/query/distinctAccountIndustries.graphql +0 -19
  53. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/api/query/distinctAccountTypes.graphql +0 -19
  54. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/api/query/getAccountDetail.graphql +0 -121
  55. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/api/query/searchAccounts.graphql +0 -51
  56. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/pages/AccountObjectDetailPage.tsx +0 -355
  57. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/pages/AccountSearch.tsx +0 -304
  58. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/__examples__/pages/Home.tsx +0 -34
  59. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/api/objectSearchService.ts +0 -82
  60. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/ActiveFilters.tsx +0 -89
  61. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/PaginationControls.tsx +0 -109
  62. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/SearchBar.tsx +0 -41
  63. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/SortControl.tsx +0 -143
  64. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/BooleanFilter.tsx +0 -78
  65. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/DateFilter.tsx +0 -128
  66. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/DateRangeFilter.tsx +0 -70
  67. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/FilterFieldWrapper.tsx +0 -43
  68. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/MultiSelectFilter.tsx +0 -105
  69. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/NumericRangeFilter.tsx +0 -171
  70. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/SearchFilter.tsx +0 -52
  71. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/SelectFilter.tsx +0 -97
  72. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/components/filters/TextFilter.tsx +0 -93
  73. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/hooks/useDebouncedCallback.ts +0 -34
  74. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/hooks/useObjectSearchParams.ts +0 -254
  75. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/utils/debounce.ts +0 -25
  76. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/utils/filterUtils.ts +0 -404
  77. package/dist/force-app/main/default/uiBundles/reactexternalapp/src/features/object-search/utils/sortUtils.ts +0 -38
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Default filter panel used when no `renderFilters` is supplied for a source.
3
+ *
4
+ * Renders one input per entry in `source.filterBy`, picking the right
5
+ * component for each `FilterFieldType`:
6
+ *
7
+ * - text → TextFilter
8
+ * - picklist → SelectFilter (inline options or auto-fetched)
9
+ * - multipicklist → MultiSelectFilter (inline options or auto-fetched)
10
+ * - numeric → NumericRangeFilter
11
+ * - boolean → BooleanFilter
12
+ * - date / daterange / datetime / datetimerange → DateRangeFilter
13
+ * (its Between / After / Before chrome is chosen by `filter.dateMode`)
14
+ *
15
+ * Applications can still pass `renderFilters[sourceKey]` to override the
16
+ * entire panel for a specific source.
17
+ */
18
+
19
+ import { TextFilter } from "./inputs/TextFilter";
20
+ import { SelectFilter } from "./inputs/SelectFilter";
21
+ import { MultiSelectFilter } from "./inputs/MultiSelectFilter";
22
+ import { NumericRangeFilter } from "./inputs/NumericRangeFilter";
23
+ import { BooleanFilter } from "./inputs/BooleanFilter";
24
+ import { DateRangeFilter } from "./inputs/DateRangeFilter";
25
+ import { useDistinctValues } from "../../hooks/useDistinctValues";
26
+ import type { FilterFieldConfig } from "../../utils/filterUtils";
27
+ import type { SObjectSourceConfig } from "../../types";
28
+
29
+ interface DefaultFilterPanelProps {
30
+ source: SObjectSourceConfig;
31
+ }
32
+
33
+ export function DefaultFilterPanel({ source }: DefaultFilterPanelProps) {
34
+ const filters = source.filterBy ?? [];
35
+ if (filters.length === 0) return null;
36
+ return (
37
+ <>
38
+ {filters.map((filter) => (
39
+ <DefaultFilterField key={filter.field} filter={filter} source={source} />
40
+ ))}
41
+ </>
42
+ );
43
+ }
44
+
45
+ interface DefaultFilterFieldProps {
46
+ filter: FilterFieldConfig;
47
+ source: SObjectSourceConfig;
48
+ }
49
+
50
+ function DefaultFilterField({ filter, source }: DefaultFilterFieldProps) {
51
+ switch (filter.type) {
52
+ case "text":
53
+ return (
54
+ <TextFilter
55
+ field={filter.field}
56
+ label={filter.label}
57
+ placeholder={filter.placeholder}
58
+ helpText={filter.helpText}
59
+ />
60
+ );
61
+ case "picklist":
62
+ return <PicklistField filter={filter} source={source} multi={false} />;
63
+ case "multipicklist":
64
+ return <PicklistField filter={filter} source={source} multi={true} />;
65
+ case "numeric":
66
+ return (
67
+ <NumericRangeFilter field={filter.field} label={filter.label} helpText={filter.helpText} />
68
+ );
69
+ case "boolean":
70
+ return <BooleanFilter field={filter.field} label={filter.label} helpText={filter.helpText} />;
71
+ case "date":
72
+ case "daterange":
73
+ return (
74
+ <DateRangeFilter
75
+ field={filter.field}
76
+ label={filter.label}
77
+ helpText={filter.helpText}
78
+ filterType="daterange"
79
+ mode={filter.dateMode}
80
+ />
81
+ );
82
+ case "datetime":
83
+ case "datetimerange":
84
+ return (
85
+ <DateRangeFilter
86
+ field={filter.field}
87
+ label={filter.label}
88
+ helpText={filter.helpText}
89
+ filterType="datetimerange"
90
+ mode={filter.dateMode}
91
+ />
92
+ );
93
+ default:
94
+ return null;
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Resolves picklist options from inline config first; falls back to fetching
100
+ * distinct values from the GraphQL aggregate API on first render.
101
+ */
102
+ function PicklistField({
103
+ filter,
104
+ source,
105
+ multi,
106
+ }: {
107
+ filter: FilterFieldConfig;
108
+ source: SObjectSourceConfig;
109
+ multi: boolean;
110
+ }) {
111
+ const inline = filter.options;
112
+ const fetched = useDistinctValues(
113
+ inline ? null : { objectName: source.objectName, fieldName: filter.field },
114
+ );
115
+ const options = inline ?? fetched ?? [];
116
+ const Component = multi ? MultiSelectFilter : SelectFilter;
117
+ return (
118
+ <Component
119
+ field={filter.field}
120
+ label={filter.label}
121
+ options={options}
122
+ helpText={filter.helpText}
123
+ />
124
+ );
125
+ }
@@ -1,6 +1,6 @@
1
- import { createContext, useContext, useCallback, type ReactNode } from "react";
2
- import { Button } from "../../../components/ui/button";
3
- import type { ActiveFilterValue } from "../utils/filterUtils";
1
+ import { createContext, useCallback, useContext, type ReactNode } from "react";
2
+ import { Button } from "../../../../components/ui/button";
3
+ import type { ActiveFilterValue } from "../../utils/filterUtils";
4
4
 
5
5
  interface FilterContextValue {
6
6
  filters: ActiveFilterValue[];
@@ -27,14 +27,7 @@ export function FilterProvider({
27
27
  children,
28
28
  }: FilterProviderProps) {
29
29
  return (
30
- <FilterContext.Provider
31
- value={{
32
- filters,
33
- onFilterChange,
34
- onFilterRemove,
35
- onReset,
36
- }}
37
- >
30
+ <FilterContext.Provider value={{ filters, onFilterChange, onFilterRemove, onReset }}>
38
31
  {children}
39
32
  </FilterContext.Provider>
40
33
  );
@@ -51,11 +44,8 @@ export function useFilterField(field: string) {
51
44
  const value = filters.find((f) => f.field === field);
52
45
  const onChange = useCallback(
53
46
  (next: ActiveFilterValue | undefined) => {
54
- if (next) {
55
- onFilterChange(field, next);
56
- } else {
57
- onFilterRemove(field);
58
- }
47
+ if (next) onFilterChange(field, next);
48
+ else onFilterRemove(field);
59
49
  },
60
50
  [field, onFilterChange, onFilterRemove],
61
51
  );
@@ -64,10 +54,7 @@ export function useFilterField(field: string) {
64
54
 
65
55
  export function useFilterPanel() {
66
56
  const { filters, onReset } = useFilterContext();
67
- return {
68
- hasActiveFilters: filters.length > 0,
69
- resetAll: onReset,
70
- };
57
+ return { hasActiveFilters: filters.length > 0, resetAll: onReset };
71
58
  }
72
59
 
73
60
  type FilterResetButtonProps = Omit<React.ComponentProps<typeof Button>, "onClick">;
@@ -0,0 +1,50 @@
1
+ import {
2
+ Select,
3
+ SelectContent,
4
+ SelectItem,
5
+ SelectTrigger,
6
+ SelectValue,
7
+ } from "../../../../../components/ui/select";
8
+ import { useFilterField } from "../FilterContext";
9
+ import { FilterFieldWrapper } from "./FilterFieldWrapper";
10
+
11
+ const ANY_VALUE = "__any__";
12
+
13
+ interface BooleanFilterProps {
14
+ field: string;
15
+ label: string;
16
+ trueLabel?: string;
17
+ falseLabel?: string;
18
+ helpText?: string;
19
+ }
20
+
21
+ export function BooleanFilter({
22
+ field,
23
+ label,
24
+ trueLabel = "Yes",
25
+ falseLabel = "No",
26
+ helpText,
27
+ }: BooleanFilterProps) {
28
+ const { value, onChange } = useFilterField(field);
29
+ const id = `filter-${field}`;
30
+ return (
31
+ <FilterFieldWrapper label={label} htmlFor={id} helpText={helpText}>
32
+ <Select
33
+ value={value?.value ?? ANY_VALUE}
34
+ onValueChange={(v) => {
35
+ if (v === ANY_VALUE) onChange(undefined);
36
+ else onChange({ field, label, type: "boolean", value: v });
37
+ }}
38
+ >
39
+ <SelectTrigger id={id} className="w-full">
40
+ <SelectValue />
41
+ </SelectTrigger>
42
+ <SelectContent>
43
+ <SelectItem value={ANY_VALUE}>Any</SelectItem>
44
+ <SelectItem value="true">{trueLabel}</SelectItem>
45
+ <SelectItem value="false">{falseLabel}</SelectItem>
46
+ </SelectContent>
47
+ </Select>
48
+ </FilterFieldWrapper>
49
+ );
50
+ }
@@ -0,0 +1,160 @@
1
+ import { useState } from "react";
2
+ import { Input } from "../../../../../components/ui/input";
3
+ import {
4
+ Select,
5
+ SelectContent,
6
+ SelectItem,
7
+ SelectTrigger,
8
+ SelectValue,
9
+ } from "../../../../../components/ui/select";
10
+ import { useFilterField } from "../FilterContext";
11
+ import { FilterFieldWrapper } from "./FilterFieldWrapper";
12
+ import type {
13
+ ActiveFilterValue,
14
+ DateFilterMode,
15
+ FilterFieldType,
16
+ } from "../../../utils/filterUtils";
17
+
18
+ interface DateRangeFilterProps {
19
+ field: string;
20
+ label: string;
21
+ helpText?: string;
22
+ /** "daterange" (Date scalar) or "datetimerange" (DateTime scalar). */
23
+ filterType?: Extract<FilterFieldType, "daterange" | "datetimerange">;
24
+ /**
25
+ * Which comparison chrome to show. See {@link DateFilterMode}. Defaults to
26
+ * `"comparison"` (an After / Before selector with one date input).
27
+ */
28
+ mode?: DateFilterMode;
29
+ }
30
+
31
+ /**
32
+ * The three ways to constrain a date field. They map directly onto the
33
+ * `min`/`max` bounds the query builder already understands:
34
+ * - after → only `min` set → `gte`
35
+ * - before → only `max` set → `lte`
36
+ * - between → both set → `gte` AND `lte`
37
+ */
38
+ type DateOperator = "between" | "after" | "before";
39
+
40
+ const OPERATOR_LABELS: Record<DateOperator, string> = {
41
+ between: "Between",
42
+ after: "After",
43
+ before: "Before",
44
+ };
45
+
46
+ /** The operators offered for each {@link DateFilterMode}. */
47
+ const MODE_OPERATORS: Record<DateFilterMode, DateOperator[]> = {
48
+ range: ["between"],
49
+ comparison: ["after", "before"],
50
+ both: ["between", "after", "before"],
51
+ };
52
+
53
+ /** Pick the operator implied by an already-active filter (e.g. restored from the URL). */
54
+ function operatorFor(value: ActiveFilterValue | undefined): DateOperator {
55
+ const hasMin = !!value?.min;
56
+ const hasMax = !!value?.max;
57
+ if (hasMax && !hasMin) return "before";
58
+ if (hasMin && !hasMax) return "after";
59
+ return "between";
60
+ }
61
+
62
+ /**
63
+ * A date constraint whose chrome is driven by `mode`:
64
+ * - `"range"`: a single Between control (two date inputs).
65
+ * - `"comparison"` (default): an After / Before selector with one input.
66
+ * - `"both"`: a Between / After / Before selector spanning the two.
67
+ *
68
+ * "Between" shows two `<input type="date">` controls; "After" / "Before"
69
+ * collapse to one bound to the relevant end. Uses the platform-native picker —
70
+ * no popover/calendar dependency.
71
+ */
72
+ export function DateRangeFilter({
73
+ field,
74
+ label,
75
+ helpText,
76
+ filterType = "daterange",
77
+ mode = "comparison",
78
+ }: DateRangeFilterProps) {
79
+ const { value, onChange } = useFilterField(field);
80
+ const operators = MODE_OPERATORS[mode];
81
+
82
+ // Operator is local UI state: it must survive a moment where no date is yet
83
+ // entered (which clears the active filter), so it can't be derived from
84
+ // `value` on every render. Seed it from any filter restored on mount, clamped
85
+ // to an operator this mode actually offers.
86
+ const [operator, setOperator] = useState<DateOperator>(() => {
87
+ const restored = operatorFor(value);
88
+ return operators.includes(restored) ? restored : operators[0];
89
+ });
90
+
91
+ const emit = (nextMin: string | undefined, nextMax: string | undefined) => {
92
+ if (!nextMin && !nextMax) onChange(undefined);
93
+ else onChange({ field, label, type: filterType, min: nextMin, max: nextMax });
94
+ };
95
+
96
+ const changeOperator = (next: DateOperator) => {
97
+ setOperator(next);
98
+ // Re-emit, keeping only the bound(s) the new operator uses.
99
+ if (next === "after") emit(value?.min, undefined);
100
+ else if (next === "before") emit(undefined, value?.max);
101
+ else emit(value?.min, value?.max);
102
+ };
103
+
104
+ const operatorId = `filter-${field}-op`;
105
+ // A lone "between" operator (mode="range") needs no selector — it can't change.
106
+ const showSelector = operators.length > 1;
107
+
108
+ return (
109
+ <FilterFieldWrapper label={label} helpText={helpText}>
110
+ <div className="flex flex-col gap-2">
111
+ {showSelector && (
112
+ <Select value={operator} onValueChange={(v) => changeOperator(v as DateOperator)}>
113
+ <SelectTrigger id={operatorId} className="w-full" aria-label={`${label} comparison`}>
114
+ <SelectValue />
115
+ </SelectTrigger>
116
+ <SelectContent>
117
+ {operators.map((op) => (
118
+ <SelectItem key={op} value={op}>
119
+ {OPERATOR_LABELS[op]}
120
+ </SelectItem>
121
+ ))}
122
+ </SelectContent>
123
+ </Select>
124
+ )}
125
+
126
+ {operator === "between" ? (
127
+ <div className="flex items-center gap-2">
128
+ <Input
129
+ type="date"
130
+ value={value?.min ?? ""}
131
+ onChange={(e) => emit(e.target.value || undefined, value?.max)}
132
+ aria-label={`${label} from`}
133
+ />
134
+ <span className="text-sm text-muted-foreground">–</span>
135
+ <Input
136
+ type="date"
137
+ value={value?.max ?? ""}
138
+ onChange={(e) => emit(value?.min, e.target.value || undefined)}
139
+ aria-label={`${label} to`}
140
+ />
141
+ </div>
142
+ ) : operator === "after" ? (
143
+ <Input
144
+ type="date"
145
+ value={value?.min ?? ""}
146
+ onChange={(e) => emit(e.target.value || undefined, undefined)}
147
+ aria-label={`${label} after`}
148
+ />
149
+ ) : (
150
+ <Input
151
+ type="date"
152
+ value={value?.max ?? ""}
153
+ onChange={(e) => emit(undefined, e.target.value || undefined)}
154
+ aria-label={`${label} before`}
155
+ />
156
+ )}
157
+ </div>
158
+ </FilterFieldWrapper>
159
+ );
160
+ }
@@ -0,0 +1,26 @@
1
+ import type { ReactNode } from "react";
2
+ import { Label } from "../../../../../components/ui/label";
3
+
4
+ interface FilterFieldWrapperProps {
5
+ label: string;
6
+ htmlFor?: string;
7
+ helpText?: string;
8
+ className?: string;
9
+ children: ReactNode;
10
+ }
11
+
12
+ export function FilterFieldWrapper({
13
+ label,
14
+ htmlFor,
15
+ helpText,
16
+ className,
17
+ children,
18
+ }: FilterFieldWrapperProps) {
19
+ return (
20
+ <div className={`space-y-1 ${className ?? ""}`}>
21
+ <Label htmlFor={htmlFor}>{label}</Label>
22
+ {children}
23
+ {helpText && <p className="text-xs text-muted-foreground min-h-4">{helpText}</p>}
24
+ </div>
25
+ );
26
+ }
@@ -0,0 +1,88 @@
1
+ import { ChevronDown } from "lucide-react";
2
+ import { Button } from "../../../../../components/ui/button";
3
+ import { Checkbox } from "../../../../../components/ui/checkbox";
4
+ import { Label } from "../../../../../components/ui/label";
5
+ import {
6
+ Popover,
7
+ PopoverContent,
8
+ PopoverTrigger,
9
+ } from "../../../../../components/ui/popover";
10
+ import { useFilterField } from "../FilterContext";
11
+ import { FilterFieldWrapper } from "./FilterFieldWrapper";
12
+
13
+ interface MultiSelectFilterProps {
14
+ field: string;
15
+ label: string;
16
+ options: Array<{ value: string; label: string }>;
17
+ helpText?: string;
18
+ }
19
+
20
+ export function MultiSelectFilter({ field, label, options, helpText }: MultiSelectFilterProps) {
21
+ const { value, onChange } = useFilterField(field);
22
+ const selected = new Set(value?.value ? value.value.split(",").filter(Boolean) : []);
23
+
24
+ const toggle = (v: string, on: boolean) => {
25
+ const next = new Set(selected);
26
+ if (on) next.add(v);
27
+ else next.delete(v);
28
+ const joined = Array.from(next).join(",");
29
+ if (joined === "") onChange(undefined);
30
+ else onChange({ field, label, type: "multipicklist", value: joined });
31
+ };
32
+
33
+ // Summarize the selection on the collapsed trigger: the sole label when one is
34
+ // picked, a count when several are, and a placeholder when none.
35
+ const summary =
36
+ selected.size === 0
37
+ ? `Select ${label.toLowerCase()}`
38
+ : selected.size === 1
39
+ ? (options.find((o) => selected.has(o.value))?.label ?? `${selected.size} selected`)
40
+ : `${selected.size} selected`;
41
+ const triggerId = `filter-${field}`;
42
+
43
+ return (
44
+ <FilterFieldWrapper label={label} htmlFor={triggerId} helpText={helpText}>
45
+ <Popover>
46
+ <PopoverTrigger asChild>
47
+ <Button
48
+ id={triggerId}
49
+ variant="outline"
50
+ className="w-full justify-between font-normal"
51
+ aria-label={`${label}: ${summary}`}
52
+ >
53
+ <span className={`truncate ${selected.size === 0 ? "text-muted-foreground" : ""}`}>
54
+ {summary}
55
+ </span>
56
+ <ChevronDown className="ml-2 size-4 shrink-0 opacity-50" aria-hidden="true" />
57
+ </Button>
58
+ </PopoverTrigger>
59
+ <PopoverContent
60
+ align="start"
61
+ className="w-(--radix-popover-trigger-width) max-h-72 overflow-y-auto"
62
+ >
63
+ <div role="group" aria-label={label} className="flex flex-col gap-1">
64
+ {options.length === 0 ? (
65
+ <p className="px-1 py-2 text-sm text-muted-foreground">No options available.</p>
66
+ ) : (
67
+ options.map((opt) => {
68
+ const id = `filter-${field}-${opt.value}`;
69
+ return (
70
+ <div key={opt.value} className="flex items-center gap-2">
71
+ <Checkbox
72
+ id={id}
73
+ checked={selected.has(opt.value)}
74
+ onCheckedChange={(checked) => toggle(opt.value, checked === true)}
75
+ />
76
+ <Label htmlFor={id} className="text-sm font-normal cursor-pointer">
77
+ {opt.label}
78
+ </Label>
79
+ </div>
80
+ );
81
+ })
82
+ )}
83
+ </div>
84
+ </PopoverContent>
85
+ </Popover>
86
+ </FilterFieldWrapper>
87
+ );
88
+ }
@@ -0,0 +1,78 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { Input } from "../../../../../components/ui/input";
3
+ import { useFilterField } from "../FilterContext";
4
+ import { FilterFieldWrapper } from "./FilterFieldWrapper";
5
+ import { debounce, FILTER_DEBOUNCE_MS } from "../../../utils/debounce";
6
+
7
+ interface NumericRangeFilterProps {
8
+ field: string;
9
+ label: string;
10
+ helpText?: string;
11
+ min?: number;
12
+ max?: number;
13
+ }
14
+
15
+ export function NumericRangeFilter({ field, label, helpText, min, max }: NumericRangeFilterProps) {
16
+ const { value, onChange } = useFilterField(field);
17
+ const [draftMin, setDraftMin] = useState(value?.min ?? "");
18
+ const [draftMax, setDraftMax] = useState(value?.max ?? "");
19
+
20
+ const onChangeRef = useRef(onChange);
21
+ useEffect(() => {
22
+ onChangeRef.current = onChange;
23
+ });
24
+ // Build the debounced caller in a mount effect, not during render: creating it
25
+ // inline would read onChangeRef.current at render time (react-hooks/refs). It
26
+ // stays a single stable instance and always calls the latest onChange via the ref.
27
+ const debouncedRef = useRef<((nextMin: string, nextMax: string) => void) | undefined>(undefined);
28
+ useEffect(() => {
29
+ debouncedRef.current = debounce((nextMin: string, nextMax: string) => {
30
+ if (!nextMin && !nextMax) onChangeRef.current(undefined);
31
+ else
32
+ onChangeRef.current({
33
+ field,
34
+ label,
35
+ type: "numeric",
36
+ min: nextMin || undefined,
37
+ max: nextMax || undefined,
38
+ });
39
+ }, FILTER_DEBOUNCE_MS);
40
+ }, [field, label]);
41
+
42
+ useEffect(() => {
43
+ setDraftMin(value?.min ?? "");
44
+ setDraftMax(value?.max ?? "");
45
+ }, [value?.min, value?.max]);
46
+
47
+ return (
48
+ <FilterFieldWrapper label={label} helpText={helpText}>
49
+ <div className="flex items-center gap-2">
50
+ <Input
51
+ type="number"
52
+ placeholder="Min"
53
+ min={min}
54
+ max={max}
55
+ value={draftMin}
56
+ onChange={(e) => {
57
+ setDraftMin(e.target.value);
58
+ debouncedRef.current?.(e.target.value, draftMax);
59
+ }}
60
+ aria-label={`${label} minimum`}
61
+ />
62
+ <span className="text-sm text-muted-foreground">–</span>
63
+ <Input
64
+ type="number"
65
+ placeholder="Max"
66
+ min={min}
67
+ max={max}
68
+ value={draftMax}
69
+ onChange={(e) => {
70
+ setDraftMax(e.target.value);
71
+ debouncedRef.current?.(draftMin, e.target.value);
72
+ }}
73
+ aria-label={`${label} maximum`}
74
+ />
75
+ </div>
76
+ </FilterFieldWrapper>
77
+ );
78
+ }
@@ -0,0 +1,46 @@
1
+ import {
2
+ Select,
3
+ SelectContent,
4
+ SelectItem,
5
+ SelectTrigger,
6
+ SelectValue,
7
+ } from "../../../../../components/ui/select";
8
+ import { useFilterField } from "../FilterContext";
9
+ import { FilterFieldWrapper } from "./FilterFieldWrapper";
10
+
11
+ const ALL_VALUE = "__all__";
12
+
13
+ interface SelectFilterProps {
14
+ field: string;
15
+ label: string;
16
+ options: Array<{ value: string; label: string }>;
17
+ helpText?: string;
18
+ }
19
+
20
+ export function SelectFilter({ field, label, options, helpText }: SelectFilterProps) {
21
+ const { value, onChange } = useFilterField(field);
22
+ const id = `filter-${field}`;
23
+ return (
24
+ <FilterFieldWrapper label={label} htmlFor={id} helpText={helpText}>
25
+ <Select
26
+ value={value?.value ?? ALL_VALUE}
27
+ onValueChange={(v) => {
28
+ if (v === ALL_VALUE) onChange(undefined);
29
+ else onChange({ field, label, type: "picklist", value: v });
30
+ }}
31
+ >
32
+ <SelectTrigger id={id} className="w-full">
33
+ <SelectValue placeholder={`Select ${label.toLowerCase()}`} />
34
+ </SelectTrigger>
35
+ <SelectContent>
36
+ <SelectItem value={ALL_VALUE}>All</SelectItem>
37
+ {options.map((opt) => (
38
+ <SelectItem key={opt.value} value={opt.value}>
39
+ {opt.label}
40
+ </SelectItem>
41
+ ))}
42
+ </SelectContent>
43
+ </Select>
44
+ </FilterFieldWrapper>
45
+ );
46
+ }
@@ -0,0 +1,52 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { Input } from "../../../../../components/ui/input";
3
+ import { useFilterField } from "../FilterContext";
4
+ import { FilterFieldWrapper } from "./FilterFieldWrapper";
5
+ import { debounce, FILTER_DEBOUNCE_MS } from "../../../utils/debounce";
6
+
7
+ interface TextFilterProps {
8
+ field: string;
9
+ label: string;
10
+ placeholder?: string;
11
+ helpText?: string;
12
+ }
13
+
14
+ export function TextFilter({ field, label, placeholder, helpText }: TextFilterProps) {
15
+ const { value, onChange } = useFilterField(field);
16
+ const [draft, setDraft] = useState(value?.value ?? "");
17
+
18
+ const onChangeRef = useRef(onChange);
19
+ useEffect(() => {
20
+ onChangeRef.current = onChange;
21
+ });
22
+ // Build the debounced caller in a mount effect, not during render: creating it
23
+ // inline would read onChangeRef.current at render time (react-hooks/refs). It
24
+ // stays a single stable instance and always calls the latest onChange via the ref.
25
+ const debouncedRef = useRef<((next: string) => void) | undefined>(undefined);
26
+ useEffect(() => {
27
+ debouncedRef.current = debounce((next: string) => {
28
+ if (next === "") onChangeRef.current(undefined);
29
+ else onChangeRef.current({ field, label, type: "text", value: next });
30
+ }, FILTER_DEBOUNCE_MS);
31
+ }, [field, label]);
32
+
33
+ useEffect(() => {
34
+ setDraft(value?.value ?? "");
35
+ }, [value?.value]);
36
+
37
+ const id = `filter-${field}`;
38
+ return (
39
+ <FilterFieldWrapper label={label} htmlFor={id} helpText={helpText}>
40
+ <Input
41
+ id={id}
42
+ type="text"
43
+ value={draft}
44
+ placeholder={placeholder}
45
+ onChange={(e) => {
46
+ setDraft(e.target.value);
47
+ debouncedRef.current?.(e.target.value);
48
+ }}
49
+ />
50
+ </FilterFieldWrapper>
51
+ );
52
+ }