Skip to content

Commit 1d573af

Browse files
committed
Extract SearchSelect component into ui/public. (#23204)
1 parent 7116f14 commit 1d573af

File tree

6 files changed

+26
-74
lines changed

6 files changed

+26
-74
lines changed

x-pack/plugins/rollup/public/crud_app/sections/job_create/steps/components/field_chooser.js

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ import PropTypes from 'prop-types';
99

1010
import {
1111
EuiButton,
12-
EuiPopover,
13-
EuiBasicTable,
14-
EuiFieldSearch,
15-
EuiSpacer,
1612
} from '@elastic/eui';
1713

18-
import './field_chooser.less';
14+
import {
15+
SearchSelect,
16+
} from 'ui/search_select';
1917

2018
export class FieldChooser extends Component {
2119
static propTypes = {
20+
buttonLabel: PropTypes.node.isRequired,
2221
columns: PropTypes.array.isRequired,
23-
label: PropTypes.node.isRequired,
2422
fields: PropTypes.array.isRequired,
2523
onSelectField: PropTypes.func.isRequired,
2624
}
@@ -29,7 +27,6 @@ export class FieldChooser extends Component {
2927
super(props);
3028

3129
this.state = {
32-
searchValue: '',
3330
isOpen: false,
3431
};
3532
}
@@ -46,75 +43,41 @@ export class FieldChooser extends Component {
4643
});
4744
};
4845

49-
onSearch = (e) => {
50-
this.setState({
51-
searchValue: e.target.value,
52-
});
53-
};
46+
onSelect = (field) => {
47+
this.props.onSelectField(field);
48+
this.close();
49+
}
5450

5551
render() {
5652
const {
53+
buttonLabel,
5754
columns,
58-
label,
5955
fields,
60-
onSelectField,
6156
} = this.props;
6257

63-
const {
64-
searchValue,
65-
} = this.state;
66-
67-
const getRowProps = (field) => {
68-
return {
69-
className: 'rollupFieldChooserTableRow',
70-
onClick: () => {
71-
onSelectField(field);
72-
this.close();
73-
},
74-
};
75-
};
58+
const { isOpen } = this.state;
7659

7760
const button = (
7861
<EuiButton
7962
iconType="arrowDown"
8063
iconSide="right"
8164
onClick={this.onButtonClick}
8265
>
83-
{label}
66+
{buttonLabel}
8467
</EuiButton>
8568
);
8669

87-
const items = searchValue ? fields.filter(({ name }) => (
88-
name.toLowerCase().includes(searchValue.trim().toLowerCase())
89-
)) : fields;
90-
9170
return (
92-
<EuiPopover
93-
ownFocus
71+
<SearchSelect
9472
button={button}
95-
isOpen={this.state.isOpen}
96-
closePopover={this.close}
97-
anchorPosition="rightDown"
98-
>
99-
<EuiFieldSearch
100-
placeholder="Search fields"
101-
value={searchValue}
102-
onChange={this.onSearch}
103-
aria-label="Search fields"
104-
fullWidth
105-
/>
106-
107-
<EuiSpacer size="s" />
108-
109-
<div className="rollupFieldChooserContainer">
110-
<EuiBasicTable
111-
items={items}
112-
columns={columns}
113-
rowProps={getRowProps}
114-
responsive={false}
115-
/>
116-
</div>
117-
</EuiPopover>
73+
columns={columns}
74+
items={fields}
75+
isOpen={isOpen}
76+
close={this.close}
77+
onSelectItem={this.onSelect}
78+
searchField="name"
79+
prompt="Search fields"
80+
/>
11881
);
11982
}
12083
}

x-pack/plugins/rollup/public/crud_app/sections/job_create/steps/components/field_chooser.less

Lines changed: 0 additions & 9 deletions
This file was deleted.

x-pack/plugins/rollup/public/crud_app/sections/job_create/steps/components/field_list.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import {
1212
EuiSpacer,
1313
} from '@elastic/eui';
1414

15-
import './field_chooser.less';
16-
1715
export const FieldList = ({
1816
columns,
1917
fields,

x-pack/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ export class StepHistogramUi extends Component {
125125
<EuiSpacer />
126126

127127
<FieldChooser
128-
columns={columns}
129-
label={(
128+
buttonLabel={(
130129
<FormattedMessage
131130
id="xpack.rollupJobs.create.stepHistogram.fieldsChooser.label"
132131
defaultMessage="Select histogram fields"
133132
/>
134133
)}
134+
columns={columns}
135135
fields={unselectedHistogramFields}
136136
onSelectField={this.onSelectField}
137137
/>

x-pack/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ export class StepMetricsUi extends Component {
218218
<EuiSpacer />
219219

220220
<FieldChooser
221-
columns={this.chooserColumns}
222-
label={(
221+
buttonLabel={(
223222
<FormattedMessage
224223
id="xpack.rollupJobs.create.stepMetrics.fieldsChooser.label"
225224
defaultMessage="Select metrics fields"
226225
/>
227226
)}
227+
columns={this.chooserColumns}
228228
fields={unselectedMetricsFields}
229229
onSelectField={this.onSelectField}
230230
/>

x-pack/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ export class StepTermsUi extends Component {
130130
<EuiSpacer />
131131

132132
<FieldChooser
133-
columns={columns}
134-
label={(
133+
buttonLabel={(
135134
<FormattedMessage
136135
id="xpack.rollupJobs.create.stepTerms.fieldsChooser.label"
137136
defaultMessage="Select terms fields"
138137
/>
139138
)}
139+
columns={columns}
140140
fields={unselectedTermsFields}
141141
onSelectField={this.onSelectField}
142142
/>

0 commit comments

Comments
 (0)