fix(gui): populate empty select menus with first valid value
This commit is contained in:
parent
455bfddbc1
commit
0d1f236096
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue