@salesforce/ui-bundle-template-feature-react-search 11.3.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 (169) hide show
  1. package/LICENSE.txt +82 -0
  2. package/README.md +692 -0
  3. package/dist/.forceignore +15 -0
  4. package/dist/.husky/pre-commit +4 -0
  5. package/dist/.prettierignore +11 -0
  6. package/dist/.prettierrc +17 -0
  7. package/dist/CHANGELOG.md +3499 -0
  8. package/dist/README.md +28 -0
  9. package/dist/config/project-scratch-def.json +13 -0
  10. package/dist/eslint.config.js +7 -0
  11. package/dist/force-app/main/default/uiBundles/feature-react-search/.forceignore +15 -0
  12. package/dist/force-app/main/default/uiBundles/feature-react-search/.graphqlrc.yml +2 -0
  13. package/dist/force-app/main/default/uiBundles/feature-react-search/.prettierignore +9 -0
  14. package/dist/force-app/main/default/uiBundles/feature-react-search/.prettierrc +11 -0
  15. package/dist/force-app/main/default/uiBundles/feature-react-search/CHANGELOG.md +10 -0
  16. package/dist/force-app/main/default/uiBundles/feature-react-search/README.md +75 -0
  17. package/dist/force-app/main/default/uiBundles/feature-react-search/codegen.yml +95 -0
  18. package/dist/force-app/main/default/uiBundles/feature-react-search/components.json +18 -0
  19. package/dist/force-app/main/default/uiBundles/feature-react-search/e2e/app.spec.ts +17 -0
  20. package/dist/force-app/main/default/uiBundles/feature-react-search/eslint.config.js +169 -0
  21. package/dist/force-app/main/default/uiBundles/feature-react-search/feature-react-search.uibundle-meta.xml +7 -0
  22. package/dist/force-app/main/default/uiBundles/feature-react-search/index.html +12 -0
  23. package/dist/force-app/main/default/uiBundles/feature-react-search/package.json +76 -0
  24. package/dist/force-app/main/default/uiBundles/feature-react-search/playwright.config.ts +24 -0
  25. package/dist/force-app/main/default/uiBundles/feature-react-search/scripts/get-graphql-schema.mjs +71 -0
  26. package/dist/force-app/main/default/uiBundles/feature-react-search/scripts/rewrite-e2e-assets.mjs +23 -0
  27. package/dist/force-app/main/default/uiBundles/feature-react-search/src/api/graphqlClient.ts +44 -0
  28. package/dist/force-app/main/default/uiBundles/feature-react-search/src/app.tsx +17 -0
  29. package/dist/force-app/main/default/uiBundles/feature-react-search/src/appLayout.tsx +83 -0
  30. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/icons/book.svg +3 -0
  31. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/icons/copy.svg +4 -0
  32. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/icons/rocket.svg +3 -0
  33. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/icons/star.svg +3 -0
  34. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/images/codey-1.png +0 -0
  35. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/images/codey-2.png +0 -0
  36. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/images/codey-3.png +0 -0
  37. package/dist/force-app/main/default/uiBundles/feature-react-search/src/assets/images/vibe-codey.svg +194 -0
  38. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/alerts/status-alert.tsx +52 -0
  39. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/layouts/card-layout.tsx +29 -0
  40. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/alert.tsx +76 -0
  41. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/avatar.tsx +109 -0
  42. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/badge.tsx +48 -0
  43. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/breadcrumb.tsx +109 -0
  44. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/button.tsx +67 -0
  45. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/calendar.tsx +232 -0
  46. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/card.tsx +103 -0
  47. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/checkbox.tsx +32 -0
  48. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/collapsible.tsx +33 -0
  49. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/datePicker.tsx +127 -0
  50. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/dialog.tsx +162 -0
  51. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/dropdown-menu.tsx +257 -0
  52. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/field.tsx +237 -0
  53. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/index.ts +109 -0
  54. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/input.tsx +19 -0
  55. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/label.tsx +22 -0
  56. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/pagination.tsx +132 -0
  57. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/popover.tsx +89 -0
  58. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/select.tsx +193 -0
  59. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/separator.tsx +26 -0
  60. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/skeleton.tsx +14 -0
  61. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/sonner.tsx +20 -0
  62. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/spinner.tsx +16 -0
  63. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/table.tsx +114 -0
  64. package/dist/force-app/main/default/uiBundles/feature-react-search/src/components/ui/tabs.tsx +88 -0
  65. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/api/distinctValuesService.ts +84 -0
  66. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/api/searchService.ts +71 -0
  67. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/Search.tsx +160 -0
  68. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/SearchResults.tsx +77 -0
  69. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/SourceSection.tsx +167 -0
  70. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/PaginationControls.tsx +115 -0
  71. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/ScopeSelector.tsx +55 -0
  72. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/SearchBar.tsx +55 -0
  73. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/SortControl.tsx +62 -0
  74. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/ActiveFilters.tsx +61 -0
  75. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/DefaultFilterPanel.tsx +122 -0
  76. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/FilterContext.tsx +70 -0
  77. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/BooleanFilter.tsx +50 -0
  78. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/DateRangeFilter.tsx +50 -0
  79. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/FilterFieldWrapper.tsx +26 -0
  80. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/MultiSelectFilter.tsx +47 -0
  81. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/NumericRangeFilter.tsx +78 -0
  82. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/SelectFilter.tsx +46 -0
  83. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/TextFilter.tsx +52 -0
  84. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/results/DefaultResultRow.tsx +109 -0
  85. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/config.json +82 -0
  86. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/hooks/useAsyncData.ts +56 -0
  87. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/hooks/useDistinctValues.ts +59 -0
  88. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/hooks/useSearch.ts +442 -0
  89. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/index.ts +80 -0
  90. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/loadConfig.ts +14 -0
  91. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/queryBuilder.ts +156 -0
  92. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/types.ts +169 -0
  93. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/debounce.ts +17 -0
  94. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/fieldUtils.ts +14 -0
  95. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/filterUtils.ts +272 -0
  96. package/dist/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/sortUtils.ts +34 -0
  97. package/dist/force-app/main/default/uiBundles/feature-react-search/src/hooks/useAsyncData.ts +67 -0
  98. package/dist/force-app/main/default/uiBundles/feature-react-search/src/lib/utils.ts +6 -0
  99. package/dist/force-app/main/default/uiBundles/feature-react-search/src/navigationMenu.tsx +80 -0
  100. package/dist/force-app/main/default/uiBundles/feature-react-search/src/pages/Home.tsx +11 -0
  101. package/dist/force-app/main/default/uiBundles/feature-react-search/src/pages/NotFound.tsx +18 -0
  102. package/dist/force-app/main/default/uiBundles/feature-react-search/src/router-utils.tsx +35 -0
  103. package/dist/force-app/main/default/uiBundles/feature-react-search/src/routes.tsx +22 -0
  104. package/dist/force-app/main/default/uiBundles/feature-react-search/src/styles/global.css +135 -0
  105. package/dist/force-app/main/default/uiBundles/feature-react-search/tsconfig.json +45 -0
  106. package/dist/force-app/main/default/uiBundles/feature-react-search/tsconfig.node.json +13 -0
  107. package/dist/force-app/main/default/uiBundles/feature-react-search/ui-bundle.json +7 -0
  108. package/dist/force-app/main/default/uiBundles/feature-react-search/vite-env.d.ts +4 -0
  109. package/dist/force-app/main/default/uiBundles/feature-react-search/vite.config.ts +106 -0
  110. package/dist/force-app/main/default/uiBundles/feature-react-search/vitest-env.d.ts +2 -0
  111. package/dist/force-app/main/default/uiBundles/feature-react-search/vitest.config.ts +11 -0
  112. package/dist/force-app/main/default/uiBundles/feature-react-search/vitest.setup.ts +1 -0
  113. package/dist/jest.config.js +6 -0
  114. package/dist/package-lock.json +9995 -0
  115. package/dist/package.json +44 -0
  116. package/dist/scripts/apex/hello.apex +10 -0
  117. package/dist/scripts/gitignore-templates.json +4 -0
  118. package/dist/scripts/graphql-search.sh +191 -0
  119. package/dist/scripts/org-setup-config-schema.mjs +96 -0
  120. package/dist/scripts/org-setup.config.json +5 -0
  121. package/dist/scripts/org-setup.mjs +1392 -0
  122. package/dist/scripts/sf-project-setup.mjs +103 -0
  123. package/dist/scripts/soql/account.soql +6 -0
  124. package/dist/scripts/validate-org-setup-config.mjs +38 -0
  125. package/dist/sfdx-project.json +12 -0
  126. package/package.json +51 -0
  127. package/src/force-app/main/default/uiBundles/feature-react-search/src/__inherit__appLayout.tsx +9 -0
  128. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__alert.tsx +39 -0
  129. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__button.tsx +45 -0
  130. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__checkbox.tsx +8 -0
  131. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__input.tsx +5 -0
  132. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__label.tsx +8 -0
  133. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__pagination.tsx +47 -0
  134. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__select.tsx +57 -0
  135. package/src/force-app/main/default/uiBundles/feature-react-search/src/components/ui/__inherit__skeleton.tsx +5 -0
  136. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/api/distinctValuesService.ts +84 -0
  137. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/api/searchService.ts +71 -0
  138. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/Search.tsx +160 -0
  139. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/SearchResults.tsx +77 -0
  140. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/SourceSection.tsx +167 -0
  141. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/PaginationControls.tsx +115 -0
  142. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/ScopeSelector.tsx +55 -0
  143. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/SearchBar.tsx +55 -0
  144. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/controls/SortControl.tsx +62 -0
  145. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/ActiveFilters.tsx +61 -0
  146. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/DefaultFilterPanel.tsx +122 -0
  147. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/FilterContext.tsx +70 -0
  148. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/BooleanFilter.tsx +50 -0
  149. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/DateRangeFilter.tsx +50 -0
  150. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/FilterFieldWrapper.tsx +26 -0
  151. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/MultiSelectFilter.tsx +47 -0
  152. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/NumericRangeFilter.tsx +78 -0
  153. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/SelectFilter.tsx +46 -0
  154. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/filters/inputs/TextFilter.tsx +52 -0
  155. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/components/results/DefaultResultRow.tsx +109 -0
  156. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/config.json +82 -0
  157. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/hooks/useAsyncData.ts +56 -0
  158. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/hooks/useDistinctValues.ts +59 -0
  159. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/hooks/useSearch.ts +442 -0
  160. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/index.ts +80 -0
  161. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/loadConfig.ts +14 -0
  162. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/queryBuilder.ts +156 -0
  163. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/types.ts +169 -0
  164. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/debounce.ts +17 -0
  165. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/fieldUtils.ts +14 -0
  166. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/filterUtils.ts +272 -0
  167. package/src/force-app/main/default/uiBundles/feature-react-search/src/features/search/utils/sortUtils.ts +34 -0
  168. package/src/force-app/main/default/uiBundles/feature-react-search/src/pages/Home.tsx +11 -0
  169. package/src/force-app/main/default/uiBundles/feature-react-search/src/routes.tsx +10 -0
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Default per-node row used when no `renderResult` is supplied for a source.
3
+ *
4
+ * Layout:
5
+ * - Title: first entry in `displayFields` (preferring displayValue).
6
+ * - Subtitle: remaining display fields joined with " · ".
7
+ * - When `routePattern` is configured on the source, the row is wrapped in
8
+ * a react-router `<Link>` whose `to` is built by substituting `:fieldName`
9
+ * tokens with the corresponding field values (special token `:id`
10
+ * resolves to the configured `idField`, default "Id").
11
+ *
12
+ * Applications can still pass `renderResult[sourceKey]` to override.
13
+ */
14
+
15
+ import type { ReactNode } from "react";
16
+ import { Link } from "react-router";
17
+ import { fieldValue } from "../../utils/fieldUtils";
18
+ import type { DisplayField, SObjectSourceConfig } from "../../types";
19
+
20
+ const ROUTE_TOKEN = /:([A-Za-z_][A-Za-z0-9_]*)/g;
21
+
22
+ function fieldName(f: DisplayField): string {
23
+ return typeof f === "string" ? f : f.name;
24
+ }
25
+
26
+ /** Resolves a single dot-path against a node, returning a string or null. */
27
+ function readPath(node: unknown, path: string): string | null {
28
+ if (!node || typeof node !== "object") return null;
29
+ const parts = path.split(".");
30
+ let cursor: unknown = node;
31
+ for (let i = 0; i < parts.length - 1; i++) {
32
+ if (!cursor || typeof cursor !== "object") return null;
33
+ cursor = (cursor as Record<string, unknown>)[parts[i]];
34
+ }
35
+ const leaf = (cursor as Record<string, unknown> | null)?.[parts[parts.length - 1]];
36
+ if (leaf == null) return null;
37
+ if (typeof leaf === "object") {
38
+ return fieldValue(leaf as { value?: unknown; displayValue?: string | null });
39
+ }
40
+ return String(leaf);
41
+ }
42
+
43
+ /** Reads the user-facing string for a top-level display field. */
44
+ function readDisplayField(node: unknown, field: DisplayField): string | null {
45
+ if (typeof field === "string") return readPath(node, field);
46
+ if ("raw" in field) return readPath(node, field.name);
47
+ // Relationship: prefer the first scalar subfield's display value.
48
+ const sub = field.subfields[0];
49
+ if (!sub) return null;
50
+ const subName = fieldName(sub);
51
+ return readPath(node, `${field.name}.${subName}`);
52
+ }
53
+
54
+ /** Substitutes `:fieldName` tokens in routePattern with node values. */
55
+ function resolveRoute(pattern: string, node: unknown, idField: string): string | null {
56
+ let failed = false;
57
+ const out = pattern.replace(ROUTE_TOKEN, (_, token) => {
58
+ const path = token === "id" ? idField : token;
59
+ const value = readPath(node, path);
60
+ if (value == null) {
61
+ failed = true;
62
+ return "";
63
+ }
64
+ return encodeURIComponent(value);
65
+ });
66
+ return failed ? null : out;
67
+ }
68
+
69
+ interface DefaultResultRowProps {
70
+ node: unknown;
71
+ source: SObjectSourceConfig;
72
+ }
73
+
74
+ export function DefaultResultRow({ node, source }: DefaultResultRowProps) {
75
+ const idField = source.idField ?? "Id";
76
+ const fields = source.displayFields;
77
+ const titleField = fields[0];
78
+ const title = titleField ? readDisplayField(node, titleField) : null;
79
+
80
+ const subtitleParts = fields
81
+ .slice(1)
82
+ .map((f) => readDisplayField(node, f))
83
+ .filter((s): s is string => s != null && s !== "");
84
+
85
+ const content: ReactNode = (
86
+ <>
87
+ <span className="font-medium">{title ?? "—"}</span>
88
+ {subtitleParts.length > 0 && (
89
+ <p className="text-sm text-muted-foreground">{subtitleParts.join(" · ")}</p>
90
+ )}
91
+ </>
92
+ );
93
+
94
+ if (source.routePattern) {
95
+ const href = resolveRoute(source.routePattern, node, idField);
96
+ if (href) {
97
+ return (
98
+ <Link
99
+ to={href}
100
+ className="block hover:bg-accent rounded-md px-3 -mx-3 py-1 transition-colors"
101
+ >
102
+ {content}
103
+ </Link>
104
+ );
105
+ }
106
+ }
107
+
108
+ return <div className="px-3 -mx-3 py-1">{content}</div>;
109
+ }
@@ -0,0 +1,82 @@
1
+ {
2
+ "sources": [
3
+ {
4
+ "kind": "sobject",
5
+ "key": "accounts",
6
+ "objectName": "Account",
7
+ "label": "Accounts",
8
+ "routePattern": "/accounts/:id",
9
+ "searchableFields": ["Name", "Phone", "Industry"],
10
+ "displayFields": [
11
+ "Name",
12
+ "Industry",
13
+ "Type",
14
+ "Phone",
15
+ "AnnualRevenue",
16
+ { "name": "Owner", "subfields": ["Name"] }
17
+ ],
18
+ "filterFields": [
19
+ { "field": "Industry", "label": "Industry", "type": "picklist" },
20
+ { "field": "Type", "label": "Type", "type": "picklist" },
21
+ { "field": "AnnualRevenue", "label": "Annual Revenue", "type": "numeric" }
22
+ ],
23
+ "sortFields": [
24
+ { "field": "Name", "label": "Name" },
25
+ { "field": "Industry", "label": "Industry" },
26
+ { "field": "AnnualRevenue", "label": "Annual Revenue" },
27
+ { "field": "CreatedDate", "label": "Created Date" }
28
+ ],
29
+ "pageSize": 10,
30
+ "validPageSizes": [5, 10, 20]
31
+ },
32
+ {
33
+ "kind": "sobject",
34
+ "key": "contacts",
35
+ "objectName": "Contact",
36
+ "label": "Contacts",
37
+ "routePattern": "/contacts/:id",
38
+ "searchableFields": ["Name", "Email", "Phone"],
39
+ "displayFields": [
40
+ "Name",
41
+ "Title",
42
+ "Email",
43
+ "Phone",
44
+ { "name": "Account", "subfields": ["Name"] }
45
+ ],
46
+ "sortFields": [
47
+ { "field": "Name", "label": "Name" },
48
+ { "field": "CreatedDate", "label": "Created Date" }
49
+ ],
50
+ "pageSize": 10,
51
+ "validPageSizes": [5, 10, 20]
52
+ },
53
+ {
54
+ "kind": "sobject",
55
+ "key": "opportunities",
56
+ "objectName": "Opportunity",
57
+ "label": "Opportunities",
58
+ "routePattern": "/opportunities/:id",
59
+ "searchableFields": ["Name"],
60
+ "displayFields": [
61
+ "Name",
62
+ "StageName",
63
+ "Amount",
64
+ "CloseDate",
65
+ { "name": "Account", "subfields": ["Name"] }
66
+ ],
67
+ "filterFields": [
68
+ { "field": "StageName", "label": "Stage", "type": "picklist" },
69
+ { "field": "Amount", "label": "Amount", "type": "numeric" },
70
+ { "field": "CloseDate", "label": "Close Date", "type": "daterange" }
71
+ ],
72
+ "sortFields": [
73
+ { "field": "CloseDate", "label": "Close Date" },
74
+ { "field": "Amount", "label": "Amount" },
75
+ { "field": "Name", "label": "Name" }
76
+ ],
77
+ "defaultSort": { "field": "CloseDate", "direction": "DESC" },
78
+ "pageSize": 10,
79
+ "validPageSizes": [5, 10, 20]
80
+ }
81
+ ]
82
+ }
@@ -0,0 +1,56 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+
3
+ interface UseAsyncDataResult<T> {
4
+ data: T | null;
5
+ loading: boolean;
6
+ error: string | null;
7
+ }
8
+
9
+ /**
10
+ * Runs an async fetcher on mount and whenever `deps` change. Stale responses
11
+ * (deps changed during a fetch, or component unmounted) are dropped via a
12
+ * cancellation flag.
13
+ */
14
+ export function useAsyncData<T>(
15
+ fetcher: () => Promise<T>,
16
+ deps: React.DependencyList,
17
+ ): UseAsyncDataResult<T> {
18
+ const [data, setData] = useState<T | null>(null);
19
+ const [loading, setLoading] = useState(true);
20
+ const [error, setError] = useState<string | null>(null);
21
+ const [generation, setGeneration] = useState(0);
22
+
23
+ const fetcherRef = useRef(fetcher);
24
+ useEffect(() => {
25
+ fetcherRef.current = fetcher;
26
+ });
27
+
28
+ const [prevDeps, setPrevDeps] = useState(deps);
29
+ if (deps.length !== prevDeps.length || deps.some((d, i) => d !== prevDeps[i])) {
30
+ setPrevDeps(deps);
31
+ setGeneration((g) => g + 1);
32
+ if (!loading) setLoading(true);
33
+ if (error !== null) setError(null);
34
+ }
35
+
36
+ useEffect(() => {
37
+ let cancelled = false;
38
+ fetcherRef
39
+ .current()
40
+ .then((result) => {
41
+ if (!cancelled) setData(result);
42
+ })
43
+ .catch((err) => {
44
+ console.error(err);
45
+ if (!cancelled) setError(err instanceof Error ? err.message : "An error occurred");
46
+ })
47
+ .finally(() => {
48
+ if (!cancelled) setLoading(false);
49
+ });
50
+ return () => {
51
+ cancelled = true;
52
+ };
53
+ }, [generation]);
54
+
55
+ return { data, loading, error };
56
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Caches and serves distinct picklist values fetched via the GraphQL
3
+ * aggregate API. The cache key is `${objectName}.${fieldName}`; entries
4
+ * persist for the lifetime of the page so repeated mounts of the same
5
+ * picklist filter share the same response.
6
+ *
7
+ * Pass `null` to short-circuit the fetch (e.g. when inline options are
8
+ * available on the filter config).
9
+ */
10
+
11
+ import { useEffect, useState } from "react";
12
+ import { fetchDistinctValues, type PicklistOption } from "../api/distinctValuesService";
13
+
14
+ const cache = new Map<string, PicklistOption[]>();
15
+ const inflight = new Map<string, Promise<PicklistOption[]>>();
16
+
17
+ interface DistinctValuesQuery {
18
+ objectName: string;
19
+ fieldName: string;
20
+ }
21
+
22
+ export function useDistinctValues(query: DistinctValuesQuery | null): PicklistOption[] | null {
23
+ const cacheKey = query ? `${query.objectName}.${query.fieldName}` : null;
24
+ const [options, setOptions] = useState<PicklistOption[] | null>(() =>
25
+ cacheKey ? (cache.get(cacheKey) ?? null) : null,
26
+ );
27
+
28
+ useEffect(() => {
29
+ if (!query || !cacheKey) return;
30
+ const cached = cache.get(cacheKey);
31
+ if (cached) {
32
+ setOptions(cached);
33
+ return;
34
+ }
35
+ let cancelled = false;
36
+ const existing = inflight.get(cacheKey);
37
+ const promise =
38
+ existing ??
39
+ fetchDistinctValues(query.objectName, query.fieldName).then((result) => {
40
+ cache.set(cacheKey, result);
41
+ inflight.delete(cacheKey);
42
+ return result;
43
+ });
44
+ if (!existing) inflight.set(cacheKey, promise);
45
+ promise
46
+ .then((result) => {
47
+ if (!cancelled) setOptions(result);
48
+ })
49
+ .catch((err: unknown) => {
50
+ inflight.delete(cacheKey);
51
+ console.error(`Failed to fetch distinct values for ${cacheKey}:`, err);
52
+ });
53
+ return () => {
54
+ cancelled = true;
55
+ };
56
+ }, [cacheKey, query]);
57
+
58
+ return options;
59
+ }