Skip to content

Commit

Permalink
Fix issue with datastore type auth options
Browse files Browse the repository at this point in the history
  • Loading branch information
johnaohara committed Dec 23, 2024
1 parent d49bb67 commit 5f02bf8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ public class ConfigServiceImpl implements ConfigService {

private static final Logger log = Logger.getLogger(ConfigServiceImpl.class);

//cache available datastores
private static final List<DatastoreType.TypeConfig> datastoreTypes;

static {
List<DatastoreType.TypeConfig> values = new ArrayList<>();
Arrays.asList(DatastoreType.values()).stream().filter(type -> !type.getConfig().builtIn)
.forEach(type -> values.add(type.getConfig()));
datastoreTypes = values;

}
//cache available dataStore configurations
private static final List<DatastoreType.TypeConfig> datastoreTypes = Arrays.asList(
DatastoreType.values()).stream()
.map(type -> type.getConfig())
.collect(Collectors.toList()
);

@ConfigProperty(name = "horreum.privacy")
Optional<String> privacyStatement;
Expand Down
2 changes: 1 addition & 1 deletion horreum-web/src/domain/admin/Datastores.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const DatastoresTable = ( props: dataStoreTableProps) => {
const rowActions: IAction[] | null = defaultActions(teamDatastore);
return (
<Tr key={teamDatastore.id}>
<Td dataLabel={columnNames.type}>{teamDatastore.type}</Td>
<Td dataLabel={columnNames.type}>{props.datastoreTypes.find( (type) => type.enumName === teamDatastore.type)?.label}</Td>
<Td dataLabel={columnNames.name}>{teamDatastore.name}</Td>
<Td isActionCell>
<ActionsColumn
Expand Down
29 changes: 12 additions & 17 deletions horreum-web/src/domain/admin/datastore/ModifyDatastoreModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState} from "react"
import React, {useEffect, useState} from "react"

import {
Button, Form,
Expand Down Expand Up @@ -109,28 +109,23 @@ function ApiKeyAuth ({dataStore, updateDatastore} : UpdateDatastoreProps){

export default function ModifyDatastoreModal({isOpen, onClose, persistDatastore, dataStore, dataStoreTypes, updateDatastore}: ConfirmDeleteModalProps) {

const [authOptions, setAuthOptions] = useState<Array<string>>([
"none",
]);
const [selected , setSelected] = useState<string>("")

const [authOptions, setAuthOptions] = useState<Array<string>>( []);

const handleOptionChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
updateOptionChange(value)
};
useEffect(() => { //find initial auth options for the selected datastore
const typeConf = dataStoreTypes.filter( optionvalue => optionvalue.enumName === dataStore.type).pop()
setAuthOptions(typeConf?.supportedAuths || [])
}, [dataStore]);

const updateOptionChange= (value: string) => {
const selectedOption: TypeConfig | undefined = dataStoreTypes.filter( optionvalue => optionvalue.name === value).pop()
const handleOptionChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
const selectedOption: TypeConfig | undefined = dataStoreTypes.filter( optionvalue => optionvalue.enumName === value).pop()
if ( selectedOption ){
setSelected( value)
setAuthOptions(selectedOption.supportedAuths || [])
//some ts wizardry to get the enum value from the option name string
const datastoreTyped = selectedOption.name as keyof typeof DatastoreTypeEnum;
// let enumKey = Object.keys(DatastoreTypeEnum)[Object.values(DatastoreTypeEnum).indexOf(option.name)];
updateDatastore({...dataStore, type: DatastoreTypeEnum[datastoreTyped] })
}

}
};

const handleAuthOptionChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
switch ( value) { //pita, but TS compiler complains need to switch on String value to get the correct union type
Expand Down Expand Up @@ -158,15 +153,15 @@ export default function ModifyDatastoreModal({isOpen, onClose, persistDatastore,
<Form isHorizontal>
<FormGroup label="Datastore Type" fieldId="horizontal-form-datastore-type">
<FormSelect
value={selected}
value={dataStore.type}
onChange={handleOptionChange}
id="horizontal-form-datastore-type"
name="horizontal-form-datastore-type"
aria-label="Backend Type"
>
<FormSelectOption isDisabled={false} key={0} value={''} label={'Please select type'} placeholder={"true"}/>
{dataStoreTypes.map((option, index) => (
<FormSelectOption isDisabled={option.builtIn} key={index} value={option.name} label={option.label || ""}/>
{dataStoreTypes.filter( type => !type.builtIn).map((option, index) => (
<FormSelectOption isDisabled={option.builtIn} key={index} value={option.enumName} label={option.label || ""}/>
))}
</FormSelect>
</FormGroup>
Expand Down

0 comments on commit 5f02bf8

Please sign in to comment.