From 298ef0d38e7dc9950f8f1110ca345a33841f2c23 Mon Sep 17 00:00:00 2001 From: jsers Date: Wed, 12 Oct 2022 20:21:17 +0800 Subject: [PATCH] refactor: flexible batch modify callbacks --- src/pages/warning/strategy/PageTable.tsx | 3 + .../warning/strategy/components/editModal.tsx | 90 ++++++++++++++----- src/services/warning.ts | 1 + 3 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/pages/warning/strategy/PageTable.tsx b/src/pages/warning/strategy/PageTable.tsx index 699138b3..761b7029 100644 --- a/src/pages/warning/strategy/PageTable.tsx +++ b/src/pages/warning/strategy/PageTable.tsx @@ -349,10 +349,13 @@ const PageTable: React.FC = ({ bgid }) => { const editModalFinish = async (isOk, fieldsData?) => { if (isOk) { + const action = fieldsData.action; + delete fieldsData.action; const res = await updateAlertRules( { ids: selectRowKeys, fields: fieldsData, + action, }, curBusiItem.id, ); diff --git a/src/pages/warning/strategy/components/editModal.tsx b/src/pages/warning/strategy/components/editModal.tsx index 72098276..aec76777 100644 --- a/src/pages/warning/strategy/components/editModal.tsx +++ b/src/pages/warning/strategy/components/editModal.tsx @@ -246,7 +246,12 @@ const editModal: React.FC = ({ isModalVisible, editModalFinish }) => { data.enable_in_bg = values.enable_in_bg ? 1 : 0; break; case 'callbacks': - data.callbacks = values.callbacks.map((item) => item.url); + if (data.action === 'cover') { + delete data.action; + data.callbacks = values.callbacks.map((item) => item.url); + } else { + data.callbacks = values.callbacks; + } break; case 'cluster': data.cluster = values.cluster.join(' '); @@ -606,27 +611,70 @@ const editModal: React.FC = ({ isModalVisible, editModalFinish }) => { case 'callbacks': return ( <> - - - {(fields, { add, remove }, { errors }) => ( - <> - {fields.map((field, index) => ( - - - - - - + + { + if (e.target.value === 'cover') { + form.setFieldsValue({ + callbacks: [ + { + url: '', + }, + ], + }); + } else { + form.setFieldsValue({ callbacks: '' }); + } + }} + > + 覆盖 + 新增 + 删除 + + + + {({ getFieldValue }) => { + const action = getFieldValue('action'); + if (action === 'cover') { + return ( + + + {(fields, { add, remove }, { errors }) => ( + <> + {fields.map((field, index) => ( + + + + + + - - remove(field.name)} /> - - - ))} - add()} /> - - )} - + + remove(field.name)} /> + + + ))} + add()} /> + + )} + + + ); + } else if (action === 'callback_add') { + return ( + + + + ); + } else if (action === 'callback_del') { + return ( + + + + ); + } + }} ); diff --git a/src/services/warning.ts b/src/services/warning.ts index 1a3cf718..91edd41d 100644 --- a/src/services/warning.ts +++ b/src/services/warning.ts @@ -187,6 +187,7 @@ export const updateAlertRules = function ( data: { ids: React.Key[]; fields: any; + action?: string; }, busiId: number, ) {