@salesforce/ui-bundle-template-app-react-template-b2e 11.19.0 → 11.20.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 (76) hide show
  1. package/dist/CHANGELOG.md +8 -0
  2. package/dist/force-app/main/default/uiBundles/reactinternalapp/package.json +4 -4
  3. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/{features/object-search/components → components}/ObjectBreadcrumb.tsx +7 -2
  4. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/api/distinctValuesService.ts +84 -0
  5. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/api/searchService.ts +71 -0
  6. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/MergedSearchResults.tsx +263 -0
  7. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/Search.tsx +185 -0
  8. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/SearchResults.tsx +77 -0
  9. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/SourceSection.tsx +166 -0
  10. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/controls/PaginationControls.tsx +185 -0
  11. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/controls/ScopeSelector.tsx +55 -0
  12. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/controls/SearchBar.tsx +55 -0
  13. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/controls/SortControl.tsx +62 -0
  14. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/ActiveFilters.tsx +61 -0
  15. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/DefaultFilterPanel.tsx +125 -0
  16. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/{object-search/components → search/components/filters}/FilterContext.tsx +7 -20
  17. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/inputs/BooleanFilter.tsx +50 -0
  18. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/inputs/DateRangeFilter.tsx +160 -0
  19. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/inputs/FilterFieldWrapper.tsx +26 -0
  20. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/inputs/MultiSelectFilter.tsx +88 -0
  21. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/inputs/NumericRangeFilter.tsx +78 -0
  22. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/inputs/SelectFilter.tsx +46 -0
  23. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/filters/inputs/TextFilter.tsx +52 -0
  24. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/components/results/DefaultResultRow.tsx +109 -0
  25. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/config.json +83 -0
  26. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/{object-search → search}/hooks/useAsyncData.ts +3 -10
  27. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/hooks/useDistinctValues.ts +59 -0
  28. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/hooks/useSearch.ts +703 -0
  29. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/index.ts +90 -0
  30. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/loadConfig.ts +14 -0
  31. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/queryBuilder.ts +156 -0
  32. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/types.ts +307 -0
  33. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/utils/debounce.ts +17 -0
  34. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/utils/fieldUtils.ts +14 -0
  35. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/utils/filterUtils.ts +285 -0
  36. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/search/utils/sortUtils.ts +34 -0
  37. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/pages/AccountObjectDetailPage.tsx +49 -16
  38. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/pages/AccountSearch.tsx +21 -293
  39. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/pages/Home.tsx +21 -6
  40. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/{features/object-search/utils/fieldUtils.ts → utils/accountFields.ts} +9 -0
  41. package/dist/force-app/main/default/uiBundles/reactinternalapp/tsconfig.tsbuildinfo +1 -1
  42. package/dist/package-lock.json +2 -2
  43. package/dist/package.json +1 -1
  44. package/package.json +1 -1
  45. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/accountSearchService.ts +0 -46
  46. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/query/distinctAccountIndustries.graphql +0 -19
  47. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/query/distinctAccountTypes.graphql +0 -19
  48. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/query/searchAccounts.graphql +0 -51
  49. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/graphql-operations-types.ts +0 -11260
  50. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/accountSearchService.ts +0 -46
  51. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/distinctAccountIndustries.graphql +0 -19
  52. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/distinctAccountTypes.graphql +0 -19
  53. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/getAccountDetail.graphql +0 -121
  54. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/searchAccounts.graphql +0 -51
  55. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/pages/AccountObjectDetailPage.tsx +0 -355
  56. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/pages/AccountSearch.tsx +0 -304
  57. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/pages/Home.tsx +0 -34
  58. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/api/objectSearchService.ts +0 -82
  59. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/ActiveFilters.tsx +0 -89
  60. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/PaginationControls.tsx +0 -109
  61. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/SearchBar.tsx +0 -41
  62. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/SortControl.tsx +0 -143
  63. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/BooleanFilter.tsx +0 -78
  64. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/DateFilter.tsx +0 -128
  65. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/DateRangeFilter.tsx +0 -70
  66. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/FilterFieldWrapper.tsx +0 -43
  67. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/MultiSelectFilter.tsx +0 -105
  68. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/NumericRangeFilter.tsx +0 -171
  69. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/SearchFilter.tsx +0 -52
  70. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/SelectFilter.tsx +0 -97
  71. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/TextFilter.tsx +0 -93
  72. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/hooks/useDebouncedCallback.ts +0 -34
  73. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/hooks/useObjectSearchParams.ts +0 -254
  74. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/utils/debounce.ts +0 -25
  75. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/utils/filterUtils.ts +0 -404
  76. package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/utils/sortUtils.ts +0 -38
