@salesforce/ui-bundle-template-app-react-sample-b2e 11.19.0 → 11.21.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 (102) hide show
  1. package/dist/CHANGELOG.md +16 -0
  2. package/dist/force-app/main/default/uiBundles/propertymanagementapp/package.json +4 -4
  3. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/applications/applicationSearchService.ts +25 -43
  4. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceRequests/maintenanceRequestSearchService.ts +31 -65
  5. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceWorkers/maintenanceWorkerSearchService.ts +21 -43
  6. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/properties/propertySearchService.ts +33 -53
  7. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/applications/ApplicationCard.tsx +80 -0
  8. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/dashboard/GlobalSearchBar.tsx +2 -2
  9. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/layout/VerticalNav.tsx +28 -18
  10. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/maintenanceRequests/MaintenanceRequestCard.tsx +79 -52
  11. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/maintenanceWorkers/WorkerCard.tsx +87 -0
  12. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/search/UnifiedSearch.tsx +213 -0
  13. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/api/distinctValuesService.ts +84 -0
  14. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/api/searchService.ts +71 -0
  15. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/MergedSearchResults.tsx +263 -0
  16. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/Search.tsx +185 -0
  17. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/SearchResults.tsx +77 -0
  18. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/SourceSection.tsx +166 -0
  19. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/controls/PaginationControls.tsx +185 -0
  20. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/controls/ScopeSelector.tsx +55 -0
  21. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/controls/SearchBar.tsx +55 -0
  22. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/controls/SortControl.tsx +62 -0
  23. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/ActiveFilters.tsx +61 -0
  24. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/DefaultFilterPanel.tsx +125 -0
  25. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/{object-search/components → search/components/filters}/FilterContext.tsx +7 -20
  26. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/inputs/BooleanFilter.tsx +50 -0
  27. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/inputs/DateRangeFilter.tsx +160 -0
  28. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/inputs/FilterFieldWrapper.tsx +26 -0
  29. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/inputs/MultiSelectFilter.tsx +88 -0
  30. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/inputs/NumericRangeFilter.tsx +78 -0
  31. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/inputs/SelectFilter.tsx +46 -0
  32. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/filters/inputs/TextFilter.tsx +52 -0
  33. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/components/results/DefaultResultRow.tsx +109 -0
  34. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/config.json +83 -0
  35. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/{object-search → search}/hooks/useAsyncData.ts +3 -10
  36. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/hooks/useDistinctValues.ts +59 -0
  37. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/hooks/useSearch.ts +703 -0
  38. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/index.ts +90 -0
  39. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/loadConfig.ts +14 -0
  40. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/queryBuilder.ts +156 -0
  41. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/types.ts +307 -0
  42. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/utils/debounce.ts +17 -0
  43. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/utils/fieldUtils.ts +14 -0
  44. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/utils/filterUtils.ts +285 -0
  45. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/search/utils/sortUtils.ts +34 -0
  46. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/lib/constants.ts +16 -29
  47. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/lib/routeConfig.ts +1 -0
  48. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/lib/searchConfig.ts +190 -0
  49. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/pages/ApplicationSearch.tsx +8 -385
  50. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/pages/Home.tsx +4 -2
  51. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/pages/MaintenanceRequestSearch.tsx +8 -458
  52. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/pages/MaintenanceWorkerSearch.tsx +8 -341
  53. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/pages/PropertySearch.tsx +7 -243
  54. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/pages/Search.tsx +16 -0
  55. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/routes.tsx +6 -0
  56. package/dist/force-app/main/default/uiBundles/propertymanagementapp/tsconfig.tsbuildinfo +1 -1
  57. package/dist/package-lock.json +2 -2
  58. package/dist/package.json +1 -1
  59. package/package.json +2 -2
  60. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/applications/query/distinctApplicationStatus.graphql +0 -19
  61. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/applications/query/searchApplications.graphql +0 -65
  62. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceRequests/query/distinctMaintenanceRequestPriority.graphql +0 -19
  63. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceRequests/query/distinctMaintenanceRequestStatus.graphql +0 -19
  64. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceRequests/query/distinctMaintenanceRequestType.graphql +0 -19
  65. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceRequests/query/searchMaintenanceRequests.graphql +0 -82
  66. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceWorkers/query/distinctMaintenanceWorkerEmploymentType.graphql +0 -19
  67. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/maintenanceWorkers/query/searchMaintenanceWorkers.graphql +0 -64
  68. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/properties/query/distinctPropertyStatus.graphql +0 -19
  69. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/properties/query/distinctPropertyType.graphql +0 -19
  70. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/api/properties/query/searchProperties.graphql +0 -105
  71. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/shared/ObjectSearchErrorState.tsx +0 -45
  72. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/components/shared/UserAvatar.tsx +0 -35
  73. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/api/accountSearchService.ts +0 -46
  74. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/api/query/distinctAccountIndustries.graphql +0 -19
  75. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/api/query/distinctAccountTypes.graphql +0 -19
  76. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/api/query/getAccountDetail.graphql +0 -121
  77. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/api/query/searchAccounts.graphql +0 -51
  78. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/pages/AccountObjectDetailPage.tsx +0 -355
  79. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/pages/AccountSearch.tsx +0 -304
  80. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/__examples__/pages/Home.tsx +0 -34
  81. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/api/objectSearchService.ts +0 -82
  82. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/ActiveFilters.tsx +0 -89
  83. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/ObjectBreadcrumb.tsx +0 -66
  84. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/PaginationControls.tsx +0 -109
  85. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/SearchBar.tsx +0 -41
  86. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/SortControl.tsx +0 -143
  87. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/BooleanFilter.tsx +0 -78
  88. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/DateFilter.tsx +0 -128
  89. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/DateRangeFilter.tsx +0 -70
  90. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/FilterFieldWrapper.tsx +0 -43
  91. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/MultiSelectFilter.tsx +0 -105
  92. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/NumericRangeFilter.tsx +0 -171
  93. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/SearchFilter.tsx +0 -52
  94. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/SelectFilter.tsx +0 -97
  95. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/components/filters/TextFilter.tsx +0 -93
  96. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/hooks/useDebouncedCallback.ts +0 -34
  97. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/hooks/useObjectSearchParams.ts +0 -254
  98. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/utils/debounce.ts +0 -25
  99. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/utils/fieldUtils.ts +0 -29
  100. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/utils/filterUtils.ts +0 -404
  101. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/features/object-search/utils/sortUtils.ts +0 -38
  102. package/dist/force-app/main/default/uiBundles/propertymanagementapp/src/lib/filterUtils.ts +0 -11
