value设置
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
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";
|
||||
@ -10,16 +11,20 @@ import { useTranslation } from "react-i18next";
|
||||
|
||||
const FormItem = Form.Item;
|
||||
|
||||
interface ValueModel {
|
||||
key: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
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<Value[]>([]);
|
||||
const [data, setData] = useState<ValueModel[]>([]);
|
||||
const inputRef = useRef<RefInputType>(null);
|
||||
const [currentValue, setCurrentValue] = useState<Value>();
|
||||
const [currentValue, setCurrentValue] = useState<ValueModel>();
|
||||
const [visibleEdit, setVisibleEdit] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const { t } = useTranslation();
|
||||
@ -28,31 +33,13 @@ const ScriptStorage: React.FC<{
|
||||
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();
|
||||
};
|
||||
valueClient.getScriptValue(script).then((value) => {
|
||||
setData(
|
||||
Object.keys(value).map((key) => {
|
||||
return { key: key, value: value[key] };
|
||||
})
|
||||
);
|
||||
});
|
||||
}, [script]);
|
||||
const columns: ColumnProps[] = [
|
||||
{
|
||||
@ -61,7 +48,6 @@ const ScriptStorage: React.FC<{
|
||||
key: "key",
|
||||
filterIcon: <IconSearch />,
|
||||
width: 140,
|
||||
// eslint-disable-next-line react/no-unstable-nested-components
|
||||
filterDropdown: ({ filterKeys, setFilterKeys, confirm }: any) => {
|
||||
return (
|
||||
<div className="arco-table-custom-filter">
|
||||
@ -120,7 +106,7 @@ const ScriptStorage: React.FC<{
|
||||
},
|
||||
{
|
||||
title: t("action"),
|
||||
render(_col, value: Value, index) {
|
||||
render(_col, value: { key: string; value: string }, index) {
|
||||
return (
|
||||
<Space>
|
||||
<Button
|
||||
@ -136,7 +122,7 @@ const ScriptStorage: React.FC<{
|
||||
iconOnly
|
||||
icon={<IconDelete />}
|
||||
onClick={() => {
|
||||
valueCtrl.setValue(script!.id, value.key, undefined);
|
||||
valueClient.setScriptValue(script!.uuid, value.key, undefined);
|
||||
Message.info({
|
||||
content: t("delete_success"),
|
||||
});
|
||||
@ -179,7 +165,7 @@ const ScriptStorage: React.FC<{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
valueCtrl.setValue(script!.id, value.key, value.value);
|
||||
valueClient.setScriptValue(script!.uuid, value.key, value.value);
|
||||
if (currentValue) {
|
||||
Message.info({
|
||||
content: t("update_success"),
|
||||
@ -201,13 +187,8 @@ const ScriptStorage: React.FC<{
|
||||
});
|
||||
setData([
|
||||
{
|
||||
id: 0,
|
||||
scriptId: script!.id,
|
||||
storageName: (script?.metadata.storagename && script?.metadata.storagename[0]) || "",
|
||||
key: value.key,
|
||||
value: value.value,
|
||||
createtime: Date.now(),
|
||||
updatetime: 0,
|
||||
},
|
||||
...data,
|
||||
]);
|
||||
@ -254,7 +235,7 @@ const ScriptStorage: React.FC<{
|
||||
onOk={() => {
|
||||
setData((prev) => {
|
||||
prev.forEach((v) => {
|
||||
valueCtrl.setValue(script!.id, v.key, undefined);
|
||||
valueClient.setScriptValue(script!.uuid, v.key, undefined);
|
||||
});
|
||||
Message.info({
|
||||
content: t("clear_success"),
|
||||
|
Reference in New Issue
Block a user