-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathProfileDiffForm.tsx
88 lines (78 loc) · 2.46 KB
/
ProfileDiffForm.tsx
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { RunFormProps } from "../run/types";
import { useEffect, useState } from "react";
import useModelColumns from "@/lib/hooks/useModelColumns";
import { Select } from "chakra-react-select";
import { Box, Checkbox, FormControl, FormLabel, Input, VStack } from "@chakra-ui/react";
interface ProfileDiffFormParams {
model: string;
primary_key?: string | (string | undefined)[];
columns?: string[];
}
type ProfileDiffFormProp = RunFormProps<ProfileDiffFormParams>;
export function ProfileDiffForm({
params,
onParamsChanged,
setIsReadyToExecute,
}: ProfileDiffFormProp) {
const [allColumns, setAllColumns] = useState<boolean>(
!params.columns || params.columns.length === 0,
);
const model = params.model;
const { columns, isLoading, error } = useModelColumns(params.model);
useEffect(() => {
setIsReadyToExecute(model ? true : false);
}, [model, setIsReadyToExecute]);
const columnNames = columns.map((c) => c.name);
if (isLoading) {
return <Box>Loading...</Box>;
}
if (columnNames.length === 0 || error) {
return <Box>Error: Please provide the 'catalog.json' to list column candidates</Box>;
}
return (
<VStack gap={5} m="8px 24px" paddingBottom="200px">
<FormControl>
<FormLabel>Model</FormLabel>
<Input isReadOnly={true} value={params.model} />
</FormControl>
<FormControl>
<FormLabel>Columns</FormLabel>
<Checkbox
marginBottom="10px"
isChecked={allColumns}
onChange={(e) => {
setAllColumns(e.target.checked);
onParamsChanged({
...params,
columns: undefined,
});
}}>
All columns
</Checkbox>
{!allColumns && (
<Select
isMulti
closeMenuOnSelect={false}
options={columnNames.map((c) => ({ label: c, value: c }))}
value={(params.columns ?? []).map((c) => ({
label: c,
value: c,
}))}
onChange={(newValue) => {
let cols: string[] | undefined;
const newCols = newValue.map((v) => v.value);
if (newCols.length === 0) {
cols = undefined;
} else {
cols = newCols;
}
onParamsChanged({
...params,
columns: cols,
});
}}></Select>
)}
</FormControl>
</VStack>
);
}