Skip to content

Commit

Permalink
Replace OuiSelect component with OuiSuperSelect in data-source plugin (
Browse files Browse the repository at this point in the history
…#5315)

* Replace OuiSelect component with OuiSuperSelect in data-source plugin

Signed-off-by: Bandini Bhopi <[email protected]>

* Fix UT

Signed-off-by: Bandini Bhopi <[email protected]>

---------

Signed-off-by: Bandini Bhopi <[email protected]>
(cherry picked from commit 18607a2)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jan 8, 2024
1 parent a0a94b2 commit 0be5c59
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ describe('Datasource Management: Create Datasource form', () => {
};

const setAuthTypeValue = (testSubjId: string, value: string) => {
component.find(testSubjId).last().simulate('change', {
target: {
value,
},
});
component.find(testSubjId).last().simulate('click');
component.find({ id: value }).last().simulate('click');
};

beforeEach(() => {
Expand Down Expand Up @@ -103,7 +100,7 @@ describe('Datasource Management: Create Datasource form', () => {

const { authType, username, password } = getFields(component);

expect(authType.prop('value')).toBe(AuthType.NoAuth);
expect(authType.prop('valueOfSelected')).toBe(AuthType.NoAuth);
expect(username.exists()).toBeFalsy(); // username field does not exist when No Auth option is selected
expect(password.exists()).toBeFalsy(); // password field does not exist when No Auth option is selected
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
EuiForm,
EuiFormRow,
EuiPageContent,
EuiSelect,
EuiSuperSelect,
EuiSpacer,
EuiText,
} from '@elastic/eui';
Expand Down Expand Up @@ -124,8 +124,7 @@ export class CreateDataSourceForm extends React.Component<
});
};

onChangeAuthType = (e: React.ChangeEvent<HTMLSelectElement>) => {
const authType = e.target.value as AuthType;
onChangeAuthType = (authType: AuthType) => {
this.setState({
auth: {
...this.state.auth,
Expand All @@ -140,13 +139,13 @@ export class CreateDataSourceForm extends React.Component<
});
};

onChangeSigV4ServiceName = (e: React.ChangeEvent<HTMLSelectElement>) => {
onChangeSigV4ServiceName = (service: SigV4ServiceName) => {
this.setState({
auth: {
...this.state.auth,
credentials: {
...this.state.auth.credentials,
service: e.target.value as SigV4ServiceName,
service,
},
},
});
Expand Down Expand Up @@ -425,10 +424,10 @@ export class CreateDataSourceForm extends React.Component<
defaultMessage: 'Service Name',
})}
>
<EuiSelect
<EuiSuperSelect
options={sigV4ServiceOptions}
value={this.state.auth.credentials.service}
onChange={(e) => this.onChangeSigV4ServiceName(e)}
valueOfSelected={this.state.auth.credentials.service}
onChange={(value) => this.onChangeSigV4ServiceName(value)}

Check warning on line 430 in src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx#L430

Added line #L430 was not covered by tests
name="ServiceName"
data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"
/>
Expand Down Expand Up @@ -598,10 +597,10 @@ export class CreateDataSourceForm extends React.Component<
{/* Credential source */}
<EuiSpacer size="l" />
<EuiFormRow>
<EuiSelect
<EuiSuperSelect
options={credentialSourceOptions}
value={this.state.auth.type}
onChange={(e) => this.onChangeAuthType(e)}
valueOfSelected={this.state.auth.type}
onChange={(value) => this.onChangeAuthType(value)}
name="Credential"
data-test-subj="createDataSourceFormAuthTypeSelect"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ describe('Datasource Management: Edit Datasource Form', () => {
};

const setAuthTypeValue = (testSubjId: string, value: string) => {
component.find(testSubjId).last().simulate('change', {
target: {
value,
},
});
component.find(testSubjId).last().simulate('click');
component.find({ id: value }).last().simulate('click');
};

describe('Case 1: With Username & Password', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EuiFormRow,
EuiHorizontalRule,
EuiPanel,
EuiSelect,
EuiSuperSelect,
EuiSpacer,
EuiText,
} from '@elastic/eui';
Expand Down Expand Up @@ -166,8 +166,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
});
};

onChangeAuthType = (e: React.ChangeEvent<HTMLSelectElement>) => {
const authType = e.target.value as AuthType;
onChangeAuthType = (authType: AuthType) => {
this.setState(
{
auth: {
Expand Down Expand Up @@ -241,13 +240,13 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
});
};

onChangeSigV4ServiceName = (e: React.ChangeEvent<HTMLSelectElement>) => {
onChangeSigV4ServiceName = (service: SigV4ServiceName) => {
this.setState({
auth: {
...this.state.auth,
credentials: {
...this.state.auth.credentials,
service: e.target.value as SigV4ServiceName,
service,
} as SigV4Content,
},
});
Expand Down Expand Up @@ -772,9 +771,9 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
defaultMessage: 'Credential',
})}
>
<EuiSelect
<EuiSuperSelect
options={credentialSourceOptions}
value={this.state.auth.type}
valueOfSelected={this.state.auth.type}
onChange={this.onChangeAuthType}
name="Credential"
data-test-subj="editDataSourceSelectAuthType"
Expand Down Expand Up @@ -827,10 +826,10 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
defaultMessage: 'Service Name',
})}
>
<EuiSelect
<EuiSuperSelect
options={sigV4ServiceOptions}
value={this.state.auth.credentials?.service}
onChange={(e) => this.onChangeSigV4ServiceName(e)}
valueOfSelected={this.state.auth.credentials?.service}
onChange={(value) => this.onChangeSigV4ServiceName(value)}

Check warning on line 832 in src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx#L832

Added line #L832 was not covered by tests
name="ServiceName"
data-test-subj="editDataSourceFormSigV4ServiceTypeSelect"
/>
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/data_source_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ export enum AuthType {
export const credentialSourceOptions = [
{
value: AuthType.NoAuth,
text: i18n.translate('dataSourceManagement.credentialSourceOptions.NoAuthentication', {
inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.NoAuthentication', {
defaultMessage: 'No authentication',
}),
},
{
value: AuthType.UsernamePasswordType,
text: i18n.translate('dataSourceManagement.credentialSourceOptions.UsernamePassword', {
inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.UsernamePassword', {
defaultMessage: 'Username & Password',
}),
},
{
value: AuthType.SigV4,
text: i18n.translate('dataSourceManagement.credentialSourceOptions.AwsSigV4', {
inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.AwsSigV4', {
defaultMessage: 'AWS SigV4',
}),
},
Expand All @@ -82,13 +82,13 @@ export const credentialSourceOptions = [
export const sigV4ServiceOptions = [
{
value: SigV4ServiceName.OpenSearch,
text: i18n.translate('dataSourceManagement.SigV4ServiceOptions.OpenSearch', {
inputDisplay: i18n.translate('dataSourceManagement.SigV4ServiceOptions.OpenSearch', {
defaultMessage: 'Amazon OpenSearch Service',
}),
},
{
value: SigV4ServiceName.OpenSearchServerless,
text: i18n.translate('dataSourceManagement.SigV4ServiceOptions.OpenSearchServerless', {
inputDisplay: i18n.translate('dataSourceManagement.SigV4ServiceOptions.OpenSearchServerless', {
defaultMessage: 'Amazon OpenSearch Serverless',
}),
},
Expand Down

0 comments on commit 0be5c59

Please sign in to comment.