Add search for relationships

This commit is contained in:
1ilit 2023-09-19 15:48:32 +03:00
parent 4fec674ac6
commit 525ca9f5c7
5 changed files with 316 additions and 268 deletions

View File

@ -319,7 +319,7 @@ export default function ControlPanel() {
</Dropdown.Menu> </Dropdown.Menu>
} }
> >
<div className="px-3 py-1 hover:bg-gray-100 rounded-md"> <div className="px-3 py-1 hover:bg-gray-100 rounded">
{category} {category}
</div> </div>
</Dropdown> </Dropdown>
@ -363,7 +363,7 @@ export default function ControlPanel() {
</div> </div>
</nav> </nav>
)} )}
<div className="p-2 px-5 flex justify-between items-center rounded-xl bg-slate-100 my-1 mx-6 text-slate-700"> <div className="p-2 px-5 flex justify-between items-center rounded-xl bg-slate-100 my-1 mx-6 text-slate-700 select-none">
<div className="flex justify-start items-center"> <div className="flex justify-start items-center">
<Dropdown <Dropdown
position="bottomLeft" position="bottomLeft"
@ -396,7 +396,7 @@ export default function ControlPanel() {
} }
trigger="click" trigger="click"
> >
<div className="py-1 px-2 hover:bg-slate-200 rounded-md"> <div className="py-1 px-2 hover:bg-slate-200 rounded">
<i className="fa-solid fa-table-list"></i> <IconCaretdown /> <i className="fa-solid fa-table-list"></i> <IconCaretdown />
</div> </div>
</Dropdown> </Dropdown>
@ -435,33 +435,27 @@ export default function ControlPanel() {
} }
trigger="click" trigger="click"
> >
<div className="py-1 px-2 hover:bg-slate-200 rounded-md"> <div className="py-1 px-2 hover:bg-slate-200 rounded">
zoom <IconCaretdown /> zoom <IconCaretdown />
</div> </div>
</Dropdown> </Dropdown>
<button <button
className="py-1 px-2 hover:bg-slate-200 rounded-md" className="py-1 px-2 hover:bg-slate-200 rounded"
title="Zoom in" title="Zoom in"
> >
<i className="fa-solid fa-magnifying-glass-plus"></i> <i className="fa-solid fa-magnifying-glass-plus"></i>
</button> </button>
<button <button
className="py-1 px-2 hover:bg-slate-200 rounded-md" className="py-1 px-2 hover:bg-slate-200 rounded"
title="Zoom out" title="Zoom out"
> >
<i className="fa-solid fa-magnifying-glass-minus"></i> <i className="fa-solid fa-magnifying-glass-minus"></i>
</button> </button>
<Divider layout="vertical" margin="8px" /> <Divider layout="vertical" margin="8px" />
<button <button className="py-1 px-2 hover:bg-slate-200 rounded" title="Undo">
className="py-1 px-2 hover:bg-slate-200 rounded-md"
title="Undo"
>
<i className="fa-solid fa-rotate-left "></i> <i className="fa-solid fa-rotate-left "></i>
</button> </button>
<button <button className="py-1 px-2 hover:bg-slate-200 rounded" title="Redo">
className="py-1 px-2 hover:bg-slate-200 rounded-md"
title="Redo"
>
<i className="fa-solid fa-rotate-right"></i> <i className="fa-solid fa-rotate-right"></i>
</button> </button>
<Divider layout="vertical" margin="8px" /> <Divider layout="vertical" margin="8px" />
@ -478,31 +472,25 @@ export default function ControlPanel() {
} }
trigger="click" trigger="click"
> >
<div className="py-1 px-2 hover:bg-slate-200 rounded-md"> <div className="py-1 px-2 hover:bg-slate-200 rounded">
<i className="fa-solid fa-plus"></i> <IconCaretdown /> <i className="fa-solid fa-plus"></i> <IconCaretdown />
</div> </div>
</Dropdown> </Dropdown>
<button <button className="py-1 px-2 hover:bg-slate-200 rounded" title="Edit">
className="py-1 px-2 hover:bg-slate-200 rounded-md"
title="Edit"
>
<i className="fa-solid fa-pen-to-square"></i> <i className="fa-solid fa-pen-to-square"></i>
</button> </button>
<button <button
className="py-1 px-2 hover:bg-slate-200 rounded-md" className="py-1 px-2 hover:bg-slate-200 rounded"
title="Delete" title="Delete"
> >
<i className="fa-solid fa-trash"></i> <i className="fa-solid fa-trash"></i>
</button> </button>
<Divider layout="vertical" margin="8px" /> <Divider layout="vertical" margin="8px" />
<button <button className="py-1 px-2 hover:bg-slate-200 rounded" title="Save">
className="py-1 px-2 hover:bg-slate-200 rounded-md"
title="Save"
>
<i className="fa-regular fa-floppy-disk"></i> <i className="fa-regular fa-floppy-disk"></i>
</button> </button>
<button <button
className="py-1 px-2 hover:bg-slate-200 rounded-md" className="py-1 px-2 hover:bg-slate-200 rounded"
title="Commit" title="Commit"
> >
<i className="fa-solid fa-code-branch"></i> <i className="fa-solid fa-code-branch"></i>

