@appdirect/design-system 0.0.17 → 0.0.19
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/bin/ad-sync-design-md.mjs +0 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.js +15 -51
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +91 -139
- package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
- package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
- package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
- package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
- package/dist/ComplexComponents/DataTable/index.js +5 -1
- package/dist/ComplexComponents/DataTable/index.ts +13 -2
- package/dist/ComplexComponents/DataTable/table.module.css +9 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
- package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
- package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
- package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
- package/dist/ComplexComponents/DataTable/types.js +5 -0
- package/dist/ComplexComponents/DataTable/types.ts +17 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
- package/dist/ComplexComponents/KeyInsight/index.ts +1 -1
- package/dist/DESIGN.md +9 -10
- package/dist/contracts/DashboardWidget.json +92 -0
- package/dist/contracts/DataTable.json +83 -6
- package/dist/contracts/index.json +6 -1
- package/dist/css/foundations.css +4 -0
- package/dist/css/mantine.css +173 -7
- package/dist/css/tokens.css +3195 -0
- package/dist/index.js +3 -0
- package/dist/index.ts +14 -1
- package/dist/stories/ComplexComponents/DashboardWidget/DashboardWidget.stories.tsx +76 -1
- package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
- package/dist/stories/index.json +16 -15
- package/package.json +5 -3
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
- package/dist/hooks/useTableHandlers.js +0 -136
- package/dist/hooks/useTableHandlers.ts +0 -179
- package/dist/hooks/useTableRenderFunctions.js +0 -164
- package/dist/hooks/useTableRenderFunctions.tsx +0 -283
- package/dist/hooks/useTableState.js +0 -70
- package/dist/hooks/useTableState.ts +0 -81
|
@@ -1,410 +1,99 @@
|
|
|
1
|
-
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
4
|
import React, { useEffect, useState } from "react";
|
|
3
|
-
import { ActionIcon, Indicator, Stack, Text,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { SimpleGrid } from '../../../Layout/SimpleGrid.js';
|
|
7
|
-
import { Inline } from '../../../Layout/Inline.js';
|
|
8
|
-
import { IconFilter, IconMaximize, IconMinimize, IconBaselineDensityMedium, IconBaselineDensitySmall, IconBaselineDensityLarge } from '@tabler/icons-react';
|
|
9
|
-
import { MRT_ToolbarAlertBanner as BaseMRTToolbarAlertBanner, } from "mantine-react-table-open";
|
|
10
|
-
import { translate } from '../translations/index.js';
|
|
5
|
+
import { ActionIcon, Group, Indicator, Stack, Text, SimpleGrid } from "@mantine/core";
|
|
6
|
+
import { RiFilterLine as FilterIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
7
|
+
import { translate } from "../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
11
8
|
import SelectFilter from "./SelectFilter.js";
|
|
12
9
|
import SearchFilter from "./SearchFilter.js";
|
|
13
10
|
import DateRangeSelector from "./DateRangeSelectorFilter/index.js";
|
|
14
11
|
import FilterChip from "./FilterChip.js";
|
|
15
|
-
import ResultCount from "./ResultCount
|
|
16
|
-
|
|
17
|
-
// TYPES & INTERFACES
|
|
18
|
-
// =============================================================================
|
|
19
|
-
/**
|
|
20
|
-
* Enum defining all available cities for filtering
|
|
21
|
-
* @TODO: Consider moving this to a separate constants file for better maintainability
|
|
22
|
-
*/
|
|
12
|
+
import ResultCount from "./ResultCount.js";
|
|
13
|
+
import styles from "./CustomTopToolbar.module.css";
|
|
23
14
|
export var City;
|
|
24
15
|
(function (City) {
|
|
25
16
|
City["NEW_YORK"] = "New York";
|
|
26
17
|
City["LOS_ANGELES"] = "Los Angeles";
|
|
27
|
-
City["CHICAGO"] = "Chicago";
|
|
28
|
-
City["SAN_FRANCISCO"] = "San Francisco";
|
|
29
|
-
City["BOSTON"] = "Boston";
|
|
30
|
-
City["SEATTLE"] = "Seattle";
|
|
31
18
|
City["DENVER"] = "Denver";
|
|
32
|
-
City["PORTLAND"] = "Portland";
|
|
33
|
-
City["AUSTIN"] = "Austin";
|
|
34
|
-
City["MIAMI"] = "Miami";
|
|
35
|
-
City["PHOENIX"] = "Phoenix";
|
|
36
|
-
City["LAS_VEGAS"] = "Las Vegas";
|
|
37
|
-
City["DETROIT"] = "Detroit";
|
|
38
|
-
City["NASHVILLE"] = "Nashville";
|
|
39
|
-
City["ATLANTA"] = "Atlanta";
|
|
40
|
-
City["ORLANDO"] = "Orlando";
|
|
41
|
-
City["TAMPA"] = "Tampa";
|
|
42
|
-
City["CHARLOTTE"] = "Charlotte";
|
|
43
|
-
City["INDIANAPOLIS"] = "Indianapolis";
|
|
44
|
-
City["COLUMBUS"] = "Columbus";
|
|
45
19
|
})(City || (City = {}));
|
|
46
|
-
|
|
47
|
-
// CONSTANTS & UTILITIES
|
|
48
|
-
// =============================================================================
|
|
49
|
-
/**
|
|
50
|
-
* Typed wrapper for the MRT Toolbar Alert Banner
|
|
51
|
-
*/
|
|
52
|
-
const MRTToolbarAlertBanner = BaseMRTToolbarAlertBanner;
|
|
53
|
-
/**
|
|
54
|
-
* Date formatting options for display purposes
|
|
55
|
-
*/
|
|
56
|
-
const DATE_FORMAT_OPTIONS = {
|
|
20
|
+
const dateOptions = {
|
|
57
21
|
year: "numeric",
|
|
58
22
|
month: "long",
|
|
59
23
|
day: "numeric",
|
|
24
|
+
timeZone: "UTC", // DS-ADAPT: range dates are stored as UTC calendar days, so format them in UTC to avoid a day shift
|
|
60
25
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const ACTION_BUTTON_STYLES = {
|
|
65
|
-
width: rem(30),
|
|
66
|
-
height: rem(30),
|
|
67
|
-
minWidth: rem(30),
|
|
68
|
-
minHeight: rem(30),
|
|
69
|
-
padding: 0,
|
|
70
|
-
display: 'flex',
|
|
71
|
-
alignItems: 'center',
|
|
72
|
-
justifyContent: 'center',
|
|
73
|
-
borderRadius: 'var(--mantine-radius-sm)',
|
|
74
|
-
border: '1px solid var(--ad-color-border-default)',
|
|
75
|
-
background: 'var(--ad-white)',
|
|
76
|
-
};
|
|
77
|
-
const ACTION_ICON_STYLES = {
|
|
78
|
-
width: rem(30),
|
|
79
|
-
height: rem(30),
|
|
80
|
-
borderRadius: 'var(--mantine-radius-sm)',
|
|
81
|
-
border: '1px solid var(--ad-color-border-default)',
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Icon styling for consistent appearance
|
|
85
|
-
*/
|
|
86
|
-
const ICON_STYLES = {
|
|
87
|
-
color: 'var(--ad-color-text-default)',
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* City options data for the select filter
|
|
91
|
-
* @TODO: Consider moving this to a separate data file or fetching from an API
|
|
92
|
-
*/
|
|
93
|
-
const CITY_OPTIONS = [
|
|
94
|
-
{ value: City.ATLANTA, label: "table.filters.city.atlanta" },
|
|
95
|
-
{ value: City.AUSTIN, label: "table.filters.city.austin" },
|
|
96
|
-
{ value: City.BOSTON, label: "table.filters.city.boston" },
|
|
97
|
-
{ value: City.CHARLOTTE, label: "table.filters.city.charlotte" },
|
|
98
|
-
{ value: City.CHICAGO, label: "table.filters.city.chicago" },
|
|
99
|
-
{ value: City.COLUMBUS, label: "table.filters.city.columbus" },
|
|
100
|
-
{ value: City.DENVER, label: "table.filters.city.denver" },
|
|
101
|
-
{ value: City.DETROIT, label: "table.filters.city.detroit" },
|
|
102
|
-
{ value: City.INDIANAPOLIS, label: "table.filters.city.indianapolis" },
|
|
103
|
-
{ value: City.LAS_VEGAS, label: "table.filters.city.las.vegas" },
|
|
104
|
-
{ value: City.LOS_ANGELES, label: "table.filters.city.los.angeles" },
|
|
105
|
-
{ value: City.MIAMI, label: "table.filters.city.miami" },
|
|
106
|
-
{ value: City.NASHVILLE, label: "table.filters.city.nashville" },
|
|
107
|
-
{ value: City.NEW_YORK, label: "table.filters.city.new.york" },
|
|
108
|
-
{ value: City.ORLANDO, label: "table.filters.city.orlando" },
|
|
109
|
-
{ value: City.PHOENIX, label: "table.filters.city.phoenix" },
|
|
110
|
-
{ value: City.PORTLAND, label: "table.filters.city.portland" },
|
|
111
|
-
{ value: City.SAN_FRANCISCO, label: "table.filters.city.san.francisco" },
|
|
112
|
-
{ value: City.SEATTLE, label: "table.filters.city.seattle" },
|
|
113
|
-
{ value: City.TAMPA, label: "table.filters.city.tampa" },
|
|
114
|
-
].map(option => ({
|
|
115
|
-
...option,
|
|
116
|
-
label: translate(option.label),
|
|
117
|
-
}));
|
|
118
|
-
// =============================================================================
|
|
119
|
-
// UTILITY FUNCTIONS
|
|
120
|
-
// =============================================================================
|
|
121
|
-
/**
|
|
122
|
-
* Utility function to determine if filters are currently active
|
|
123
|
-
* @param filters - The current filter state
|
|
124
|
-
* @returns boolean indicating if any filters are applied
|
|
125
|
-
*/
|
|
126
|
-
const hasActiveFilters = (filters) => {
|
|
127
|
-
const { cities, dateRange } = filters;
|
|
128
|
-
return Boolean((cities && cities.length > 0) ||
|
|
129
|
-
(dateRange && dateRange.start && dateRange.end));
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Utility function to process date range selection
|
|
133
|
-
* Handles the logic for ensuring both dates are selected and sets end time to end of day
|
|
134
|
-
* @param value - The selected date range value
|
|
135
|
-
* @returns Processed DateRange or null
|
|
136
|
-
*/
|
|
137
|
-
const toBoundaryDate = (v) => {
|
|
138
|
-
if (v == null)
|
|
139
|
-
return null;
|
|
140
|
-
return v instanceof Date ? v : new Date(`${v}T12:00:00`);
|
|
141
|
-
};
|
|
142
|
-
const processDateRangeSelection = (value) => {
|
|
143
|
-
// Helper functions for date validation
|
|
144
|
-
const isOnlyOneDateSelected = () => {
|
|
145
|
-
return !!(value && (value[0] === null || value[1] === null));
|
|
146
|
-
};
|
|
147
|
-
const areBothDatesSelected = () => {
|
|
148
|
-
return !!(value && value[0] !== null && value[1] !== null);
|
|
149
|
-
};
|
|
150
|
-
// Return early if only one date is selected (incomplete selection)
|
|
151
|
-
if (isOnlyOneDateSelected()) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
let range = null;
|
|
155
|
-
if (value !== null && areBothDatesSelected()) {
|
|
156
|
-
const start = toBoundaryDate(value[0]);
|
|
157
|
-
let endDate = toBoundaryDate(value[1]);
|
|
158
|
-
if (endDate) {
|
|
159
|
-
const endOfDay = new Date(endDate);
|
|
160
|
-
endOfDay.setHours(23, 59, 59, 999);
|
|
161
|
-
endDate = endOfDay;
|
|
162
|
-
}
|
|
163
|
-
range = {
|
|
164
|
-
start,
|
|
165
|
-
end: endDate,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
return range;
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Utility function to get the appropriate density icon based on current state
|
|
172
|
-
* @param density - Current table density setting
|
|
173
|
-
* @returns React element for the density icon
|
|
174
|
-
*/
|
|
175
|
-
const getDensityIcon = (density) => {
|
|
176
|
-
const iconProps = { size: 18, style: ICON_STYLES };
|
|
177
|
-
switch (density) {
|
|
178
|
-
case 'md':
|
|
179
|
-
return _jsx(IconBaselineDensityMedium, { ...iconProps });
|
|
180
|
-
case 'xs':
|
|
181
|
-
return _jsx(IconBaselineDensitySmall, { ...iconProps });
|
|
182
|
-
case 'xl':
|
|
183
|
-
return _jsx(IconBaselineDensityLarge, { ...iconProps });
|
|
184
|
-
default:
|
|
185
|
-
return _jsx(IconBaselineDensityMedium, { ...iconProps });
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
/**
|
|
189
|
-
* Utility function to cycle through density options
|
|
190
|
-
* @param currentDensity - Current density setting
|
|
191
|
-
* @returns Next density setting in the cycle
|
|
192
|
-
*/
|
|
193
|
-
const getNextDensity = (currentDensity) => {
|
|
194
|
-
const densityMap = {
|
|
195
|
-
'xs': 'md',
|
|
196
|
-
'md': 'xl',
|
|
197
|
-
'xl': 'xs'
|
|
198
|
-
};
|
|
199
|
-
return densityMap[currentDensity] || 'md';
|
|
200
|
-
};
|
|
201
|
-
// =============================================================================
|
|
202
|
-
// SUB-COMPONENTS
|
|
203
|
-
// =============================================================================
|
|
204
|
-
/**
|
|
205
|
-
* Reusable action icon component with consistent styling
|
|
206
|
-
* Used for fullscreen and density toggle buttons
|
|
207
|
-
*/
|
|
208
|
-
const ActionIconButton = ({ onClick, ariaLabel, icon, testId }) => (_jsx(ActionIcon, { variant: "subtle", onClick: onClick, "aria-label": ariaLabel, style: ACTION_ICON_STYLES, "data-testid": testId, children: icon }));
|
|
209
|
-
/**
|
|
210
|
-
* Filter toggle button with indicator support
|
|
211
|
-
* Shows an indicator dot when filters are active
|
|
212
|
-
* Conditionally renders ActionIcon (icon-only) or Button (icon+text) based on text prop
|
|
213
|
-
*/
|
|
214
|
-
const FilterIconButton = ({ onClick, areFiltersShown, text }) => {
|
|
215
|
-
const icon = _jsx(IconFilter, { size: 18, style: ICON_STYLES });
|
|
216
|
-
// If no text provided or empty string, use ActionIcon for icon-only display with perfect centering
|
|
217
|
-
if (!text || text.trim() === '') {
|
|
218
|
-
return (_jsx(ActionIcon, { "data-testid": "additional-filter-toggle", onClick: onClick, "aria-label": translate("table.filters.toggle.aria"), style: {
|
|
219
|
-
width: rem(30),
|
|
220
|
-
height: rem(30),
|
|
221
|
-
borderRadius: 'var(--mantine-radius-sm)',
|
|
222
|
-
border: areFiltersShown
|
|
223
|
-
? '1px solid var(--ad-color-brand-primary)'
|
|
224
|
-
: '1px solid var(--ad-color-border-default)',
|
|
225
|
-
background: 'var(--ad-white)',
|
|
226
|
-
color: 'var(--ad-color-text-default)',
|
|
227
|
-
}, children: icon }));
|
|
228
|
-
}
|
|
229
|
-
// If text is provided, use Button with leftSection for icon + text display
|
|
230
|
-
return (_jsx(Button, { "data-testid": "additional-filter-toggle", variant: areFiltersShown ? "outline" : "default", onClick: onClick, "aria-label": translate("table.filters.toggle.aria"), size: "xs", leftSection: icon, style: {
|
|
231
|
-
height: rem(30),
|
|
232
|
-
borderRadius: 'var(--mantine-radius-sm)',
|
|
233
|
-
border: areFiltersShown
|
|
234
|
-
? '1px solid var(--ad-color-brand-primary)'
|
|
235
|
-
: '1px solid var(--ad-color-border-default)',
|
|
236
|
-
background: 'var(--ad-white)',
|
|
237
|
-
}, children: text }));
|
|
238
|
-
};
|
|
239
|
-
const ActiveFilters = ({ filters, onClearFilters, onRemoveCity, onRemoveDateRange, }) => {
|
|
240
|
-
const { cities, dateRange } = filters;
|
|
241
|
-
return (_jsxs(_Fragment, { children: [_jsx(Text, { size: "xs", span: true, role: "button", fw: 600, style: { cursor: "pointer" }, onClick: onClearFilters, c: "blue", "data-testid": "clear-filters", children: translate("table.filters.clear.filters") }), cities && cities.map((city) => (_jsx(FilterChip, { label: city, onClick: () => onRemoveCity(city) }, city))), dateRange && (_jsx(FilterChip, { label: translate("table.filters.chip.date.range.label", {
|
|
242
|
-
startDate: dateRange.start?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
|
|
243
|
-
endDate: dateRange.end?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
|
|
244
|
-
}), onClick: onRemoveDateRange }))] }));
|
|
245
|
-
};
|
|
246
|
-
const ToolbarActions = ({ table }) => {
|
|
247
|
-
const isFullScreen = table.getState().isFullScreen ?? false;
|
|
248
|
-
const currentDensity = table.getState().density;
|
|
249
|
-
const handleFullscreenToggle = () => {
|
|
250
|
-
table.setIsFullScreen(!isFullScreen);
|
|
251
|
-
};
|
|
252
|
-
const handleDensityToggle = () => {
|
|
253
|
-
const nextDensity = getNextDensity(currentDensity);
|
|
254
|
-
table.setDensity(nextDensity);
|
|
255
|
-
};
|
|
256
|
-
return (_jsxs(Inline, { justify: "flex-end", gap: "xs", children: [_jsx(ActionIconButton, { onClick: handleFullscreenToggle, ariaLabel: isFullScreen ? "Exit fullscreen" : "Enter fullscreen", icon: isFullScreen ?
|
|
257
|
-
_jsx(IconMinimize, { size: 18, style: ICON_STYLES }) :
|
|
258
|
-
_jsx(IconMaximize, { size: 18, style: ICON_STYLES }) }), _jsx(ActionIconButton, { onClick: handleDensityToggle, ariaLabel: "Toggle density", icon: getDensityIcon(currentDensity), testId: "toggle-dense-padding" })] }));
|
|
259
|
-
};
|
|
260
|
-
const ExpandableFilters = ({ visible, locale, cities, onDateChange, onCityChange, dateRangeSelectorKey, }) => {
|
|
261
|
-
if (!visible)
|
|
262
|
-
return null;
|
|
263
|
-
return (_jsxs(SimpleGrid, { "data-testid": "additional-filters", cols: 3, spacing: "xs", role: "menu", children: [_jsx(DateRangeSelector, { label: translate("table.filters.applied.on"), locale: locale, onChange: onDateChange }, dateRangeSelectorKey), _jsx(SelectFilter, { label: translate("table.filters.city"), onChange: onCityChange, selectedValue: cities || null, placeholderEmpty: translate("table.filters.placeholder.all"), placeholderWithSelection: translate("table.filters.placeholder.select.more"), data: CITY_OPTIONS })] }));
|
|
264
|
-
};
|
|
265
|
-
// =============================================================================
|
|
266
|
-
// MAIN COMPONENT
|
|
267
|
-
// =============================================================================
|
|
268
|
-
/**
|
|
269
|
-
* CustomTopToolbar - Main toolbar component for data tables
|
|
270
|
-
*
|
|
271
|
-
* Features:
|
|
272
|
-
* - Search functionality
|
|
273
|
-
* - Filter toggle with indicator
|
|
274
|
-
* - Active filter chips with remove functionality
|
|
275
|
-
* - Fullscreen and density controls
|
|
276
|
-
* - Expandable filter section (date range, city selection)
|
|
277
|
-
* - Result count display
|
|
278
|
-
* - Selection alert banner integration
|
|
279
|
-
*
|
|
280
|
-
* @param props - CustomTopToolbarProps containing all necessary data and handlers
|
|
281
|
-
*/
|
|
282
|
-
const CustomTopToolbar = ({ filtersState, locale, resultCount, totalCount, onChange, table, numberOfSelectedRows, isLoading, showFilters, onFilterToggleChange, }) => {
|
|
283
|
-
// =============================================================================
|
|
284
|
-
// STATE MANAGEMENT
|
|
285
|
-
// =============================================================================
|
|
286
|
-
const { searchTerm, cities, dateRange } = filtersState;
|
|
26
|
+
const FilterIconButton = ({ onClick, areFiltersShown, }) => (_jsx(ActionIcon, { "data-testid": "additional-filter-toggle", variant: areFiltersShown ? "outline" : "default", onClick: onClick, "aria-label": translate("table.filters.toggle.aria"), children: _jsx(FilterIcon, { color: "var(--ad-color-text-default)", style: { width: "71%", height: "71%" } }) }));
|
|
27
|
+
const CustomTopToolbar = ({ filtersState, locale, resultCount, onChange, isLoading, showFilters, onFilterToggleChange, fullscreenControl, densityControl, alertBanner, }) => {
|
|
28
|
+
const { searchTerm, city, dateRange } = filtersState;
|
|
287
29
|
const [dateRangeSelectorRefreshKey, setDateRangeSelectorRefreshKey] = useState(0);
|
|
288
|
-
const [showFiltersState, setShowFiltersState] = useState(showFilters);
|
|
289
|
-
// =============================================================================
|
|
290
|
-
// EFFECTS
|
|
291
|
-
// =============================================================================
|
|
292
|
-
/**
|
|
293
|
-
* Reset date range selector when date range is cleared
|
|
294
|
-
* This forces the component to re-render and clear its internal state
|
|
295
|
-
*/
|
|
296
30
|
useEffect(() => {
|
|
297
31
|
if (dateRange === null) {
|
|
298
32
|
setDateRangeSelectorRefreshKey(prev => prev + 1);
|
|
299
33
|
}
|
|
300
34
|
}, [dateRange]);
|
|
301
|
-
//
|
|
302
|
-
//
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
*/
|
|
308
|
-
const handleDateChange = (value) => {
|
|
309
|
-
const processedRange = processDateRangeSelection(value);
|
|
310
|
-
// Only update if we have a complete range or null (clear)
|
|
311
|
-
if (processedRange !== null || value === null) {
|
|
312
|
-
onChange({ dateRange: processedRange });
|
|
35
|
+
// DS-ADAPT: resolve the picked calendar day from local parts (strings are local YYYY-MM-DD)
|
|
36
|
+
// so the applied UTC day range does not shift with the user's timezone.
|
|
37
|
+
const getCalendarParts = (value) => {
|
|
38
|
+
if (typeof value === "string") {
|
|
39
|
+
const [y, m, d] = value.slice(0, 10).split("-").map(Number);
|
|
40
|
+
return [y, m - 1, d];
|
|
313
41
|
}
|
|
42
|
+
return [value.getFullYear(), value.getMonth(), value.getDate()];
|
|
314
43
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
44
|
+
const handleDateChange = (value) => {
|
|
45
|
+
let range = null;
|
|
46
|
+
if (value && (value[0] === null || value[1] === null)) {
|
|
47
|
+
return; // only one date selected yet
|
|
48
|
+
}
|
|
49
|
+
if (value && value[0] !== null && value[1] !== null) {
|
|
50
|
+
const [sy, sm, sd] = getCalendarParts(value[0]);
|
|
51
|
+
const [ey, em, ed] = getCalendarParts(value[1]);
|
|
52
|
+
range = {
|
|
53
|
+
start: new Date(Date.UTC(sy, sm, sd)),
|
|
54
|
+
end: new Date(Date.UTC(ey, em, ed, 23, 59, 59, 999)),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
onChange({
|
|
58
|
+
dateRange: range,
|
|
59
|
+
});
|
|
322
60
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const handleClearAllFilters = () => {
|
|
61
|
+
const areFiltersActive = () => Boolean(city) || Boolean(dateRange); // DS-ADAPT: optional keys may be undefined
|
|
62
|
+
const onToggleFilterClick = () => onFilterToggleChange();
|
|
63
|
+
const clearFilters = () => {
|
|
327
64
|
onChange({
|
|
328
65
|
searchTerm,
|
|
329
|
-
|
|
66
|
+
city: null,
|
|
330
67
|
dateRange: null,
|
|
331
68
|
});
|
|
332
69
|
setDateRangeSelectorRefreshKey(prev => prev + 1);
|
|
333
70
|
};
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
// =============================================================================
|
|
362
|
-
// COMPUTED VALUES
|
|
363
|
-
// =============================================================================
|
|
364
|
-
const filtersAreActive = hasActiveFilters(filtersState);
|
|
365
|
-
// Get correct result counts from table state
|
|
366
|
-
const currentFilteredTotal = table.getFilteredRowModel().rows.length; // Total filtered results across all pages
|
|
367
|
-
const totalRecords = table.getCoreRowModel().rows.length; // Total unfiltered records
|
|
368
|
-
const currentPageSize = table.getState().pagination.pageSize;
|
|
369
|
-
const currentPageData = table.getRowModel().rows.length; // Current page only
|
|
370
|
-
// Determine the correct counts to display based on filter state and server-side vs client-side
|
|
371
|
-
let displayResultCount;
|
|
372
|
-
let displayTotalCount;
|
|
373
|
-
if (totalCount !== undefined) {
|
|
374
|
-
// Server-side/manual pagination: use provided props
|
|
375
|
-
displayTotalCount = totalCount;
|
|
376
|
-
if (filtersAreActive) {
|
|
377
|
-
// When filters are active, show filtered count vs total
|
|
378
|
-
displayResultCount = resultCount;
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
// When no filters are active, show total count only
|
|
382
|
-
displayResultCount = totalCount;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
// Client-side pagination with full dataset: use table instance methods
|
|
387
|
-
if (filtersAreActive) {
|
|
388
|
-
// When filters are active, show filtered count
|
|
389
|
-
displayResultCount = currentFilteredTotal;
|
|
390
|
-
displayTotalCount = totalRecords;
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
// When no filters are active, show total count only
|
|
394
|
-
displayResultCount = totalRecords;
|
|
395
|
-
displayTotalCount = totalRecords;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
// =============================================================================
|
|
399
|
-
// RENDER
|
|
400
|
-
// =============================================================================
|
|
401
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Stack, { p: "md", gap: "xshalf", style: {
|
|
402
|
-
borderBottom: "1px solid var(--ad-color-border-subtle)",
|
|
403
|
-
}, children: [_jsxs(Grid, { gap: "md", children: [_jsx(Grid.Col, { span: { base: 12, md: 6 }, children: _jsxs(Inline, { gap: "xs", align: "center", children: [filtersAreActive ? (_jsx(Indicator, { size: "8", children: _jsx(FilterIconButton, { areFiltersShown: showFiltersState, onClick: handleFilterToggle, text: "" }) })) : (_jsx(FilterIconButton, { areFiltersShown: showFiltersState, onClick: handleFilterToggle, text: "" })), _jsx(SearchFilter, { searchTerm: searchTerm, onChange: handleSearchChange })] }) }), _jsx(Grid.Col, { span: { base: 12, md: 6 }, children: _jsx(ToolbarActions, { table: table }) })] }), _jsx(Inline, { justify: "space-between", children: _jsxs(Inline, { gap: "xs", children: [filtersAreActive && (_jsx(ActiveFilters, { filters: filtersState, onClearFilters: handleClearAllFilters, onRemoveCity: handleRemoveCity, onRemoveDateRange: handleRemoveDateRange })), _jsx(ResultCount, { resultCount: displayResultCount, totalCount: displayTotalCount, isLoading: isLoading ?? false, hasActiveFilters: filtersAreActive })] }) }), _jsx(ExpandableFilters, { visible: showFiltersState, locale: locale, cities: cities, onDateChange: handleDateChange, onCityChange: handleCityChange, dateRangeSelectorKey: dateRangeSelectorRefreshKey })] }), _jsx(MRTToolbarAlertBanner, { stackAlertBanner: true, table: table, bg: "blue", numberofselectedrows: numberOfSelectedRows, style: {
|
|
404
|
-
borderRadius: 0,
|
|
405
|
-
color: 'var(--ad-white)',
|
|
406
|
-
borderTop: '1px solid var(--ad-color-brand-primary)',
|
|
407
|
-
padding: 'var(--mantine-spacing-xs)',
|
|
408
|
-
} })] }));
|
|
71
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Stack, { p: "md", gap: "xshalf", className: styles.toolbar, children: [_jsxs(SimpleGrid, { cols: 2, children: [_jsxs(Group, { gap: "xs", align: "center", children: [areFiltersActive() ? (_jsx(Indicator, { size: "8", children: _jsx(FilterIconButton, { areFiltersShown: showFilters, onClick: onToggleFilterClick }) })) : (_jsx(FilterIconButton, { areFiltersShown: showFilters, onClick: onToggleFilterClick })), _jsx(SearchFilter, { searchTerm: searchTerm, onChange: (value) => onChange({
|
|
72
|
+
searchTerm: value,
|
|
73
|
+
}) })] }), _jsxs(Group, { justify: "end", gap: "xs", children: [fullscreenControl, densityControl] })] }), _jsx(Group, { justify: "space-between", children: _jsxs(Group, { gap: "xs", children: [areFiltersActive() && (_jsxs(_Fragment, { children: [_jsx(Text, { className: styles.clearFilters, size: "xs", span: true, role: "button", fw: 600, onClick: clearFilters, c: "var(--ad-color-text-link)", "data-testid": "clear-filters", children: translate("table.filters.clear.filters") }), filtersState.city && (_jsx(FilterChip, { label: filtersState.city, onClick: () => onChange({
|
|
74
|
+
city: null,
|
|
75
|
+
}) })), filtersState.dateRange && (_jsx(FilterChip, { label: translate("table.filters.chip.date.range.label", {
|
|
76
|
+
startDate: filtersState.dateRange.start?.toLocaleDateString(undefined, dateOptions),
|
|
77
|
+
endDate: filtersState.dateRange.end?.toLocaleDateString(undefined, dateOptions),
|
|
78
|
+
}), onClick: () => onChange({
|
|
79
|
+
dateRange: null,
|
|
80
|
+
}) }))] })), _jsx(ResultCount, { resultCount: resultCount, isLoading: isLoading })] }) }), showFilters && (_jsxs(SimpleGrid, { "data-testid": "additional-filters", cols: 3, spacing: "xs", role: "menu", children: [_jsx(DateRangeSelector, { label: translate("table.filters.applied.on"), locale: locale, onChange: handleDateChange }, dateRangeSelectorRefreshKey), _jsx(SelectFilter, { label: translate("table.filters.city"), onChange: (value) => {
|
|
81
|
+
onChange({
|
|
82
|
+
city: value,
|
|
83
|
+
});
|
|
84
|
+
}, selectedValue: city || null, data: [
|
|
85
|
+
{
|
|
86
|
+
value: City.DENVER,
|
|
87
|
+
label: translate("table.filters.city.denver"),
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
value: City.LOS_ANGELES,
|
|
91
|
+
label: translate("table.filters.city.los.angeles"),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
value: City.NEW_YORK,
|
|
95
|
+
label: translate("table.filters.city.new.york"),
|
|
96
|
+
},
|
|
97
|
+
] })] }))] }), alertBanner] }));
|
|
409
98
|
};
|
|
410
99
|
export default CustomTopToolbar;
|