2023-09-19 20:47:59 +08:00
|
|
|
import React from "react";
|
2023-09-19 20:48:01 +08:00
|
|
|
import {
|
|
|
|
Collapse,
|
|
|
|
Input,
|
|
|
|
Form,
|
|
|
|
Row,
|
|
|
|
Col,
|
|
|
|
Button,
|
|
|
|
Checkbox,
|
2023-09-19 20:48:03 +08:00
|
|
|
Popover,
|
|
|
|
Table,
|
2023-09-19 20:48:01 +08:00
|
|
|
} from "@douyinfe/semi-ui";
|
2023-09-19 20:48:02 +08:00
|
|
|
import {
|
|
|
|
IconRowsStroked,
|
|
|
|
IconDeleteStroked,
|
|
|
|
IconLoopTextStroked,
|
2023-09-19 20:48:03 +08:00
|
|
|
IconMore,
|
2023-09-19 20:48:02 +08:00
|
|
|
} from "@douyinfe/semi-icons";
|
2023-09-19 20:48:01 +08:00
|
|
|
import { Cardinality, Constraint } from "../data/data";
|
|
|
|
|
2023-09-19 20:47:59 +08:00
|
|
|
export default function ReferenceOverview(props) {
|
2023-09-19 20:48:03 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: "Primary",
|
|
|
|
dataIndex: "primary",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Foreign",
|
|
|
|
dataIndex: "foreign",
|
|
|
|
},
|
|
|
|
];
|
2023-09-19 20:47:59 +08:00
|
|
|
return (
|
|
|
|
<Collapse>
|
|
|
|
{props.relationships.map((r, i) => (
|
|
|
|
<Collapse.Panel
|
|
|
|
key={i}
|
|
|
|
header={
|
|
|
|
<div>
|
|
|
|
<Input defaultValue={r.name} borderless />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
itemKey={`${i}`}
|
|
|
|
>
|
2023-09-19 20:48:01 +08:00
|
|
|
<Form>
|
2023-09-19 20:48:02 +08:00
|
|
|
<div className="flex justify-between items-center my-1">
|
2023-09-19 20:48:03 +08:00
|
|
|
<div className="me-3">
|
2023-09-19 20:48:02 +08:00
|
|
|
<strong>Primary: </strong>
|
2023-09-19 20:48:03 +08:00
|
|
|
{props.tables[r.endTableId].name}
|
2023-09-19 20:48:02 +08:00
|
|
|
</div>
|
|
|
|
<div className="mx-1">
|
|
|
|
<strong>Foreign: </strong>
|
2023-09-19 20:48:03 +08:00
|
|
|
{props.tables[r.startTableId].name}
|
2023-09-19 20:48:02 +08:00
|
|
|
</div>
|
|
|
|
<div className="ms-1">
|
2023-09-19 20:48:03 +08:00
|
|
|
<Popover
|
|
|
|
content={
|
|
|
|
<div className="p-2 w-[260px]">
|
|
|
|
<Table
|
|
|
|
columns={columns}
|
|
|
|
dataSource={[
|
|
|
|
{
|
|
|
|
key: "1",
|
|
|
|
foreign: props.tables[r.startTableId].name,
|
|
|
|
primary: props.tables[r.endTableId].name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "2",
|
|
|
|
foreign:
|
|
|
|
props.tables[r.startTableId].fields[
|
|
|
|
r.startFieldId
|
|
|
|
].name,
|
|
|
|
primary:
|
|
|
|
props.tables[r.endTableId].fields[r.endFieldId]
|
|
|
|
.name,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
pagination={false}
|
|
|
|
bordered
|
|
|
|
/>
|
|
|
|
<div className="mt-2">
|
|
|
|
<Button icon={<IconLoopTextStroked />} block>
|
|
|
|
Swap
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
trigger="click"
|
|
|
|
position="rightTop"
|
|
|
|
showArrow
|
|
|
|
>
|
|
|
|
<Button icon={<IconMore />} type="tertiary"></Button>
|
|
|
|
</Popover>
|
2023-09-19 20:48:02 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-09-19 20:48:03 +08:00
|
|
|
<Form.Input initValue={r.name} field="name" label="Name" />
|
2023-09-19 20:48:01 +08:00
|
|
|
<Form.Select
|
|
|
|
optionList={Object.values(Cardinality).map((v) => ({
|
|
|
|
label: v,
|
|
|
|
value: v,
|
|
|
|
}))}
|
|
|
|
field="cardinality"
|
|
|
|
label="Cardinality"
|
|
|
|
initValue={r.cardinality}
|
|
|
|
className="w-full"
|
|
|
|
></Form.Select>
|
|
|
|
<Row gutter={6}>
|
|
|
|
<Col span={12}>
|
|
|
|
<Form.Select
|
|
|
|
optionList={Object.values(Constraint).map((v) => ({
|
|
|
|
label: v,
|
|
|
|
value: v,
|
|
|
|
}))}
|
|
|
|
field="updateConstraint"
|
|
|
|
label="On update"
|
|
|
|
initValue={r.updateConstraint}
|
|
|
|
className="w-full"
|
|
|
|
></Form.Select>
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
|
|
|
<Form.Select
|
|
|
|
optionList={Object.values(Constraint).map((v) => ({
|
|
|
|
label: v,
|
|
|
|
value: v,
|
|
|
|
}))}
|
|
|
|
field="deleteConstraint"
|
|
|
|
label="On delete"
|
|
|
|
initValue={r.deleteConstraint}
|
|
|
|
className="w-full"
|
|
|
|
></Form.Select>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2023-09-19 20:48:03 +08:00
|
|
|
<div className="flex justify-between items-center my-3">
|
2023-09-19 20:48:01 +08:00
|
|
|
<label htmlFor="unique" className="font-medium text-black">
|
|
|
|
Mandetory
|
|
|
|
</label>
|
|
|
|
<Checkbox
|
|
|
|
value="mandetory"
|
|
|
|
defaultChecked={r.mandetory}
|
|
|
|
onChange={(checkedValues) => {}}
|
|
|
|
></Checkbox>
|
|
|
|
</div>
|
|
|
|
<Row gutter={6} className="mt-1">
|
|
|
|
<Col span={12}>
|
|
|
|
<Button
|
|
|
|
icon={<IconRowsStroked />}
|
|
|
|
disabled={r.Cardinality === Cardinality.ONE_TO_ONE}
|
|
|
|
block
|
|
|
|
>
|
|
|
|
Extract to table
|
|
|
|
</Button>
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
|
|
|
<Button icon={<IconDeleteStroked />} block type="danger">
|
|
|
|
Delete
|
|
|
|
</Button>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Form>
|
2023-09-19 20:47:59 +08:00
|
|
|
</Collapse.Panel>
|
|
|
|
))}
|
|
|
|
</Collapse>
|
|
|
|
);
|
|
|
|
}
|