@appdirect/design-system 0.0.17 → 0.0.18

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 (85) hide show
  1. package/bin/ad-sync-design-md.mjs +0 -0
  2. package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
  3. package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
  4. package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
  5. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
  6. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
  7. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
  8. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
  9. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
  10. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
  11. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
  12. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
  13. package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
  14. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
  15. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
  16. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
  17. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
  18. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
  19. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
  20. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
  21. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
  22. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
  23. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
  24. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
  25. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
  26. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
  27. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
  28. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
  29. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
  30. package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
  31. package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
  32. package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
  33. package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
  34. package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
  35. package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
  36. package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
  37. package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
  38. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
  39. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
  40. package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
  41. package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
  42. package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
  43. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
  44. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
  45. package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
  46. package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
  47. package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
  48. package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
  49. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
  50. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
  51. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
  52. package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
  53. package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
  54. package/dist/ComplexComponents/DataTable/index.js +5 -1
  55. package/dist/ComplexComponents/DataTable/index.ts +13 -2
  56. package/dist/ComplexComponents/DataTable/table.module.css +9 -0
  57. package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
  58. package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
  59. package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
  60. package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
  61. package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
  62. package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
  63. package/dist/ComplexComponents/DataTable/types.js +5 -0
  64. package/dist/ComplexComponents/DataTable/types.ts +17 -0
  65. package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
  66. package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
  67. package/dist/DESIGN.md +9 -10
  68. package/dist/contracts/DataTable.json +83 -6
  69. package/dist/contracts/index.json +1 -1
  70. package/dist/css/foundations.css +4 -0
  71. package/dist/css/mantine.css +1 -1
  72. package/dist/css/tokens.css +3145 -0
  73. package/dist/index.js +3 -0
  74. package/dist/index.ts +14 -1
  75. package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
  76. package/dist/stories/index.json +13 -15
  77. package/package.json +5 -3
  78. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
  79. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
  80. package/dist/hooks/useTableHandlers.js +0 -136
  81. package/dist/hooks/useTableHandlers.ts +0 -179
  82. package/dist/hooks/useTableRenderFunctions.js +0 -164
  83. package/dist/hooks/useTableRenderFunctions.tsx +0 -283
  84. package/dist/hooks/useTableState.js +0 -70
  85. package/dist/hooks/useTableState.ts +0 -81
@@ -1,786 +1,245 @@
1
+ 'use client'; // DS-ADAPT: Next.js App Router
2
+ // Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
1
3
  import React, { ReactElement, useEffect, useState } from "react";
