import React, { useContext, 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"; import { TableContext } from "../pages/editor"; export default function ReferenceOverview(props) { const columns = [ { title: "Primary", dataIndex: "primary", }, { title: "Foreign", dataIndex: "foreign", }, ]; const { tables, relationships, setRelationships } = useContext(TableContext); const [refActiveIndex, setRefActiveIndex] = useState(""); const [value, setValue] = useState(""); const [filteredResult, setFilteredResult] = useState( relationships.map((t) => { return t.name; }) ); const handleStringSearch = (value) => { setFilteredResult( 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 } = relationships.find((t) => t.name === v); setRefActiveIndex(`${id}`); document .getElementById(`scroll_ref_${id}`) .scrollIntoView({ behavior: "smooth" }); }} className="w-full" /> setRefActiveIndex(k)} accordion > {relationships.length <= 0 ? (
} darkModeImage={ } title="No relationships" description="Drag to connect fields and form relationships!" />
) : ( relationships.map((r, i) => (
{r.name}
} itemKey={`${i}`}>
setRelationships((prev) => prev.map((e, idx) => idx === i ? { ...e, ...value.values } : e ) ) } >
Primary: {tables[r.endTableId].name}
Foreign: {tables[r.startTableId].name}
} trigger="click" position="rightTop" showArrow > ({ 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" >
setRelationships((prev) => prev.map((e, idx) => idx === i ? { ...e, [checkedValues.target.value]: checkedValues.target.checked, } : e ) ) } >
)) )} ); }