@salesforce/webapp-template-app-react-template-b2e-experimental 1.59.2 → 1.60.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.
- package/dist/CHANGELOG.md +8 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package-lock.json +4255 -227
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package.json +11 -2
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/index.ts +19 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/objectDetailService.ts +125 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/objectInfoGraphQLService.ts +194 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/objectInfoService.ts +199 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/recordListGraphQLService.ts +365 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/FiltersPanel.tsx +375 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/LoadingFallback.tsx +61 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/SearchResultCard.tsx +131 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/alerts/status-alert.tsx +45 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/DetailFields.tsx +55 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/DetailForm.tsx +146 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/DetailHeader.tsx +34 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/DetailLayoutSections.tsx +80 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/Section.tsx +108 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/SectionRow.tsx +20 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/UiApiDetailForm.tsx +140 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/formatted/FieldValueDisplay.tsx +73 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/formatted/FormattedAddress.tsx +29 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/formatted/FormattedEmail.tsx +17 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/formatted/FormattedPhone.tsx +24 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/formatted/FormattedText.tsx +11 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/formatted/FormattedUrl.tsx +29 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/detail/formatted/index.ts +6 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/filters/FilterField.tsx +54 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/filters/FilterInput.tsx +55 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/filters/FilterSelect.tsx +72 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/filters-form.tsx +114 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/submit-button.tsx +47 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/card-layout.tsx +19 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/search/ResultCardFields.tsx +71 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/search/SearchHeader.tsx +31 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/search/SearchPagination.tsx +144 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/search/SearchResultsPanel.tsx +197 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/shared/GlobalSearchInput.tsx +114 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/alert.tsx +69 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/button.tsx +67 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/card.tsx +92 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/dialog.tsx +143 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/field.tsx +222 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/index.ts +84 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/input.tsx +19 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/label.tsx +19 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/pagination.tsx +112 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/select.tsx +183 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/separator.tsx +26 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/skeleton.tsx +14 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/spinner.tsx +15 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/table.tsx +87 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/tabs.tsx +78 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components.json +18 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/constants.ts +39 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/global-search/index.ts +33 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/form.tsx +208 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/index.ts +22 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/useObjectInfoBatch.ts +65 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/useObjectSearchData.ts +380 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/useRecordDetailLayout.ts +156 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/useRecordListGraphQL.ts +135 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/DetailPage.tsx +109 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/GlobalSearch.tsx +229 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Home.tsx +11 -10
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/routes.tsx +22 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/styles/global.css +122 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/filters/filters.ts +120 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/filters/picklist.ts +32 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/index.ts +4 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/objectInfo/objectInfo.ts +166 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/recordDetail/recordDetail.ts +61 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/search/searchResults.ts +229 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/apiUtils.ts +125 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/cacheUtils.ts +76 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/debounce.ts +89 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/fieldUtils.ts +354 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/fieldValueExtractor.ts +67 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/filterUtils.ts +32 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/formDataTransformUtils.ts +260 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/formUtils.ts +142 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/graphQLNodeFieldUtils.ts +186 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/graphQLObjectInfoAdapter.ts +319 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/graphQLRecordAdapter.ts +90 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/index.ts +59 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/layoutTransformUtils.ts +236 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/linkUtils.ts +14 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/paginationUtils.ts +49 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/recordUtils.ts +159 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/sanitizationUtils.ts +49 -0
- package/dist/package.json +1 -1
- package/package.json +2 -2
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/DetailPage.tsx
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useParams, useNavigate } from "react-router";
|
|
3
|
+
import { Card, CardContent, CardHeader, CardTitle } from "../components/ui/card";
|
|
4
|
+
import { Skeleton } from "../components/ui/skeleton";
|
|
5
|
+
import { Alert, AlertDescription, AlertTitle } from "../components/ui/alert";
|
|
6
|
+
import { AlertCircle } from "lucide-react";
|
|
7
|
+
import DetailHeader from "../components/detail/DetailHeader";
|
|
8
|
+
import { UiApiDetailForm } from "../components/detail/UiApiDetailForm";
|
|
9
|
+
import { OBJECT_API_NAMES, DEFAULT_DETAIL_PAGE_TITLE } from "../constants";
|
|
10
|
+
import { toRecordDisplayNameMetadata } from "../utils/fieldUtils";
|
|
11
|
+
import { useRecordDetailLayout } from "../hooks/useRecordDetailLayout";
|
|
12
|
+
import { getGraphQLRecordDisplayName } from "../utils/graphQLNodeFieldUtils";
|
|
13
|
+
|
|
14
|
+
export default function DetailPage() {
|
|
15
|
+
const { objectApiName: objectApiNameParam, recordId } = useParams<{
|
|
16
|
+
objectApiName: string;
|
|
17
|
+
recordId: string;
|
|
18
|
+
}>();
|
|
19
|
+
const navigate = useNavigate();
|
|
20
|
+
const objectApiName = objectApiNameParam ?? OBJECT_API_NAMES[0];
|
|
21
|
+
|
|
22
|
+
const { layout, record, objectMetadata, loading, error } = useRecordDetailLayout({
|
|
23
|
+
objectApiName,
|
|
24
|
+
recordId: recordId ?? null,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const recordTitle = useMemo(
|
|
28
|
+
() =>
|
|
29
|
+
record
|
|
30
|
+
? getGraphQLRecordDisplayName(record, toRecordDisplayNameMetadata(objectMetadata))
|
|
31
|
+
: DEFAULT_DETAIL_PAGE_TITLE,
|
|
32
|
+
[record, objectMetadata],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const handleBack = () => navigate(-1);
|
|
36
|
+
|
|
37
|
+
if (loading) {
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12"
|
|
41
|
+
role="status"
|
|
42
|
+
aria-live="polite"
|
|
43
|
+
aria-label="Loading record details"
|
|
44
|
+
>
|
|
45
|
+
<span className="sr-only">Loading record details</span>
|
|
46
|
+
<Skeleton className="h-10 w-32 mb-6" aria-hidden="true" />
|
|
47
|
+
<Card aria-hidden="true">
|
|
48
|
+
<CardHeader>
|
|
49
|
+
<Skeleton className="h-8 w-3/4" />
|
|
50
|
+
</CardHeader>
|
|
51
|
+
<CardContent className="space-y-4">
|
|
52
|
+
{[1, 2, 3, 4].map((i) => (
|
|
53
|
+
<div key={i} className="space-y-2">
|
|
54
|
+
<Skeleton className="h-4 w-24" />
|
|
55
|
+
<Skeleton className="h-4 w-full" />
|
|
56
|
+
</div>
|
|
57
|
+
))}
|
|
58
|
+
</CardContent>
|
|
59
|
+
</Card>
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (error) {
|
|
65
|
+
return (
|
|
66
|
+
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
|
67
|
+
<DetailHeader title="" onBack={handleBack} />
|
|
68
|
+
<Alert variant="destructive" role="alert">
|
|
69
|
+
<AlertCircle className="h-4 w-4" aria-hidden="true" />
|
|
70
|
+
<AlertTitle>Error</AlertTitle>
|
|
71
|
+
<AlertDescription>{error}</AlertDescription>
|
|
72
|
+
</Alert>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!layout || !record) {
|
|
78
|
+
return (
|
|
79
|
+
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
|
80
|
+
<DetailHeader title="" onBack={handleBack} />
|
|
81
|
+
<Alert role="alert">
|
|
82
|
+
<AlertCircle className="h-4 w-4" aria-hidden="true" />
|
|
83
|
+
<AlertTitle>Not Found</AlertTitle>
|
|
84
|
+
<AlertDescription>Record not found</AlertDescription>
|
|
85
|
+
</Alert>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<main className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12" aria-label="Record details">
|
|
92
|
+
<DetailHeader title={recordTitle} onBack={handleBack} />
|
|
93
|
+
<Card>
|
|
94
|
+
<CardHeader>
|
|
95
|
+
<CardTitle className="text-2xl">{recordTitle}</CardTitle>
|
|
96
|
+
</CardHeader>
|
|
97
|
+
<CardContent>
|
|
98
|
+
<UiApiDetailForm
|
|
99
|
+
objectApiName={objectApiName}
|
|
100
|
+
recordId={recordId!}
|
|
101
|
+
layout={layout}
|
|
102
|
+
record={record}
|
|
103
|
+
objectMetadata={objectMetadata}
|
|
104
|
+
/>
|
|
105
|
+
</CardContent>
|
|
106
|
+
</Card>
|
|
107
|
+
</main>
|
|
108
|
+
);
|
|
109
|
+
}
|
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/GlobalSearch.tsx
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GlobalSearch Page Component
|
|
3
|
+
*
|
|
4
|
+
* Main page component for displaying global search results.
|
|
5
|
+
* Uses GraphQL API (useRecordListGraphQL) for list data; results are adapted to the
|
|
6
|
+
* same record shape as before so SearchResultCard and filters/sort/pagination work unchanged.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* - Supports single object search (no tabs)
|
|
10
|
+
* - Displays filters panel on the left and results on the right
|
|
11
|
+
* - Pagination uses a cursor stack: we only query forward (first + after) and store endCursor per page;
|
|
12
|
+
* Previous re-queries using the stored cursor for the previous page so both Next and Previous work.
|
|
13
|
+
*/
|
|
14
|
+
import { useMemo, useState, useCallback, useEffect, useRef } from "react";
|
|
15
|
+
import { useParams } from "react-router";
|
|
16
|
+
import { OBJECT_API_NAMES, DEFAULT_PAGE_SIZE } from "../constants";
|
|
17
|
+
import { useObjectListMetadata } from "../hooks/useObjectSearchData";
|
|
18
|
+
import { useObjectInfoBatch } from "../hooks/useObjectInfoBatch";
|
|
19
|
+
import { useRecordListGraphQL } from "../hooks/useRecordListGraphQL";
|
|
20
|
+
import FiltersPanel from "../components/FiltersPanel";
|
|
21
|
+
import SearchHeader from "../components/search/SearchHeader";
|
|
22
|
+
import SearchResultsPanel from "../components/search/SearchResultsPanel";
|
|
23
|
+
import { Card, CardContent, CardHeader, CardTitle } from "../components/ui/card";
|
|
24
|
+
import { Skeleton } from "../components/ui/skeleton";
|
|
25
|
+
import type { FilterCriteria } from "../types/filters/filters";
|
|
26
|
+
import type { SearchResultRecord } from "../types/search/searchResults";
|
|
27
|
+
import { graphQLNodeToSearchResultRecordData } from "../utils/graphQLRecordAdapter";
|
|
28
|
+
|
|
29
|
+
const EMPTY_HIGHLIGHT = { fields: {}, snippet: null };
|
|
30
|
+
const EMPTY_SEARCH_INFO = { isPromoted: false, isSpellCorrected: false };
|
|
31
|
+
|
|
32
|
+
export default function GlobalSearch() {
|
|
33
|
+
const { query } = useParams<{ query: string }>();
|
|
34
|
+
|
|
35
|
+
const objectApiName = OBJECT_API_NAMES[0];
|
|
36
|
+
|
|
37
|
+
const [searchPageSize, setSearchPageSize] = useState(DEFAULT_PAGE_SIZE);
|
|
38
|
+
const [afterCursor, setAfterCursor] = useState<string | null>(null);
|
|
39
|
+
const [pageIndex, setPageIndex] = useState(0);
|
|
40
|
+
/** Cursor stack: cursorStack[i] is the `after` value that returns page i. cursorStack[0] = null (first page). */
|
|
41
|
+
const [cursorStack, setCursorStack] = useState<(string | null)[]>([null]);
|
|
42
|
+
const [appliedFilters, setAppliedFilters] = useState<FilterCriteria[]>([]);
|
|
43
|
+
const [sortBy, setSortBy] = useState("Name");
|
|
44
|
+
|
|
45
|
+
const decodedQuery = useMemo(() => {
|
|
46
|
+
if (!query) return "";
|
|
47
|
+
try {
|
|
48
|
+
return decodeURIComponent(query);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return query;
|
|
51
|
+
}
|
|
52
|
+
}, [query]);
|
|
53
|
+
|
|
54
|
+
const isBrowseAll = decodedQuery === "browse__all";
|
|
55
|
+
const searchQuery = isBrowseAll ? "" : decodedQuery.trim();
|
|
56
|
+
|
|
57
|
+
// Reset pagination when the URL search query changes so we don't use an old cursor with a new result set
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
setAfterCursor(null);
|
|
60
|
+
setPageIndex(0);
|
|
61
|
+
setCursorStack([null]);
|
|
62
|
+
}, [query]);
|
|
63
|
+
|
|
64
|
+
const listMeta = useObjectListMetadata(objectApiName);
|
|
65
|
+
const { objectInfos } = useObjectInfoBatch([...OBJECT_API_NAMES]);
|
|
66
|
+
const labelPlural = (objectInfos[0]?.labelPlural as string | undefined) ?? "records";
|
|
67
|
+
const {
|
|
68
|
+
edges,
|
|
69
|
+
pageInfo,
|
|
70
|
+
loading: resultsLoading,
|
|
71
|
+
error: resultsError,
|
|
72
|
+
} = useRecordListGraphQL({
|
|
73
|
+
objectApiName,
|
|
74
|
+
first: searchPageSize,
|
|
75
|
+
after: afterCursor,
|
|
76
|
+
filters: appliedFilters,
|
|
77
|
+
sortBy: sortBy === "relevance" ? "Name" : sortBy,
|
|
78
|
+
searchQuery: searchQuery || undefined,
|
|
79
|
+
columns: listMeta.columns,
|
|
80
|
+
columnsLoading: listMeta.loading,
|
|
81
|
+
columnsError: listMeta.error,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Store endCursor for the next page so we can re-query when user clicks Next; also enables Previous via stack.
|
|
85
|
+
// Only update when not loading so a stale response cannot write a cursor into the wrong stack index (e.g. after rapid Next clicks).
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (resultsLoading) return;
|
|
88
|
+
const cursor = pageInfo?.endCursor ?? null;
|
|
89
|
+
if (cursor == null) return;
|
|
90
|
+
setCursorStack((prev) => {
|
|
91
|
+
const next = [...prev];
|
|
92
|
+
next[pageIndex + 1] = cursor;
|
|
93
|
+
return next;
|
|
94
|
+
});
|
|
95
|
+
}, [resultsLoading, pageInfo?.endCursor, pageIndex]);
|
|
96
|
+
|
|
97
|
+
const results: SearchResultRecord[] = useMemo(
|
|
98
|
+
() =>
|
|
99
|
+
(edges ?? []).map((edge) => ({
|
|
100
|
+
record: graphQLNodeToSearchResultRecordData(
|
|
101
|
+
edge?.node as Record<string, unknown>,
|
|
102
|
+
objectApiName,
|
|
103
|
+
),
|
|
104
|
+
highlightInfo: EMPTY_HIGHLIGHT,
|
|
105
|
+
searchInfo: EMPTY_SEARCH_INFO,
|
|
106
|
+
})),
|
|
107
|
+
[edges, objectApiName],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const nextPageToken = pageInfo?.endCursor ?? null;
|
|
111
|
+
/** Entry cursor for the previous page; used when user clicks Previous to re-query with after=cursorStack[pageIndex-1]. */
|
|
112
|
+
const previousPageToken = pageIndex > 0 ? (cursorStack[pageIndex - 1] ?? null) : null;
|
|
113
|
+
const hasNextPage = pageInfo?.hasNextPage === true;
|
|
114
|
+
const hasPreviousPage = pageIndex > 0;
|
|
115
|
+
const currentPageToken = pageIndex.toString();
|
|
116
|
+
|
|
117
|
+
const cursorStackRef = useRef(cursorStack);
|
|
118
|
+
const pageIndexRef = useRef(pageIndex);
|
|
119
|
+
cursorStackRef.current = cursorStack;
|
|
120
|
+
pageIndexRef.current = pageIndex;
|
|
121
|
+
|
|
122
|
+
const canRenderFilters =
|
|
123
|
+
!listMeta.loading && listMeta.filters !== undefined && listMeta.picklistValues !== undefined;
|
|
124
|
+
|
|
125
|
+
const handleApplyFilters = useCallback((filterCriteria: FilterCriteria[]) => {
|
|
126
|
+
setAppliedFilters(filterCriteria);
|
|
127
|
+
setAfterCursor(null);
|
|
128
|
+
setPageIndex(0);
|
|
129
|
+
setCursorStack([null]);
|
|
130
|
+
}, []);
|
|
131
|
+
|
|
132
|
+
const handlePageChange = useCallback(
|
|
133
|
+
(newPageToken: string, direction?: "next" | "prev" | "first") => {
|
|
134
|
+
if (direction === "first" || newPageToken === "0") {
|
|
135
|
+
setAfterCursor(null);
|
|
136
|
+
setPageIndex(0);
|
|
137
|
+
} else if (direction === "prev") {
|
|
138
|
+
const idx = pageIndexRef.current;
|
|
139
|
+
const stack = cursorStackRef.current;
|
|
140
|
+
const prevCursor = idx > 0 ? (stack[idx - 1] ?? null) : null;
|
|
141
|
+
setAfterCursor(prevCursor);
|
|
142
|
+
setPageIndex((prev) => Math.max(0, prev - 1));
|
|
143
|
+
} else {
|
|
144
|
+
setAfterCursor(newPageToken);
|
|
145
|
+
setPageIndex((prev) => prev + 1);
|
|
146
|
+
}
|
|
147
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
148
|
+
},
|
|
149
|
+
[],
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const handlePageSizeChange = useCallback((newPageSize: number) => {
|
|
153
|
+
setSearchPageSize(newPageSize);
|
|
154
|
+
setAfterCursor(null);
|
|
155
|
+
setPageIndex(0);
|
|
156
|
+
setCursorStack([null]);
|
|
157
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
158
|
+
}, []);
|
|
159
|
+
|
|
160
|
+
const handleSortByChange = useCallback((newSortBy: string) => {
|
|
161
|
+
setSortBy(newSortBy);
|
|
162
|
+
setAfterCursor(null);
|
|
163
|
+
setPageIndex(0);
|
|
164
|
+
setCursorStack([null]);
|
|
165
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
166
|
+
}, []);
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
|
|
170
|
+
<SearchHeader query={decodedQuery} isBrowseAll={isBrowseAll} labelPlural={labelPlural} />
|
|
171
|
+
|
|
172
|
+
<div className="grid grid-cols-1 lg:grid-cols-4 gap-6">
|
|
173
|
+
<aside className="lg:col-span-1" aria-label="Filters panel">
|
|
174
|
+
{canRenderFilters ? (
|
|
175
|
+
<FiltersPanel
|
|
176
|
+
filters={listMeta.filters}
|
|
177
|
+
picklistValues={listMeta.picklistValues}
|
|
178
|
+
loading={listMeta.loading}
|
|
179
|
+
objectApiName={objectApiName}
|
|
180
|
+
onApplyFilters={handleApplyFilters}
|
|
181
|
+
/>
|
|
182
|
+
) : (
|
|
183
|
+
<Card className="w-full" role="region" aria-label="Filters panel">
|
|
184
|
+
<CardHeader>
|
|
185
|
+
<CardTitle>Filters</CardTitle>
|
|
186
|
+
</CardHeader>
|
|
187
|
+
<CardContent
|
|
188
|
+
className="space-y-4"
|
|
189
|
+
role="status"
|
|
190
|
+
aria-live="polite"
|
|
191
|
+
aria-label="Loading filters"
|
|
192
|
+
>
|
|
193
|
+
<span className="sr-only">Loading filters</span>
|
|
194
|
+
{[1, 2, 3].map((i) => (
|
|
195
|
+
<div key={i} className="space-y-2" aria-hidden="true">
|
|
196
|
+
<Skeleton className="h-4 w-24" />
|
|
197
|
+
<Skeleton className="h-9 w-full" />
|
|
198
|
+
</div>
|
|
199
|
+
))}
|
|
200
|
+
</CardContent>
|
|
201
|
+
</Card>
|
|
202
|
+
)}
|
|
203
|
+
</aside>
|
|
204
|
+
|
|
205
|
+
<section className="lg:col-span-3" aria-label="Search results">
|
|
206
|
+
<SearchResultsPanel
|
|
207
|
+
objectApiName={objectApiName}
|
|
208
|
+
columns={listMeta.columns}
|
|
209
|
+
results={results}
|
|
210
|
+
columnsLoading={listMeta.loading}
|
|
211
|
+
resultsLoading={resultsLoading}
|
|
212
|
+
columnsError={listMeta.error}
|
|
213
|
+
resultsError={resultsError}
|
|
214
|
+
currentPageToken={currentPageToken}
|
|
215
|
+
nextPageToken={nextPageToken}
|
|
216
|
+
previousPageToken={previousPageToken}
|
|
217
|
+
hasNextPage={hasNextPage}
|
|
218
|
+
hasPreviousPage={hasPreviousPage}
|
|
219
|
+
pageSize={searchPageSize}
|
|
220
|
+
sortBy={sortBy}
|
|
221
|
+
onPageChange={handlePageChange}
|
|
222
|
+
onPageSizeChange={handlePageSizeChange}
|
|
223
|
+
onSortByChange={handleSortByChange}
|
|
224
|
+
/>
|
|
225
|
+
</section>
|
|
226
|
+
</div>
|
|
227
|
+
</main>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { GlobalSearchInput } from "../components/shared/GlobalSearchInput";
|
|
2
|
+
|
|
1
3
|
export default function Home() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
);
|
|
4
|
+
return (
|
|
5
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
|
6
|
+
<div className="text-center">
|
|
7
|
+
<h1 className="text-4xl font-bold text-gray-900 mb-4">Home</h1>
|
|
8
|
+
<p className="text-lg text-gray-600 mb-8">Welcome to your React application.</p>
|
|
9
|
+
</div>
|
|
10
|
+
<GlobalSearchInput />
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
12
13
|
}
|
|
@@ -3,6 +3,10 @@ import AppLayout from './appLayout';
|
|
|
3
3
|
import Home from './pages/Home';
|
|
4
4
|
import NotFound from './pages/NotFound';
|
|
5
5
|
import TestAccPage from "./pages/TestAccPage";
|
|
6
|
+
import GlobalSearch from "./pages/GlobalSearch";
|
|
7
|
+
import DetailPage from "./pages/DetailPage";
|
|
8
|
+
import { Suspense } from "react";
|
|
9
|
+
import LoadingFallback from "./components/LoadingFallback";
|
|
6
10
|
|
|
7
11
|
export const routes: RouteObject[] = [
|
|
8
12
|
{
|
|
@@ -22,6 +26,24 @@ export const routes: RouteObject[] = [
|
|
|
22
26
|
path: "test-acc",
|
|
23
27
|
element: <TestAccPage />,
|
|
24
28
|
handle: { showInNavigation: true, label: "Test ACC" }
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: "global-search/:query",
|
|
32
|
+
element: (
|
|
33
|
+
<Suspense fallback={<LoadingFallback />}>
|
|
34
|
+
<GlobalSearch />
|
|
35
|
+
</Suspense>
|
|
36
|
+
),
|
|
37
|
+
handle: { showInNavigation: false }
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: "object/:objectApiName/:recordId",
|
|
41
|
+
element: (
|
|
42
|
+
<Suspense fallback={<LoadingFallback />}>
|
|
43
|
+
<DetailPage />
|
|
44
|
+
</Suspense>
|
|
45
|
+
),
|
|
46
|
+
handle: { showInNavigation: false }
|
|
25
47
|
}
|
|
26
48
|
]
|
|
27
49
|
}
|
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/styles/global.css
CHANGED
|
@@ -11,3 +11,125 @@
|
|
|
11
11
|
@apply antialiased bg-white;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
@import "tw-animate-css";
|
|
16
|
+
@import "shadcn/tailwind.css";
|
|
17
|
+
|
|
18
|
+
@custom-variant dark (&:is(.dark *));
|
|
19
|
+
|
|
20
|
+
@theme inline {
|
|
21
|
+
--color-background: var(--background);
|
|
22
|
+
--color-foreground: var(--foreground);
|
|
23
|
+
--color-card: var(--card);
|
|
24
|
+
--color-card-foreground: var(--card-foreground);
|
|
25
|
+
--color-popover: var(--popover);
|
|
26
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
27
|
+
--color-primary: var(--primary);
|
|
28
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
29
|
+
--color-secondary: var(--secondary);
|
|
30
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
31
|
+
--color-muted: var(--muted);
|
|
32
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
33
|
+
--color-accent: var(--accent);
|
|
34
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
35
|
+
--color-destructive: var(--destructive);
|
|
36
|
+
--color-destructive-foreground: var(--destructive-foreground);
|
|
37
|
+
--color-border: var(--border);
|
|
38
|
+
--color-input: var(--input);
|
|
39
|
+
--color-ring: var(--ring);
|
|
40
|
+
--color-chart-1: var(--chart-1);
|
|
41
|
+
--color-chart-2: var(--chart-2);
|
|
42
|
+
--color-chart-3: var(--chart-3);
|
|
43
|
+
--color-chart-4: var(--chart-4);
|
|
44
|
+
--color-chart-5: var(--chart-5);
|
|
45
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
46
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
47
|
+
--radius-lg: var(--radius);
|
|
48
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
49
|
+
--color-sidebar: var(--sidebar);
|
|
50
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
51
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
52
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
53
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
54
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
55
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
56
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
:root {
|
|
60
|
+
--radius: 0.625rem;
|
|
61
|
+
--background: oklch(1 0 0);
|
|
62
|
+
--foreground: oklch(0.145 0 0);
|
|
63
|
+
--card: oklch(1 0 0);
|
|
64
|
+
--card-foreground: oklch(0.145 0 0);
|
|
65
|
+
--popover: oklch(1 0 0);
|
|
66
|
+
--popover-foreground: oklch(0.145 0 0);
|
|
67
|
+
--primary: oklch(0.205 0 0);
|
|
68
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
69
|
+
--secondary: oklch(0.97 0 0);
|
|
70
|
+
--secondary-foreground: oklch(0.205 0 0);
|
|
71
|
+
--muted: oklch(0.97 0 0);
|
|
72
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
73
|
+
--accent: oklch(0.97 0 0);
|
|
74
|
+
--accent-foreground: oklch(0.205 0 0);
|
|
75
|
+
--destructive: oklch(0.577 0.245 27.325);
|
|
76
|
+
--border: oklch(0.922 0 0);
|
|
77
|
+
--input: oklch(0.922 0 0);
|
|
78
|
+
--ring: oklch(0.708 0 0);
|
|
79
|
+
--chart-1: oklch(0.646 0.222 41.116);
|
|
80
|
+
--chart-2: oklch(0.6 0.118 184.704);
|
|
81
|
+
--chart-3: oklch(0.398 0.07 227.392);
|
|
82
|
+
--chart-4: oklch(0.828 0.189 84.429);
|
|
83
|
+
--chart-5: oklch(0.769 0.188 70.08);
|
|
84
|
+
--sidebar: oklch(0.985 0 0);
|
|
85
|
+
--sidebar-foreground: oklch(0.145 0 0);
|
|
86
|
+
--sidebar-primary: oklch(0.205 0 0);
|
|
87
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
88
|
+
--sidebar-accent: oklch(0.97 0 0);
|
|
89
|
+
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
90
|
+
--sidebar-border: oklch(0.922 0 0);
|
|
91
|
+
--sidebar-ring: oklch(0.708 0 0);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.dark {
|
|
95
|
+
--background: oklch(0.145 0 0);
|
|
96
|
+
--foreground: oklch(0.985 0 0);
|
|
97
|
+
--card: oklch(0.205 0 0);
|
|
98
|
+
--card-foreground: oklch(0.985 0 0);
|
|
99
|
+
--popover: oklch(0.205 0 0);
|
|
100
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
101
|
+
--primary: oklch(0.922 0 0);
|
|
102
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
103
|
+
--secondary: oklch(0.269 0 0);
|
|
104
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
105
|
+
--muted: oklch(0.269 0 0);
|
|
106
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
107
|
+
--accent: oklch(0.269 0 0);
|
|
108
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
109
|
+
--destructive: oklch(0.704 0.191 22.216);
|
|
110
|
+
--border: oklch(1 0 0 / 10%);
|
|
111
|
+
--input: oklch(1 0 0 / 15%);
|
|
112
|
+
--ring: oklch(0.556 0 0);
|
|
113
|
+
--chart-1: oklch(0.488 0.243 264.376);
|
|
114
|
+
--chart-2: oklch(0.696 0.17 162.48);
|
|
115
|
+
--chart-3: oklch(0.769 0.188 70.08);
|
|
116
|
+
--chart-4: oklch(0.627 0.265 303.9);
|
|
117
|
+
--chart-5: oklch(0.645 0.246 16.439);
|
|
118
|
+
--sidebar: oklch(0.205 0 0);
|
|
119
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
120
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
121
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
122
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
123
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
124
|
+
--sidebar-border: oklch(1 0 0 / 10%);
|
|
125
|
+
--sidebar-ring: oklch(0.556 0 0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@layer base {
|
|
129
|
+
* {
|
|
130
|
+
@apply border-border outline-ring/50;
|
|
131
|
+
}
|
|
132
|
+
body {
|
|
133
|
+
@apply bg-background text-foreground;
|
|
134
|
+
}
|
|
135
|
+
}
|
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/filters/filters.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type definitions for filter structures
|
|
5
|
+
* All types are derived from Zod schemas using z.infer for type safety
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Allowed filter operators for Salesforce search queries
|
|
10
|
+
*/
|
|
11
|
+
export const FILTER_OPERATORS = [
|
|
12
|
+
"eq", // Equals
|
|
13
|
+
"ne", // Not equals
|
|
14
|
+
"like", // Pattern matching (contains)
|
|
15
|
+
"gt", // Greater than
|
|
16
|
+
"gte", // Greater than or equal
|
|
17
|
+
"lt", // Less than
|
|
18
|
+
"lte", // Less than or equal
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Filter operator type
|
|
23
|
+
*/
|
|
24
|
+
export type FilterOperator = (typeof FILTER_OPERATORS)[number];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Salesforce field path validation regex
|
|
28
|
+
* Validates field paths like:
|
|
29
|
+
* - Simple fields: "Name", "FieldName__c"
|
|
30
|
+
* - Relationship fields: "Account__r.Name", "Owner__r.FieldName__c"
|
|
31
|
+
* - Nested relationships: "Account__r.Owner__r.Name"
|
|
32
|
+
*
|
|
33
|
+
* Pattern explanation:
|
|
34
|
+
* - ^[A-Za-z][A-Za-z0-9_]* - Starts with letter, followed by letters/numbers/underscores
|
|
35
|
+
* - (__[cr])? - Optional relationship suffix (__r or __c)
|
|
36
|
+
* - (\.[A-Za-z][A-Za-z0-9_]*(__[cr])?)* - Optional relationship traversal (dot notation)
|
|
37
|
+
*/
|
|
38
|
+
const SALESFORCE_FIELD_PATH_REGEX =
|
|
39
|
+
/^[A-Za-z][A-Za-z0-9_]*(__[cr])?(\.[A-Za-z][A-Za-z0-9_]*(__[cr])?)*$/;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Validates Salesforce field path format
|
|
43
|
+
* @param fieldPath - The field path to validate
|
|
44
|
+
* @returns true if valid, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
function isValidSalesforceFieldPath(fieldPath: string): boolean {
|
|
47
|
+
if (!fieldPath || fieldPath.trim().length === 0) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return SALESFORCE_FIELD_PATH_REGEX.test(fieldPath);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Zod Schema for Filter Attributes
|
|
54
|
+
const FilterAttributesSchema = z.object({
|
|
55
|
+
affordance: z.string().optional(),
|
|
56
|
+
placeholder: z.string().optional(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Filter attributes containing input-specific properties
|
|
61
|
+
*/
|
|
62
|
+
export type FilterAttributes = z.infer<typeof FilterAttributesSchema>;
|
|
63
|
+
|
|
64
|
+
// Zod Schema for Filter
|
|
65
|
+
const FilterSchema = z.object({
|
|
66
|
+
affordance: z.string(),
|
|
67
|
+
attributes: FilterAttributesSchema.optional(),
|
|
68
|
+
defaultValues: z.array(z.string()).optional(),
|
|
69
|
+
helpMessage: z.string().nullable().optional(),
|
|
70
|
+
label: z.string(),
|
|
71
|
+
targetFieldPath: z.string().refine((value) => isValidSalesforceFieldPath(value), {
|
|
72
|
+
message:
|
|
73
|
+
"Invalid Salesforce field path format. Field paths must start with a letter and can contain letters, numbers, underscores, and relationship notation (__r or __c). Use dot notation for relationships (e.g., 'Account__r.Name').",
|
|
74
|
+
}),
|
|
75
|
+
type: z.string(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Single filter definition from getObjectListFilters API
|
|
80
|
+
*/
|
|
81
|
+
export type Filter = z.infer<typeof FilterSchema>;
|
|
82
|
+
|
|
83
|
+
// Export schema for validation
|
|
84
|
+
export const FilterArraySchema = z.array(FilterSchema);
|
|
85
|
+
|
|
86
|
+
// Zod Schema for Filter Criteria with operator and field path validation
|
|
87
|
+
const FilterCriteriaSchema = z.object({
|
|
88
|
+
objectApiName: z.string().min(1, "Object API name is required"),
|
|
89
|
+
fieldPath: z
|
|
90
|
+
.string()
|
|
91
|
+
.min(1, "Field path is required")
|
|
92
|
+
.refine((value) => isValidSalesforceFieldPath(value), {
|
|
93
|
+
message:
|
|
94
|
+
"Invalid Salesforce field path format. Field paths must start with a letter and can contain letters, numbers, underscores, and relationship notation (__r or __c). Use dot notation for relationships (e.g., 'Account__r.Name').",
|
|
95
|
+
}),
|
|
96
|
+
operator: z.enum(FILTER_OPERATORS, {
|
|
97
|
+
message: `Operator must be one of: ${FILTER_OPERATORS.join(", ")}`,
|
|
98
|
+
}),
|
|
99
|
+
values: z.array(z.union([z.string(), z.number()])).min(1, "At least one value is required"),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Filter criteria structure for filtering search results
|
|
104
|
+
*/
|
|
105
|
+
export type FilterCriteria = z.infer<typeof FilterCriteriaSchema>;
|
|
106
|
+
|
|
107
|
+
// Export schema for validation
|
|
108
|
+
export const FilterCriteriaArraySchema = z.array(FilterCriteriaSchema);
|
|
109
|
+
|
|
110
|
+
// Zod Schema for Filters Response
|
|
111
|
+
const FiltersResponseSchema = z.record(z.string(), z.unknown()).and(
|
|
112
|
+
z.object({
|
|
113
|
+
filters: FilterArraySchema.optional(),
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Filters response structure
|
|
119
|
+
*/
|
|
120
|
+
export type FiltersResponse = z.infer<typeof FiltersResponseSchema>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type definitions for picklist value structures
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Zod Schema for Picklist Value
|
|
8
|
+
const PicklistValueSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
// 1. Cleanup: Attributes are usually an object, not just 'unknown'
|
|
11
|
+
attributes: z.record(z.string(), z.unknown()).nullish(),
|
|
12
|
+
label: z.string(),
|
|
13
|
+
|
|
14
|
+
// 2. Precise Typing: 'validFor' is an array of indices (numbers)
|
|
15
|
+
// pointing to the controlling field's values.
|
|
16
|
+
validFor: z.array(z.number()).nullish(),
|
|
17
|
+
value: z.string(),
|
|
18
|
+
|
|
19
|
+
// 3. Usability: Added common API fields that are useful for UI logic
|
|
20
|
+
// (marked optional in case the specific API version omits them)
|
|
21
|
+
defaultValue: z.boolean().nullish(),
|
|
22
|
+
active: z.boolean().nullish(),
|
|
23
|
+
})
|
|
24
|
+
.passthrough();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Single picklist value from the API
|
|
28
|
+
*/
|
|
29
|
+
export type PicklistValue = z.infer<typeof PicklistValueSchema>;
|
|
30
|
+
|
|
31
|
+
// Export schema for validation
|
|
32
|
+
export const PicklistValueArraySchema = z.array(PicklistValueSchema);
|