-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathVariableSearch.jsx
More file actions
43 lines (40 loc) · 1.35 KB
/
VariableSearch.jsx
File metadata and controls
43 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { useSearchParams } from "react-router-dom";
import { copySearchParams } from "../../api/call";
import SearchOptions from "../../controls/SearchOptions";
export default function VariableSearch(props) {
const { metadata, callback } = props;
const countryId = window.location.pathname.split("/")[1];
const [searchParams, setSearchParams] = useSearchParams();
const showComputed = searchParams.get("showComputedVariables") === "true";
const options = Object.values(metadata.variables)
.filter((variable) => !variable.hidden_input)
.filter((variable) => showComputed || variable.isInputVariable)
.map((variable) => ({
value: variable.moduleName + "." + variable.name,
label: variable.label,
}))
.filter((option) => !!option.label && !!option.value);
options.push({
value:
countryId === "us"
? "input.geography.countyName"
: "input.household.countyName",
label: "County name",
});
return (
<SearchOptions
options={options}
defaultValue={null}
style={{ margin: 0, width: "100%" }}
placeholder="Search for a variable"
onSelect={(value) => {
let newSearch = copySearchParams(searchParams);
newSearch.set("focus", value);
setSearchParams(newSearch);
if (callback instanceof Function) {
callback();
}
}}
/>
);
}