Skip to content

Commit

Permalink
Fixed bug with simultaneous oddrn and connectionUrl in payload. (#299)
Browse files Browse the repository at this point in the history
Now in editing datasource user can't change type of adapter (url or oddrn)
  • Loading branch information
Leshe4ka authored Dec 8, 2021
1 parent b988bd6 commit b3bb421
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,21 @@ const DataSourceForm: React.FC<DataSourceFormDialogProps> = ({
}>(initialState);

type RadioType = 'URL' | 'ODDRN';
const [radioValue, setRadioValue] = React.useState<RadioType>('URL');
const isODDRN = () => radioValue === 'ODDRN';
const getDefaultRadioValues = (): RadioType =>
dataSource?.connectionUrl ? 'URL' : 'ODDRN';
const [radioValue, setRadioValue] = React.useState<RadioType>(
getDefaultRadioValues()
);
const isODDRN = React.useCallback(() => radioValue === 'ODDRN', [
radioValue,
]);

const handleRadioChange = (
event: ChangeEvent<HTMLInputElement>,
value: string
) => {
setRadioValue(value as RadioType);
if (isODDRN()) setValue('connectionUrl', '');
setValue('connectionUrl', '');
setValue('oddrn', '');
};

Expand Down Expand Up @@ -217,14 +223,16 @@ const DataSourceForm: React.FC<DataSourceFormDialogProps> = ({
>
<Grid container>
<FormControlLabel
value="URL"
disabled={!!dataSource}
value="ODDRN"
control={<AppRadio />}
label="URL"
label="ODDRN"
/>
<FormControlLabel
value="ODDRN"
disabled={!!dataSource}
value="URL"
control={<AppRadio />}
label="ODDRN"
label="URL"
/>
</Grid>
</RadioGroup>
Expand All @@ -244,7 +252,6 @@ const DataSourceForm: React.FC<DataSourceFormDialogProps> = ({
label="ODDRN"
placeholder="e.g. //kafka/"
required
// disabled={!!dataSource}
customEndAdornment={{
variant: 'clear',
showAdornment: !!field.value,
Expand Down

0 comments on commit b3bb421

Please sign in to comment.