Skip to content

Commit

Permalink
fix(gui): populate empty select menus with first valid value
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 22, 2023
1 parent 455bfdd commit 0d1f236
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gui/src/components/input/QueryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export function QueryList<T>(props: QueryListProps<T>) {
const { labels, query, value } = props;
const { result } = query;

function firstValidValue(): string {
if (doesExist(value) && data.includes(value)) {
return value;
} else {
return data[0];
}
}

if (result.status === 'error') {
if (result.error instanceof Error) {
return <Alert severity='error'>Error: {result.error.message}</Alert>;
Expand All @@ -65,7 +73,7 @@ export function QueryList<T>(props: QueryListProps<T>) {
<Select
labelId={labelID}
label={props.name}
value={value}
value={firstValidValue()}
onChange={(e) => {
if (doesExist(props.onChange)) {
props.onChange(e.target.value);
Expand Down

0 comments on commit 0d1f236

Please sign in to comment.