Skip to content

Commit 22f6210

Browse files
refactor
1 parent 62978c5 commit 22f6210

File tree

6 files changed

+86
-106
lines changed

6 files changed

+86
-106
lines changed

src/components/ControlPlane/FluxList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { timeAgo } from '../../utils/i18n/timeAgo.ts';
1616
import { ResourceStatusCell } from '../Shared/ResourceStatusCell.tsx';
1717
import { YamlViewButton } from '../Yaml/YamlViewButton.tsx';
1818
import { useMemo } from 'react';
19-
import StatusFilter from '../Shared/StatusFilter.tsx';
19+
import StatusFilter from '../Shared/StatusFilter/StatusFilter.tsx';
2020

2121
export default function FluxList() {
2222
const {

src/components/ControlPlane/ManagedResources.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { resourcesInterval } from '../../lib/shared/constants';
1515
import { ResourceStatusCell } from '../Shared/ResourceStatusCell';
1616
import { YamlViewButton } from '../Yaml/YamlViewButton.tsx';
1717
import { useMemo } from 'react';
18-
import StatusFilter from '../Shared/StatusFilter.tsx';
18+
import StatusFilter from '../Shared/StatusFilter/StatusFilter.tsx';
1919

2020
interface CellData<T> {
2121
cell: {

src/components/ControlPlane/Providers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { YamlViewButton } from '../Yaml/YamlViewButton.tsx';
1717

1818
import '@ui5/webcomponents-icons/dist/sys-enter-2';
1919
import '@ui5/webcomponents-icons/dist/sys-cancel-2';
20-
import StatusFilter from '../Shared/StatusFilter.tsx';
20+
import StatusFilter from '../Shared/StatusFilter/StatusFilter.tsx';
2121

2222
interface CellData<T> {
2323
cell: {

src/components/Shared/StatusFilter.tsx

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.option {
2+
padding: 6px 10px;
3+
}
4+
5+
.container {
6+
display: flex;
7+
align-items: center;
8+
gap: 8px;
9+
}
10+
11+
.icon {
12+
width: 16px;
13+
height: 16px;
14+
flex-shrink: 0;
15+
}
16+
17+
.label {
18+
font-size: 14px;
19+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Icon, Option, Select } from '@ui5/webcomponents-react';
2+
import { useTranslation } from 'react-i18next';
3+
import styles from './StatusFilter.module.css';
4+
5+
interface StatusFilterProps {
6+
column: {
7+
filterValue?: string;
8+
setFilter?: (value?: string | undefined) => void;
9+
};
10+
}
11+
12+
interface OptionConfig {
13+
value: string;
14+
iconName: string;
15+
color: string;
16+
labelKey: string;
17+
}
18+
19+
const StatusFilter: React.FC<StatusFilterProps> = ({ column }) => {
20+
const { t } = useTranslation();
21+
22+
const options: OptionConfig[] = [
23+
{ value: 'all', iconName: 'filter', color: 'gray', labelKey: 'All' },
24+
{
25+
value: 'true',
26+
iconName: 'sys-enter-2',
27+
color: 'green',
28+
labelKey: 'Enabled',
29+
},
30+
{
31+
value: 'false',
32+
iconName: 'sys-cancel-2',
33+
color: 'red',
34+
labelKey: 'Disabled',
35+
},
36+
];
37+
38+
const handleChange = (
39+
e: CustomEvent<{ selectedOption: { dataset?: { value?: string } } }>,
40+
) => {
41+
const value = e.detail.selectedOption.dataset?.value;
42+
column.setFilter?.(value === 'all' ? undefined : value);
43+
};
44+
45+
const renderOption = ({ value, iconName, color, labelKey }: OptionConfig) => (
46+
<Option
47+
key={value}
48+
data-value={value}
49+
selected={
50+
column.filterValue === value || (value === 'all' && !column.filterValue)
51+
}
52+
className={styles.option}
53+
>
54+
<div className={styles.container}>
55+
<Icon name={iconName} style={{ color }} className={styles.icon} />
56+
<span className={styles.label}>{t(labelKey)}</span>
57+
</div>
58+
</Option>
59+
);
60+
61+
return <Select onChange={handleChange}>{options.map(renderOption)}</Select>;
62+
};
63+
64+
export default StatusFilter;

0 commit comments

Comments
 (0)