import React, { useState } from "react";
import {
AutoComplete,
Collapse,
Empty,
Form,
Row,
Col,
Button,
Checkbox,
Popover,
Table,
} from "@douyinfe/semi-ui";
import {
IconRowsStroked,
IconDeleteStroked,
IconLoopTextStroked,
IconMore,
IconSearch,
} from "@douyinfe/semi-icons";
import {
IllustrationNoContent,
IllustrationNoContentDark,
} from "@douyinfe/semi-illustrations";
import { Cardinality, Constraint } from "../data/data";
export default function ReferenceOverview(props) {
const columns = [
{
title: "Primary",
dataIndex: "primary",
},
{
title: "Foreign",
dataIndex: "foreign",
},
];
const [refActiveIndex, setRefActiveIndex] = useState("");
const [value, setValue] = useState("");
const [filteredResult, setFilteredResult] = useState(
props.relationships.map((t) => {
return t.name;
})
);
const handleStringSearch = (value) => {
setFilteredResult(
props.relationships
.map((t) => {
return t.name;
})
.filter((i) => i.includes(value))
);
};
return (
<>
}
placeholder="Search..."
emptyContent={
No relationships found
}
onSearch={(v) => handleStringSearch(v)}
onChange={(v) => setValue(v)}
onSelect={(v) => {
const { id } = props.relationships.find((t) => t.name === v);
setRefActiveIndex(`${id}`);
document
.getElementById(`scroll_ref_${id}`)
.scrollIntoView({ behavior: "smooth" });
}}
className="w-full"
/>
setRefActiveIndex(k)}
accordion
>
{props.relationships.length <= 0 ? (
}
darkModeImage={
}
title="No relationships"
description="Drag to connect fields and form relationships!"
/>
) : (
props.relationships.map((r, i) => (
{r.name}
} itemKey={`${i}`}>
({
label: v,
value: v,
}))}
field="cardinality"
label="Cardinality"
initValue={r.cardinality}
className="w-full"
>
({
label: v,
value: v,
}))}
field="updateConstraint"
label="On update"
initValue={r.updateConstraint}
className="w-full"
>
({
label: v,
value: v,
}))}
field="deleteConstraint"
label="On delete"
initValue={r.deleteConstraint}
className="w-full"
>
props.setRelationships((prev) =>
prev.map((e, idx) =>
idx === i
? {
...e,
[checkedValues.target.value]:
checkedValues.target.checked,
}
: e
)
)
}
>
}
disabled={r.cardinality === Cardinality.ONE_TO_ONE}
block
>
Extract to table
}
block
type="danger"
onClick={() =>
props.setRelationships((prev) =>
prev
.filter((e) => e.id !== i)
.map((e, idx) => ({ ...e, id: idx }))
)
}
>
Delete
))
)}
>
);
}