CEC-5039: view and update sums_version column (#452)

* CEC-5039: view and update sums_version column

* move async function

* add deps

* useEffect

* add deps
This commit is contained in:
Tristan Timblin
2023-09-28 14:35:18 -07:00
committed by GitHub
parent 15e092b1c9
commit 019b1bc034
9 changed files with 200 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
import * as React from 'react';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
export default function SearchSelect({
label = "",
value = "",
setValue = () => { },
getData = () => [],
research = false,
}) {
const [open, setOpen] = React.useState(false);
const [searchCount, setSearchCount] = React.useState(0);
const [inputValue, setInputValue] = React.useState("");
const [options, setOptions] = React.useState([{ label: value }]);
React.useEffect(() => {
function canSearch() {
if (research || searchCount === 0) {
return true;
}
return false;
}
async function fetchData() {
setOptions(await getData(value));
}
if (!open && canSearch()) {
fetchData();
setSearchCount((searchCount) => searchCount + 1);
}
}, [open, value, research, searchCount, getData]);
return (
<Autocomplete
fullWidth
value={value}
onChange={(_, value) => setValue(value)}
inputValue={inputValue}
onInputChange={(_, inputValue) => setInputValue(inputValue)}
open={open}
onOpen={() => setOpen(true)}
onClose={() => setOpen(false)}
options={options}
renderInput={(params) =>
<TextField
{...params}
label={label}
name={label}
variant="outlined"
margin="normal"
/>
}
/>
);
}

View File

@@ -0,0 +1 @@
export * from "./SearchSelect";