Skip to content

Commit 37e8ff9

Browse files
author
solovevayaroslavna
committed
PMM-11773-Templates-select-issues: fix default value
1 parent 4f57b17 commit 37e8ff9

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export const DBClusterAdvancedOptions: FC<DBClusterAdvancedOptionsProps> = ({
211211
<Templates
212212
k8sClusterName={selectedCluster ? selectedCluster.kubernetesClusterName : kubernetesCluster?.value}
213213
databaseType={databaseType?.value}
214+
form={form}
214215
/>
215216
<div className={styles.line}>
216217
<NumberInputField

public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Templates/Templates.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { AdvancedOptionsFields } from '../DBClusterAdvancedOptions.types';
1111

1212
import { Messages } from './Templates.messages';
1313
import { TemplatesProps } from './Templates.types';
14-
import { getTemplatesOptions } from './Templates.utils';
14+
import { getTemplatesOptions, notSelectedOption } from './Templates.utils';
1515

16-
export const Templates: FC<TemplatesProps> = ({ k8sClusterName, databaseType }) => {
16+
export const Templates: FC<TemplatesProps> = ({ k8sClusterName, databaseType, form }) => {
1717
const dispatch = useDispatch();
1818
const { result, loading } = useSelector(getDbaaSTemplates);
1919

@@ -24,8 +24,16 @@ export const Templates: FC<TemplatesProps> = ({ k8sClusterName, databaseType })
2424
if (dbClusterType) {
2525
dispatch(fetchDBaaSTemplatesAction({ k8sClusterName, dbClusterType }));
2626
}
27+
// eslint-disable-next-line react-hooks/exhaustive-deps
2728
}, [databaseType, dispatch, k8sClusterName]);
2829

30+
useEffect(() => {
31+
if (templatesOptions.length === 1) {
32+
form.mutators.resetTemplate(notSelectedOption);
33+
}
34+
// eslint-disable-next-line react-hooks/exhaustive-deps
35+
}, [templatesOptions]);
36+
2937
return (
3038
<Field
3139
dataTestId="templates-field"
@@ -34,6 +42,7 @@ export const Templates: FC<TemplatesProps> = ({ k8sClusterName, databaseType })
3442
component={AsyncSelectFieldAdapter}
3543
loading={loading}
3644
options={templatesOptions}
45+
defaultValue={notSelectedOption}
3746
/>
3847
);
3948
};

public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Templates/Templates.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { FormApi } from 'final-form';
2+
13
import { Databases } from '../../../../../../shared/core';
24
import { DBClusterType } from '../../../DBCluster.types';
35

46
export interface TemplatesProps {
57
k8sClusterName: string;
68
databaseType: Databases;
9+
form: FormApi<Record<string, any>, Partial<Record<string, any>>>;
710
}
811

912
export interface DBClusterTemplate {
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SelectableValue } from '@grafana/data';
22

33
import { DBClusterTemplatesResponse } from './Templates.types';
4-
4+
export const notSelectedOption = { label: 'Not selected', value: '' };
55
export const getTemplatesOptions = (
66
templatesResponce: DBClusterTemplatesResponse | undefined
77
): Array<SelectableValue<string>> => {
@@ -10,7 +10,5 @@ export const getTemplatesOptions = (
1010
label: template.name,
1111
value: template.kind,
1212
}));
13-
const notSelectedOption = { label: 'Not selected', value: '' };
14-
1513
return options?.length ? [...options, notSelectedOption] : [notSelectedOption];
1614
};

public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import React, { FC, useCallback, useEffect, useState } from 'react';
44
import { Form } from 'react-final-form';
55
import { Redirect, useHistory } from 'react-router-dom';
66

7+
import { SelectableValue } from '@grafana/data';
78
import { Spinner, useStyles2 } from '@grafana/ui/src';
9+
import { AdvancedOptionsFields } from 'app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.types';
810
import { useShowPMMAddressWarning } from 'app/percona/shared/components/hooks/showPMMAddressWarning';
911
import { useSelector, useDispatch } from 'app/types';
1012

@@ -93,6 +95,9 @@ export const EditDBClusterPage: FC<EditDBClusterPageProps> = () => {
9395
trimConfiguration: ([configuration]: string[], state, { changeValue }) => {
9496
changeValue(state, ConfigurationFields.configuration, () => configuration.trim());
9597
},
98+
resetTemplate: (templateValue: SelectableValue<string>, state, { changeValue }) => {
99+
changeValue(state, AdvancedOptionsFields.template, () => templateValue);
100+
},
96101
...arrayMutators,
97102
}}
98103
render={({ form, handleSubmit, valid, pristine, ...props }) => (

0 commit comments

Comments
 (0)