1
0
Fork 0

fix(gui): populate empty select menus with first valid value

This commit is contained in:
Sean Sube 2023-01-21 22:50:12 -06:00
parent 455bfddbc1
commit 0d1f236096
1 changed files with 9 additions and 1 deletions

View File

@ -40,6 +40,14 @@ export function QueryList<T>(props: QueryListProps<T>) {
const { labels, query, value } = props; const { labels, query, value } = props;
const { result } = query; const { result } = query;
function firstValidValue(): string {
if (doesExist(value) && data.includes(value)) {
return value;
} else {
return data[0];
}
}
if (result.status === 'error') { if (result.status === 'error') {
if (result.error instanceof Error) { if (result.error instanceof Error) {
return <Alert severity='error'>Error: {result.error.message}</Alert>; return <Alert severity='error'>Error: {result.error.message}</Alert>;
@ -65,7 +73,7 @@ export function QueryList<T>(props: QueryListProps<T>) {
<Select <Select
labelId={labelID} labelId={labelID}
label={props.name} label={props.name}
value={value} value={firstValidValue()}
onChange={(e) => { onChange={(e) => {
if (doesExist(props.onChange)) { if (doesExist(props.onChange)) {
props.onChange(e.target.value); props.onChange(e.target.value);