View File

@ -30,25 +30,18 @@ const EditorPanel = (props) => {
const tabList = [ const tabList = [
{ tab: "Tables", itemKey: "1" }, { tab: "Tables", itemKey: "1" },
{ tab: "References", itemKey: "2" }, { tab: "Relationships", itemKey: "2" },
{ tab: "Shapes", itemKey: "3" }, { tab: "Shapes", itemKey: "3" },
{ tab: "Editor", itemKey: "4" }, { tab: "Editor", itemKey: "4" },
]; ];
const contentList = [ const contentList = [
<div> <TableOverview tables={props.tables} setTables={props.setTables} />,
<TableOverview tables={props.tables} setTables={props.setTables} />
</div>,
<div>
<ReferenceOverview <ReferenceOverview
relationships={props.relationships} relationships={props.relationships}
setRelationships={props.setRelationships} setRelationships={props.setRelationships}
tables={props.tables} tables={props.tables}
/> />,
</div>, <Shape />,
<div>
<Shape />
</div>,
<div>
<CodeMirror <CodeMirror
value={props.code} value={props.code}
height="100%" height="100%"
@ -57,13 +50,12 @@ const EditorPanel = (props) => {
onChange={(e) => { onChange={(e) => {
props.setCode(e); props.setCode(e);
}} }}
/> />,
</div>,
]; ];
return ( return (
<div className="h-screen flex overflow-clip relative"> <div className="h-screen flex overflow-clip relative">
<div className="mt-2" style={{ width: `${props.width}px` }}> <div style={{ width: `${props.width}px` }}>
<Tabs <Tabs
type="card" type="card"
tabList={tabList} tabList={tabList}
@ -72,7 +64,7 @@ const EditorPanel = (props) => {
}} }}
collapsible collapsible
> >
{contentList[parseInt(tab) - 1]} <div className="p-2">{contentList[parseInt(tab) - 1]}</div>
</Tabs> </Tabs>
<button <button
onClick={() => { onClick={() => {
@ -151,7 +143,9 @@ const EditorPanel = (props) => {
</button> </button>
</div> </div>
<div <div
className={`flex justify-center items-center p-1 h-full hover:bg-slate-300 cursor-col-resize ${props.resize? "bg-slate-300": ""}`} className={`flex justify-center items-center p-1 h-full hover:bg-slate-300 cursor-col-resize ${
props.resize ? "bg-slate-300" : ""
}`}
onMouseDown={() => props.setResize(true)} onMouseDown={() => props.setResize(true)}
> >
<div className="w-1 border-x border-white h-1/6" /> <div className="w-1 border-x border-white h-1/6" />

View File

@ -1,6 +1,8 @@
import React from "react"; import React, { useState } from "react";
import { import {
AutoComplete,
Collapse, Collapse,
Empty,
Form, Form,
Row, Row,
Col, Col,
@ -14,7 +16,12 @@ import {
IconDeleteStroked, IconDeleteStroked,
IconLoopTextStroked, IconLoopTextStroked,
IconMore, IconMore,
IconSearch,
} from "@douyinfe/semi-icons"; } from "@douyinfe/semi-icons";
import {
IllustrationNoContent,
IllustrationNoContentDark,
} from "@douyinfe/semi-illustrations";
import { Cardinality, Constraint } from "../data/data"; import { Cardinality, Constraint } from "../data/data";
export default function ReferenceOverview(props) { export default function ReferenceOverview(props) {
@ -28,10 +35,67 @@ export default function ReferenceOverview(props) {
dataIndex: "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 ( return (
<Collapse> <>
{props.relationships.map((r, i) => ( <AutoComplete
<Collapse.Panel key={i} header={<div>{r.name}</div>} itemKey={`${i}`}> data={filteredResult}
value={value}
showClear
prefix={<IconSearch />}
placeholder="Search..."
emptyContent={<div className="p-3">No relationships found</div>}
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"
/>
<Collapse
activeKey={refActiveIndex}
onChange={(k) => setRefActiveIndex(k)}
accordion
>
{props.relationships.length <= 0 ? (
<div className="select-none">
<Empty
image={
<IllustrationNoContent style={{ width: 160, height: 160 }} />
}
darkModeImage={
<IllustrationNoContentDark
style={{ width: 160, height: 160 }}
/>
}
title="No relationships"
description="Drag to connect fields and form relationships!"
/>
</div>
) : (
props.relationships.map((r, i) => (
<div id={`scroll_ref_${r.id}`} key={i}>
<Collapse.Panel header={<div>{r.name}</div>} itemKey={`${i}`}>
<Form <Form
onChange={(value) => onChange={(value) =>
props.setRelationships((prev) => props.setRelationships((prev) =>
@ -69,8 +133,9 @@ export default function ReferenceOverview(props) {
r.startFieldId r.startFieldId
].name, ].name,
primary: primary:
props.tables[r.endTableId].fields[r.endFieldId] props.tables[r.endTableId].fields[
.name, r.endFieldId
].name,
}, },
]} ]}
pagination={false} pagination={false}
@ -179,7 +244,10 @@ export default function ReferenceOverview(props) {
</Col> </Col>
</Row> </Row>
</Collapse.Panel> </Collapse.Panel>
))} </div>
))
)}
</Collapse> </Collapse>
</>
); );
} }

View File

@ -80,7 +80,6 @@ export default function TableOverview(props) {
return ( return (
<> <>
<div className="p-2">
<Row gutter={6}> <Row gutter={6}>
<Col span={16}> <Col span={16}>
<AutoComplete <AutoComplete
@ -93,10 +92,10 @@ export default function TableOverview(props) {
onSearch={(v) => handleStringSearch(v)} onSearch={(v) => handleStringSearch(v)}
onChange={(v) => setValue(v)} onChange={(v) => setValue(v)}
onSelect={(v) => { onSelect={(v) => {
const { id, name } = props.tables.find((t) => t.name === v); const { id } = props.tables.find((t) => t.name === v);
setTableActiveKey(`${id}`); setTableActiveKey(`${id}`);
document document
.getElementById(`${name}_scroll_id`) .getElementById(`scroll_table_${id}`)
.scrollIntoView({ behavior: "smooth" }); .scrollIntoView({ behavior: "smooth" });
}} }}
className="w-full" className="w-full"
@ -140,7 +139,6 @@ export default function TableOverview(props) {
</Button> </Button>
</Col> </Col>
</Row> </Row>
</div>
<Collapse <Collapse
activeKey={tableActiveKey} activeKey={tableActiveKey}
onChange={(k) => setTableActiveKey(k)} onChange={(k) => setTableActiveKey(k)}
@ -163,7 +161,7 @@ export default function TableOverview(props) {
</div> </div>
) : ( ) : (
props.tables.map((t, i) => ( props.tables.map((t, i) => (
<div id={`${t.name}_scroll_id`} key={t.id}> <div id={`scroll_table_${t.id}`} key={t.id}>
<Collapse.Panel header={<div>{t.name}</div>} itemKey={`${t.id}`}> <Collapse.Panel header={<div>{t.name}</div>} itemKey={`${t.id}`}>
{t.fields.map((f, j) => ( {t.fields.map((f, j) => (
<Form <Form

View File

@ -12,12 +12,12 @@ export default function Editor(props) {
const [relationships, setRelationships] = useState([]); const [relationships, setRelationships] = useState([]);
const [areas, setAreas] = useState([]); const [areas, setAreas] = useState([]);
const [resize, setResize] = useState(false); const [resize, setResize] = useState(false);
const [width, setWidth] = useState(320); const [width, setWidth] = useState(340);
const dragHandler = (e) => { const dragHandler = (e) => {
if (!resize) return; if (!resize) return;
const w = e.clientX; const w = e.clientX;
if (w > 320) setWidth(w); if (w > 340) setWidth(w);
}; };
return ( return (