2
- import { ActionIcon, Indicator, Stack, Text, rem } from '@mantine/core';
3
- import { Button } from '../../../Buttons/Button';
4
- import { Grid } from '../../../Layout/Grid';
5
- import { SimpleGrid } from '../../../Layout/SimpleGrid';
6
- import { Inline } from '../../../Layout/Inline';
7
- import { IconFilter, IconMaximize, IconMinimize, IconBaselineDensityMedium, IconBaselineDensitySmall, IconBaselineDensityLarge } from '@tabler/icons-react';
8
- import { DatesRangeValue, type DateValue } from "@mantine/dates";
9
- import {
10
- MRT_TableInstance as MRTTableInstance,
11
- MRT_ToggleFullScreenButton as MRTToggleFullScreenButton,
12
- MRT_ToggleDensePaddingButton as MRTToggleDensePaddingButton,
13
- MRT_ToolbarAlertBanner as BaseMRTToolbarAlertBanner,
14
- MRT_RowData,
15
- } from "mantine-react-table-open";
16
- import { translate } from '../translations';
4
+ import { ActionIcon, Group, Indicator, Stack, Text, SimpleGrid } from "@mantine/core";
5
+ import { RiFilterLine as FilterIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
6
+ import { translate } from "../translations"; // DS-ADAPT: translate lives in DataTable/translations
17
7
  import SelectFilter from "./SelectFilter";
18
8
  import SearchFilter from "./SearchFilter";
19
- import DateRangeSelector from "./DateRangeSelectorFilter";
9
+ import DateRangeSelector, { type DateRangeInput } from "./DateRangeSelectorFilter";
20
10
  import FilterChip from "./FilterChip";
21
- import ResultCount from "./ResultCount/index";
11
+ import ResultCount from "./ResultCount";
12
+ import styles from "./CustomTopToolbar.module.css";
22
13
 
23
- // =============================================================================
24
- // TYPES & INTERFACES
25
- // =============================================================================
26
-
27
- /**
28
- * Enum defining all available cities for filtering
29
- * @TODO: Consider moving this to a separate constants file for better maintainability
30
- */
31
- export enum City {
14
+ export enum City { // DS-ADAPT: exported for DataTable props
32
15
  NEW_YORK = "New York",
33
16
  LOS_ANGELES = "Los Angeles",
34
- CHICAGO = "Chicago",
35
- SAN_FRANCISCO = "San Francisco",
36
- BOSTON = "Boston",
37
- SEATTLE = "Seattle",
38
17
  DENVER = "Denver",
39
- PORTLAND = "Portland",
40
- AUSTIN = "Austin",
41
- MIAMI = "Miami",
42
- PHOENIX = "Phoenix",
43
- LAS_VEGAS = "Las Vegas",
44
- DETROIT = "Detroit",
45
- NASHVILLE = "Nashville",
46
- ATLANTA = "Atlanta",
47
- ORLANDO = "Orlando",
48
- TAMPA = "Tampa",
49
- CHARLOTTE = "Charlotte",
50
- INDIANAPOLIS = "Indianapolis",
51
- COLUMBUS = "Columbus",
52
18
  }
53
19
 
54
- /**
55
- * Interface for date range filter values
56
- */
57
- export interface DateRange {
20
+ export interface DateRange { // DS-ADAPT: exported for DataTable props
58
21
  start: Date | null;
59
22
  end: Date | null;
60
23
  }
61
24
 
62
- /**
63
- * Central interface for all filter states
64
- */
65
- export interface Filters {
66
- cities?: City[] | null;
25
+ export interface Filters { // DS-ADAPT: exported for DataTable props
26
+ city?: City | null;
67
27
  dateRange?: DateRange | null;
68
28
  searchTerm?: string;
69
29
  }
70
30
 
71
- /**
72
- * Props for the main CustomTopToolbar component
73
- */
74
- export interface CustomTopToolbarProps<T extends MRT_RowData> {
31
+ export interface CustomTopToolbarProps {
75
32
  filtersState: Filters;
76
33
  locale: string;
77
34
  onChange: (filters: Filters) => void;
78
35
  resultCount: number;
79
- totalCount?: number; // Total records across all pages (unfiltered)
80
- numberOfSelectedRows: number;
81
- table: MRTTableInstance<T>;
82
36
  isLoading?: boolean;
83
37
  onFilterToggleChange: () => void;
84
38
  showFilters: boolean;
39
+ fullscreenControl: React.ReactNode;
40
+ densityControl: React.ReactNode;
41
+ alertBanner: React.ReactNode;
85
42
  }
86
43
 
87
- /**
88
- * Extended props for the MRT Toolbar Alert Banner
89
- */
90
- interface ExtendedAlertBannerProps<T extends MRT_RowData> {
91
- stackAlertBanner?: boolean;
92
- table: MRTTableInstance<T>;
93
- bg?: string;
94
- numberofselectedrows: number;
95
- style?: React.CSSProperties;
96
- }
97
-
98
- /**
99
- * Props for the filter icon button component
100
- */
101
- interface FilterIconButtonProps {
102
- onClick: () => void;
103
- areFiltersShown: boolean;
104
- text?: string;
105
- }
106
-
107
- /**
108
- * Props for action icon components (fullscreen, density)
109
- */
110
- interface ActionIconButtonProps {
111
- onClick: () => void;
112
- ariaLabel: string;
113
- icon: ReactElement;
114
- testId?: string;
115
- }
116
-
117
- // =============================================================================
118
- // CONSTANTS & UTILITIES
119
- // =============================================================================
120
-
121
- /**
122
- * Typed wrapper for the MRT Toolbar Alert Banner
123
- */
124
- const MRTToolbarAlertBanner = BaseMRTToolbarAlertBanner as React.ComponentType<ExtendedAlertBannerProps<any>>;
125
-
126
- /**
127
- * Date formatting options for display purposes
128
- */
129
- const DATE_FORMAT_OPTIONS: Intl.DateTimeFormatOptions = {
44
+ const dateOptions: Intl.DateTimeFormatOptions = {
130
45
  year: "numeric",
131
46
  month: "long",
132
47
  day: "numeric",
48
+ timeZone: "UTC", // DS-ADAPT: range dates are stored as UTC calendar days, so format them in UTC to avoid a day shift
133
49
  };
134
50
 
135
- /**
136
- * Shared styling for action buttons (30x30 square buttons)
137
- */
138
- const ACTION_BUTTON_STYLES = {
139
- width: rem(30),
140
- height: rem(30),
141
- minWidth: rem(30),
142
- minHeight: rem(30),
143
- padding: 0,
144
- display: 'flex',
145
- alignItems: 'center',
146
- justifyContent: 'center',
147
- borderRadius: 'var(--mantine-radius-sm)',
148
- border: '1px solid var(--ad-color-border-default)',
149
- background: 'var(--ad-white)',
150
- } as const;
151
-
152
- const ACTION_ICON_STYLES = {
153
- width: rem(30),
154
- height: rem(30),
155
- borderRadius: 'var(--mantine-radius-sm)',
156
- border: '1px solid var(--ad-color-border-default)',
157
- } as const;
158
-
159
- /**
160
- * Icon styling for consistent appearance
161
- */
162
- const ICON_STYLES = {
163
- color: 'var(--ad-color-text-default)',
164
- };
165
-
166
- /**
167
- * City options data for the select filter
168
- * @TODO: Consider moving this to a separate data file or fetching from an API
169
- */
170
- const CITY_OPTIONS = [
171
- { value: City.ATLANTA, label: "table.filters.city.atlanta" as const },
172
- { value: City.AUSTIN, label: "table.filters.city.austin" as const },
173
- { value: City.BOSTON, label: "table.filters.city.boston" as const },
174
- { value: City.CHARLOTTE, label: "table.filters.city.charlotte" as const },
175
- { value: City.CHICAGO, label: "table.filters.city.chicago" as const },
176
- { value: City.COLUMBUS, label: "table.filters.city.columbus" as const },
177
- { value: City.DENVER, label: "table.filters.city.denver" as const },
178
- { value: City.DETROIT, label: "table.filters.city.detroit" as const },
179
- { value: City.INDIANAPOLIS, label: "table.filters.city.indianapolis" as const },
180
- { value: City.LAS_VEGAS, label: "table.filters.city.las.vegas" as const },
181
- { value: City.LOS_ANGELES, label: "table.filters.city.los.angeles" as const },
182
- { value: City.MIAMI, label: "table.filters.city.miami" as const },
183
- { value: City.NASHVILLE, label: "table.filters.city.nashville" as const },
184
- { value: City.NEW_YORK, label: "table.filters.city.new.york" as const },
185
- { value: City.ORLANDO, label: "table.filters.city.orlando" as const },
186
- { value: City.PHOENIX, label: "table.filters.city.phoenix" as const },
187
- { value: City.PORTLAND, label: "table.filters.city.portland" as const },
188
- { value: City.SAN_FRANCISCO, label: "table.filters.city.san.francisco" as const },
189
- { value: City.SEATTLE, label: "table.filters.city.seattle" as const },
190
- { value: City.TAMPA, label: "table.filters.city.tampa" as const },
191
- ].map(option => ({
192
- ...option,
193
- label: translate(option.label),
194
- }));
195
-
196
- // =============================================================================
197
- // UTILITY FUNCTIONS
198
- // =============================================================================
199
-
200
- /**
201
- * Utility function to determine if filters are currently active
202
- * @param filters - The current filter state
203
- * @returns boolean indicating if any filters are applied
204
- */
205
- const hasActiveFilters = (filters: Filters): boolean => {
206
- const { cities, dateRange } = filters;
207
- return Boolean(
208
- (cities && cities.length > 0) ||
209
- (dateRange && dateRange.start && dateRange.end)
210
- );
211
- };
212
-
213
- /**
214
- * Utility function to process date range selection
215
- * Handles the logic for ensuring both dates are selected and sets end time to end of day
216
- * @param value - The selected date range value
217
- * @returns Processed DateRange or null
218
- */
219
- const toBoundaryDate = (v: DateValue | null): Date | null => {
220
- if (v == null) return null;
221
- return v instanceof Date ? v : new Date(`${v}T12:00:00`);
222
- };
223
-
224
- const processDateRangeSelection = (value: DatesRangeValue | null): DateRange | null => {
225
- // Helper functions for date validation
226
- const isOnlyOneDateSelected = (): boolean => {
227
- return !!(value && (value[0] === null || value[1] === null));
228
- };
229
-
230
- const areBothDatesSelected = (): boolean => {
231
- return !!(value && value[0] !== null && value[1] !== null);
232
- };
233
-
234
- // Return early if only one date is selected (incomplete selection)
235
- if (isOnlyOneDateSelected()) {
236
- return null;
237
- }
238
-
239
- let range: DateRange | null = null;
240
-
241
- if (value !== null && areBothDatesSelected()) {
242
- const start = toBoundaryDate(value[0]);
243
- let endDate = toBoundaryDate(value[1]);
244
-
245
- if (endDate) {
246
- const endOfDay = new Date(endDate);
247
- endOfDay.setHours(23, 59, 59, 999);
248
- endDate = endOfDay;
249
- }
250
-
251
- range = {
252
- start,
253
- end: endDate,
254
- };
255
- }
256
-
257
- return range;
258
- };
259
-
260
- /**
261
- * Utility function to get the appropriate density icon based on current state
262
- * @param density - Current table density setting
263
- * @returns React element for the density icon
264
- */
265
- const getDensityIcon = (density: string): ReactElement => {
266
- const iconProps = { size: 18, style: ICON_STYLES };
267
-
268
- switch (density) {
269
- case 'md':
270
- return <IconBaselineDensityMedium {...iconProps} />;
271
- case 'xs':
272
- return <IconBaselineDensitySmall {...iconProps} />;
273
- case 'xl':
274
- return <IconBaselineDensityLarge {...iconProps} />;
275
- default:
276
- return <IconBaselineDensityMedium {...iconProps} />;
277
- }
278
- };
279
-
280
- /**
281
- * Utility function to cycle through density options
282
- * @param currentDensity - Current density setting
283
- * @returns Next density setting in the cycle
284
- */
285
- const getNextDensity = (currentDensity: string): 'xs' | 'md' | 'xl' => {
286
- const densityMap: Record<string, 'xs' | 'md' | 'xl'> = {
287
- 'xs': 'md',
288
- 'md': 'xl',
289
- 'xl': 'xs'
290
- };
291
- return densityMap[currentDensity] || 'md';
292
- };
293
-
294
- // =============================================================================
295
- // SUB-COMPONENTS
296
- // =============================================================================
297
-
298
- /**
299
- * Reusable action icon component with consistent styling
300
- * Used for fullscreen and density toggle buttons
301
- */
302
- const ActionIconButton: React.FC<ActionIconButtonProps> = ({
303
- onClick,
304
- ariaLabel,
305
- icon,
306
- testId
307
- }) => (
51
+ const FilterIconButton = ({
52
+ onClick,
53
+ areFiltersShown,
54
+ }: {
55
+ onClick: () => void;
56
+ areFiltersShown: boolean;
57
+ }): ReactElement => (
308
58
  <ActionIcon
309
- variant="subtle"
59
+ data-testid="additional-filter-toggle"
60
+ variant={areFiltersShown ? "outline" : "default"}
310
61
  onClick={onClick}
311
- aria-label={ariaLabel}
312
- style={ACTION_ICON_STYLES}
313
- data-testid={testId}
62
+ aria-label={translate("table.filters.toggle.aria")}
314
63
  >
315
- {icon}
64
+ <FilterIcon color="var(--ad-color-text-default)" style={{ width: "71%", height: "71%" }} />
316
65
  </ActionIcon>
317
66
  );
318
67
 
319
- /**
320
- * Filter toggle button with indicator support
321
- * Shows an indicator dot when filters are active
322
- * Conditionally renders ActionIcon (icon-only) or Button (icon+text) based on text prop
323
- */
324
- const FilterIconButton: React.FC<FilterIconButtonProps> = ({
325
- onClick,
326
- areFiltersShown,
327
- text
328
- }) => {
329
- const icon = <IconFilter size={18} style={ICON_STYLES} />;
330
-
331
- // If no text provided or empty string, use ActionIcon for icon-only display with perfect centering
332
- if (!text || text.trim() === '') {
333
- return (
334
- <ActionIcon
335
- data-testid="additional-filter-toggle"
336
- onClick={onClick}
337
- aria-label={translate("table.filters.toggle.aria")}
338
- style={{
339
- width: rem(30),
340
- height: rem(30),
341
- borderRadius: 'var(--mantine-radius-sm)',
342
- border: areFiltersShown
343
- ? '1px solid var(--ad-color-brand-primary)'
344
- : '1px solid var(--ad-color-border-default)',
345
- background: 'var(--ad-white)',
346
- color: 'var(--ad-color-text-default)',
347
- }}
348
- >
349
- {icon}
350
- </ActionIcon>
351
- );
352
- }
353
-
354
- // If text is provided, use Button with leftSection for icon + text display
355
- return (
356
- <Button
357
- data-testid="additional-filter-toggle"
358
- variant={areFiltersShown ? "outline" : "default"}
359
- onClick={onClick}
360
- aria-label={translate("table.filters.toggle.aria")}
361
- size="xs"
362
- leftSection={icon}
363
- style={{
364
- height: rem(30),
365
- borderRadius: 'var(--mantine-radius-sm)',
366
- border: areFiltersShown
367
- ? '1px solid var(--ad-color-brand-primary)'
368
- : '1px solid var(--ad-color-border-default)',
369
- background: 'var(--ad-white)',
370
- }}
371
- >
372
- {text}
373
- </Button>
374
- );
375
- };
376
-
377
- /**
378
- * Active filters display section
379
- * Shows filter chips for currently applied filters and clear all button
380
- */
381
- interface ActiveFiltersProps {
382
- filters: Filters;
383
- onClearFilters: () => void;
384
- onRemoveCity: (cityToRemove: City) => void;
385
- onRemoveDateRange: () => void;
386
- }
387
-
388
- const ActiveFilters: React.FC<ActiveFiltersProps> = ({
389
- filters,
390
- onClearFilters,
391
- onRemoveCity,
392
- onRemoveDateRange,
393
- }) => {
394
- const { cities, dateRange } = filters;
395
-
396
- return (
397
- <>
398
- {/* Clear all filters button */}
399
- <Text
400
- size="xs"
401
- span
402
- role="button"
403
- fw={600}
404
- style={{ cursor: "pointer" }}
405
- onClick={onClearFilters}
406
- c="blue"
407
- data-testid="clear-filters"
408
- >
409
- {translate("table.filters.clear.filters")}
410
- </Text>
411
-
412
- {/* City filter chips */}
413
- {cities && cities.map((city) => (
414
- <FilterChip
415
- key={city}
416
- label={city}
417
- onClick={() => onRemoveCity(city)}
418
- />
419
- ))}
420
-
421
- {/* Date range filter chip */}
422
- {dateRange && (
423
- <FilterChip
424
- label={translate("table.filters.chip.date.range.label", {
425
- startDate: dateRange.start?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
426
- endDate: dateRange.end?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
427
- })}
428
- onClick={onRemoveDateRange}
429
- />
430
- )}
431
- </>
432
- );
433
- };
434
-
435
- /**
436
- * Toolbar action buttons section
437
- * Contains fullscreen toggle and density toggle buttons
438
- */
439
- interface ToolbarActionsProps<T extends MRT_RowData> {
440
- table: MRTTableInstance<T>;
441
- }
442
-
443
- const ToolbarActions = <T extends MRT_RowData>({ table }: ToolbarActionsProps<T>) => {
444
- const isFullScreen = table.getState().isFullScreen ?? false;
445
- const currentDensity = table.getState().density;
446
-
447
- const handleFullscreenToggle = () => {
448
- table.setIsFullScreen(!isFullScreen);
449
- };
450
-
451
- const handleDensityToggle = () => {
452
- const nextDensity = getNextDensity(currentDensity);
453
- table.setDensity(nextDensity);
454
- };
455
-
456
- return (
457
- <Inline justify="flex-end" gap="xs">
458
- {/* Fullscreen toggle button */}
459
- <ActionIconButton
460
- onClick={handleFullscreenToggle}
461
- ariaLabel={isFullScreen ? "Exit fullscreen" : "Enter fullscreen"}
462
- icon={isFullScreen ?
463
- <IconMinimize size={18} style={ICON_STYLES} /> :
464
- <IconMaximize size={18} style={ICON_STYLES} />
465
- }
466
- />
467
-
468
- {/* Density toggle button */}
469
- <ActionIconButton
470
- onClick={handleDensityToggle}
471
- ariaLabel="Toggle density"
472
- icon={getDensityIcon(currentDensity)}
473
- testId="toggle-dense-padding"
474
- />
475
- </Inline>
476
- );
477
- };
478
-
479
- /**
480
- * Expandable filters section
481
- * Contains date range and city selection filters
482
- */
483
- interface ExpandableFiltersProps {
484
- visible: boolean;
485
- locale: string;
486
- cities: City[] | null | undefined;
487
- onDateChange: (value: DatesRangeValue | null) => void;
488
- onCityChange: (value: string[] | null) => void;
489
- dateRangeSelectorKey: number;
490
- }
491
-
492
- const ExpandableFilters: React.FC<ExpandableFiltersProps> = ({
493
- visible,
494
- locale,
495
- cities,
496
- onDateChange,
497
- onCityChange,
498
- dateRangeSelectorKey,
499
- }) => {
500
- if (!visible) return null;
501
-
502
- return (
503
- <SimpleGrid data-testid="additional-filters" cols={3} spacing="xs" role="menu">
504
- {/* Date range selector */}
505
- <DateRangeSelector
506
- key={dateRangeSelectorKey}
507
- label={translate("table.filters.applied.on")}
508
- locale={locale}
509
- onChange={onDateChange}
510
- />
511
-
512
- {/* City multi-select filter */}
513
- <SelectFilter
514
- label={translate("table.filters.city")}
515
- onChange={onCityChange}
516
- selectedValue={(cities as string[]) || null}
517
- placeholderEmpty={translate("table.filters.placeholder.all")}
518
- placeholderWithSelection={translate("table.filters.placeholder.select.more")}
519
- data={CITY_OPTIONS}
520
- />
521
- </SimpleGrid>
522
- );
523
- };
524
-
525
- // =============================================================================
526
- // MAIN COMPONENT
527
- // =============================================================================
528
-
529
- /**
530
- * CustomTopToolbar - Main toolbar component for data tables
531
- *
532
- * Features:
533
- * - Search functionality
534
- * - Filter toggle with indicator
535
- * - Active filter chips with remove functionality
536
- * - Fullscreen and density controls
537
- * - Expandable filter section (date range, city selection)
538
- * - Result count display
539
- * - Selection alert banner integration
540
- *
541
- * @param props - CustomTopToolbarProps containing all necessary data and handlers
542
- */
543
- const CustomTopToolbar = <T extends MRT_RowData>({
68
+ const CustomTopToolbar = ({
544
69
  filtersState,
545
70
  locale,
546
71
  resultCount,
547
- totalCount,
548
72
  onChange,
549
- table,
550
- numberOfSelectedRows,
551
73
  isLoading,
552
74
  showFilters,
553
75
  onFilterToggleChange,
554
- }: CustomTopToolbarProps<T>): ReactElement => {
555
-
556
- // =============================================================================
557
- // STATE MANAGEMENT
558
- // =============================================================================
559
-
560
- const { searchTerm, cities, dateRange } = filtersState;
76
+ fullscreenControl,
77
+ densityControl,
78
+ alertBanner,
79
+ }: CustomTopToolbarProps): ReactElement => {
80
+ const { searchTerm, city, dateRange } = filtersState;
561
81
  const [dateRangeSelectorRefreshKey, setDateRangeSelectorRefreshKey] = useState<number>(0);
562
- const [showFiltersState, setShowFiltersState] = useState(showFilters);
563
82
 
564
- // =============================================================================
565
- // EFFECTS
566
- // =============================================================================
567
-
568
- /**
569
- * Reset date range selector when date range is cleared
570
- * This forces the component to re-render and clear its internal state
571
- */
572
83
  useEffect(() => {
573
84
  if (dateRange === null) {
574
85
  setDateRangeSelectorRefreshKey(prev => prev + 1);
575
86
  }
576
87
  }, [dateRange]);
577
88
 
578
- // =============================================================================
579
- // EVENT HANDLERS
580
- // =============================================================================
581
-
582
- /**
583
- * Handles date range selection changes
584
- * Processes the raw date selection and converts it to our DateRange format
585
- */
586
- const handleDateChange = (value: DatesRangeValue | null): void => {
587
- const processedRange = processDateRangeSelection(value);
588
-
589
- // Only update if we have a complete range or null (clear)
590
- if (processedRange !== null || value === null) {
591
- onChange({ dateRange: processedRange });
89
+ // DS-ADAPT: resolve the picked calendar day from local parts (strings are local YYYY-MM-DD)
90
+ // so the applied UTC day range does not shift with the user's timezone.
91
+ const getCalendarParts = (value: Date | string): [number, number, number] => {
92
+ if (typeof value === "string") {
93
+ const [y, m, d] = value.slice(0, 10).split("-").map(Number);
94
+ return [y, m - 1, d];
592
95
  }
96
+ return [value.getFullYear(), value.getMonth(), value.getDate()];
593
97
  };
594
98
 
595
- /**
596
- * Toggles the visibility of the expandable filters section
597
- */
598
- const handleFilterToggle = (): void => {
599
- const newShowFilters = !showFiltersState;
600
- setShowFiltersState(newShowFilters);
601
- onFilterToggleChange?.();
602
- };
99
+ const handleDateChange = (value: DateRangeInput | null): void => {
100
+ let range: DateRange | null = null;
603
101
 
604
- /**
605
- * Clears all applied filters except search term
606
- */
607
- const handleClearAllFilters = (): void => {
608
- onChange({
609
- searchTerm,
610
- cities: null,
611
- dateRange: null,
612
- });
613
- setDateRangeSelectorRefreshKey(prev => prev + 1);
614
- };
102
+ if (value && (value[0] === null || value[1] === null)) {
103
+ return; // only one date selected yet
104
+ }
615
105
 
616
- /**
617
- * Removes a specific city from the cities filter
618
- */
619
- const handleRemoveCity = (cityToRemove: City): void => {
620
- const updatedCities = cities?.filter((city) => city !== cityToRemove) || [];
106
+ if (value && value[0] !== null && value[1] !== null) {
107
+ const [sy, sm, sd] = getCalendarParts(value[0]);
108
+ const [ey, em, ed] = getCalendarParts(value[1]);
109
+ range = {
110
+ start: new Date(Date.UTC(sy, sm, sd)),
111
+ end: new Date(Date.UTC(ey, em, ed, 23, 59, 59, 999)),
112
+ };
113
+ }
621
114
  onChange({
622
- cities: updatedCities.length > 0 ? updatedCities : null,
115
+ dateRange: range,
623
116
  });
624
117
  };
625
118
 
626
- /**
627
- * Removes the date range filter
628
- */
629
- const handleRemoveDateRange = (): void => {
630
- onChange({ dateRange: null });
631
- };
119
+ const areFiltersActive = (): boolean => Boolean(city) || Boolean(dateRange); // DS-ADAPT: optional keys may be undefined
632
120
 
633
- /**
634
- * Handles search term changes
635
- */
636
- const handleSearchChange = (value: string): void => {
637
- onChange({ searchTerm: value });
638
- };
121
+ const onToggleFilterClick = (): void => onFilterToggleChange();
639
122
 
640
- /**
641
- * Handles city selection changes
642
- */
643
- const handleCityChange = (value: string[] | null): void => {
644
- onChange({ cities: value as City[] | null });
123
+ const clearFilters = (): void => {
124
+ onChange({
125
+ searchTerm,
126
+ city: null,
127
+ dateRange: null,
128
+ });
129
+ setDateRangeSelectorRefreshKey(prev => prev + 1);
645
130
  };
646
131
 
647
- // =============================================================================
648
- // COMPUTED VALUES
649
- // =============================================================================
650
-
651
- const filtersAreActive = hasActiveFilters(filtersState);
652
-
653
- // Get correct result counts from table state
654
- const currentFilteredTotal = table.getFilteredRowModel().rows.length; // Total filtered results across all pages
655
- const totalRecords = table.getCoreRowModel().rows.length; // Total unfiltered records
656
- const currentPageSize = table.getState().pagination.pageSize;
657
- const currentPageData = table.getRowModel().rows.length; // Current page only
658
-
659
- // Determine the correct counts to display based on filter state and server-side vs client-side
660
- let displayResultCount: number;
661
- let displayTotalCount: number;
662
-
663
- if (totalCount !== undefined) {
664
- // Server-side/manual pagination: use provided props
665
- displayTotalCount = totalCount;
666
-
667
- if (filtersAreActive) {
668
- // When filters are active, show filtered count vs total
669
- displayResultCount = resultCount;
670
- } else {
671
- // When no filters are active, show total count only
672
- displayResultCount = totalCount;
673
- }
674
- } else {
675
- // Client-side pagination with full dataset: use table instance methods
676
- if (filtersAreActive) {
677
- // When filters are active, show filtered count
678
- displayResultCount = currentFilteredTotal;
679
- displayTotalCount = totalRecords;
680
- } else {
681
- // When no filters are active, show total count only
682
- displayResultCount = totalRecords;
683
- displayTotalCount = totalRecords;
684
- }
685
- }
686
-
687
- // =============================================================================
688
- // RENDER
689
- // =============================================================================
690
-
691
132
  return (
692
133
  <>
693
- {/* Main toolbar content */}
694
- <Stack
695
- p="md"
696
- gap="xshalf"
697
- style={{
698
- borderBottom: "1px solid var(--ad-color-border-subtle)",
699
- }}
700
- >
701
- {/* Top row: Search and action buttons */}
702
- <Grid gap="md">
703
- <Grid.Col span={{ base: 12, md: 6 }}>
704
- {/* Left side: Filter toggle and search */}
705
- <Inline gap="xs" align="center">
706
- {/* Filter toggle button with optional indicator */}
707
- {filtersAreActive ? (
708
- <Indicator size="8">
709
- <FilterIconButton
710
- areFiltersShown={showFiltersState}
711
- onClick={handleFilterToggle}
712
- text=""
134
+ <Stack p="md" gap="xshalf" className={styles.toolbar}>
135
+ <SimpleGrid cols={2}>
136
+ <Group gap="xs" align="center">
137
+ {areFiltersActive() ? (
138
+ <Indicator size="8">
139
+ <FilterIconButton areFiltersShown={showFilters} onClick={onToggleFilterClick} />
140
+ </Indicator>
141
+ ) : (
142
+ <FilterIconButton areFiltersShown={showFilters} onClick={onToggleFilterClick} />
143
+ )}
144
+ <SearchFilter
145
+ searchTerm={searchTerm as string}
146
+ onChange={(value): void =>
147
+ onChange({
148
+ searchTerm: value,
149
+ })
150
+ }
151
+ />
152
+ </Group>
153
+ <Group justify="end" gap="xs">
154
+ {fullscreenControl}
155
+ {densityControl}
156
+ </Group>
157
+ </SimpleGrid>
158
+ <Group justify="space-between">
159
+ <Group gap="xs">
160
+ {areFiltersActive() && (
161
+ <>
162
+ <Text
163
+ className={styles.clearFilters}
164
+ size="xs"
165
+ span
166
+ role="button"
167
+ fw={600}
168
+ onClick={clearFilters}
169
+ c="var(--ad-color-text-link)"
170
+ data-testid="clear-filters"
171
+ >
172
+ {translate("table.filters.clear.filters")}
173
+ </Text>
174
+ {filtersState.city && (
175
+ <FilterChip
176
+ label={filtersState.city}
177
+ onClick={(): void =>
178
+ onChange({
179
+ city: null,
180
+ })
181
+ }
713
182
  />
714
- </Indicator>
715
- ) : (
716
- <FilterIconButton
717
- areFiltersShown={showFiltersState}
718
- onClick={handleFilterToggle}
719
- text=""
720
- />
721
- )}
722
-
723
- {/* Search input */}
724
- <SearchFilter
725
- searchTerm={searchTerm as string}
726
- onChange={handleSearchChange}
727
- />
728
- </Inline>
729
- </Grid.Col>
730
-
731
- {/* Right side: Action buttons */}
732
- <Grid.Col span={{ base: 12, md: 6 }}>
733
- <ToolbarActions table={table} />
734
- </Grid.Col>
735
- </Grid>
736
-
737
- {/* Second row: Active filters and result count */}
738
- <Inline justify="space-between">
739
- <Inline gap="xs">
740
- {/* Show active filters if any exist */}
741
- {filtersAreActive && (
742
- <ActiveFilters
743
- filters={filtersState}
744
- onClearFilters={handleClearAllFilters}
745
- onRemoveCity={handleRemoveCity}
746
- onRemoveDateRange={handleRemoveDateRange}
747
- />
183
+ )}
184
+ {filtersState.dateRange && (
185
+ <FilterChip
186
+ label={translate("table.filters.chip.date.range.label", {
187
+ startDate: filtersState.dateRange.start?.toLocaleDateString(
188
+ undefined,
189
+ dateOptions
190
+ ),
191
+ endDate: filtersState.dateRange.end?.toLocaleDateString(
192
+ undefined,
193
+ dateOptions
194
+ ),
195
+ })}
196
+ onClick={(): void =>
197
+ onChange({
198
+ dateRange: null,
199
+ })
200
+ }
201
+ />
202
+ )}
203
+ </>
748
204
  )}
749
-
750
- {/* Result count display */}
751
- <ResultCount
752
- resultCount={displayResultCount}
753
- totalCount={displayTotalCount}
754
- isLoading={isLoading ?? false}
755
- hasActiveFilters={filtersAreActive}
205
+ <ResultCount resultCount={resultCount} isLoading={isLoading} />
206
+ </Group>
207
+ </Group>
208
+ {showFilters && (
209
+ <SimpleGrid data-testid="additional-filters" cols={3} spacing="xs" role="menu">
210
+ <DateRangeSelector
211
+ key={dateRangeSelectorRefreshKey}
212
+ label={translate("table.filters.applied.on")} // DS-ADAPT: use translations
213
+ locale={locale}
214
+ onChange={handleDateChange}
756
215
  />
757
- </Inline>
758
- </Inline>
759
-
760
- {/* Expandable filters section */}
761
- <ExpandableFilters
762
- visible={showFiltersState}
763
- locale={locale}
764
- cities={cities}
765
- onDateChange={handleDateChange}
766
- onCityChange={handleCityChange}
767
- dateRangeSelectorKey={dateRangeSelectorRefreshKey}
768
- />
216
+ <SelectFilter
217
+ label={translate("table.filters.city")} // DS-ADAPT: use translations
218
+ onChange={(value): void => {
219
+ onChange({
220
+ city: value as City | null,
221
+ });
222
+ }}
223
+ selectedValue={city || null}
224
+ data={[
225
+ {
226
+ value: City.DENVER,
227
+ label: translate("table.filters.city.denver"),
228
+ },
229
+ {
230
+ value: City.LOS_ANGELES,
231
+ label: translate("table.filters.city.los.angeles"),
232
+ },
233
+ {
234
+ value: City.NEW_YORK,
235
+ label: translate("table.filters.city.new.york"),
236
+ },
237
+ ]}
238
+ />
239
+ </SimpleGrid>
240
+ )}
769
241
  </Stack>
770
-
771
- {/* Selection alert banner */}
772
- <MRTToolbarAlertBanner
773
- stackAlertBanner
774
- table={table as any}
775
- bg="blue"
776
- numberofselectedrows={numberOfSelectedRows}
777
- style={{
778
- borderRadius: 0,
779
- color: 'var(--ad-white)',
780
- borderTop: '1px solid var(--ad-color-brand-primary)',
781
- padding: 'var(--mantine-spacing-xs)',
782
- }}
783
- />
242
+ {alertBanner}
784
243
  </>
785
244
  );
786
245
  };