-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathuseSortingOptions.tsx
68 lines (62 loc) · 2.25 KB
/
useSortingOptions.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
//
// SPDX-License-Identifier: Apache-2.0
import BarChartIcon from '@mui/icons-material/BarChart';
import SortByAlphaIcon from '@mui/icons-material/SortByAlpha';
import WhatshotIcon from '@mui/icons-material/Whatshot';
import { useMemo } from 'react';
import { text } from '../../../shared/text';
import { useShowClassifications } from '../../state/variables/use-show-classifications';
import { useShowCriticality } from '../../state/variables/use-show-criticality';
import { ClassificationCIcon } from '../Icons/Icons';
export type SortOption =
| 'alphabetically'
| 'criticality'
| 'occurrence'
| 'classification';
export interface SortOptionConfiguration {
label: string;
icon: React.FC<{ color?: 'action' | 'disabled' }>;
active: boolean;
}
export type SortConfiguration = Record<SortOption, SortOptionConfiguration>;
export function useSortConfiguration(): SortConfiguration {
const showClassifications = useShowClassifications();
const showCriticality = useShowCriticality();
return useMemo(() => {
return {
alphabetically: {
label: text.sortings.name,
icon: ({ color }: { color?: 'action' | 'disabled' }) => (
<SortByAlphaIcon color={color || 'action'} fontSize={'inherit'} />
),
active: true,
},
criticality: {
label: text.sortings.criticality,
icon: ({ color }: { color?: 'action' | 'disabled' }) => (
<WhatshotIcon color={color || 'warning'} fontSize={'inherit'} />
),
active: showCriticality,
},
occurrence: {
label: text.sortings.occurrence,
icon: ({ color }: { color?: 'action' | 'disabled' }) => (
<BarChartIcon color={color || 'info'} fontSize={'inherit'} />
),
active: true,
},
classification: {
label: text.sortings.classification,
icon: ({ color }: { color?: 'action' | 'disabled' }) => (
<ClassificationCIcon
color={color || 'warning'}
fontSize={'inherit'}
/>
),
active: showClassifications,
},
};
}, [showClassifications, showCriticality]);
}