import React, { useContext, useState } from "react"; import { AutoComplete, Collapse, Empty, Row, Col, Select, Button, Checkbox, Popover, Table, } from "@douyinfe/semi-ui"; import { IconDeleteStroked, IconLoopTextStroked, IconMore, IconSearch, } from "@douyinfe/semi-icons"; import { IllustrationNoContent, IllustrationNoContentDark, } from "@douyinfe/semi-illustrations"; import { Cardinality, Constraint, Action, ObjectType } from "../data/data"; import { TableContext, UndoRedoContext } from "../pages/Editor"; export default function ReferenceOverview(props) { const columns = [ { title: "Primary", dataIndex: "primary", }, { title: "Foreign", dataIndex: "foreign", }, ]; const { tables, relationships, setRelationships, deleteRelationship } = useContext(TableContext); const { setUndoStack, setRedoStack } = useContext(UndoRedoContext); 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}`}>
Primary: {tables[r.endTableId].name}
Foreign: {tables[r.startTableId].name}
} trigger="click" position="rightTop" showArrow >
Cardinality
On update:
On delete:
Mandetory
{ setUndoStack((prev) => [ ...prev, { action: Action.EDIT, element: ObjectType.RELATIONSHIP, rid: i, undo: { [checkedValues.target.value]: !checkedValues.target.checked, }, redo: { [checkedValues.target.value]: checkedValues.target.checked, }, message: `Make foreign key mandetory`, }, ]); setRedoStack([]); setRelationships((prev) => prev.map((e, idx) => idx === i ? { ...e, [checkedValues.target.value]: checkedValues.target.checked, } : e ) ); }} >
)) )} ); }