@schandlergarcia/sf-web-components 2.3.16 → 2.4.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/CHANGELOG.md +27 -0
- package/CLAUDE.md +12 -13
- package/README.md +0 -15
- package/dist/styles/global.css +46 -48
- package/package.json +1 -2
- package/scripts/apply-brand.mjs +47 -30
- package/scripts/postinstall.mjs +1 -11
- package/src/styles/global.css +46 -48
- package/brands/engine/PARTNER_HUB_PRD.md +0 -584
- package/brands/engine/agentApiConfig.ts +0 -36
- package/brands/engine/app/api/graphql-operations-types.ts +0 -11260
- package/brands/engine/app/api/graphqlClient.ts +0 -25
- package/brands/engine/app/api/partnerQueries.ts +0 -212
- package/brands/engine/app/appLayout.tsx +0 -5
- package/brands/engine/app/components/AgentPanel.tsx +0 -402
- package/brands/engine/app/components/AgentforceConversationClient.tsx +0 -201
- package/brands/engine/app/components/__inherit_AgentforceConversationClient.tsx +0 -3
- package/brands/engine/app/components/alerts/status-alert.tsx +0 -49
- package/brands/engine/app/components/layouts/card-layout.tsx +0 -29
- package/brands/engine/app/components/workspace/CommandCenter.tsx +0 -16
- package/brands/engine/app/config/agentApi.ts +0 -36
- package/brands/engine/app/features/object-search/__examples__/api/accountSearchService.ts +0 -46
- package/brands/engine/app/features/object-search/__examples__/api/query/distinctAccountIndustries.graphql +0 -19
- package/brands/engine/app/features/object-search/__examples__/api/query/distinctAccountTypes.graphql +0 -19
- package/brands/engine/app/features/object-search/__examples__/api/query/getAccountDetail.graphql +0 -121
- package/brands/engine/app/features/object-search/__examples__/api/query/searchAccounts.graphql +0 -51
- package/brands/engine/app/features/object-search/__examples__/pages/AccountObjectDetailPage.tsx +0 -357
- package/brands/engine/app/features/object-search/__examples__/pages/AccountSearch.tsx +0 -312
- package/brands/engine/app/features/object-search/__examples__/pages/Home.tsx +0 -34
- package/brands/engine/app/features/object-search/api/objectSearchService.ts +0 -84
- package/brands/engine/app/features/object-search/components/ActiveFilters.tsx +0 -89
- package/brands/engine/app/features/object-search/components/FilterContext.tsx +0 -83
- package/brands/engine/app/features/object-search/components/ObjectBreadcrumb.tsx +0 -66
- package/brands/engine/app/features/object-search/components/PaginationControls.tsx +0 -109
- package/brands/engine/app/features/object-search/components/SearchBar.tsx +0 -41
- package/brands/engine/app/features/object-search/components/SortControl.tsx +0 -143
- package/brands/engine/app/features/object-search/components/filters/BooleanFilter.tsx +0 -78
- package/brands/engine/app/features/object-search/components/filters/DateFilter.tsx +0 -128
- package/brands/engine/app/features/object-search/components/filters/DateRangeFilter.tsx +0 -70
- package/brands/engine/app/features/object-search/components/filters/FilterFieldWrapper.tsx +0 -33
- package/brands/engine/app/features/object-search/components/filters/MultiSelectFilter.tsx +0 -97
- package/brands/engine/app/features/object-search/components/filters/NumericRangeFilter.tsx +0 -163
- package/brands/engine/app/features/object-search/components/filters/SearchFilter.tsx +0 -50
- package/brands/engine/app/features/object-search/components/filters/SelectFilter.tsx +0 -97
- package/brands/engine/app/features/object-search/components/filters/TextFilter.tsx +0 -91
- package/brands/engine/app/features/object-search/hooks/useAsyncData.ts +0 -54
- package/brands/engine/app/features/object-search/hooks/useCachedAsyncData.ts +0 -184
- package/brands/engine/app/features/object-search/hooks/useDebouncedCallback.ts +0 -34
- package/brands/engine/app/features/object-search/hooks/useObjectSearchParams.ts +0 -252
- package/brands/engine/app/features/object-search/utils/debounce.ts +0 -25
- package/brands/engine/app/features/object-search/utils/fieldUtils.ts +0 -29
- package/brands/engine/app/features/object-search/utils/filterUtils.ts +0 -404
- package/brands/engine/app/features/object-search/utils/sortUtils.ts +0 -38
- package/brands/engine/app/hooks/useEngineLiveData.ts +0 -49
- package/brands/engine/app/hooks/useEvaAgent.ts +0 -288
- package/brands/engine/app/hooks/usePartnerDashboardData.ts +0 -141
- package/brands/engine/app/navigationMenu.tsx +0 -80
- package/brands/engine/app/pages/AccountObjectDetailPage.tsx +0 -361
- package/brands/engine/app/pages/AccountSearch.tsx +0 -305
- package/brands/engine/app/pages/BlankDashboard.tsx +0 -15
- package/brands/engine/app/pages/DataTest.tsx +0 -78
- package/brands/engine/app/pages/Home.tsx +0 -5
- package/brands/engine/app/pages/NotFound.tsx +0 -19
- package/brands/engine/app/pages/PartnerHubDashboard.tsx +0 -2077
- package/brands/engine/app/pages/Search.tsx +0 -13
- package/brands/engine/app/router-utils.tsx +0 -35
- package/brands/engine/app/routes.tsx +0 -39
- package/brands/engine/app/styles/global.css +0 -269
- package/brands/engine/brand.css +0 -40
- package/brands/engine/engine-command-center-prd.md +0 -575
- package/brands/engine/engine-live-data.js +0 -135
- package/brands/engine/engine-sample-data.js +0 -378
- package/brands/engine/engine_logo.png +0 -0
- package/brands/engine/global.css +0 -269
- package/brands/engine/partner-hub-sample-data.js +0 -281
- package/brands/engine/schema.graphql +0 -292
- package/brands/engine/useEngineLiveData.ts +0 -49
- package/brands/engine/useEvaAgent.ts +0 -288
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* filterUtils.ts
|
|
3
|
-
*
|
|
4
|
-
* Centralizes all filter-related transformations for the object search feature.
|
|
5
|
-
* This module handles two distinct concerns:
|
|
6
|
-
*
|
|
7
|
-
* 1. **URL serialization** — Converting filter/sort state to and from
|
|
8
|
-
* URLSearchParams so that search criteria can be bookmarked, shared, and
|
|
9
|
-
* restored on page load.
|
|
10
|
-
*
|
|
11
|
-
* 2. **GraphQL query building** — Converting the same filter state into the
|
|
12
|
-
* `where` clause shape expected by the GraphQL API.
|
|
13
|
-
*
|
|
14
|
-
* Both concerns operate on the shared {@link ActiveFilterValue} type, which
|
|
15
|
-
* represents a single active filter with a field name, filter type, and one or
|
|
16
|
-
* more values (value, min, max).
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import type { SortState } from "./sortUtils";
|
|
20
|
-
|
|
21
|
-
export type FilterFieldType =
|
|
22
|
-
| "text"
|
|
23
|
-
| "picklist"
|
|
24
|
-
| "numeric"
|
|
25
|
-
| "boolean"
|
|
26
|
-
| "date"
|
|
27
|
-
| "daterange"
|
|
28
|
-
| "datetime"
|
|
29
|
-
| "datetimerange"
|
|
30
|
-
| "multipicklist"
|
|
31
|
-
| "search";
|
|
32
|
-
|
|
33
|
-
export type FilterFieldConfig<TFieldName extends string = string> = {
|
|
34
|
-
field: TFieldName;
|
|
35
|
-
label: string;
|
|
36
|
-
type: FilterFieldType;
|
|
37
|
-
placeholder?: string;
|
|
38
|
-
/** Required for picklist type. */
|
|
39
|
-
options?: Array<{ value: string; label: string }>;
|
|
40
|
-
helpText?: string;
|
|
41
|
-
/** Required for search type — the fields to match against with `or`. */
|
|
42
|
-
searchFields?: string[];
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type ActiveFilterValue<TFieldName extends string = string> = {
|
|
46
|
-
field: TFieldName;
|
|
47
|
-
label: string;
|
|
48
|
-
type: FilterFieldType;
|
|
49
|
-
value?: string;
|
|
50
|
-
min?: string;
|
|
51
|
-
max?: string;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// ---------------------------------------------------------------------------
|
|
55
|
-
// URL Serialization
|
|
56
|
-
// ---------------------------------------------------------------------------
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Prefix applied to all filter-related URL search params.
|
|
60
|
-
* This namespaces filter params so they don't collide with other query params
|
|
61
|
-
* (e.g. pagination, feature flags).
|
|
62
|
-
*
|
|
63
|
-
* @example "f.Industry=Technology" or "f.AnnualRevenue.min=1000000"
|
|
64
|
-
*/
|
|
65
|
-
const FILTER_PREFIX = "f.";
|
|
66
|
-
|
|
67
|
-
/** URL param key for the multi-field search term. */
|
|
68
|
-
const SEARCH_KEY = "q";
|
|
69
|
-
|
|
70
|
-
/** URL param key for the currently sorted field name. */
|
|
71
|
-
const SORT_KEY = "sort";
|
|
72
|
-
|
|
73
|
-
/** URL param key for the sort direction (ASC or DESC). */
|
|
74
|
-
const DIR_KEY = "dir";
|
|
75
|
-
|
|
76
|
-
/** URL param key for the page size preference. */
|
|
77
|
-
const PAGE_SIZE_KEY = "ps";
|
|
78
|
-
const PAGE_KEY = "page";
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Serializes filter and sort state into URLSearchParams.
|
|
82
|
-
*
|
|
83
|
-
* Encoding scheme:
|
|
84
|
-
* - Simple values (text, picklist, boolean, multipicklist):
|
|
85
|
-
* `f.<field>=<value>`
|
|
86
|
-
* - Range values (numeric, date, daterange):
|
|
87
|
-
* `f.<field>.min=<min>` and/or `f.<field>.max=<max>`
|
|
88
|
-
* - Sort: `sort=<field>&dir=ASC|DESC`
|
|
89
|
-
*
|
|
90
|
-
* @param filters - The currently active filters to serialize.
|
|
91
|
-
* @param sort - The current sort state, or null if no sort is applied.
|
|
92
|
-
* @returns A URLSearchParams instance representing the full search state.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* const params = filtersToSearchParams(
|
|
97
|
-
* [{ field: "Industry", type: "picklist", value: "Technology" }],
|
|
98
|
-
* { field: "Name", direction: "ASC" },
|
|
99
|
-
* );
|
|
100
|
-
* // params.toString() => "f.Industry=Technology&sort=Name&dir=ASC"
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
export function filtersToSearchParams(
|
|
104
|
-
filters: ActiveFilterValue[],
|
|
105
|
-
sort: SortState | null,
|
|
106
|
-
pageSize?: number,
|
|
107
|
-
pageIndex?: number,
|
|
108
|
-
): URLSearchParams {
|
|
109
|
-
const params = new URLSearchParams();
|
|
110
|
-
|
|
111
|
-
for (const filter of filters) {
|
|
112
|
-
if (filter.type === "search") {
|
|
113
|
-
if (filter.value) params.set(SEARCH_KEY, filter.value);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
if (filter.value !== undefined && filter.value !== "") {
|
|
117
|
-
params.set(`${FILTER_PREFIX}${filter.field}`, filter.value);
|
|
118
|
-
}
|
|
119
|
-
if (filter.min !== undefined && filter.min !== "") {
|
|
120
|
-
params.set(`${FILTER_PREFIX}${filter.field}.min`, filter.min);
|
|
121
|
-
}
|
|
122
|
-
if (filter.max !== undefined && filter.max !== "") {
|
|
123
|
-
params.set(`${FILTER_PREFIX}${filter.field}.max`, filter.max);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (sort) {
|
|
128
|
-
params.set(SORT_KEY, sort.field);
|
|
129
|
-
params.set(DIR_KEY, sort.direction);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (pageSize !== undefined) {
|
|
133
|
-
params.set(PAGE_SIZE_KEY, String(pageSize));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (pageIndex !== undefined && pageIndex > 0) {
|
|
137
|
-
params.set(PAGE_KEY, String(pageIndex + 1));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return params;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Deserializes URLSearchParams back into filter and sort state.
|
|
145
|
-
*
|
|
146
|
-
* Requires the full list of filter configs so it knows which URL params to look
|
|
147
|
-
* for and what type each filter is. Params that don't match a known config are
|
|
148
|
-
* silently ignored, making this safe against stale or hand-edited URLs.
|
|
149
|
-
*
|
|
150
|
-
* @param params - The URLSearchParams to parse (typically from the browser URL).
|
|
151
|
-
* @param configs - The filter field configurations defining available filters.
|
|
152
|
-
* @returns An object containing the deserialized `filters` array and `sort` state.
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* const url = new URLSearchParams("f.Industry=Technology&sort=Name&dir=ASC");
|
|
157
|
-
* const { filters, sort } = searchParamsToFilters(url, filterConfigs);
|
|
158
|
-
* // filters => [{ field: "Industry", type: "picklist", value: "Technology" }]
|
|
159
|
-
* // sort => { field: "Name", direction: "ASC" }
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
export function searchParamsToFilters(
|
|
163
|
-
params: URLSearchParams,
|
|
164
|
-
configs: FilterFieldConfig[],
|
|
165
|
-
): {
|
|
166
|
-
filters: ActiveFilterValue[];
|
|
167
|
-
sort: SortState | null;
|
|
168
|
-
pageSize: number | undefined;
|
|
169
|
-
pageIndex: number;
|
|
170
|
-
} {
|
|
171
|
-
const filters: ActiveFilterValue[] = [];
|
|
172
|
-
|
|
173
|
-
for (const config of configs) {
|
|
174
|
-
const { field, label, type } = config;
|
|
175
|
-
|
|
176
|
-
if (type === "search") {
|
|
177
|
-
const q = params.get(SEARCH_KEY);
|
|
178
|
-
if (q) {
|
|
179
|
-
filters.push({ field, label, type: "search", value: q });
|
|
180
|
-
}
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const value = params.get(`${FILTER_PREFIX}${field}`) ?? undefined;
|
|
185
|
-
const min = params.get(`${FILTER_PREFIX}${field}.min`) ?? undefined;
|
|
186
|
-
const max = params.get(`${FILTER_PREFIX}${field}.max`) ?? undefined;
|
|
187
|
-
|
|
188
|
-
const hasValue = value !== undefined && value !== "";
|
|
189
|
-
const hasRange = (min !== undefined && min !== "") || (max !== undefined && max !== "");
|
|
190
|
-
|
|
191
|
-
if (hasValue || hasRange) {
|
|
192
|
-
filters.push({ field, label, type, value, min, max });
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
let sort: SortState | null = null;
|
|
197
|
-
const sortField = params.get(SORT_KEY);
|
|
198
|
-
const sortDir = params.get(DIR_KEY);
|
|
199
|
-
if (sortField) {
|
|
200
|
-
sort = {
|
|
201
|
-
field: sortField,
|
|
202
|
-
direction: sortDir === "DESC" ? "DESC" : "ASC",
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const pageSizeRaw = params.get(PAGE_SIZE_KEY);
|
|
207
|
-
const pageSize = pageSizeRaw ? parseInt(pageSizeRaw, 10) : undefined;
|
|
208
|
-
|
|
209
|
-
const pageRaw = params.get(PAGE_KEY);
|
|
210
|
-
const page = pageRaw ? parseInt(pageRaw, 10) : 1;
|
|
211
|
-
const pageIndex = !isNaN(page) && page > 1 ? page - 1 : 0;
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
filters,
|
|
215
|
-
sort,
|
|
216
|
-
pageSize: pageSize && !isNaN(pageSize) ? pageSize : undefined,
|
|
217
|
-
pageIndex,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// ---------------------------------------------------------------------------
|
|
222
|
-
// GraphQL Filter Building
|
|
223
|
-
// ---------------------------------------------------------------------------
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Converts an array of active filter values into a GraphQL `where` clause.
|
|
227
|
-
*
|
|
228
|
-
* Each filter is individually converted to a clause via {@link buildSingleFilter},
|
|
229
|
-
* then multiple clauses are combined with a top-level `and` operator. This ensures
|
|
230
|
-
* all active filters are applied simultaneously (intersection semantics).
|
|
231
|
-
*
|
|
232
|
-
* @typeParam TFilter - The GraphQL filter input type (e.g. `AccountFilterInput`).
|
|
233
|
-
* @param filters - The active filters to convert.
|
|
234
|
-
* @returns A filter object for the GraphQL `where` variable, or `undefined` if
|
|
235
|
-
* no filters are active (which tells the API to return unfiltered results).
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* const where = buildFilter<AccountFilterInput>([
|
|
240
|
-
* { field: "Industry", type: "picklist", value: "Technology" },
|
|
241
|
-
* { field: "AnnualRevenue", type: "numeric", min: "1000000" },
|
|
242
|
-
* ]);
|
|
243
|
-
* // where => { and: [
|
|
244
|
-
* // { Industry: { eq: "Technology" } },
|
|
245
|
-
* // { AnnualRevenue: { gte: 1000000 } },
|
|
246
|
-
* // ]}
|
|
247
|
-
* ```
|
|
248
|
-
*/
|
|
249
|
-
export function buildFilter<TFilter>(
|
|
250
|
-
filters: ActiveFilterValue[],
|
|
251
|
-
configs: FilterFieldConfig[],
|
|
252
|
-
): TFilter | undefined {
|
|
253
|
-
const configMap = new Map(configs.map((c) => [c.field, c]));
|
|
254
|
-
const clauses: TFilter[] = [];
|
|
255
|
-
|
|
256
|
-
for (const filter of filters) {
|
|
257
|
-
const clause = buildSingleFilter<TFilter>(filter, configMap.get(filter.field));
|
|
258
|
-
if (clause) clauses.push(clause);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (clauses.length === 0) return undefined;
|
|
262
|
-
if (clauses.length === 1) return clauses[0];
|
|
263
|
-
return { and: clauses } as TFilter;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Converts a YYYY-MM-DD date string to a full ISO-8601 datetime at midnight UTC.
|
|
268
|
-
* Used as the inclusive lower bound for date range queries.
|
|
269
|
-
*/
|
|
270
|
-
function toStartOfDay(dateStr: string): string {
|
|
271
|
-
return `${dateStr}T00:00:00.000Z`;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Converts a YYYY-MM-DD date string to a full ISO-8601 datetime at the last
|
|
276
|
-
* millisecond of the day in UTC. Used as the inclusive upper bound for date
|
|
277
|
-
* range queries.
|
|
278
|
-
*/
|
|
279
|
-
function toEndOfDay(dateStr: string): string {
|
|
280
|
-
return `${dateStr}T23:59:59.999Z`;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Converts a single active filter value into a GraphQL filter clause.
|
|
285
|
-
*
|
|
286
|
-
* Supported filter types and their GraphQL mappings:
|
|
287
|
-
*
|
|
288
|
-
* | Type | GraphQL operator(s) | Example output |
|
|
289
|
-
* |-----------------|---------------------|----------------------------------------------------------|
|
|
290
|
-
* | `text` | `like` | `{ Name: { like: "%Acme%" } }` |
|
|
291
|
-
* | `picklist` | `eq` | `{ Industry: { eq: "Technology" } }` |
|
|
292
|
-
* | `multipicklist` | `eq` or `in` | `{ Type: { in: ["A", "B"] } }` |
|
|
293
|
-
* | `numeric` | `gte` / `lte` | `{ Revenue: { gte: 1000, lte: 5000 } }` |
|
|
294
|
-
* | `boolean` | `eq` | `{ IsActive: { eq: true } }` |
|
|
295
|
-
* | `date` | dynamic operator | `{ CreatedDate: { gte: { value: "..." } } }` |
|
|
296
|
-
* | `daterange` | `gte` + `lte` | Combined with `and` if both bounds set |
|
|
297
|
-
* | `search` | `like` + `or` | `{ or: [{ Name: { like: "%x%" } }, { Phone: { like: "%x%" } }] }` |
|
|
298
|
-
*
|
|
299
|
-
* The `search` type uses `config.searchFields` to build an `or` clause that
|
|
300
|
-
* matches the search term across multiple fields simultaneously (union semantics).
|
|
301
|
-
*
|
|
302
|
-
* @param filter - The active filter value to convert.
|
|
303
|
-
* @param config - The corresponding field config. Required for `search` type
|
|
304
|
-
* (provides `searchFields`); optional for all other types.
|
|
305
|
-
* @returns A single filter clause, or `null` if the filter has no meaningful value.
|
|
306
|
-
*/
|
|
307
|
-
function buildSingleFilter<TFilter>(
|
|
308
|
-
filter: ActiveFilterValue,
|
|
309
|
-
config?: FilterFieldConfig,
|
|
310
|
-
): TFilter | null {
|
|
311
|
-
const { field, type, value, min, max } = filter;
|
|
312
|
-
|
|
313
|
-
switch (type) {
|
|
314
|
-
case "text": {
|
|
315
|
-
if (!value) return null;
|
|
316
|
-
return { [field]: { like: `%${value}%` } } as TFilter;
|
|
317
|
-
}
|
|
318
|
-
case "picklist": {
|
|
319
|
-
if (!value) return null;
|
|
320
|
-
return { [field]: { eq: value } } as TFilter;
|
|
321
|
-
}
|
|
322
|
-
case "numeric": {
|
|
323
|
-
if (!min && !max) return null;
|
|
324
|
-
const ops: Record<string, number> = {};
|
|
325
|
-
if (min) ops.gte = Number(min);
|
|
326
|
-
if (max) ops.lte = Number(max);
|
|
327
|
-
return { [field]: ops } as TFilter;
|
|
328
|
-
}
|
|
329
|
-
case "boolean": {
|
|
330
|
-
if (value === undefined || value === "") return null;
|
|
331
|
-
return { [field]: { eq: value === "true" } } as TFilter;
|
|
332
|
-
}
|
|
333
|
-
case "multipicklist": {
|
|
334
|
-
if (!value) return null;
|
|
335
|
-
const values = value.split(",");
|
|
336
|
-
if (values.length === 1) {
|
|
337
|
-
return { [field]: { eq: values[0] } } as TFilter;
|
|
338
|
-
}
|
|
339
|
-
return { [field]: { in: values } } as TFilter;
|
|
340
|
-
}
|
|
341
|
-
case "date": {
|
|
342
|
-
if (!min && !max) return null;
|
|
343
|
-
const op = value ?? (min ? "gte" : "lte");
|
|
344
|
-
const dateStr = min ?? max;
|
|
345
|
-
return { [field]: { [op]: { value: dateStr } } } as TFilter;
|
|
346
|
-
}
|
|
347
|
-
case "daterange": {
|
|
348
|
-
if (!min && !max) return null;
|
|
349
|
-
const clauses: TFilter[] = [];
|
|
350
|
-
if (min) {
|
|
351
|
-
clauses.push({
|
|
352
|
-
[field]: { gte: { value: min } },
|
|
353
|
-
} as TFilter);
|
|
354
|
-
}
|
|
355
|
-
if (max) {
|
|
356
|
-
clauses.push({
|
|
357
|
-
[field]: { lte: { value: max } },
|
|
358
|
-
} as TFilter);
|
|
359
|
-
}
|
|
360
|
-
return clauses.length === 1 ? clauses[0] : ({ and: clauses } as TFilter);
|
|
361
|
-
}
|
|
362
|
-
case "datetime": {
|
|
363
|
-
if (!min && !max) return null;
|
|
364
|
-
const op = value ?? (min ? "gte" : "lte");
|
|
365
|
-
const dateStr = min ?? max;
|
|
366
|
-
const isoStr = op === "gte" || op === "gt" ? toStartOfDay(dateStr!) : toEndOfDay(dateStr!);
|
|
367
|
-
return { [field]: { [op]: { value: isoStr } } } as TFilter;
|
|
368
|
-
}
|
|
369
|
-
case "datetimerange": {
|
|
370
|
-
if (!min && !max) return null;
|
|
371
|
-
const clauses: TFilter[] = [];
|
|
372
|
-
if (min) {
|
|
373
|
-
clauses.push({
|
|
374
|
-
[field]: { gte: { value: toStartOfDay(min) } },
|
|
375
|
-
} as TFilter);
|
|
376
|
-
}
|
|
377
|
-
if (max) {
|
|
378
|
-
clauses.push({
|
|
379
|
-
[field]: { lte: { value: toEndOfDay(max) } },
|
|
380
|
-
} as TFilter);
|
|
381
|
-
}
|
|
382
|
-
return clauses.length === 1 ? clauses[0] : ({ and: clauses } as TFilter);
|
|
383
|
-
}
|
|
384
|
-
case "search": {
|
|
385
|
-
if (!value) return null;
|
|
386
|
-
const searchFields = config?.searchFields ?? [];
|
|
387
|
-
if (searchFields.length === 0) return null;
|
|
388
|
-
// Supports dot-notation for relationship fields (e.g. "User__r.Name")
|
|
389
|
-
// by building nested filter objects: { User__r: { Name: { like: "%x%" } } }
|
|
390
|
-
const clauses = searchFields.map((f) => {
|
|
391
|
-
const parts = f.split(".");
|
|
392
|
-
let clause: Record<string, unknown> = { like: `%${value}%` };
|
|
393
|
-
for (let i = parts.length - 1; i >= 0; i--) {
|
|
394
|
-
clause = { [parts[i]]: clause };
|
|
395
|
-
}
|
|
396
|
-
return clause as TFilter;
|
|
397
|
-
});
|
|
398
|
-
if (clauses.length === 1) return clauses[0];
|
|
399
|
-
return { or: clauses } as TFilter;
|
|
400
|
-
}
|
|
401
|
-
default:
|
|
402
|
-
return null;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ResultOrder, NullOrder } from "../../../api/graphql-operations-types";
|
|
2
|
-
|
|
3
|
-
export type SortFieldConfig<TFieldName extends string = string> = {
|
|
4
|
-
field: TFieldName;
|
|
5
|
-
label: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type SortState<TFieldName extends string = string> = {
|
|
9
|
-
field: TFieldName;
|
|
10
|
-
direction: "ASC" | "DESC";
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Converts a {@link SortState} into a GraphQL order-by object.
|
|
15
|
-
*
|
|
16
|
-
* @typeParam TOrderBy - The GraphQL order-by input type (e.g. `AccountOrderByInput`).
|
|
17
|
-
* @param sort - The current sort state from the UI, or `null` if no sort is applied.
|
|
18
|
-
* @returns An order-by object for the GraphQL query's `orderBy` variable, or
|
|
19
|
-
* `undefined` if no sort is active (which uses the API's default ordering).
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const orderBy = buildOrderBy<AccountOrderByInput>({
|
|
24
|
-
* field: "Name",
|
|
25
|
-
* direction: "ASC",
|
|
26
|
-
* });
|
|
27
|
-
* // orderBy => { Name: { order: ResultOrder.Asc, nulls: NullOrder.Last } }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function buildOrderBy<TOrderBy>(sort: SortState | null): TOrderBy | undefined {
|
|
31
|
-
if (!sort) return undefined;
|
|
32
|
-
return {
|
|
33
|
-
[sort.field]: {
|
|
34
|
-
order: sort.direction === "ASC" ? ResultOrder.Asc : ResultOrder.Desc,
|
|
35
|
-
nulls: NullOrder.Last,
|
|
36
|
-
},
|
|
37
|
-
} as TOrderBy;
|
|
38
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from "react";
|
|
2
|
-
import * as live from "@/data/engine-live-data";
|
|
3
|
-
|
|
4
|
-
const SIMULATED_LOAD_MS = 2000;
|
|
5
|
-
|
|
6
|
-
export interface EngineLiveData {
|
|
7
|
-
loading: boolean;
|
|
8
|
-
mapMarkers: typeof live.MAP_MARKERS;
|
|
9
|
-
mapArcs: typeof live.MAP_ARCS;
|
|
10
|
-
mapOverlays: typeof live.MAP_OVERLAYS;
|
|
11
|
-
flightStatusList: typeof live.FLIGHT_STATUS_LIST;
|
|
12
|
-
travelerCards: typeof live.TRAVELER_CARDS;
|
|
13
|
-
disruptionCards: typeof live.DISRUPTION_CARDS;
|
|
14
|
-
escalationCards: typeof live.ESCALATION_CARDS;
|
|
15
|
-
monthlySpend: typeof live.MONTHLY_SPEND;
|
|
16
|
-
metrics: typeof live.METRICS;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Provides the live dataset for the Engine Travel Command Center.
|
|
21
|
-
*
|
|
22
|
-
* Simulates a 2-second network fetch, then resolves with all live data.
|
|
23
|
-
* Does NOT control the data mode — that's handled by ENABLE_SAMPLE_DATA_CACHE
|
|
24
|
-
* in src/lib/dataStrategy.ts. When the flag is false, every useDataSource call
|
|
25
|
-
* returns its live prop (which this hook provides) instead of its sample prop.
|
|
26
|
-
*/
|
|
27
|
-
export function useEngineLiveData(): EngineLiveData {
|
|
28
|
-
const [loading, setLoading] = useState(true);
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
const timer = setTimeout(() => {
|
|
32
|
-
setLoading(false);
|
|
33
|
-
}, SIMULATED_LOAD_MS);
|
|
34
|
-
return () => clearTimeout(timer);
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
loading,
|
|
39
|
-
mapMarkers: live.MAP_MARKERS,
|
|
40
|
-
mapArcs: live.MAP_ARCS,
|
|
41
|
-
mapOverlays: live.MAP_OVERLAYS,
|
|
42
|
-
flightStatusList: live.FLIGHT_STATUS_LIST,
|
|
43
|
-
travelerCards: live.TRAVELER_CARDS,
|
|
44
|
-
disruptionCards: live.DISRUPTION_CARDS,
|
|
45
|
-
escalationCards: live.ESCALATION_CARDS,
|
|
46
|
-
monthlySpend: live.MONTHLY_SPEND,
|
|
47
|
-
metrics: live.METRICS,
|
|
48
|
-
};
|
|
49
|
-
}
|