import { Action, ObjectType } from "../../../data/constants"; import { Input, Button, Popover, Checkbox, Select } from "@douyinfe/semi-ui"; import { IconMore, IconDeleteStroked } from "@douyinfe/semi-icons"; import { useDiagram, useUndoRedo } from "../../../hooks"; import { useTranslation } from "react-i18next"; import { useMemo, useState } from "react"; export default function IndexDetails({ data, fields, iid, tid }) { const { t } = useTranslation(); const { tables, updateTable } = useDiagram(); const { setUndoStack, setRedoStack } = useUndoRedo(); const [editField, setEditField] = useState({}); const table = useMemo(() => tables.find((t) => t.id === tid), [tables, tid]); return (
setEditField({ name: data.name, }) } onChange={(value) => updateTable(tid, { indices: table.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: table.name, extra: "[index]", }), }, ]); setRedoStack([]); }} />
{t("unique")}
{ 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: table.name, extra: "[index field]", }), }, ]); setRedoStack([]); updateTable(tid, { indices: table.indices.map((index) => index.id === iid ? { ...index, [checkedValues.target.value]: checkedValues.target.checked, } : index, ), }); }} >
} trigger="click" position="rightTop" showArrow >