@@ -2,7 +2,7 @@ import {useEffect, useMemo, useState} from 'react';
22import { escapeRegExp } from 'lodash/fp' ;
33
44import { 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
77import type { ValueOf } from '../../../../../types/common' ;
88
@@ -15,8 +15,8 @@ import {b} from '../Partitions';
1515
1616interface 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 }
0 commit comments