@@ -0,0 +1,185 @@
1
+ import {
2
+ Pagination,
3
+ PaginationContent,
4
+ PaginationEllipsis,
5
+ PaginationItem,
6
+ PaginationLink,
7
+ PaginationNext,
8
+ PaginationPrevious,
9
+ } from "../../../../components/ui/pagination";
10
+ import {
11
+ Select,
12
+ SelectContent,
13
+ SelectItem,
14
+ SelectTrigger,
15
+ SelectValue,
16
+ } from "../../../../components/ui/select";
17
+ import { Label } from "../../../../components/ui/label";
18
+ import type { KeyboardEvent } from "react";
19
+
20
+ interface PaginationControlsProps {
21
+ pageIndex: number;
22
+ hasNextPage: boolean;
23
+ hasPreviousPage: boolean;
24
+ pageSize: number;
25
+ pageSizeOptions: readonly number[];
26
+ onNextPage: () => void;
27
+ onPreviousPage: () => void;
28
+ onPageSizeChange: (size: number) => void;
29
+ /**
30
+ * Total number of pages. When provided (with {@link onGoToPage}) and `> 1`,
31
+ * the control renders numbered page buttons with ellipsis truncation instead
32
+ * of a plain "Page N" label. Omit for cursor-style sources where the total
33
+ * page count is unknown.
34
+ */
35
+ pageCount?: number;
36
+ /** Jump to a 0-based page. Required to render numbered page buttons. */
37
+ onGoToPage?: (pageIndex: number) => void;
38
+ disabled?: boolean;
39
+ idPrefix?: string;
40
+ }
41
+
42
+ /**
43
+ * Builds the list of page tokens to render: 0-based page numbers plus
44
+ * `"ellipsis"` gap markers. Always shows the first and last page, a window
45
+ * around the current page, and collapses the rest. e.g. for current=5,
46
+ * total=12 → [0, ellipsis, 4, 5, 6, ellipsis, 11].
47
+ */
48
+ function getPageTokens(currentIndex: number, pageCount: number): Array<number | "ellipsis"> {
49
+ const SIBLINGS = 1; // pages shown on each side of the current page
50
+ const last = pageCount - 1;
51
+ const pages = new Set<number>([0, last]);
52
+ for (let p = currentIndex - SIBLINGS; p <= currentIndex + SIBLINGS; p++) {
53
+ if (p >= 0 && p <= last) pages.add(p);
54
+ }
55
+ const sorted = [...pages].sort((a, b) => a - b);
56
+ const tokens: Array<number | "ellipsis"> = [];
57
+ let prev = -1;
58
+ for (const p of sorted) {
59
+ if (prev !== -1 && p - prev > 1) tokens.push("ellipsis");
60
+ tokens.push(p);
61
+ prev = p;
62
+ }
63
+ return tokens;
64
+ }
65
+
66
+ export function PaginationControls({
67
+ pageIndex,
68
+ hasNextPage,
69
+ hasPreviousPage,
70
+ pageSize,
71
+ pageSizeOptions,
72
+ onNextPage,
73
+ onPreviousPage,
74
+ onPageSizeChange,
75
+ pageCount,
76
+ onGoToPage,
77
+ disabled = false,
78
+ idPrefix = "page-size",
79
+ }: PaginationControlsProps) {
80
+ const handlePageSizeChange = (next: string) => {
81
+ const size = parseInt(next, 10);
82
+ if (!isNaN(size) && size !== pageSize) onPageSizeChange(size);
83
+ };
84
+ const prevDisabled = disabled || !hasPreviousPage;
85
+ const nextDisabled = disabled || !hasNextPage;
86
+ const selectId = `${idPrefix}-select`;
87
+
88
+ // Numbered page buttons require both a known page count and a seek callback.
89
+ const showNumberedPages = pageCount != null && pageCount > 1 && onGoToPage != null;
90
+
91
+ // The underlying pagination control renders an <a> without an href, so it is
92
+ // not keyboard-operable on its own. Activate it on Enter/Space to match the
93
+ // behaviour of a native button (WCAG 2.2 SC 2.1.1 Keyboard).
94
+ const handleActivationKey = (action: () => void) => (event: KeyboardEvent) => {
95
+ if (event.key === "Enter" || event.key === " ") {
96
+ event.preventDefault();
97
+ action();
98
+ }
99
+ };
100
+
101
+ return (
102
+ <div className="w-full grid grid-cols-1 sm:grid-cols-2 items-center gap-4 py-2">
103
+ <div className="flex justify-center sm:justify-start items-center gap-2">
104
+ <Label htmlFor={selectId} className="text-sm font-normal whitespace-nowrap">
105
+ Results per page:
106
+ </Label>
107
+ <Select
108
+ value={pageSize.toString()}
109
+ onValueChange={handlePageSizeChange}
110
+ disabled={disabled}
111
+ >
112
+ <SelectTrigger id={selectId} className="w-16">
113
+ <SelectValue />
114
+ </SelectTrigger>
115
+ <SelectContent>
116
+ {pageSizeOptions.map((size) => (
117
+ <SelectItem key={size} value={size.toString()}>
118
+ {size}
119
+ </SelectItem>
120
+ ))}
121
+ </SelectContent>
122
+ </Select>
123
+ </div>
124
+ <Pagination className="w-full mx-0 sm:justify-end">
125
+ <PaginationContent>
126
+ <PaginationItem>
127
+ <PaginationPrevious
128
+ role="button"
129
+ tabIndex={prevDisabled ? -1 : 0}
130
+ onClick={prevDisabled ? undefined : onPreviousPage}
131
+ onKeyDown={prevDisabled ? undefined : handleActivationKey(onPreviousPage)}
132
+ aria-disabled={prevDisabled}
133
+ className={prevDisabled ? "pointer-events-none opacity-50" : "cursor-pointer"}
134
+ />
135
+ </PaginationItem>
136
+
137
+ {showNumberedPages ? (
138
+ getPageTokens(pageIndex, pageCount).map((token, i) =>
139
+ token === "ellipsis" ? (
140
+ <PaginationItem key={`ellipsis-${i}`}>
141
+ <PaginationEllipsis />
142
+ </PaginationItem>
143
+ ) : (
144
+ <PaginationItem key={token}>
145
+ <PaginationLink
146
+ role="button"
147
+ tabIndex={disabled ? -1 : 0}
148
+ isActive={token === pageIndex}
149
+ aria-label={`Go to page ${token + 1}`}
150
+ aria-current={token === pageIndex ? "page" : undefined}
151
+ onClick={disabled ? undefined : () => onGoToPage(token)}
152
+ onKeyDown={disabled ? undefined : handleActivationKey(() => onGoToPage(token))}
153
+ aria-disabled={disabled}
154
+ className={disabled ? "pointer-events-none opacity-50" : "cursor-pointer"}
155
+ >
156
+ {token + 1}
157
+ </PaginationLink>
158
+ </PaginationItem>
159
+ ),
160
+ )
161
+ ) : (
162
+ <PaginationItem>
163
+ <span className="min-w-16 text-center text-sm text-muted-foreground px-2">
164
+ {pageCount != null && pageCount > 0
165
+ ? `Page ${pageIndex + 1} of ${pageCount}`
166
+ : `Page ${pageIndex + 1}`}
167
+ </span>
168
+ </PaginationItem>
169
+ )}
170
+
171
+ <PaginationItem>
172
+ <PaginationNext
173
+ role="button"
174
+ tabIndex={nextDisabled ? -1 : 0}
175
+ onClick={nextDisabled ? undefined : onNextPage}
176
+ onKeyDown={nextDisabled ? undefined : handleActivationKey(onNextPage)}
177
+ aria-disabled={nextDisabled}
178
+ className={nextDisabled ? "pointer-events-none opacity-50" : "cursor-pointer"}
179
+ />
180
+ </PaginationItem>
181
+ </PaginationContent>
182
+ </Pagination>
183
+ </div>
184
+ );
185
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Dropdown that narrows the search to a single source (or "All").
3
+ *
4
+ * Sits next to the search bar in the default {@link Search} layout. The
5
+ * options are derived from the configured sources: an "All" entry plus one
6
+ * entry per source (using each source's `label`).
7
+ *
8
+ * Selecting a non-"All" scope tells {@link useSearch} to fetch and render
9
+ * only that source. Switching scope resets per-source pagination cursors —
10
+ * the visible result set is changing.
11
+ */
12
+
13
+ import {
14
+ Select,
15
+ SelectContent,
16
+ SelectItem,
17
+ SelectTrigger,
18
+ SelectValue,
19
+ } from "../../../../components/ui/select";
20
+ import { ALL_SCOPE, type SearchConfig, type SearchScope } from "../../types";
21
+
22
+ interface ScopeSelectorProps {
23
+ config: SearchConfig;
24
+ scope: SearchScope;
25
+ onScopeChange: (scope: SearchScope) => void;
26
+ allLabel?: string;
27
+ className?: string;
28
+ }
29
+
30
+ export function ScopeSelector({
31
+ config,
32
+ scope,
33
+ onScopeChange,
34
+ allLabel = "All",
35
+ className,
36
+ }: ScopeSelectorProps) {
37
+ if (config.sources.length === 0) return null;
38
+ return (
39
+ <div className={className}>
40
+ <Select value={scope} onValueChange={onScopeChange}>
41
+ <SelectTrigger size="sm" className="min-w-[140px]" aria-label="Search scope">
42
+ <SelectValue />
43
+ </SelectTrigger>
44
+ <SelectContent>
45
+ <SelectItem value={ALL_SCOPE}>{allLabel}</SelectItem>
46
+ {config.sources.map((source) => (
47
+ <SelectItem key={source.key} value={source.key}>
48
+ {source.label}
49
+ </SelectItem>
50
+ ))}
51
+ </SelectContent>
52
+ </Select>
53
+ </div>
54
+ );
55
+ }
@@ -0,0 +1,55 @@
1
+ import { Search } from "lucide-react";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { Input } from "../../../../components/ui/input";
4
+ import { debounce } from "../../utils/debounce";
5
+
6
+ const TYPE_DEBOUNCE_MS = 250;
7
+
8
+ interface SearchBarProps {
9
+ value: string;
10
+ onChange: (next: string) => void;
11
+ placeholder?: string;
12
+ className?: string;
13
+ }
14
+
15
+ /**
16
+ * Debounced text input for the global `q` term. Keeps a local `draft` so
17
+ * keystrokes feel responsive while the upstream `onChange` is rate-limited.
18
+ */
19
+ export function SearchBar({ value, onChange, placeholder = "Search…", className }: SearchBarProps) {
20
+ const [draft, setDraft] = useState(value);
21
+ const onChangeRef = useRef(onChange);
22
+ useEffect(() => {
23
+ onChangeRef.current = onChange;
24
+ });
25
+
26
+ // Build the debounced caller in a mount effect, not during render: creating it
27
+ // inline would read onChangeRef.current at render time (react-hooks/refs). It
28
+ // stays a single stable instance and always calls the latest onChange via the ref.
29
+ const debouncedRef = useRef<((next: string) => void) | undefined>(undefined);
30
+ useEffect(() => {
31
+ debouncedRef.current = debounce((next: string) => onChangeRef.current(next), TYPE_DEBOUNCE_MS);
32
+ }, []);
33
+
34
+ // External value can change (URL restore, reset). Keep draft in sync.
35
+ useEffect(() => {
36
+ setDraft(value);
37
+ }, [value]);
38
+
39
+ return (
40
+ <div className={`relative flex-1 ${className ?? ""}`}>
41
+ <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
42
+ <Input
43
+ type="text"
44
+ value={draft}
45
+ onChange={(e) => {
46
+ setDraft(e.target.value);
47
+ debouncedRef.current?.(e.target.value);
48
+ }}
49
+ placeholder={placeholder}
50
+ className="pl-9"
51
+ aria-label="Unified search"
52
+ />
53
+ </div>
54
+ );
55
+ }
@@ -0,0 +1,62 @@
1
+ import { ArrowDown, ArrowUp } from "lucide-react";
2
+ import {
3
+ Select,
4
+ SelectContent,
5
+ SelectItem,
6
+ SelectTrigger,
7
+ SelectValue,
8
+ } from "../../../../components/ui/select";
9
+ import { Button } from "../../../../components/ui/button";
10
+ import type { SortFieldConfig, SortState } from "../../utils/sortUtils";
11
+
12
+ const NONE_VALUE = "__none__";
13
+
14
+ interface SortControlProps {
15
+ configs: SortFieldConfig[];
16
+ sort: SortState | null;
17
+ onSortChange: (sort: SortState | null) => void;
18
+ className?: string;
19
+ }
20
+
21
+ export function SortControl({ configs, sort, onSortChange, className }: SortControlProps) {
22
+ if (configs.length === 0) return null;
23
+ return (
24
+ <div className={`flex items-center gap-2 ${className ?? ""}`}>
25
+ <span className="text-sm text-muted-foreground whitespace-nowrap">Sort by</span>
26
+ <Select
27
+ value={sort?.field ?? NONE_VALUE}
28
+ onValueChange={(v) => {
29
+ if (v === NONE_VALUE) onSortChange(null);
30
+ else onSortChange({ field: v, direction: sort?.direction ?? "ASC" });
31
+ }}
32
+ >
33
+ <SelectTrigger size="sm" className="w-[160px]">
34
+ <SelectValue placeholder="Default" />
35
+ </SelectTrigger>
36
+ <SelectContent>
37
+ <SelectItem value={NONE_VALUE}>Default</SelectItem>
38
+ {configs.map((c) => (
39
+ <SelectItem key={c.field} value={c.field}>
40
+ {c.label}
41
+ </SelectItem>
42
+ ))}
43
+ </SelectContent>
44
+ </Select>
45
+ {sort && (
46
+ <Button
47
+ variant="ghost"
48
+ size="icon-sm"
49
+ onClick={() =>
50
+ onSortChange({
51
+ ...sort,
52
+ direction: sort.direction === "ASC" ? "DESC" : "ASC",
53
+ })
54
+ }
55
+ aria-label={`Sort ${sort.direction === "ASC" ? "descending" : "ascending"}`}
56
+ >
57
+ {sort.direction === "ASC" ? <ArrowUp /> : <ArrowDown />}
58
+ </Button>
59
+ )}
60
+ </div>
61
+ );
62
+ }
@@ -0,0 +1,61 @@
1
+ import { X } from "lucide-react";
2
+ import { Button } from "../../../../components/ui/button";
3
+ import type { ActiveFilterValue } from "../../utils/filterUtils";
4
+
5
+ function formatLabel(filter: ActiveFilterValue): string {
6
+ const { label, type, value, min, max } = filter;
7
+ switch (type) {
8
+ case "text":
9
+ case "picklist":
10
+ return `${label}: ${value ?? ""}`;
11
+ case "multipicklist": {
12
+ const values = value ? value.split(",") : [];
13
+ if (values.length <= 2) return `${label}: ${values.join(", ")}`;
14
+ return `${label}: ${values.length} selected`;
15
+ }
16
+ case "boolean":
17
+ return `${label}: ${value === "true" ? "Yes" : "No"}`;
18
+ case "numeric": {
19
+ if (min && max) return `${label}: ${min} – ${max}`;
20
+ if (min) return `${label}: ≥ ${min}`;
21
+ return `${label}: ≤ ${max ?? ""}`;
22
+ }
23
+ case "date":
24
+ case "daterange":
25
+ case "datetime":
26
+ case "datetimerange": {
27
+ if (min && max) return `${label}: ${min} → ${max}`;
28
+ if (min) return `${label}: from ${min}`;
29
+ return `${label}: until ${max ?? ""}`;
30
+ }
31
+ default:
32
+ return label;
33
+ }
34
+ }
35
+
36
+ interface ActiveFiltersProps {
37
+ filters: ActiveFilterValue[];
38
+ onRemove: (field: string) => void;
39
+ className?: string;
40
+ }
41
+
42
+ export function ActiveFilters({ filters, onRemove, className }: ActiveFiltersProps) {
43
+ if (filters.length === 0) return null;
44
+ return (
45
+ <div className={`flex flex-wrap gap-2 ${className ?? ""}`}>
46
+ {filters.map((filter) => (
47
+ <Button
48
+ key={filter.field}
49
+ variant="outline"
50
+ size="sm"
51
+ className="gap-1 h-7 text-xs"
52
+ aria-label={`Remove ${formatLabel(filter)}`}
53
+ onClick={() => onRemove(filter.field)}
54
+ >
55
+ {formatLabel(filter)}
56
+ <X className="h-3 w-3" aria-hidden="true" />
57
+ </Button>
58
+ ))}
59
+ </div>
60
+ );
61
+ }
@@ -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
+ }