@appdirect/design-system 0.0.0-stage → 0.0.2
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/README.md +12 -2
- package/dist/Buttons/ActionIcon.tsx +37 -0
- package/dist/Buttons/Button.module.css +5 -0
- package/dist/Buttons/Button.tsx +124 -0
- package/dist/Buttons/CloseButton.tsx +83 -0
- package/dist/Buttons/index.ts +20 -0
- package/dist/Combobox/AutocompleteClearable.tsx +128 -0
- package/dist/Combobox/Combobox.tsx +37 -0
- package/dist/Combobox/Multiselect.tsx +158 -0
- package/dist/Combobox/SearchableSelect.tsx +131 -0
- package/dist/Combobox/Select.tsx +154 -0
- package/dist/Combobox/index.ts +20 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +313 -0
- package/dist/ComplexComponents/DashboardWidget/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +177 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +35 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +74 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +358 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.tsx +71 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.tsx +158 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.tsx +79 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.tsx +65 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.ts +70 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.ts +140 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +76 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +73 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +50 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +788 -0
- package/dist/ComplexComponents/DataTable/DataTable.tsx +582 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +29 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +57 -0
- package/dist/ComplexComponents/DataTable/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/translations/en.ts +115 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +23 -0
- package/dist/ComplexComponents/KeyInsight/KeyInsights.tsx +221 -0
- package/dist/ComplexComponents/KeyInsight/index.ts +2 -0
- package/dist/ComplexComponents/NameValue/NameValue.tsx +175 -0
- package/dist/ComplexComponents/NameValue/NameValueItem.tsx +100 -0
- package/dist/ComplexComponents/NameValue/index.ts +4 -0
- package/dist/ComplexComponents/PageContentHeader/DescriptionBlock.tsx +65 -0
- package/dist/ComplexComponents/PageContentHeader/PageContentHeader.tsx +383 -0
- package/dist/ComplexComponents/PageContentHeader/index.ts +4 -0
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +82 -0
- package/dist/ComplexComponents/Utilities/index.ts +2 -0
- package/dist/DataDisplay/Alert.tsx +130 -0
- package/dist/DataDisplay/Avatar.tsx +216 -0
- package/dist/DataDisplay/Badge.tsx +119 -0
- package/dist/DataDisplay/Card.module.css +26 -0
- package/dist/DataDisplay/Card.tsx +163 -0
- package/dist/DataDisplay/Chip.tsx +66 -0
- package/dist/DataDisplay/Indicator.tsx +122 -0
- package/dist/DataDisplay/List.tsx +90 -0
- package/dist/DataDisplay/Pill.tsx +125 -0
- package/dist/DataDisplay/Progress.tsx +77 -0
- package/dist/DataDisplay/Table.tsx +57 -0
- package/dist/DataDisplay/ThemeIcon.tsx +67 -0
- package/dist/DataDisplay/index.ts +41 -0
- package/dist/Inputs/Checkbox.tsx +94 -0
- package/dist/Inputs/ColorInput.tsx +124 -0
- package/dist/Inputs/DropZone.tsx +78 -0
- package/dist/Inputs/FileInput.tsx +120 -0
- package/dist/Inputs/NumberInput.tsx +125 -0
- package/dist/Inputs/Radio.tsx +86 -0
- package/dist/Inputs/RadioGroup.tsx +90 -0
- package/dist/Inputs/SegmentedControl.tsx +64 -0
- package/dist/Inputs/Slider.tsx +69 -0
- package/dist/Inputs/Switch.tsx +67 -0
- package/dist/Inputs/TextArea.tsx +126 -0
- package/dist/Inputs/TextInput.tsx +167 -0
- package/dist/Inputs/index.ts +51 -0
- package/dist/Layout/Box.tsx +82 -0
- package/dist/Layout/Center.tsx +17 -0
- package/dist/Layout/Container.tsx +17 -0
- package/dist/Layout/Flex.tsx +18 -0
- package/dist/Layout/Grid.tsx +31 -0
- package/dist/Layout/Group.tsx +54 -0
- package/dist/Layout/Inline.tsx +86 -0
- package/dist/Layout/SimpleGrid.tsx +50 -0
- package/dist/Layout/Stack.tsx +86 -0
- package/dist/Layout/index.ts +29 -0
- package/dist/Misc/Divider.tsx +27 -0
- package/dist/Misc/Paper.tsx +47 -0
- package/dist/Misc/index.ts +15 -0
- package/dist/Navigation/Breadcrumb.tsx +138 -0
- package/dist/Navigation/NavLink.tsx +37 -0
- package/dist/Navigation/Stepper.tsx +17 -0
- package/dist/Navigation/Tabs.tsx +29 -0
- package/dist/Navigation/index.ts +17 -0
- package/dist/Overlays/Drawer.tsx +123 -0
- package/dist/Overlays/Menu.tsx +192 -0
- package/dist/Overlays/Modal.tsx +159 -0
- package/dist/Overlays/Popover.tsx +319 -0
- package/dist/Overlays/Tooltip.tsx +131 -0
- package/dist/Overlays/index.ts +19 -0
- package/dist/Shell/AppShellLayout.tsx +56 -0
- package/dist/Shell/HeaderBar.tsx +26 -0
- package/dist/Shell/SidebarNav.tsx +47 -0
- package/dist/Shell/SidebarNavLink.tsx +50 -0
- package/dist/Shell/SingleColumnLayout.tsx +22 -0
- package/dist/Shell/TertiaryColumnLayout.tsx +32 -0
- package/dist/Shell/index.ts +17 -0
- package/dist/Typography/Code.tsx +27 -0
- package/dist/Typography/Kbd.tsx +87 -0
- package/dist/Typography/Text.tsx +27 -0
- package/dist/Typography/Title.tsx +34 -0
- package/dist/Typography/index.ts +21 -0
- package/dist/bin/ds-audit.js +521 -0
- package/dist/config.ts +226 -0
- package/dist/contracts/Alert.json +80 -0
- package/dist/contracts/Badge.json +78 -0
- package/dist/contracts/Box.json +52 -0
- package/dist/contracts/Button.json +111 -0
- package/dist/contracts/DataTable.json +68 -0
- package/dist/contracts/Grid.json +35 -0
- package/dist/contracts/Group.json +44 -0
- package/dist/contracts/Inline.json +73 -0
- package/dist/contracts/PageContentHeader.json +107 -0
- package/dist/contracts/Stack.json +62 -0
- package/dist/contracts/ds-component-contract.v1.json +23 -0
- package/dist/contracts/index.json +55 -0
- package/dist/css/foundations.css +703 -0
- package/dist/css/mantine.css +1777 -0
- package/dist/hooks/useTableHandlers.ts +179 -0
- package/dist/hooks/useTableRenderFunctions.tsx +283 -0
- package/dist/hooks/useTableState.ts +81 -0
- package/dist/index.ts +210 -0
- package/dist/types.ts +202 -0
- package/package.json +56 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DatesRangeValue } from '@mantine/dates';
|
|
3
|
+
import DateRangeSelector from '../DateRangeSelectorFilter';
|
|
4
|
+
import { FilterRendererProps, DateRangeFilterConfig } from './types';
|
|
5
|
+
import { translate } from '../../translations';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* DateRangeFilter - Renders a date range picker within the flexible filter system
|
|
9
|
+
*/
|
|
10
|
+
const DateRangeFilter: React.FC<FilterRendererProps<DatesRangeValue | null>> = ({
|
|
11
|
+
config,
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
}) => {
|
|
15
|
+
const dateConfig = config as DateRangeFilterConfig;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<DateRangeSelector
|
|
19
|
+
label={translate(config.labelKey)}
|
|
20
|
+
locale={dateConfig.locale || 'en-US'}
|
|
21
|
+
onChange={onChange}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default DateRangeFilter;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box } from '@mantine/core';
|
|
3
|
+
import DateRangeFilter from './DateRangeFilter';
|
|
4
|
+
import SingleSelectFilter from './SingleSelectFilter';
|
|
5
|
+
import MultiSelectFilter from './MultiSelectFilter';
|
|
6
|
+
import {
|
|
7
|
+
FilterType,
|
|
8
|
+
FilterRendererProps,
|
|
9
|
+
FilterConfig,
|
|
10
|
+
DateRangeFilterConfig,
|
|
11
|
+
SingleSelectFilterConfig,
|
|
12
|
+
MultiSelectFilterConfig
|
|
13
|
+
} from './types';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* FilterRenderer - Factory component that renders the appropriate filter type
|
|
17
|
+
* based on the configuration provided
|
|
18
|
+
*/
|
|
19
|
+
const FilterRenderer: React.FC<FilterRendererProps> = ({
|
|
20
|
+
config,
|
|
21
|
+
value,
|
|
22
|
+
onChange,
|
|
23
|
+
}) => {
|
|
24
|
+
// Don't render if filter is explicitly disabled
|
|
25
|
+
if (config.enabled === false) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const renderFilter = () => {
|
|
30
|
+
switch (config.type) {
|
|
31
|
+
case FilterType.DATE_RANGE:
|
|
32
|
+
return (
|
|
33
|
+
<DateRangeFilter
|
|
34
|
+
config={config as DateRangeFilterConfig}
|
|
35
|
+
value={value}
|
|
36
|
+
onChange={onChange}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
case FilterType.SINGLE_SELECT:
|
|
41
|
+
return (
|
|
42
|
+
<SingleSelectFilter
|
|
43
|
+
config={config as SingleSelectFilterConfig}
|
|
44
|
+
value={value}
|
|
45
|
+
onChange={onChange}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
case FilterType.MULTI_SELECT:
|
|
50
|
+
return (
|
|
51
|
+
<MultiSelectFilter
|
|
52
|
+
config={config as MultiSelectFilterConfig}
|
|
53
|
+
value={value}
|
|
54
|
+
onChange={onChange}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
default:
|
|
59
|
+
console.warn(`Unknown filter type: ${(config as any).type}`);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Box className={config.className}>
|
|
66
|
+
{renderFilter()}
|
|
67
|
+
</Box>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default FilterRenderer;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Alert } from '@mantine/core';
|
|
3
|
+
import { SimpleGrid } from '../../../..';
|
|
4
|
+
import { IconAlertCircle } from '@tabler/icons-react';
|
|
5
|
+
import FilterRenderer from './FilterRenderer';
|
|
6
|
+
import { translate } from '../../translations';
|
|
7
|
+
import {
|
|
8
|
+
FilterSystemConfig,
|
|
9
|
+
FilterChangeEvent,
|
|
10
|
+
FilterValidationResult,
|
|
11
|
+
FilterType
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Validates filter system configuration
|
|
16
|
+
*/
|
|
17
|
+
const validateFilterConfig = (config: FilterSystemConfig): FilterValidationResult => {
|
|
18
|
+
const errors: string[] = [];
|
|
19
|
+
const warnings: string[] = [];
|
|
20
|
+
|
|
21
|
+
// Check maximum filters limit
|
|
22
|
+
const maxFilters = config.maxFilters || 6;
|
|
23
|
+
if (config.filters.length > maxFilters) {
|
|
24
|
+
errors.push(translate('table.filters.system.validation.max.exceeded', {
|
|
25
|
+
maxFilters: maxFilters.toString(),
|
|
26
|
+
filterCount: config.filters.length.toString(),
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Check for duplicate IDs
|
|
31
|
+
const filterIds = config.filters.map(f => f.id);
|
|
32
|
+
const duplicateIds = filterIds.filter((id, index) => filterIds.indexOf(id) !== index);
|
|
33
|
+
if (duplicateIds.length > 0) {
|
|
34
|
+
errors.push(translate('table.filters.system.validation.duplicate.ids', {
|
|
35
|
+
duplicateIds: duplicateIds.join(', '),
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Check for missing required fields
|
|
40
|
+
config.filters.forEach(filter => {
|
|
41
|
+
if (!filter.id) {
|
|
42
|
+
errors.push(translate('table.filters.system.validation.missing.id'));
|
|
43
|
+
}
|
|
44
|
+
if (!filter.labelKey) {
|
|
45
|
+
warnings.push(translate('table.filters.system.validation.missing.label', {
|
|
46
|
+
filterId: filter.id,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
isValid: errors.length === 0,
|
|
53
|
+
errors,
|
|
54
|
+
warnings,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* FilterSystem - Main component for managing multiple filters with layout and validation
|
|
60
|
+
*/
|
|
61
|
+
const FilterSystem: React.FC<FilterSystemConfig> = ({
|
|
62
|
+
filters,
|
|
63
|
+
values,
|
|
64
|
+
onChange,
|
|
65
|
+
visible = true,
|
|
66
|
+
columns = 3,
|
|
67
|
+
maxFilters = 6,
|
|
68
|
+
}) => {
|
|
69
|
+
// Validate configuration
|
|
70
|
+
const validation = validateFilterConfig({
|
|
71
|
+
filters,
|
|
72
|
+
values,
|
|
73
|
+
onChange,
|
|
74
|
+
visible,
|
|
75
|
+
columns,
|
|
76
|
+
maxFilters
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Don't render if not visible
|
|
80
|
+
if (!visible) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Show validation errors
|
|
85
|
+
if (!validation.isValid) {
|
|
86
|
+
return (
|
|
87
|
+
<Alert
|
|
88
|
+
color="red"
|
|
89
|
+
icon={<IconAlertCircle size={16} />}
|
|
90
|
+
title={translate('table.filters.system.validation.title')}
|
|
91
|
+
>
|
|
92
|
+
<ul>
|
|
93
|
+
{validation.errors.map((error, index) => (
|
|
94
|
+
<li key={index}>{error}</li>
|
|
95
|
+
))}
|
|
96
|
+
</ul>
|
|
97
|
+
</Alert>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Show warnings in development
|
|
102
|
+
if (validation.warnings.length > 0 && process.env.NODE_ENV === 'development') {
|
|
103
|
+
console.warn('Filter System Warnings:', validation.warnings);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Limit filters to maximum allowed
|
|
107
|
+
const limitedFilters = filters.slice(0, maxFilters);
|
|
108
|
+
|
|
109
|
+
const handleFilterChange = (filterId: string, value: any, filterType: FilterType) => {
|
|
110
|
+
const changeEvent: FilterChangeEvent = {
|
|
111
|
+
filterId,
|
|
112
|
+
value,
|
|
113
|
+
filterType,
|
|
114
|
+
};
|
|
115
|
+
onChange(changeEvent);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<Box>
|
|
120
|
+
<SimpleGrid
|
|
121
|
+
cols={Math.min(columns, limitedFilters.length)}
|
|
122
|
+
spacing="xs"
|
|
123
|
+
role="region"
|
|
124
|
+
aria-label="Data filters"
|
|
125
|
+
>
|
|
126
|
+
{limitedFilters.map((filterConfig) => {
|
|
127
|
+
const currentValue = values[filterConfig.id];
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<FilterRenderer
|
|
131
|
+
key={filterConfig.id}
|
|
132
|
+
config={filterConfig}
|
|
133
|
+
value={currentValue}
|
|
134
|
+
onChange={(value) =>
|
|
135
|
+
handleFilterChange(filterConfig.id, value, filterConfig.type)
|
|
136
|
+
}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
})}
|
|
140
|
+
</SimpleGrid>
|
|
141
|
+
|
|
142
|
+
{filters.length > maxFilters && (
|
|
143
|
+
<Alert
|
|
144
|
+
color="yellow"
|
|
145
|
+
mt="xs"
|
|
146
|
+
icon={<IconAlertCircle size={14} />}
|
|
147
|
+
>
|
|
148
|
+
{translate('table.filters.system.overflow.warning', {
|
|
149
|
+
maxFilters: maxFilters.toString(),
|
|
150
|
+
hiddenCount: (filters.length - maxFilters).toString(),
|
|
151
|
+
})}
|
|
152
|
+
</Alert>
|
|
153
|
+
)}
|
|
154
|
+
</Box>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export default FilterSystem;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { MultiSelect, CloseButton } from '@mantine/core';
|
|
3
|
+
import { FilterRendererProps, MultiSelectFilterConfig } from './types';
|
|
4
|
+
import { translate } from '../../translations';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* MultiSelectFilter - Renders a multiple selection dropdown within the flexible filter system
|
|
8
|
+
*/
|
|
9
|
+
const MultiSelectFilter: React.FC<FilterRendererProps<string[] | null>> = ({
|
|
10
|
+
config,
|
|
11
|
+
value,
|
|
12
|
+
onChange,
|
|
13
|
+
}) => {
|
|
14
|
+
const multiConfig = config as MultiSelectFilterConfig;
|
|
15
|
+
|
|
16
|
+
const handleClear = () => {
|
|
17
|
+
onChange(null);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Transform options to use translated labels
|
|
21
|
+
const translatedOptions = multiConfig.options.map(option => ({
|
|
22
|
+
value: option.value,
|
|
23
|
+
label: translate(option.labelKey),
|
|
24
|
+
disabled: option.disabled,
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
// Dynamic placeholder based on selection state
|
|
28
|
+
const placeholder = useMemo(() => {
|
|
29
|
+
if (!value || value.length === 0) {
|
|
30
|
+
if (multiConfig.placeholderEmptyKey) {
|
|
31
|
+
return translate(multiConfig.placeholderEmptyKey);
|
|
32
|
+
}
|
|
33
|
+
if (config.placeholderKey) {
|
|
34
|
+
return translate(config.placeholderKey);
|
|
35
|
+
}
|
|
36
|
+
return translate('table.filters.placeholder.select.options');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (multiConfig.placeholderWithSelectionKey) {
|
|
40
|
+
return translate(multiConfig.placeholderWithSelectionKey);
|
|
41
|
+
}
|
|
42
|
+
return translate('table.filters.placeholder.select.more');
|
|
43
|
+
}, [value, multiConfig.placeholderEmptyKey, multiConfig.placeholderWithSelectionKey, config.placeholderKey]);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<MultiSelect
|
|
47
|
+
label={translate(config.labelKey)}
|
|
48
|
+
placeholder={placeholder}
|
|
49
|
+
data={translatedOptions}
|
|
50
|
+
value={value || []}
|
|
51
|
+
onChange={onChange}
|
|
52
|
+
searchable={multiConfig.searchable}
|
|
53
|
+
clearable
|
|
54
|
+
size="xs"
|
|
55
|
+
rightSection={
|
|
56
|
+
value && value.length > 0 ? (
|
|
57
|
+
<CloseButton
|
|
58
|
+
size="xs"
|
|
59
|
+
variant="transparent"
|
|
60
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
61
|
+
onClick={handleClear}
|
|
62
|
+
aria-label={translate('table.filters.system.clear.aria', {
|
|
63
|
+
filterLabel: translate(config.labelKey)
|
|
64
|
+
})}
|
|
65
|
+
/>
|
|
66
|
+
) : undefined
|
|
67
|
+
}
|
|
68
|
+
styles={{
|
|
69
|
+
label: {
|
|
70
|
+
fontWeight: 600,
|
|
71
|
+
},
|
|
72
|
+
}}
|
|
73
|
+
disabled={config.enabled === false}
|
|
74
|
+
className={config.className}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default MultiSelectFilter;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Select, CloseButton } from '@mantine/core';
|
|
3
|
+
import { FilterRendererProps, SingleSelectFilterConfig } from './types';
|
|
4
|
+
import { translate } from '../../translations';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SingleSelectFilter - Renders a single selection dropdown within the flexible filter system
|
|
8
|
+
*/
|
|
9
|
+
const SingleSelectFilter: React.FC<FilterRendererProps<string | null>> = ({
|
|
10
|
+
config,
|
|
11
|
+
value,
|
|
12
|
+
onChange,
|
|
13
|
+
}) => {
|
|
14
|
+
const selectConfig = config as SingleSelectFilterConfig;
|
|
15
|
+
|
|
16
|
+
const handleClear = () => {
|
|
17
|
+
onChange(null);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Transform options to use translated labels
|
|
21
|
+
const translatedOptions = selectConfig.options.map(option => ({
|
|
22
|
+
value: option.value,
|
|
23
|
+
label: translate(option.labelKey),
|
|
24
|
+
disabled: option.disabled,
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
const placeholder = config.placeholderKey
|
|
28
|
+
? translate(config.placeholderKey)
|
|
29
|
+
: translate('table.filters.placeholder.select.option');
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Select
|
|
33
|
+
label={translate(config.labelKey)}
|
|
34
|
+
placeholder={placeholder}
|
|
35
|
+
data={translatedOptions}
|
|
36
|
+
value={value}
|
|
37
|
+
onChange={onChange}
|
|
38
|
+
searchable={selectConfig.searchable}
|
|
39
|
+
clearable
|
|
40
|
+
size="xs"
|
|
41
|
+
rightSection={
|
|
42
|
+
value ? (
|
|
43
|
+
<CloseButton
|
|
44
|
+
size="xs"
|
|
45
|
+
variant="transparent"
|
|
46
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
47
|
+
onClick={handleClear}
|
|
48
|
+
aria-label={translate('table.filters.system.clear.aria', {
|
|
49
|
+
filterLabel: translate(config.labelKey)
|
|
50
|
+
})}
|
|
51
|
+
/>
|
|
52
|
+
) : undefined
|
|
53
|
+
}
|
|
54
|
+
styles={{
|
|
55
|
+
label: {
|
|
56
|
+
fontWeight: 600,
|
|
57
|
+
},
|
|
58
|
+
}}
|
|
59
|
+
disabled={config.enabled === false}
|
|
60
|
+
className={config.className}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default SingleSelectFilter;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Main components
|
|
2
|
+
export { default as FilterSystem } from './FilterSystem';
|
|
3
|
+
export { default as FilterRenderer } from './FilterRenderer';
|
|
4
|
+
export { default as DateRangeFilter } from './DateRangeFilter';
|
|
5
|
+
export { default as SingleSelectFilter } from './SingleSelectFilter';
|
|
6
|
+
export { default as MultiSelectFilter } from './MultiSelectFilter';
|
|
7
|
+
|
|
8
|
+
// Types and interfaces
|
|
9
|
+
export * from './types';
|
|
10
|
+
|
|
11
|
+
// Import types for helper functions
|
|
12
|
+
import {
|
|
13
|
+
FilterType,
|
|
14
|
+
DateRangeFilterConfig,
|
|
15
|
+
SingleSelectFilterConfig,
|
|
16
|
+
MultiSelectFilterConfig,
|
|
17
|
+
SelectOption,
|
|
18
|
+
} from './types';
|
|
19
|
+
import { TranslationKey } from '../../translations';
|
|
20
|
+
|
|
21
|
+
// Helper function to create filter configurations
|
|
22
|
+
export const createFilterConfig = {
|
|
23
|
+
dateRange: (
|
|
24
|
+
id: string,
|
|
25
|
+
labelKey: TranslationKey,
|
|
26
|
+
options?: Partial<Omit<DateRangeFilterConfig, 'id' | 'labelKey' | 'type'>>
|
|
27
|
+
): DateRangeFilterConfig => ({
|
|
28
|
+
id,
|
|
29
|
+
labelKey,
|
|
30
|
+
type: FilterType.DATE_RANGE,
|
|
31
|
+
...options,
|
|
32
|
+
}),
|
|
33
|
+
|
|
34
|
+
singleSelect: (
|
|
35
|
+
id: string,
|
|
36
|
+
labelKey: TranslationKey,
|
|
37
|
+
optionsArray: SelectOption[],
|
|
38
|
+
config?: Partial<Omit<SingleSelectFilterConfig, 'id' | 'labelKey' | 'type' | 'options'>>
|
|
39
|
+
): SingleSelectFilterConfig => ({
|
|
40
|
+
id,
|
|
41
|
+
labelKey,
|
|
42
|
+
type: FilterType.SINGLE_SELECT,
|
|
43
|
+
options: optionsArray,
|
|
44
|
+
...config,
|
|
45
|
+
}),
|
|
46
|
+
|
|
47
|
+
multiSelect: (
|
|
48
|
+
id: string,
|
|
49
|
+
labelKey: TranslationKey,
|
|
50
|
+
optionsArray: SelectOption[],
|
|
51
|
+
config?: Partial<Omit<MultiSelectFilterConfig, 'id' | 'labelKey' | 'type' | 'options'>>
|
|
52
|
+
): MultiSelectFilterConfig => ({
|
|
53
|
+
id,
|
|
54
|
+
labelKey,
|
|
55
|
+
type: FilterType.MULTI_SELECT,
|
|
56
|
+
options: optionsArray,
|
|
57
|
+
...config,
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Helper function to create select options with translation keys
|
|
62
|
+
export const createSelectOption = (
|
|
63
|
+
value: string,
|
|
64
|
+
labelKey: TranslationKey,
|
|
65
|
+
disabled?: boolean
|
|
66
|
+
): SelectOption => ({
|
|
67
|
+
value,
|
|
68
|
+
labelKey,
|
|
69
|
+
disabled,
|
|
70
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { DatesRangeValue } from "@mantine/dates";
|
|
2
|
+
import { TranslationKey } from '../../translations';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Supported filter types for the flexible filter system
|
|
6
|
+
*/
|
|
7
|
+
export enum FilterType {
|
|
8
|
+
DATE_RANGE = "date_range",
|
|
9
|
+
SINGLE_SELECT = "single_select",
|
|
10
|
+
MULTI_SELECT = "multi_select",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Base interface for all filter configurations
|
|
15
|
+
*/
|
|
16
|
+
export interface BaseFilterConfig {
|
|
17
|
+
/** Unique identifier for the filter */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Translation key for the display label */
|
|
20
|
+
labelKey: TranslationKey;
|
|
21
|
+
/** Type of filter component to render */
|
|
22
|
+
type: FilterType;
|
|
23
|
+
/** Whether the filter is currently enabled */
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
/** Translation key for placeholder text */
|
|
26
|
+
placeholderKey?: TranslationKey;
|
|
27
|
+
/** Custom CSS classes */
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for date range filters
|
|
33
|
+
*/
|
|
34
|
+
export interface DateRangeFilterConfig extends BaseFilterConfig {
|
|
35
|
+
type: FilterType.DATE_RANGE;
|
|
36
|
+
/** Locale for date formatting */
|
|
37
|
+
locale?: string;
|
|
38
|
+
/** Default date range value */
|
|
39
|
+
defaultValue?: DatesRangeValue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Option for select-based filters with translation support
|
|
44
|
+
*/
|
|
45
|
+
export interface SelectOption {
|
|
46
|
+
value: string;
|
|
47
|
+
/** Translation key for the option label */
|
|
48
|
+
labelKey: TranslationKey;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Configuration for single selection filters
|
|
54
|
+
*/
|
|
55
|
+
export interface SingleSelectFilterConfig extends BaseFilterConfig {
|
|
56
|
+
type: FilterType.SINGLE_SELECT;
|
|
57
|
+
/** Available options for selection */
|
|
58
|
+
options: SelectOption[];
|
|
59
|
+
/** Default selected value */
|
|
60
|
+
defaultValue?: string;
|
|
61
|
+
/** Whether to show search in dropdown */
|
|
62
|
+
searchable?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Configuration for multi-selection filters
|
|
67
|
+
*/
|
|
68
|
+
export interface MultiSelectFilterConfig extends BaseFilterConfig {
|
|
69
|
+
type: FilterType.MULTI_SELECT;
|
|
70
|
+
/** Available options for selection */
|
|
71
|
+
options: SelectOption[];
|
|
72
|
+
/** Default selected values */
|
|
73
|
+
defaultValue?: string[];
|
|
74
|
+
/** Whether to show search in dropdown */
|
|
75
|
+
searchable?: boolean;
|
|
76
|
+
/** Translation key for placeholder when no items selected */
|
|
77
|
+
placeholderEmptyKey?: TranslationKey;
|
|
78
|
+
/** Translation key for placeholder when items are selected */
|
|
79
|
+
placeholderWithSelectionKey?: TranslationKey;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Union type for all filter configurations
|
|
84
|
+
*/
|
|
85
|
+
export type FilterConfig =
|
|
86
|
+
| DateRangeFilterConfig
|
|
87
|
+
| SingleSelectFilterConfig
|
|
88
|
+
| MultiSelectFilterConfig;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Current values for all filters
|
|
92
|
+
*/
|
|
93
|
+
export interface FilterValues {
|
|
94
|
+
[filterId: string]: any;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Filter change event data
|
|
99
|
+
*/
|
|
100
|
+
export interface FilterChangeEvent {
|
|
101
|
+
filterId: string;
|
|
102
|
+
value: any;
|
|
103
|
+
filterType: FilterType;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Configuration for the entire filter system
|
|
108
|
+
*/
|
|
109
|
+
export interface FilterSystemConfig {
|
|
110
|
+
/** Array of filter configurations (max 6) */
|
|
111
|
+
filters: FilterConfig[];
|
|
112
|
+
/** Current filter values */
|
|
113
|
+
values: FilterValues;
|
|
114
|
+
/** Callback when any filter value changes */
|
|
115
|
+
onChange: (event: FilterChangeEvent) => void;
|
|
116
|
+
/** Whether to show the filter system */
|
|
117
|
+
visible?: boolean;
|
|
118
|
+
/** Number of columns for layout (default: 3) */
|
|
119
|
+
columns?: number;
|
|
120
|
+
/** Maximum number of filters allowed (default: 6) */
|
|
121
|
+
maxFilters?: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Props for individual filter renderers
|
|
126
|
+
*/
|
|
127
|
+
export interface FilterRendererProps<T = any> {
|
|
128
|
+
config: FilterConfig;
|
|
129
|
+
value: T;
|
|
130
|
+
onChange: (value: T) => void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Validation result for filter configurations
|
|
135
|
+
*/
|
|
136
|
+
export interface FilterValidationResult {
|
|
137
|
+
isValid: boolean;
|
|
138
|
+
errors: string[];
|
|
139
|
+
warnings: string[];
|
|
140
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { ReactElement } from "react";
|
|
2
|
+
import { Text } from "@mantine/core";
|
|
3
|
+
import { translate } from '../../translations';
|
|
4
|
+
|
|
5
|
+
interface ResultCountProps {
|
|
6
|
+
resultCount?: number;
|
|
7
|
+
totalCount?: number;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
hasActiveFilters: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ResultCount = ({
|
|
13
|
+
resultCount,
|
|
14
|
+
totalCount,
|
|
15
|
+
isLoading,
|
|
16
|
+
hasActiveFilters
|
|
17
|
+
}: ResultCountProps): ReactElement => {
|
|
18
|
+
|
|
19
|
+
if (isLoading) {
|
|
20
|
+
return (
|
|
21
|
+
<Text size="xs" span>
|
|
22
|
+
{translate("table.filters.result.count.loading")}
|
|
23
|
+
</Text>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// When filters are active, show filtered results
|
|
28
|
+
if (hasActiveFilters) {
|
|
29
|
+
const filteredCount = resultCount || 0;
|
|
30
|
+
const total = totalCount || 0;
|
|
31
|
+
|
|
32
|
+
if (filteredCount === 0) {
|
|
33
|
+
return (
|
|
34
|
+
<Text size="xs" span>
|
|
35
|
+
{translate("table.filters.result.count.filtered.none", { total })}
|
|
36
|
+
</Text>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (filteredCount === 1) {
|
|
41
|
+
return (
|
|
42
|
+
<Text size="xs" span>
|
|
43
|
+
{translate("table.filters.result.count.filtered.one", { total })}
|
|
44
|
+
</Text>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Text size="xs" span>
|
|
50
|
+
{translate("table.filters.result.count.filtered.many", {
|
|
51
|
+
count: filteredCount,
|
|
52
|
+
total
|
|
53
|
+
})}
|
|
54
|
+
</Text>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// When no filters, show total records
|
|
59
|
+
const count = totalCount || resultCount || 0;
|
|
60
|
+
|
|
61
|
+
if (count === 1) {
|
|
62
|
+
return (
|
|
63
|
+
<Text size="xs" span>
|
|
64
|
+
{translate("table.filters.result.count.total.one")}
|
|
65
|
+
</Text>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Text size="xs" span>
|
|
71
|
+
{translate("table.filters.result.count.total.many", { count })}
|
|
72
|
+
</Text>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default ResultCount;
|