@schandlergarcia/sf-web-components 2.2.1 → 2.3.1

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 (61) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/brands/engine/app/api/graphql-operations-types.ts +11260 -0
  3. package/brands/engine/app/api/graphqlClient.ts +25 -0
  4. package/brands/engine/app/api/partnerQueries.ts +212 -0
  5. package/brands/engine/app/appLayout.tsx +13 -0
  6. package/brands/engine/app/components/AgentforceConversationClient.tsx +201 -0
  7. package/brands/engine/app/components/__inherit_AgentforceConversationClient.tsx +3 -0
  8. package/brands/engine/app/components/alerts/status-alert.tsx +49 -0
  9. package/brands/engine/app/components/layouts/card-layout.tsx +29 -0
  10. package/brands/engine/app/components/workspace/CommandCenter.tsx +16 -0
  11. package/brands/engine/app/config/agentApi.ts +36 -0
  12. package/brands/engine/app/features/object-search/__examples__/api/accountSearchService.ts +46 -0
  13. package/brands/engine/app/features/object-search/__examples__/api/query/distinctAccountIndustries.graphql +19 -0
  14. package/brands/engine/app/features/object-search/__examples__/api/query/distinctAccountTypes.graphql +19 -0
  15. package/brands/engine/app/features/object-search/__examples__/api/query/getAccountDetail.graphql +121 -0
  16. package/brands/engine/app/features/object-search/__examples__/api/query/searchAccounts.graphql +51 -0
  17. package/brands/engine/app/features/object-search/__examples__/pages/AccountObjectDetailPage.tsx +357 -0
  18. package/brands/engine/app/features/object-search/__examples__/pages/AccountSearch.tsx +312 -0
  19. package/brands/engine/app/features/object-search/__examples__/pages/Home.tsx +34 -0
  20. package/brands/engine/app/features/object-search/api/objectSearchService.ts +84 -0
  21. package/brands/engine/app/features/object-search/components/ActiveFilters.tsx +89 -0
  22. package/brands/engine/app/features/object-search/components/FilterContext.tsx +83 -0
  23. package/brands/engine/app/features/object-search/components/ObjectBreadcrumb.tsx +66 -0
  24. package/brands/engine/app/features/object-search/components/PaginationControls.tsx +109 -0
  25. package/brands/engine/app/features/object-search/components/SearchBar.tsx +41 -0
  26. package/brands/engine/app/features/object-search/components/SortControl.tsx +143 -0
  27. package/brands/engine/app/features/object-search/components/filters/BooleanFilter.tsx +78 -0
  28. package/brands/engine/app/features/object-search/components/filters/DateFilter.tsx +128 -0
  29. package/brands/engine/app/features/object-search/components/filters/DateRangeFilter.tsx +70 -0
  30. package/brands/engine/app/features/object-search/components/filters/FilterFieldWrapper.tsx +33 -0
  31. package/brands/engine/app/features/object-search/components/filters/MultiSelectFilter.tsx +97 -0
  32. package/brands/engine/app/features/object-search/components/filters/NumericRangeFilter.tsx +163 -0
  33. package/brands/engine/app/features/object-search/components/filters/SearchFilter.tsx +50 -0
  34. package/brands/engine/app/features/object-search/components/filters/SelectFilter.tsx +97 -0
  35. package/brands/engine/app/features/object-search/components/filters/TextFilter.tsx +91 -0
  36. package/brands/engine/app/features/object-search/hooks/useAsyncData.ts +54 -0
  37. package/brands/engine/app/features/object-search/hooks/useCachedAsyncData.ts +184 -0
  38. package/brands/engine/app/features/object-search/hooks/useDebouncedCallback.ts +34 -0
  39. package/brands/engine/app/features/object-search/hooks/useObjectSearchParams.ts +252 -0
  40. package/brands/engine/app/features/object-search/utils/debounce.ts +25 -0
  41. package/brands/engine/app/features/object-search/utils/fieldUtils.ts +29 -0
  42. package/brands/engine/app/features/object-search/utils/filterUtils.ts +404 -0
  43. package/brands/engine/app/features/object-search/utils/sortUtils.ts +38 -0
  44. package/brands/engine/app/hooks/useEngineLiveData.ts +49 -0
  45. package/brands/engine/app/hooks/useEvaAgent.ts +288 -0
  46. package/brands/engine/app/hooks/usePartnerDashboardData.ts +141 -0
  47. package/brands/engine/app/navigationMenu.tsx +80 -0
  48. package/brands/engine/app/pages/AccountObjectDetailPage.tsx +361 -0
  49. package/brands/engine/app/pages/AccountSearch.tsx +305 -0
  50. package/brands/engine/app/pages/BlankDashboard.tsx +15 -0
  51. package/brands/engine/app/pages/DataTest.tsx +78 -0
  52. package/brands/engine/app/pages/Home.tsx +5 -0
  53. package/brands/engine/app/pages/NotFound.tsx +19 -0
  54. package/brands/engine/app/pages/PartnerHubDashboard.tsx +2010 -0
  55. package/brands/engine/app/pages/Search.tsx +13 -0
  56. package/brands/engine/app/router-utils.tsx +35 -0
  57. package/brands/engine/app/routes.tsx +39 -0
  58. package/brands/engine/app/styles/global.css +270 -0
  59. package/package.json +1 -1
  60. package/scripts/apply-brand.mjs +160 -76
  61. package/scripts/postinstall.mjs +6 -0
