import { Script } from "@App/app/repo/scripts"; import { Value } from "@App/app/repo/value"; import { valueType } from "@App/pkg/utils/utils"; import { Button, Drawer, Form, Input, Message, Modal, Popconfirm, Select, Space, Table } from "@arco-design/web-react"; import { RefInputType } from "@arco-design/web-react/es/Input/interface"; import { ColumnProps } from "@arco-design/web-react/es/Table"; import { IconDelete, IconEdit, IconSearch } from "@arco-design/web-react/icon"; import React, { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; const FormItem = Form.Item; const ScriptStorage: React.FC<{ // eslint-disable-next-line react/require-default-props script?: Script; visible: boolean; onOk: () => void; onCancel: () => void; }> = ({ script, visible, onCancel, onOk }) => { const [data, setData] = useState([]); const inputRef = useRef(null); const [currentValue, setCurrentValue] = useState(); const [visibleEdit, setVisibleEdit] = useState(false); const [form] = Form.useForm(); const { t } = useTranslation(); useEffect(() => { if (!script) { return () => {}; } // valueCtrl.getValues(script).then((values) => { // setData(values); // }); // Monitor value changes // const channel = valueCtrl.watchValue(script); // channel.setHandler((value: Value) => { // setData((prev) => { // const index = prev.findIndex((item) => item.key === value.key); // if (index === -1) { // if (value.value === undefined) { // return prev; // } // return [value, ...prev]; // } // if (value.value === undefined) { // prev.splice(index, 1); // return [...prev]; // } // prev[index] = value; // return [...prev]; // }); // }); return () => { // channel.disChannel(); }; }, [script]); const columns: ColumnProps[] = [ { title: t("key"), dataIndex: "key", key: "key", filterIcon: , width: 140, // eslint-disable-next-line react/no-unstable-nested-components filterDropdown: ({ filterKeys, setFilterKeys, confirm }: any) => { return (
{ setFilterKeys(value ? [value] : []); }} onSearch={() => { confirm(); }} />
); }, onFilter: (value, row) => (value ? row.key.indexOf(value) !== -1 : true), onFilterDropdownVisibleChange: (v) => { if (v) { setTimeout(() => inputRef.current!.focus(), 150); } }, }, { title: t("value"), dataIndex: "value", key: "value", className: "max-table-cell", render(col) { switch (typeof col) { case "string": return col; default: return ( {JSON.stringify(col, null, 2)} ); } }, }, { title: t("type"), dataIndex: "value", width: 90, key: "type", render(col) { return valueType(col); }, }, { title: t("action"), render(_col, value: Value, index) { return ( ); }; export default ScriptStorage;