import { Script } from "@App/app/repo/scripts"; import { Value } from "@App/app/repo/value"; import { valueClient } from "@App/pages/store/features/script"; 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; interface ValueModel { key: string; value: any; } const ScriptStorage: React.FC<{ 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 () => {}; } valueClient.getScriptValue(script).then((value) => { setData( Object.keys(value).map((key) => { return { key: key, value: value[key] }; }) ); }); }, [script]); const columns: ColumnProps[] = [ { title: t("key"), dataIndex: "key", key: "key", filterIcon: , width: 140, 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: { key: string; value: string }, index) { return ( ); }; export default ScriptStorage;