Fix two issues related to the data store type selection (#1033)

This commit is contained in:
jbirddog 2024-02-15 08:33:57 -05:00 committed by GitHub
parent bdbb13b57a
commit 330f18fa4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 46 additions and 24 deletions

View File

@ -155,8 +155,14 @@ export default function DataStoreForm({
const onTypeChanged = (newType: any) => {
setTypeInvalid(false);
const newTypeSelection = newType.selectedItem;
const updateDict = { type: newTypeSelection.type };
updateDataStore(updateDict);
if (
newTypeSelection &&
typeof newTypeSelection === 'object' &&
'type' in newTypeSelection
) {
const updateDict = { type: newTypeSelection.type };
updateDataStore(updateDict);
}
setSelectedDataStoreType(newTypeSelection);
};
@ -166,6 +172,18 @@ export default function DataStoreForm({
updateDataStore(updateDict);
};
const dataStoreTypeDisplayString = (
dataStoreType: DataStoreType | null
): string => {
if (dataStoreType) {
return `${dataStoreType.name} (${truncateString(
dataStoreType.description,
75
)})`;
}
return '';
};
const formElements = () => {
const textInputs = [
<TextInput
@ -200,28 +218,32 @@ export default function DataStoreForm({
/>
);
textInputs.push(
<ComboBox
onChange={onTypeChanged}
id="data-store-type-select"
data-qa="data-store-type-selection"
items={dataStoreTypes}
itemToString={(dataStoreType: DataStoreType) => {
if (dataStoreType) {
return `${dataStoreType.name} (${truncateString(
dataStoreType.description,
75
)})`;
}
return null;
}}
titleText="Type*"
invalidText="Type is required."
invalid={typeInvalid}
placeholder="Choose the data store type"
selectedItem={selectedDataStoreType}
/>
);
if (mode === 'edit') {
textInputs.push(
<TextInput
id="data-store-type"
name="data-store-type"
readonly
labelText="Type*"
value={dataStoreTypeDisplayString(selectedDataStoreType)}
/>
);
} else {
textInputs.push(
<ComboBox
onChange={onTypeChanged}
id="data-store-type-select"
data-qa="data-store-type-selection"
items={dataStoreTypes}
itemToString={dataStoreTypeDisplayString}
titleText="Type*"
invalidText="Type is required."
invalid={typeInvalid}
placeholder="Choose the data store type"
selectedItem={selectedDataStoreType}
/>
);
}
textInputs.push(
<TextArea