Skip to content

Commit a7df6d1

Browse files
fix(Partitions): update Select empty value
1 parent 4fe21a0 commit a7df6d1

File tree

7 files changed

+31
-33
lines changed

7 files changed

+31
-33
lines changed

src/containers/Tenant/Diagnostics/Partitions/Partitions.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
width: 220px;
1717
}
1818

19+
&__select-option_empty {
20+
color: var(--yc-color-text-hint);
21+
}
22+
1923
&__search {
2024
@include search();
2125
&_partition {

src/containers/Tenant/Diagnostics/Partitions/Partitions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const Partitions = ({path}: PartitionsProps) => {
113113
selectedConsumer && consumers && !consumers.includes(selectedConsumer);
114114

115115
if (isTopicWithoutConsumers || wrongSelectedConsumer) {
116-
dispatch(setSelectedConsumer());
116+
dispatch(setSelectedConsumer(''));
117117
}
118118
}, [dispatch, topicWasLoaded, selectedConsumer, consumers]);
119119

@@ -125,7 +125,7 @@ export const Partitions = ({path}: PartitionsProps) => {
125125
setHiddenColumns(newHiddenColumns);
126126
};
127127

128-
const handleSelectedConsumerChange = (value?: string) => {
128+
const handleSelectedConsumerChange = (value: string) => {
129129
dispatch(setSelectedConsumer(value));
130130
};
131131

src/containers/Tenant/Diagnostics/Partitions/PartitionsControls/PartitionsControls.tsx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {useEffect, useMemo, useState} from 'react';
22
import {escapeRegExp} from 'lodash/fp';
33

44
import {TableColumnSetupItem} from '@gravity-ui/uikit/build/esm/components/Table/hoc/withTableSettings/withTableSettings';
5-
import {Select, TableColumnSetup} from '@gravity-ui/uikit';
5+
import {Select, SelectOption, TableColumnSetup} from '@gravity-ui/uikit';
66

77
import type {ValueOf} from '../../../../../types/common';
88

@@ -15,8 +15,8 @@ import {b} from '../Partitions';
1515

1616
interface PartitionsControlsProps {
1717
consumers: string[] | undefined;
18-
selectedConsumer: string | undefined;
19-
onSelectedConsumerChange: (consumer: string | undefined) => void;
18+
selectedConsumer: string;
19+
onSelectedConsumerChange: (consumer: string) => void;
2020
selectDisabled: boolean;
2121
partitions: PreparedPartitionDataWithHosts[] | undefined;
2222
onSearchChange: (filteredPartitions: PreparedPartitionDataWithHosts[]) => void;
@@ -39,9 +39,6 @@ export const PartitionsControls = ({
3939
const [generalSearchValue, setGeneralSearchValue] = useState('');
4040
const [partitionIdSearchValue, setPartitionIdSearchValue] = useState('');
4141

42-
// Manual select control to enforce single-select behaviour for multiple select type
43-
const [consumerSelectOpen, setConsumerSelectOpen] = useState(false);
44-
4542
useEffect(() => {
4643
if (!partitions) {
4744
return;
@@ -83,16 +80,17 @@ export const PartitionsControls = ({
8380
onSearchChange(filteredPartitions);
8481
}, [partitionIdSearchValue, generalSearchValue, partitions, onSearchChange]);
8582

86-
const consumersToSelect = useMemo(
87-
() =>
88-
consumers
83+
const consumersToSelect = useMemo(() => {
84+
const options =
85+
consumers && consumers.length
8986
? consumers.map((consumer) => ({
9087
value: consumer,
9188
content: consumer,
9289
}))
93-
: undefined,
94-
[consumers],
95-
);
90+
: [];
91+
92+
return [{value: '', content: i18n('controls.consumerSelector.emptyOption')}, ...options];
93+
}, [consumers]);
9694

9795
const columnsToSelect = useMemo(() => {
9896
return initialColumnsIds.map((id) => {
@@ -106,10 +104,7 @@ export const PartitionsControls = ({
106104
}, [initialColumnsIds, hiddenColumns]);
107105

108106
const handleConsumerSelectChange = (value: string[]) => {
109-
// As we have selector with multiple options, the first value corresponds to previous value
110-
// The second value is currently chosen consumer
111-
onSelectedConsumerChange(value[1]);
112-
setConsumerSelectOpen(false);
107+
onSelectedConsumerChange(value[0]);
113108
};
114109

115110
const handlePartitionIdSearchChange = (value: string) => {
@@ -137,25 +132,24 @@ export const PartitionsControls = ({
137132
onHiddenColumnsChange(result);
138133
};
139134

135+
const renderOption = (option: SelectOption) => {
136+
return (
137+
<div className={b('select-option', {empty: option.value === ''})}>{option.content}</div>
138+
);
139+
};
140+
140141
return (
141142
<div className={b('controls')}>
142143
<Select
143144
className={b('consumer-select')}
144-
placeholder={i18n('controls.consumerSelector.placeholder')}
145145
label={i18n('controls.consumerSelector')}
146146
options={consumersToSelect}
147-
value={[selectedConsumer || '']}
147+
value={[selectedConsumer]}
148148
onUpdate={handleConsumerSelectChange}
149149
filterable={consumers && consumers.length > 5}
150150
disabled={selectDisabled || !consumers || !consumers.length}
151-
open={consumerSelectOpen}
152-
onOpenChange={setConsumerSelectOpen}
153-
// Although only one value could be selected
154-
// Multiple type Select is used
155-
// The reason - we need Select to be able to work with no value
156-
// And it is easier to make multiple Select close on value change
157-
// Than to enable single select to work with empty values
158-
multiple
151+
renderOption={renderOption}
152+
renderSelectedOption={renderOption}
159153
/>
160154
<Search
161155
onChange={handlePartitionIdSearchChange}

src/containers/Tenant/Diagnostics/Partitions/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"headers.unread": "End offset - Last read offset",
55
"headers.uncommited": "End offset - Committed offset",
66
"controls.consumerSelector": "Consumer:",
7-
"controls.consumerSelector.placeholder": "Consumer",
7+
"controls.consumerSelector.emptyOption": "No consumer",
88
"controls.partitionSearch": "Partition ID",
99
"controls.generalSearch": "Host, Host ID, Reader, Read Session ID",
1010
"table.emptyDataMessage": "No partitions match the current search",

src/containers/Tenant/Diagnostics/Partitions/i18n/ru.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"headers.unread": "End offset - Last read offset",
55
"headers.uncommited": "End offset - Committed offset",
66
"controls.consumerSelector": "Читатель:",
7-
"controls.consumerSelector.placeholder": "Читатель",
7+
"controls.consumerSelector.emptyOption": "Нет читателя",
88
"controls.partitionSearch": "Partition ID",
99
"controls.generalSearch": "Host, Host ID, Reader, Read Session ID",
1010
"table.emptyDataMessage": "По заданному поиску нет партиций",

src/store/reducers/partitions/partitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const SET_DATA_WAS_NOT_LOADED = 'partitions/SET_DATA_WAS_NOT_LOADED';
1515
const initialState = {
1616
loading: false,
1717
wasLoaded: false,
18-
selectedConsumer: undefined,
18+
selectedConsumer: '',
1919
};
2020

2121
const partitions: Reducer<PartitionsState, PartitionsAction> = (state = initialState, action) => {
@@ -63,7 +63,7 @@ const partitions: Reducer<PartitionsState, PartitionsAction> = (state = initialS
6363
}
6464
};
6565

66-
export const setSelectedConsumer = (value?: string) => {
66+
export const setSelectedConsumer = (value: string) => {
6767
return {
6868
type: SET_SELECTED_CONSUMER,
6969
data: value,

src/store/reducers/partitions/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface PreparedPartitionData {
3636
export interface PartitionsState {
3737
loading: boolean;
3838
wasLoaded: boolean;
39-
selectedConsumer: string | undefined;
39+
selectedConsumer: string;
4040
partitions?: PreparedPartitionData[];
4141
error?: IResponseError;
4242
}

0 commit comments

Comments
 (0)