Skip to content

add names to indices list and improve layout for better display #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
334 changes: 163 additions & 171 deletions src/components/EditorSidePanel/TablesTab/IndexDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Action, ObjectType } from "../../../data/constants";
import { Input, Button, Popover, Checkbox, Select } from "@douyinfe/semi-ui";
import { IconMore, IconDeleteStroked } from "@douyinfe/semi-icons";
import { Input, Button, Checkbox, Select, Row, Col } from "@douyinfe/semi-ui";
import { IconDeleteStroked } from "@douyinfe/semi-icons";
import { useDiagram, useUndoRedo } from "../../../hooks";
import { useTranslation } from "react-i18next";
import { useState } from "react";
Expand All @@ -12,181 +12,173 @@ export default function IndexDetails({ data, fields, iid, tid }) {
const [editField, setEditField] = useState({});

return (
<div className="flex justify-between items-center mb-2">
<Select
placeholder={t("select_fields")}
multiple
validateStatus={data.fields.length === 0 ? "error" : "default"}
optionList={fields}
className="w-full"
value={data.fields}
onChange={(value) => {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index",
tid: tid,
iid: iid,
undo: {
fields: [...data.fields],
},
redo: {
fields: [...value],
},
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[index field]",
}),
},
]);
setRedoStack([]);
updateTable(tid, {
indices: tables[tid].indices.map((index) =>
index.id === iid
? {
...index,
fields: [...value],
}
: index,
),
});
}}
/>
<Popover
content={
<div className="px-1 popover-theme">
<div className="font-semibold mb-1">{t("name")}: </div>
<Input
value={data.name}
placeholder={t("name")}
validateStatus={data.name.trim() === "" ? "error" : "default"}
onFocus={() =>
setEditField({
name: data.name,
})
}
onChange={(value) =>
updateTable(tid, {
indices: tables[tid].indices.map((index) =>
index.id === iid
? {
...index,
name: value,
}
: index,
),
})
}
onBlur={(e) => {
if (e.target.value === editField.name) return;
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index",
tid: tid,
iid: iid,
undo: editField,
redo: { name: e.target.value },
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[index]",
}),
},
]);
setRedoStack([]);
}}
/>
<div className="flex justify-between items-center my-3">
<div className="font-medium">{t("unique")}</div>
<Checkbox
value="unique"
checked={data.unique}
onChange={(checkedValues) => {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index",
tid: tid,
iid: iid,
undo: {
[checkedValues.target.value]:
!checkedValues.target.checked,
},
redo: {
[checkedValues.target.value]:
checkedValues.target.checked,
},
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[index field]",
}),
},
]);
setRedoStack([]);
updateTable(tid, {
<div className="hover-1">
<Row gutter={6} className="my-2 flex items-center">
<Col span={16}>
<Input
value={data.name}
placeholder={t("name")}
validateStatus={data.name.trim() === "" ? "error" : "default"}
onFocus={() =>
setEditField({
name: data.name,
})
}
onChange={(value) =>
updateTable(tid, {
indices: tables[tid].indices.map((index) =>
index.id === iid
index.id === iid
? {
...index,
[checkedValues.target.value]:
checkedValues.target.checked,
}
name: value,
}
: index,
),
});
})
}
onBlur={(e) => {
if (e.target.value === editField.name) return;
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index",
tid: tid,
iid: iid,
undo: editField,
redo: { name: e.target.value },
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[index]",
}),
},
]);
setRedoStack([]);
}}
/>
</Col>
<Col span={7} className="flex justify-between items-center ml-1">
<div className="font-medium">{t("unique")}</div>
<Checkbox
value="unique"
checked={data.unique}
onChange={(checkedValues) => {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index",
tid: tid,
iid: iid,
undo: {
[checkedValues.target.value]:
!checkedValues.target.checked,
},
redo: {
[checkedValues.target.value]:
checkedValues.target.checked,
},
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[index field]",
}),
},
]);
setRedoStack([]);
updateTable(tid, {
indices: tables[tid].indices.map((index) =>
index.id === iid
? {
...index,
[checkedValues.target.value]:
checkedValues.target.checked,
}
: index,
),
});
}}
></Checkbox>
</Col>
</Row>
<Row gutter={6} className="my-2">
<Col span={20}>
<Select
placeholder={t("select_fields")}
multiple
validateStatus={data.fields.length === 0 ? "error" : "default"}
optionList={fields}
className="w-full"
value={data.fields}
onChange={(value) => {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index",
tid: tid,
iid: iid,
undo: {
fields: [...data.fields],
},
redo: {
fields: [...value],
},
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[index field]",
}),
},
]);
setRedoStack([]);
updateTable(tid, {
indices: tables[tid].indices.map((index) =>
index.id === iid
? {
...index,
fields: [...value],
}
: index,
),
});
}}
/>
</Col>
<Col span={3}>
<Button
icon={<IconDeleteStroked />}
type="danger"
onClick={() => {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index_delete",
tid: tid,
data: data,
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[delete index]",
}),
},
]);
setRedoStack([]);
updateTable(tid, {
indices: tables[tid].indices
.filter((e) => e.id !== iid)
.map((e, j) => ({
...e,
id: j,
})),
});
}}
></Checkbox>
</div>
<Button
icon={<IconDeleteStroked />}
type="danger"
block
onClick={() => {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.TABLE,
component: "index_delete",
tid: tid,
data: data,
message: t("edit_table", {
tableName: tables[tid].name,
extra: "[delete index]",
}),
},
]);
setRedoStack([]);
updateTable(tid, {
indices: tables[tid].indices
.filter((e) => e.id !== iid)
.map((e, j) => ({
...e,
id: j,
})),
});
}}
>
{t("delete")}
</Button>
</div>
}
trigger="click"
position="rightTop"
showArrow
>
<Button
icon={<IconMore />}
type="tertiary"
style={{ marginLeft: "12px" }}
/>
</Popover>
>
</Button>
</Col>
</Row>
</div>
);
}