@@ -0,0 +1,312 @@
1
+ import { useMemo, useState } from "react";
2
+ import { Link } from "react-router";
3
+ import { AlertCircle, ChevronDown, SearchX } from "lucide-react";
4
+ import {
5
+ searchAccounts,
6
+ fetchDistinctIndustries,
7
+ fetchDistinctTypes,
8
+ } from "../api/accountSearchService";
9
+ import { useCachedAsyncData } from "../../hooks/useCachedAsyncData";
10
+ import { fieldValue } from "../../utils/fieldUtils";
11
+ import { useObjectSearchParams } from "../../hooks/useObjectSearchParams";
12
+ import { Alert, AlertTitle, AlertDescription } from "../../../../components/ui/alert";
13
+ import {
14
+ Card,
15
+ CardContent,
16
+ CardHeader,
17
+ CardTitle,
18
+ } from "../../../../components/ui/card";
19
+ import { Button } from "../../../../components/ui/button";
20
+ import {
21
+ Collapsible,
22
+ CollapsibleContent,
23
+ CollapsibleTrigger,
24
+ } from "../../../../components/ui/collapsible";
25
+ import { Skeleton } from "../../../../components/ui/skeleton";
26
+ import { FilterProvider, FilterResetButton } from "../../components/FilterContext";
27
+ import { SearchFilter } from "../../components/filters/SearchFilter";
28
+ import { TextFilter } from "../../components/filters/TextFilter";
29
+ import { SelectFilter } from "../../components/filters/SelectFilter";
30
+ import { MultiSelectFilter } from "../../components/filters/MultiSelectFilter";
31
+ import { NumericRangeFilter } from "../../components/filters/NumericRangeFilter";
32
+ import { DateFilter } from "../../components/filters/DateFilter";
33
+ import { DateRangeFilter } from "../../components/filters/DateRangeFilter";
34
+ import { ActiveFilters } from "../../components/ActiveFilters";
35
+ import { SortControl } from "../../components/SortControl";
36
+ import type { FilterFieldConfig } from "../../utils/filterUtils";
37
+ import type { SortFieldConfig } from "../../utils/sortUtils";
38
+ import type { Account_Filter, Account_OrderBy } from "../../../../api/graphql-operations-types";
39
+ import type { AccountSearchResult } from "../api/accountSearchService";
40
+ import { ObjectBreadcrumb } from "../../components/ObjectBreadcrumb";
41
+ import PaginationControls from "../../components/PaginationControls";
42
+ import type { PaginationConfig } from "../../hooks/useObjectSearchParams";
43
+
44
+ const PAGINATION_CONFIG: PaginationConfig = {
45
+ defaultPageSize: 6,
46
+ validPageSizes: [6, 12, 24, 48],
47
+ };
48
+
49
+ type AccountNode = NonNullable<
50
+ NonNullable<NonNullable<AccountSearchResult["edges"]>[number]>["node"]
51
+ >;
52
+
53
+ const FILTER_CONFIGS: FilterFieldConfig[] = [
54
+ {
55
+ field: "search",
56
+ label: "Search",
57
+ type: "search",
58
+ searchFields: ["Name", "Phone", "Industry"],
59
+ placeholder: "Search by name, phone, or industry...",
60
+ },
61
+ { field: "Name", label: "Account Name", type: "text", placeholder: "Search by name..." },
62
+ { field: "Industry", label: "Industry", type: "picklist" },
63
+ { field: "Type", label: "Type", type: "multipicklist" },
64
+ { field: "AnnualRevenue", label: "Annual Revenue", type: "numeric" },
65
+ { field: "CreatedDate", label: "Created Date", type: "datetime" },
66
+ { field: "LastModifiedDate", label: "Last Modified Date", type: "datetimerange" },
67
+ ];
68
+
69
+ const ACCOUNT_SORT_CONFIGS: SortFieldConfig<keyof Account_OrderBy>[] = [
70
+ { field: "Name", label: "Name" },
71
+ { field: "AnnualRevenue", label: "Annual Revenue" },
72
+ { field: "Industry", label: "Industry" },
73
+ { field: "CreatedDate", label: "Created Date" },
74
+ ];
75
+
76
+ // -- Component --------------------------------------------------------------
77
+
78
+ export default function AccountSearch() {
79
+ const [filtersOpen, setFiltersOpen] = useState(true);
80
+ const { data: industryOptions } = useCachedAsyncData(fetchDistinctIndustries, [], {
81
+ key: "distinctIndustries",
82
+ ttl: 300_000,
83
+ });
84
+ const { data: typeOptions } = useCachedAsyncData(fetchDistinctTypes, [], {
85
+ key: "distinctTypes",
86
+ ttl: 300_000,
87
+ });
88
+
89
+ const { filters, sort, query, pagination, resetAll } = useObjectSearchParams<
90
+ Account_Filter,
91
+ Account_OrderBy
92
+ >(FILTER_CONFIGS, ACCOUNT_SORT_CONFIGS, PAGINATION_CONFIG);
93
+
94
+ const searchKey = `accounts:${JSON.stringify({ where: query.where, orderBy: query.orderBy, first: pagination.pageSize, after: pagination.afterCursor })}`;
95
+ const { data, loading, error } = useCachedAsyncData(
96
+ () =>
97
+ searchAccounts({
98
+ where: query.where,
99
+ orderBy: query.orderBy,
100
+ first: pagination.pageSize,
101
+ after: pagination.afterCursor,
102
+ }),
103
+ [query.where, query.orderBy, pagination.pageSize, pagination.afterCursor],
104
+ { key: searchKey },
105
+ );
106
+
107
+ const pageInfo = data?.pageInfo;
108
+ const totalCount = data?.totalCount;
109
+ const hasNextPage = pageInfo?.hasNextPage ?? false;
110
+ const hasPreviousPage = pagination.pageIndex > 0;
111
+
112
+ const validAccountNodes = useMemo(
113
+ () =>
114
+ (data?.edges ?? []).reduce<AccountNode[]>((acc, edge) => {
115
+ if (edge?.node) acc.push(edge.node);
116
+ return acc;
117
+ }, []),
118
+ [data?.edges],
119
+ );
120
+
121
+ return (
122
+ <div className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
123
+ <ObjectBreadcrumb listPath="/accounts" listLabel="Accounts" />
124
+
125
+ <h1 className="text-2xl font-bold mb-4">Search Accounts</h1>
126
+
127
+ <div className="flex flex-col lg:flex-row gap-6">
128
+ {/* Sidebar — Filter Panel */}
129
+ <aside className="w-full lg:w-80 shrink-0">
130
+ <FilterProvider
131
+ filters={filters.active}
132
+ onFilterChange={filters.set}
133
+ onFilterRemove={filters.remove}
134
+ onReset={resetAll}
135
+ >
136
+ <Card>
137
+ <Collapsible open={filtersOpen} onOpenChange={setFiltersOpen}>
138
+ <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
139
+ <CardTitle className="text-base font-semibold">
140
+ <h2>Filters</h2>
141
+ </CardTitle>
142
+ <div className="flex items-center gap-1">
143
+ <FilterResetButton variant="destructive" size="sm" />
144
+ <CollapsibleTrigger asChild>
145
+ <Button variant="ghost" size="icon">
146
+ <ChevronDown
147
+ className={`h-4 w-4 transition-transform ${filtersOpen ? "" : "-rotate-90"}`}
148
+ />
149
+ <span className="sr-only">Toggle filters</span>
150
+ </Button>
151
+ </CollapsibleTrigger>
152
+ </div>
153
+ </CardHeader>
154
+ <CollapsibleContent>
155
+ <CardContent className="space-y-1 pt-0">
156
+ <SearchFilter
157
+ field="search"
158
+ label="Search"
159
+ placeholder="Search by name, phone, or industry..."
160
+ />
161
+ <TextFilter field="Name" label="Account Name" placeholder="Search by name..." />
162
+ <SelectFilter
163
+ field="Industry"
164
+ label="Industry"
165
+ options={industryOptions ?? []}
166
+ />
167
+ <MultiSelectFilter field="Type" label="Type" options={typeOptions ?? []} />
168
+ <NumericRangeFilter
169
+ field="AnnualRevenue"
170
+ label="Annual Revenue"
171
+ min={0}
172
+ max={1_000_000_000_000}
173
+ />
174
+ <DateFilter field="CreatedDate" label="Created Date" filterType="datetime" />
175
+ <DateRangeFilter
176
+ field="LastModifiedDate"
177
+ label="Last Modified Date"
178
+ filterType="datetimerange"
179
+ />
180
+ </CardContent>
181
+ </CollapsibleContent>
182
+ </Collapsible>
183
+ </Card>
184
+ </FilterProvider>
185
+ </aside>
186
+
187
+ {/* Main area — Sort + Results */}
188
+ <div className="flex-1 min-w-0">
189
+ {/* Sort control + active filters */}
190
+ <div className="flex flex-wrap items-center gap-2 mb-4">
191
+ <SortControl
192
+ configs={ACCOUNT_SORT_CONFIGS}
193
+ sort={sort.current}
194
+ onSortChange={sort.set}
195
+ />
196
+ <ActiveFilters filters={filters.active} onRemove={filters.remove} />
197
+ </div>
198
+
199
+ <div className="min-h-112">
200
+ {/* Loading state */}
201
+ {loading && (
202
+ <>
203
+ <Skeleton className="h-5 w-30 mb-3" />
204
+ <div className="divide-y">
205
+ {Array.from({ length: pagination.pageSize }, (_, i) => (
206
+ <div key={i} className="flex items-center justify-between py-3">
207
+ <div className="space-y-2">
208
+ <Skeleton className="h-5 w-40" />
209
+ <Skeleton className="h-4 w-28" />
210
+ </div>
211
+ <div className="space-y-2 flex flex-col items-end">
212
+ <Skeleton className="h-4 w-24" />
213
+ <Skeleton className="h-4 w-20" />
214
+ </div>
215
+ </div>
216
+ ))}
217
+ </div>
218
+ </>
219
+ )}
220
+
221
+ {/* Error state */}
222
+ {error && (
223
+ <>
224
+ <p className="text-sm text-muted-foreground mb-3">0 accounts found</p>
225
+ <Alert variant="destructive" role="alert">
226
+ <AlertCircle />
227
+ <AlertTitle>Failed to load accounts</AlertTitle>
228
+ <AlertDescription>
229
+ Something went wrong while loading accounts. Please try again later.
230
+ </AlertDescription>
231
+ </Alert>
232
+ </>
233
+ )}
234
+
235
+ {/* Results list */}
236
+ {!loading && !error && validAccountNodes.length > 0 && (
237
+ <>
238
+ <p className="text-sm text-muted-foreground mb-3">
239
+ {totalCount != null && (hasNextPage || hasPreviousPage)
240
+ ? `${totalCount} account${totalCount !== 1 ? "s" : ""} found`
241
+ : `Showing ${validAccountNodes.length} account${validAccountNodes.length !== 1 ? "s" : ""}`}
242
+ </p>
243
+ <AccountResultsList nodes={validAccountNodes} />
244
+ </>
245
+ )}
246
+
247
+ {/* No results state */}
248
+ {!loading && !error && validAccountNodes.length === 0 && (
249
+ <div className="flex flex-col items-center justify-center py-16 text-center">
250
+ <SearchX className="size-12 text-muted-foreground mb-4" />
251
+ <h2 className="text-lg font-semibold mb-1">No accounts found</h2>
252
+ <p className="text-sm text-muted-foreground">
253
+ Try adjusting your filters or search criteria.
254
+ </p>
255
+ </div>
256
+ )}
257
+ </div>
258
+
259
+ {/* Pagination — always visible, disabled while loading or on error */}
260
+ <PaginationControls
261
+ pageIndex={pagination.pageIndex}
262
+ hasNextPage={hasNextPage}
263
+ hasPreviousPage={hasPreviousPage}
264
+ pageSize={pagination.pageSize}
265
+ pageSizeOptions={PAGINATION_CONFIG.validPageSizes}
266
+ onNextPage={() => {
267
+ if (pageInfo?.endCursor) pagination.goToNextPage(pageInfo.endCursor);
268
+ }}
269
+ onPreviousPage={pagination.goToPreviousPage}
270
+ onPageSizeChange={pagination.setPageSize}
271
+ disabled={loading || !!error}
272
+ />
273
+ </div>
274
+ </div>
275
+ </div>
276
+ );
277
+ }
278
+
279
+ // -- Result Components ------------------------------------------------------
280
+
281
+ function AccountResultsList({ nodes }: { nodes: AccountNode[] }) {
282
+ return (
283
+ <ul className="divide-y">
284
+ {nodes.map((node) => (
285
+ <AccountResultItem key={node.Id} node={node} />
286
+ ))}
287
+ </ul>
288
+ );
289
+ }
290
+
291
+ function AccountResultItem({ node }: { node: AccountNode }) {
292
+ return (
293
+ <li>
294
+ <Link
295
+ to={`/accounts/${node.Id}`}
296
+ className="flex items-center justify-between py-3 px-3 -mx-3 rounded-md transition-colors hover:bg-accent"
297
+ >
298
+ <div>
299
+ <span className="font-medium">{fieldValue(node.Name) ?? "\u2014"}</span>
300
+ <p className="text-sm text-muted-foreground">
301
+ {[fieldValue(node.Industry), fieldValue(node.Type)].filter(Boolean).join(" \u00B7 ") ||
302
+ "\u2014"}
303
+ </p>
304
+ </div>
305
+ <div className="text-right text-sm">
306
+ <p>{fieldValue(node.Phone) ?? ""}</p>
307
+ <p className="text-muted-foreground">{fieldValue(node.Owner?.Name) ?? ""}</p>
308
+ </div>
309
+ </Link>
310
+ </li>
311
+ );
312
+ }
@@ -0,0 +1,34 @@
1
+ import { useState } from "react";
2
+ import { useNavigate } from "react-router";
3
+ import { SearchBar } from "../../components/SearchBar";
4
+ import { Button } from "../../../../components/ui/button";
5
+
6
+ export default function HomePage() {
7
+ const navigate = useNavigate();
8
+ const [text, setText] = useState("");
9
+
10
+ const handleSubmit = (e: React.SyntheticEvent<HTMLFormElement>) => {
11
+ e.preventDefault();
12
+ const params = text ? `?q=${encodeURIComponent(text)}` : "";
13
+ navigate(`/accounts${params}`);
14
+ };
15
+
16
+ return (
17
+ <div className="max-w-2xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
18
+ <div className="flex items-center gap-6 mb-6">
19
+ <h1 className="text-2xl font-bold">Account Search</h1>
20
+ <Button variant="outline" size="sm" onClick={() => navigate("/accounts")}>
21
+ Browse All Accounts
22
+ </Button>
23
+ </div>
24
+ <form onSubmit={handleSubmit} className="flex gap-2">
25
+ <SearchBar
26
+ placeholder="Search by name, phone, or industry..."
27
+ value={text}
28
+ handleChange={setText}
29
+ />
30
+ <Button type="submit">Search</Button>
31
+ </form>
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,84 @@
1
+ import { createDataSDK } from "@salesforce/sdk-data";
2
+
3
+ export interface ObjectSearchOptions<TWhere, TOrderBy> {
4
+ where?: TWhere;
5
+ orderBy?: TOrderBy;
6
+ first?: number;
7
+ after?: string;
8
+ }
9
+
10
+ export type PicklistOption = { value: string; label: string };
11
+
12
+ /**
13
+ * Executes a GraphQL search query and extracts the result for the given object name
14
+ * from the standard `uiapi.query.<ObjectName>` response shape.
15
+ */
16
+ export async function searchObjects<TResult, TQuery, TVariables>(
17
+ query: string,
18
+ objectName: string,
19
+ options: ObjectSearchOptions<unknown, unknown> = {},
20
+ ): Promise<TResult> {
21
+ const { where, orderBy, first = 20, after } = options;
22
+
23
+ const data = await createDataSDK();
24
+ const response = await data.graphql?.<TQuery, TVariables>(query, {
25
+ first,
26
+ after,
27
+ where,
28
+ orderBy,
29
+ } as TVariables);
30
+
31
+ if (response?.errors?.length) {
32
+ throw new Error(response.errors.map((e) => e.message).join("; "));
33
+ }
34
+
35
+ const result = (response?.data as Record<string, unknown> | undefined)?.uiapi as
36
+ | Record<string, unknown>
37
+ | undefined;
38
+ const queryResult = (result?.query as Record<string, unknown> | undefined)?.[objectName] as
39
+ | TResult
40
+ | undefined;
41
+
42
+ if (!queryResult) {
43
+ throw new Error(`No ${objectName} data returned`);
44
+ }
45
+
46
+ return queryResult;
47
+ }
48
+
49
+ /**
50
+ * Executes a GraphQL aggregate/groupBy query and extracts picklist options
51
+ * from the standard `uiapi.aggregate.<ObjectName>` response shape.
52
+ */
53
+ export async function fetchDistinctValues<TQuery>(
54
+ query: string,
55
+ objectName: string,
56
+ fieldName: string,
57
+ ): Promise<PicklistOption[]> {
58
+ const data = await createDataSDK();
59
+ const response = await data.graphql?.<TQuery>(query);
60
+ const errors = response?.errors;
61
+
62
+ if (errors?.length) {
63
+ throw new Error(errors.map((e) => e.message).join("; "));
64
+ }
65
+
66
+ const result = (response?.data as Record<string, unknown> | undefined)?.uiapi as
67
+ | Record<string, unknown>
68
+ | undefined;
69
+ const aggregate = (result?.aggregate as Record<string, unknown> | undefined)?.[objectName] as
70
+ | { edges?: Array<{ node?: { aggregate?: Record<string, unknown> } }> }
71
+ | undefined;
72
+
73
+ const edges = aggregate?.edges ?? [];
74
+ return edges
75
+ .map((edge) => {
76
+ const field = edge?.node?.aggregate?.[fieldName] as
77
+ | { value?: string | null; displayValue?: string | null; label?: string | null }
78
+ | undefined;
79
+ const value = field?.value;
80
+ if (!value) return null;
81
+ return { value, label: field.label ?? field.displayValue ?? value };
82
+ })
83
+ .filter((opt): opt is PicklistOption => opt !== null);
84
+ }
@@ -0,0 +1,89 @@
1
+ import { X } from "lucide-react";
2
+ import { Button } from "../../../components/ui/button";
3
+ import { cn } from "../../../lib/utils";
4
+ import type { ActiveFilterValue } from "../utils/filterUtils";
5
+
6
+ function formatFilterLabel(filter: ActiveFilterValue): string {
7
+ const { label, type, value, min, max } = filter;
8
+
9
+ switch (type) {
10
+ case "search":
11
+ return `Search: ${value}`;
12
+ case "text":
13
+ case "picklist":
14
+ return `${label}: ${value}`;
15
+ case "multipicklist": {
16
+ const values = value ? value.split(",") : [];
17
+ if (values.length <= 2) return `${label}: ${values.join(", ")}`;
18
+ return `${label}: ${values.length} selected`;
19
+ }
20
+ case "boolean":
21
+ return `${label}: ${value === "true" ? "Yes" : "No"}`;
22
+ case "numeric": {
23
+ if (min && max) return `${label}: ${min} - ${max}`;
24
+ if (min) return `${label}: >= ${min}`;
25
+ return `${label}: <= ${max}`;
26
+ }
27
+ case "date": {
28
+ if (min && max) return `${label}: ${min} to ${max}`;
29
+ if (min) return `${label}: from ${min}`;
30
+ return `${label}: until ${max}`;
31
+ }
32
+ default:
33
+ return label;
34
+ }
35
+ }
36
+
37
+ interface ActiveFiltersProps extends React.ComponentProps<"div"> {
38
+ filters: ActiveFilterValue[];
39
+ onRemove: (field: string) => void;
40
+ buttonProps?: Omit<React.ComponentProps<typeof ActiveFilterButton>, "filter" | "onRemove">;
41
+ }
42
+
43
+ export function ActiveFilters({
44
+ filters,
45
+ onRemove,
46
+ className,
47
+ buttonProps,
48
+ ...props
49
+ }: ActiveFiltersProps) {
50
+ if (filters.length === 0) return null;
51
+
52
+ return (
53
+ <div className={cn("flex flex-wrap gap-2", className)} {...props}>
54
+ {filters.map((filter) => (
55
+ <ActiveFilterButton
56
+ key={filter.field}
57
+ filter={filter}
58
+ onRemove={onRemove}
59
+ {...buttonProps}
60
+ />
61
+ ))}
62
+ </div>
63
+ );
64
+ }
65
+
66
+ interface ActiveFilterButtonProps extends React.ComponentProps<typeof Button> {
67
+ filter: ActiveFilterValue;
68
+ onRemove: (field: string) => void;
69
+ }
70
+
71
+ export function ActiveFilterButton({
72
+ filter,
73
+ onRemove,
74
+ className,
75
+ ...props
76
+ }: ActiveFilterButtonProps) {
77
+ return (
78
+ <Button
79
+ variant="outline"
80
+ size="sm"
81
+ className={cn("gap-1 h-7 text-xs", className)}
82
+ onClick={() => onRemove(filter.field)}
83
+ {...props}
84
+ >
85
+ {formatFilterLabel(filter)}
86
+ <X className="h-3 w-3" />
87
+ </Button>
88
+ );
89
+ }
@@ -0,0 +1,83 @@
1
+ import { createContext, useContext, useCallback, type ReactNode } from "react";
2
+ import { Button } from "../../../components/ui/button";
3
+ import type { ActiveFilterValue } from "../utils/filterUtils";
4
+
5
+ interface FilterContextValue {
6
+ filters: ActiveFilterValue[];
7
+ onFilterChange: (field: string, value: ActiveFilterValue | undefined) => void;
8
+ onFilterRemove: (field: string) => void;
9
+ onReset: () => void;
10
+ }
11
+
12
+ const FilterContext = createContext<FilterContextValue | null>(null);
13
+
14
+ interface FilterProviderProps {
15
+ filters: ActiveFilterValue[];
16
+ onFilterChange: (field: string, value: ActiveFilterValue | undefined) => void;
17
+ onFilterRemove: (field: string) => void;
18
+ onReset: () => void;
19
+ children: ReactNode;
20
+ }
21
+
22
+ export function FilterProvider({
23
+ filters,
24
+ onFilterChange,
25
+ onFilterRemove,
26
+ onReset,
27
+ children,
28
+ }: FilterProviderProps) {
29
+ return (
30
+ <FilterContext.Provider
31
+ value={{
32
+ filters,
33
+ onFilterChange,
34
+ onFilterRemove,
35
+ onReset,
36
+ }}
37
+ >
38
+ {children}
39
+ </FilterContext.Provider>
40
+ );
41
+ }
42
+
43
+ function useFilterContext() {
44
+ const ctx = useContext(FilterContext);
45
+ if (!ctx) throw new Error("useFilterField must be used within a FilterProvider");
46
+ return ctx;
47
+ }
48
+
49
+ export function useFilterField(field: string) {
50
+ const { filters, onFilterChange, onFilterRemove } = useFilterContext();
51
+ const value = filters.find((f) => f.field === field);
52
+ const onChange = useCallback(
53
+ (next: ActiveFilterValue | undefined) => {
54
+ if (next) {
55
+ onFilterChange(field, next);
56
+ } else {
57
+ onFilterRemove(field);
58
+ }
59
+ },
60
+ [field, onFilterChange, onFilterRemove],
61
+ );
62
+ return { value, onChange };
63
+ }
64
+
65
+ export function useFilterPanel() {
66
+ const { filters, onReset } = useFilterContext();
67
+ return {
68
+ hasActiveFilters: filters.length > 0,
69
+ resetAll: onReset,
70
+ };
71
+ }
72
+
73
+ type FilterResetButtonProps = Omit<React.ComponentProps<typeof Button>, "onClick">;
74
+
75
+ export function FilterResetButton({ children, ...props }: FilterResetButtonProps) {
76
+ const { hasActiveFilters, resetAll } = useFilterPanel();
77
+ if (!hasActiveFilters) return null;
78
+ return (
79
+ <Button onClick={resetAll} aria-label="Reset filters" variant="destructive" {...props}>
80
+ {children ?? "Reset"}
81
+ </Button>
82
+ );
83
+ }
@@ -0,0 +1,66 @@
1
+ import { Link } from "react-router";
2
+ import {
3
+ Breadcrumb,
4
+ BreadcrumbList,
5
+ BreadcrumbItem,
6
+ BreadcrumbLink,
7
+ BreadcrumbSeparator,
8
+ BreadcrumbPage,
9
+ } from "../../../components/ui/breadcrumb";
10
+ import { Skeleton } from "../../../components/ui/skeleton";
11
+
12
+ interface ObjectBreadcrumbProps {
13
+ listPath: string;
14
+ listLabel: string;
15
+ recordName?: string;
16
+ loading?: boolean;
17
+ includeHome?: boolean; // default is true
18
+ homeLabel?: string; // default is "Home"
19
+ }
20
+
21
+ export function ObjectBreadcrumb({
22
+ listPath,
23
+ listLabel,
24
+ recordName,
25
+ loading,
26
+ includeHome = true,
27
+ homeLabel = "Home",
28
+ }: ObjectBreadcrumbProps) {
29
+ const isDetailView = loading || recordName;
30
+
31
+ return (
32
+ <Breadcrumb className="mb-3">
33
+ <BreadcrumbList>
34
+ {includeHome && (
35
+ <BreadcrumbItem>
36
+ <BreadcrumbLink asChild>
37
+ <Link to="/">{homeLabel}</Link>
38
+ </BreadcrumbLink>
39
+ </BreadcrumbItem>
40
+ )}
41
+ <BreadcrumbSeparator />
42
+ {isDetailView ? (
43
+ <>
44
+ <BreadcrumbItem>
45
+ <BreadcrumbLink asChild>
46
+ <Link to={listPath}>{listLabel}</Link>
47
+ </BreadcrumbLink>
48
+ </BreadcrumbItem>
49
+ <BreadcrumbSeparator />
50
+ <BreadcrumbItem>
51
+ {loading && !recordName ? (
52
+ <Skeleton className="h-4 w-32" />
53
+ ) : (
54
+ <BreadcrumbPage>{recordName}</BreadcrumbPage>
55
+ )}
56
+ </BreadcrumbItem>
57
+ </>
58
+ ) : (
59
+ <BreadcrumbItem>
60
+ <BreadcrumbPage>{listLabel}</BreadcrumbPage>
61
+ </BreadcrumbItem>
62
+ )}
63
+ </BreadcrumbList>
64
+ </Breadcrumb>
65
+ );
66
+ }