Skip to content

Commit 0c1610f

Browse files
Refactoring 2
1 parent 22f6210 commit 0c1610f

File tree

2 files changed

+53
-19
lines changed

2 files changed

+53
-19
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { Option, Icon } from '@ui5/webcomponents-react';
3+
import styles from './StatusFilter.module.css';
4+
5+
interface RenderOptionProps {
6+
value: string;
7+
iconName: string;
8+
color: string;
9+
labelKey: string;
10+
t: (key: string) => string;
11+
isSelected: boolean;
12+
}
13+
14+
const RenderOption: React.FC<RenderOptionProps> = ({
15+
value,
16+
iconName,
17+
color,
18+
labelKey,
19+
t,
20+
isSelected,
21+
}) => (
22+
<Option
23+
key={value}
24+
data-value={value}
25+
selected={isSelected}
26+
className={styles.option}
27+
>
28+
<div className={styles.container}>
29+
<Icon name={iconName} style={{ color }} className={styles.icon} />
30+
<span className={styles.label}>{t(labelKey)}</span>
31+
</div>
32+
</Option>
33+
);
34+
35+
export default RenderOption;

src/components/Shared/StatusFilter/StatusFilter.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Icon, Option, Select } from '@ui5/webcomponents-react';
1+
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import styles from './StatusFilter.module.css';
3+
import { Select } from '@ui5/webcomponents-react';
4+
import RenderOption from './RenderOption';
45

56
interface StatusFilterProps {
67
column: {
78
filterValue?: string;
8-
setFilter?: (value?: string | undefined) => void;
9+
setFilter?: (value?: string) => void;
910
};
1011
}
1112

@@ -42,23 +43,21 @@ const StatusFilter: React.FC<StatusFilterProps> = ({ column }) => {
4243
column.setFilter?.(value === 'all' ? undefined : value);
4344
};
4445

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>
46+
return (
47+
<Select onChange={handleChange}>
48+
{options.map((option) => (
49+
<RenderOption
50+
key={option.value}
51+
{...option}
52+
t={t}
53+
isSelected={
54+
column.filterValue === option.value ||
55+
(option.value === 'all' && !column.filterValue)
56+
}
57+
/>
58+
))}
59+
</Select>
5960
);
60-
61-
return <Select onChange={handleChange}>{options.map(renderOption)}</Select>;
6261
};
6362

6463
export default StatusFilter;

0 commit comments

Comments
 (0)