read field info from modal form
This commit is contained in:
parent
31ae83addd
commit
11d2d2810d
@ -23,12 +23,34 @@ const Rect = (props) => {
|
|||||||
const [name, setName] = useState("New Table");
|
const [name, setName] = useState("New Table");
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [editFieldVisible, setEditFieldVisible] = useState(-1);
|
const [editFieldVisible, setEditFieldVisible] = useState(-1);
|
||||||
|
const [fields, setFields] = useState([
|
||||||
|
{
|
||||||
|
name: "id",
|
||||||
|
type: "UUID",
|
||||||
|
default: "",
|
||||||
|
primary: true,
|
||||||
|
unique: true,
|
||||||
|
notNull: true,
|
||||||
|
increment: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const [field, setField] = useState({
|
||||||
|
name: "",
|
||||||
|
type: "",
|
||||||
|
default: "",
|
||||||
|
primary: false,
|
||||||
|
unique: false,
|
||||||
|
notNull: false,
|
||||||
|
increment: false,
|
||||||
|
});
|
||||||
|
|
||||||
const handleOkEdit = () => {
|
const handleOkEdit = () => {
|
||||||
setEditFieldVisible(-1);
|
setEditFieldVisible(-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOk = () => {
|
const handleOk = () => {
|
||||||
|
console.log(field);
|
||||||
|
setFields((prev) => [...prev, field]);
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,27 +80,6 @@ const Rect = (props) => {
|
|||||||
"JSON",
|
"JSON",
|
||||||
];
|
];
|
||||||
|
|
||||||
const [fields, setFields] = useState([
|
|
||||||
{
|
|
||||||
name: "id",
|
|
||||||
type: "uuid",
|
|
||||||
default: "",
|
|
||||||
primary: true,
|
|
||||||
unique: true,
|
|
||||||
notNull: true,
|
|
||||||
increment: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "name",
|
|
||||||
type: "varchar(20)",
|
|
||||||
default: "",
|
|
||||||
primary: false,
|
|
||||||
unique: false,
|
|
||||||
notNull: true,
|
|
||||||
increment: false,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const height = fields.length * 36 + 40 + 4;
|
const height = fields.length * 36 + 40 + 4;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -127,9 +128,7 @@ const Rect = (props) => {
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="btn bg-green-600 text-white text-xs py-1 px-2 me-2 opacity-80"
|
className="btn bg-green-600 text-white text-xs py-1 px-2 me-2 opacity-80"
|
||||||
onClick={(e) => {
|
onClick={(e) => setVisible(true)}
|
||||||
setVisible(true);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<IconPlus />
|
<IconPlus />
|
||||||
</button>
|
</button>
|
||||||
@ -170,7 +169,7 @@ const Rect = (props) => {
|
|||||||
)}
|
)}
|
||||||
{e.increment && (
|
{e.increment && (
|
||||||
<Tag color="green" className="me-2 my-2">
|
<Tag color="green" className="me-2 my-2">
|
||||||
Not null
|
Increment
|
||||||
</Tag>
|
</Tag>
|
||||||
)}
|
)}
|
||||||
<p className="text-slate-600">
|
<p className="text-slate-600">
|
||||||
@ -304,14 +303,18 @@ const Rect = (props) => {
|
|||||||
title="Add new field"
|
title="Add new field"
|
||||||
visible={visible}
|
visible={visible}
|
||||||
onOk={handleOk}
|
onOk={handleOk}
|
||||||
afterClose={handleOk}
|
afterClose={() => {}}
|
||||||
onCancel={handleOk}
|
onCancel={handleOk}
|
||||||
centered
|
centered
|
||||||
closeOnEsc={true}
|
closeOnEsc={true}
|
||||||
okText="Add"
|
okText="Add"
|
||||||
cancelText="Cancel"
|
cancelText="Cancel"
|
||||||
>
|
>
|
||||||
<Form labelPosition="left" labelAlign="right">
|
<Form
|
||||||
|
labelPosition="left"
|
||||||
|
labelAlign="right"
|
||||||
|
onValueChange={(v) => setField({ ...field, ...v })}
|
||||||
|
>
|
||||||
<Row>
|
<Row>
|
||||||
<Col span={11}>
|
<Col span={11}>
|
||||||
<Form.Input field="name" label="Name" trigger="blur" />
|
<Form.Input field="name" label="Name" trigger="blur" />
|
||||||
@ -331,15 +334,41 @@ const Rect = (props) => {
|
|||||||
optionList={sqlDataTypes.map((value, index) => {
|
optionList={sqlDataTypes.map((value, index) => {
|
||||||
return {
|
return {
|
||||||
label: value,
|
label: value,
|
||||||
value: index,
|
value: value,
|
||||||
};
|
};
|
||||||
})}
|
})}
|
||||||
></Form.Select>
|
></Form.Select>
|
||||||
<div className="flex justify-around mt-2">
|
<div className="flex justify-around mt-2">
|
||||||
<Checkbox value="A">Primary</Checkbox>
|
<Checkbox
|
||||||
<Checkbox value="B">Unique</Checkbox>
|
value="primary"
|
||||||
<Checkbox value="C">Not null</Checkbox>
|
onChange={() =>
|
||||||
<Checkbox value="D">Increment</Checkbox>
|
setField({ ...field, primary: !field.primary })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Primary
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox
|
||||||
|
value="unique"
|
||||||
|
onChange={() => setField({ ...field, unique: !field.unique })}
|
||||||
|
>
|
||||||
|
Unique
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox
|
||||||
|
value="not null"
|
||||||
|
onChange={() =>
|
||||||
|
setField({ ...field, notNull: !field.notNull })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Not null
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox
|
||||||
|
value="increment"
|
||||||
|
onChange={() =>
|
||||||
|
setField({ ...field, increment: !field.increment })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Increment
|
||||||
|
</Checkbox>
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
@ -361,11 +390,23 @@ const Rect = (props) => {
|
|||||||
<Form labelPosition="left" labelAlign="right">
|
<Form labelPosition="left" labelAlign="right">
|
||||||
<Row>
|
<Row>
|
||||||
<Col span={11}>
|
<Col span={11}>
|
||||||
<Form.Input field="name" label="Name" trigger="blur" />
|
<Form.Input
|
||||||
|
field="name"
|
||||||
|
label="Name"
|
||||||
|
trigger="blur"
|
||||||
|
onChange={(e) => setField({ ...field, name: e.target.value })}
|
||||||
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={2}></Col>
|
<Col span={2}></Col>
|
||||||
<Col span={11}>
|
<Col span={11}>
|
||||||
<Form.Input field="default" label="Default" trigger="blur" />
|
<Form.Input
|
||||||
|
field="default"
|
||||||
|
label="Default"
|
||||||
|
trigger="blur"
|
||||||
|
onChange={(e) =>
|
||||||
|
setField({ ...field, default: e.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
@ -380,6 +421,7 @@ const Rect = (props) => {
|
|||||||
value: index,
|
value: index,
|
||||||
};
|
};
|
||||||
})}
|
})}
|
||||||
|
onChange={(e) => setField({ ...field, type: e.target.value })}
|
||||||
></Form.Select>
|
></Form.Select>
|
||||||
<div className="flex justify-around mt-2">
|
<div className="flex justify-around mt-2">
|
||||||
<Checkbox value="A">Primary</Checkbox>
|
<Checkbox value="A">Primary</Checkbox>
|
||||||
|
Loading…
Reference in New Issue
Block a user