@@ -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,83 @@
1
+ {
2
+ "pagination": {
3
+ "pageSize": 10,
4
+ "pageSizeOptions": [5, 10, 20]
5
+ },
6
+ "sources": [
7
+ {
8
+ "kind": "sobject",
9
+ "key": "accounts",
10
+ "objectName": "Account",
11
+ "label": "Accounts",
12
+ "labelSingular": "Account",
13
+ "routePattern": "/accounts/:id",
14
+ "searchableFields": ["Name", "Phone", "Industry"],
15
+ "displayFields": [
16
+ "Name",
17
+ "Industry",
18
+ "Type",
19
+ "Phone",
20
+ "AnnualRevenue",
21
+ { "name": "Owner", "subfields": ["Name"] }
22
+ ],
23
+ "filterBy": [
24
+ { "field": "Industry", "label": "Industry", "type": "picklist" },
25
+ { "field": "Type", "label": "Type", "type": "picklist" },
26
+ { "field": "AnnualRevenue", "label": "Annual Revenue", "type": "numeric" }
27
+ ],
28
+ "sortBy": [
29
+ { "field": "Name", "label": "Name" },
30
+ { "field": "Industry", "label": "Industry" },
31
+ { "field": "AnnualRevenue", "label": "Annual Revenue" },
32
+ { "field": "CreatedDate", "label": "Created Date" }
33
+ ]
34
+ },
35
+ {
36
+ "kind": "sobject",
37
+ "key": "contacts",
38
+ "objectName": "Contact",
39
+ "label": "Contacts",
40
+ "labelSingular": "Contact",
41
+ "routePattern": "/contacts/:id",
42
+ "searchableFields": ["Name", "Email", "Phone"],
43
+ "displayFields": [
44
+ "Name",
45
+ "Title",
46
+ "Email",
47
+ "Phone",
48
+ { "name": "Account", "subfields": ["Name"] }
49
+ ],
50
+ "sortBy": [
51
+ { "field": "Name", "label": "Name" },
52
+ { "field": "CreatedDate", "label": "Created Date" }
53
+ ]
54
+ },
55
+ {
56
+ "kind": "sobject",
57
+ "key": "opportunities",
58
+ "objectName": "Opportunity",
59
+ "label": "Opportunities",
60
+ "labelSingular": "Opportunity",
61
+ "routePattern": "/opportunities/:id",
62
+ "searchableFields": ["Name"],
63
+ "displayFields": [
64
+ "Name",
65
+ "StageName",
66
+ "Amount",
67
+ "CloseDate",
68
+ { "name": "Account", "subfields": ["Name"] }
69
+ ],
70
+ "filterBy": [
71
+ { "field": "StageName", "label": "Stage", "type": "picklist" },
72
+ { "field": "Amount", "label": "Amount", "type": "numeric" },
73
+ { "field": "CloseDate", "label": "Close Date", "type": "daterange" }
74
+ ],
75
+ "sortBy": [
76
+ { "field": "CloseDate", "label": "Close Date" },
77
+ { "field": "Amount", "label": "Amount" },
78
+ { "field": "Name", "label": "Name" }
79
+ ],
80
+ "defaultSort": { "field": "CloseDate", "direction": "DESC" }
81
+ }
82
+ ]
83
+ }
@@ -7,13 +7,9 @@ interface UseAsyncDataResult<T> {
7
7
  }
8
8
 
9
9
  /**
10
- * Runs an async fetcher on mount and whenever `deps` change.
11
- * Returns the loading/error/data state. Does not cache — every call
12
- * to the fetcher hits the source directly.
13
- *
14
- * A cleanup flag prevents state updates if the component unmounts
15
- * or deps change before the fetch completes (avoids React warnings
16
- * and stale updates from out-of-order responses).
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.
17
13
  */
18
14
  export function useAsyncData<T>(
19
15
  fetcher: () => Promise<T>,
@@ -29,7 +25,6 @@ export function useAsyncData<T>(
29
25
  fetcherRef.current = fetcher;
30
26
  });
31
27
 
32
- // Detect dep changes during render to reset loading state and bump generation
33
28
  const [prevDeps, setPrevDeps] = useState(deps);
34
29
  if (deps.length !== prevDeps.length || deps.some((d, i) => d !== prevDeps[i])) {
35
30
  setPrevDeps(deps);
@@ -40,7 +35,6 @@ export function useAsyncData<T>(
40
35
 
41
36
  useEffect(() => {
42
37
  let cancelled = false;
43
-
44
38
  fetcherRef
45
39
  .current()
46
40
  .then((result) => {
@@ -53,7 +47,6 @@ export function useAsyncData<T>(
53
47
  .finally(() => {
54
48
  if (!cancelled) setLoading(false);
55
49
  });
56
-
57
50
  return () => {
58
51
  cancelled = true;
59
52
  };
@@ -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
+ }