This is an automated email from the ASF dual-hosted git repository. likeguo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shenyu-dashboard.git
The following commit(s) were added to refs/heads/master by this push: new 3c69e844 [Improve] Rule and MetaData module adaptation namespace (#478) 3c69e844 is described below commit 3c69e84457494ca42d94c0f513f8a5e6da487e89 Author: VampireAchao <ac...@apache.org> AuthorDate: Tue Sep 3 20:35:06 2024 +0800 [Improve] Rule and MetaData module adaptation namespace (#478) * [Improve] Rule module adaptation namespace * [Improve] Metadata module adapt namespace --- src/models/common.js | 10 ++++++---- src/models/metadata.js | 8 ++++---- src/routes/Plugin/Common/Rule.js | 5 ++++- src/routes/Plugin/Common/RuleCopy.js | 1 + src/routes/Plugin/Common/index.js | 28 ++++++++++++++++++++++------ src/routes/System/Metadata/index.js | 31 +++++++++++++++++++++++-------- src/services/api.js | 17 ++++++++++------- 7 files changed, 70 insertions(+), 30 deletions(-) diff --git a/src/models/common.js b/src/models/common.js index 466d350f..e4eafb8c 100644 --- a/src/models/common.js +++ b/src/models/common.js @@ -47,6 +47,7 @@ export default { effects: { *fetchSelector({ payload }, { call, put }) { + const { namespaceId } = payload; const json = yield call(getAllSelectors, { ...payload }); if (json.code === 200) { let { page, dataList } = json.data; @@ -75,6 +76,7 @@ export default { currentPage: 1, pageSize: 12, selectorId: dataList[0].id, + namespaceId, }, }); } else { @@ -188,8 +190,8 @@ export default { }, *deleteRule(params, { call, put }) { const { payload, fetchValue } = params; - const { list } = payload; - const json = yield call(deleteRule, { list }); + const { list, namespaceId } = payload; + const json = yield call(deleteRule, { list, namespaceId }); if (json.code === 200) { message.success( getIntlContent("SHENYU.COMMON.RESPONSE.DELETE.SUCCESS"), @@ -245,8 +247,8 @@ export default { *reloadRule(params, { put }) { const { fetchValue } = params; - const { selectorId, currentPage, pageSize } = fetchValue; - const payload = { selectorId, currentPage, pageSize }; + const { selectorId, currentPage, pageSize, namespaceId } = fetchValue; + const payload = { selectorId, currentPage, pageSize, namespaceId }; yield put({ type: "fetchRule", payload }); }, diff --git a/src/models/metadata.js b/src/models/metadata.js index 1cd36ba4..a47e2f0b 100644 --- a/src/models/metadata.js +++ b/src/models/metadata.js @@ -78,8 +78,8 @@ export default { }, *delete(params, { call, put }) { const { payload, fetchValue, callback } = params; - const { list } = payload; - const json = yield call(deleteMetadata, { list }); + const { list, namespaceId } = payload; + const json = yield call(deleteMetadata, { list, namespaceId }); if (json.code === 200) { message.success( getIntlContent("SHENYU.COMMON.RESPONSE.DELETE.SUCCESS"), @@ -128,8 +128,8 @@ export default { }, *reload(params, { put }) { const { fetchValue } = params; - const { appName, currentPage, pageSize } = fetchValue; - const payload = { appName, currentPage, pageSize }; + const { appName, currentPage, pageSize, namespaceId } = fetchValue; + const payload = { appName, currentPage, pageSize, namespaceId }; yield put({ type: "fetch", payload }); }, }, diff --git a/src/routes/Plugin/Common/Rule.js b/src/routes/Plugin/Common/Rule.js index f309800e..394ecdc7 100644 --- a/src/routes/Plugin/Common/Rule.js +++ b/src/routes/Plugin/Common/Rule.js @@ -45,9 +45,10 @@ import { const FormItem = Form.Item; const { Option } = Select; -@connect(({ pluginHandle, shenyuDict }) => ({ +@connect(({ pluginHandle, shenyuDict, global }) => ({ pluginHandle, shenyuDict, + currentNamespaceId: global.currentNamespaceId, })) class AddModal extends Component { constructor(props) { @@ -71,6 +72,7 @@ class AddModal extends Component { handle, multiRuleHandle, form: { setFieldsValue }, + currentNamespaceId, } = this.props; this.setState({ pluginHandleList: [] }); let type = 2; @@ -81,6 +83,7 @@ class AddModal extends Component { type, handle, isHandleArray: multiRuleHandle, + namespaceId: currentNamespaceId, callBack: (pluginHandles, useJSON) => { this.setState({ pluginHandleList: pluginHandles }, () => { if (useJSON) { diff --git a/src/routes/Plugin/Common/RuleCopy.js b/src/routes/Plugin/Common/RuleCopy.js index c18c2c0d..e5b1d1d2 100644 --- a/src/routes/Plugin/Common/RuleCopy.js +++ b/src/routes/Plugin/Common/RuleCopy.js @@ -61,6 +61,7 @@ class RuleCopy extends Component { } = await getAllRules({ currentPage: 1, pageSize: 9999, + namespaceId: currentNamespaceId, }); const pluginMap = {}; diff --git a/src/routes/Plugin/Common/index.js b/src/routes/Plugin/Common/index.js index 40799a96..56198ce7 100755 --- a/src/routes/Plugin/Common/index.js +++ b/src/routes/Plugin/Common/index.js @@ -140,7 +140,7 @@ export default class Common extends Component { }; getAllRules = (page, pageSize) => { - const { dispatch, currentSelector } = this.props; + const { dispatch, currentSelector, currentNamespaceId } = this.props; const { ruleName } = this.state; const selectorId = currentSelector ? currentSelector.id : ""; dispatch({ @@ -150,6 +150,7 @@ export default class Common extends Component { currentPage: page, pageSize, name: ruleName, + namespaceId: currentNamespaceId, }, }); this.setState({ selectorSelectedRowKeys: [] }); @@ -324,7 +325,8 @@ export default class Common extends Component { addRule = () => { const { rulePage, rulePageSize, pluginId } = this.state; - const { dispatch, currentSelector, plugins } = this.props; + const { dispatch, currentSelector, plugins, currentNamespaceId } = + this.props; let name = this.props.match.params ? this.props.match.params.id : ""; const plugin = this.getPlugin(plugins, name); const { config } = plugin; @@ -341,11 +343,16 @@ export default class Common extends Component { handleOk={(rule) => { dispatch({ type: "common/addRule", - payload: { selectorId, ...rule }, + payload: { + selectorId, + ...rule, + namespaceId: currentNamespaceId, + }, fetchValue: { selectorId, currentPage: rulePage, pageSize: rulePageSize, + namespaceId: currentNamespaceId, }, callback: () => { this.closeModal(); @@ -751,7 +758,8 @@ export default class Common extends Component { }; editRule = (record) => { - const { dispatch, currentSelector, plugins } = this.props; + const { dispatch, currentSelector, plugins, currentNamespaceId } = + this.props; const { rulePage, rulePageSize, pluginId } = this.state; let name = this.props.match.params ? this.props.match.params.id : ""; const plugin = this.getPlugin(plugins, name); @@ -764,6 +772,7 @@ export default class Common extends Component { type: "common/fetchRuleItem", payload: { id, + namespaceId: currentNamespaceId, }, callback: (rule) => { this.setState({ @@ -780,11 +789,13 @@ export default class Common extends Component { selectorId, ...values, id, + namespaceId: currentNamespaceId, }, fetchValue: { selectorId, currentPage: rulePage, pageSize: rulePageSize, + namespaceId: currentNamespaceId, }, callback: () => { this.closeModal(); @@ -801,18 +812,20 @@ export default class Common extends Component { enableRule = ({ list, enabled }) => { const { rulePage, rulePageSize } = this.state; - const { dispatch, currentSelector } = this.props; + const { dispatch, currentSelector, currentNamespaceId } = this.props; const selectorId = currentSelector ? currentSelector.id : ""; dispatch({ type: "common/enableRule", payload: { list, enabled, + namespaceId: currentNamespaceId, }, fetchValue: { selectorId, currentPage: rulePage, pageSize: rulePageSize, + namespaceId: currentNamespaceId, }, }); }; @@ -839,7 +852,8 @@ export default class Common extends Component { }; deleteRule = (record) => { - const { dispatch, currentSelector, ruleList } = this.props; + const { dispatch, currentSelector, ruleList, currentNamespaceId } = + this.props; const { rulePage, rulePageSize } = this.state; const currentPage = rulePage > 1 && ruleList.length === 1 ? rulePage - 1 : rulePage; @@ -847,11 +861,13 @@ export default class Common extends Component { type: "common/deleteRule", payload: { list: [record.id], + namespaceId: currentNamespaceId, }, fetchValue: { selectorId: currentSelector.id, currentPage, pageSize: rulePageSize, + namespaceId: currentNamespaceId, }, }); }; diff --git a/src/routes/System/Metadata/index.js b/src/routes/System/Metadata/index.js index d8fd0613..862a96a4 100644 --- a/src/routes/System/Metadata/index.js +++ b/src/routes/System/Metadata/index.js @@ -35,6 +35,7 @@ import AuthButton from "../../../utils/AuthButton"; @connect(({ metadata, loading, global }) => ({ metadata, language: global.language, + currentNamespaceId: global.currentNamespaceId, loading: loading.effects["metadata/fetch"], })) export default class Metadata extends Component { @@ -61,13 +62,16 @@ export default class Metadata extends Component { this.initPluginColumns(); } - componentDidUpdate() { - const { language } = this.props; + componentDidUpdate(prevProps) { + const { language, currentNamespaceId } = this.props; const { localeName } = this.state; if (language !== localeName) { this.initPluginColumns(); this.changeLocale(language); } + if (prevProps.currentNamespaceId !== currentNamespaceId) { + this.query(); + } } handleResize = @@ -88,7 +92,7 @@ export default class Metadata extends Component { }; query = () => { - const { dispatch } = this.props; + const { dispatch, currentNamespaceId } = this.props; const { path, currentPage, pageSize } = this.state; dispatch({ type: "metadata/fetch", @@ -96,6 +100,7 @@ export default class Metadata extends Component { path, currentPage, pageSize, + namespaceId: currentNamespaceId, }, }); }; @@ -113,13 +118,14 @@ export default class Metadata extends Component { }; editClick = (record, copy) => { - const { dispatch } = this.props; + const { dispatch, currentNamespaceId } = this.props; const { currentPage, pageSize } = this.state; const name = this.state.appName; dispatch({ type: "metadata/fetchItem", payload: { id: record.id, + namespaceId: currentNamespaceId, }, callback: (user) => { this.setState({ @@ -151,6 +157,7 @@ export default class Metadata extends Component { rpcExt, rpcType, serviceName, + namespaceId: currentNamespaceId, }; if (copy) { delete payload.id; @@ -162,6 +169,7 @@ export default class Metadata extends Component { appName: name, currentPage, pageSize, + namespaceId: currentNamespaceId, }, callback: () => { this.closeModal(); @@ -187,18 +195,20 @@ export default class Metadata extends Component { }; deleteClick = () => { - const { dispatch } = this.props; + const { dispatch, currentNamespaceId } = this.props; const { appName, currentPage, pageSize, selectedRowKeys } = this.state; if (selectedRowKeys && selectedRowKeys.length > 0) { dispatch({ type: "metadata/delete", payload: { list: selectedRowKeys, + namespaceId: currentNamespaceId, }, fetchValue: { appName, currentPage, pageSize, + namespaceId: currentNamespaceId, }, callback: () => { this.setState({ selectedRowKeys: [], currentPage: 1 }, this.query); @@ -218,7 +228,7 @@ export default class Metadata extends Component { <AddModal isShow={true} handleOk={(values) => { - const { dispatch } = this.props; + const { dispatch, currentNamespaceId } = this.props; const { appName, enabled, @@ -242,11 +252,13 @@ export default class Metadata extends Component { rpcExt, rpcType, serviceName, + namespaceId: currentNamespaceId, }, fetchValue: { appName: name, currentPage, pageSize, + namespaceId: currentNamespaceId, }, callback: () => { this.setState( @@ -266,31 +278,34 @@ export default class Metadata extends Component { }; statusSwitch = ({ list, enabled, callback }) => { - const { dispatch } = this.props; + const { dispatch, currentNamespaceId } = this.props; const { appName, currentPage, pageSize } = this.state; dispatch({ type: "metadata/updateEn", payload: { list, enabled, + namespaceId: currentNamespaceId, }, fetchValue: { appName, currentPage, pageSize, + namespaceId: currentNamespaceId, }, callback, }); }; enableClick = () => { - const { dispatch } = this.props; + const { dispatch, currentNamespaceId } = this.props; const { selectedRowKeys } = this.state; if (selectedRowKeys && selectedRowKeys.length > 0) { dispatch({ type: "metadata/fetchItem", payload: { id: selectedRowKeys[0], + namespaceId: currentNamespaceId, }, callback: (user) => { this.statusSwitch({ diff --git a/src/services/api.js b/src/services/api.js index da693db5..16ed2d1c 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -75,10 +75,10 @@ export async function updatePassword(params) { /* get all metadata */ export async function getAllMetadata(params) { - const { path, currentPage, pageSize } = params; + const { path, currentPage, pageSize, namespaceId } = params; return request( `${baseUrl}/meta-data/queryList?${stringify( - path ? params : { currentPage, pageSize }, + path ? params : { currentPage, pageSize, namespaceId }, )}`, { method: `GET`, @@ -87,7 +87,7 @@ export async function getAllMetadata(params) { } export async function findMetadata(params) { - return request(`${baseUrl}/meta-data/${params.id}`, { + return request(`${baseUrl}/meta-data/${params.id}/${params.namespaceId}`, { method: `GET`, }); } @@ -117,6 +117,7 @@ export async function updateMetadata(params) { rpcExt: params.rpcExt, rpcType: params.rpcType, serviceName: params.serviceName, + namespaceId: params.namespaceId, }, }); } @@ -139,8 +140,8 @@ export async function getfetchMetaGroup() { /* deleteMetadata */ export async function deleteMetadata(params) { return request(`${baseUrl}/meta-data/batchDeleted`, { - method: `POST`, - body: [...params.list], + method: `DELETE`, + body: { ids: [...params.list], namespaceId: params.namespaceId }, }); } @@ -151,6 +152,7 @@ export async function updateEnabled(params) { body: { ids: params.list, enabled: params.enabled, + namespaceId: params.namespaceId, }, }); } @@ -490,12 +492,12 @@ export async function addRule(params) { export async function deleteRule(params) { return request(`${baseUrl}/rule/batch`, { method: `DELETE`, - body: [...params.list], + body: { ids: [...params.list], namespaceId: params.namespaceId }, }); } export async function findRule(params) { - return request(`${baseUrl}/rule/${params.id}`, { + return request(`${baseUrl}/rule/${params.id}/${params.namespaceId}`, { method: `GET`, }); } @@ -515,6 +517,7 @@ export async function enableRule(params) { body: { ids: params.list, enabled: params.enabled, + namespaceId: params.namespaceId, }, }); }