This is an automated email from the ASF dual-hosted git repository. hefengen 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 d7eb1218 [Improve] Selector module adaptation namespace (#471) d7eb1218 is described below commit d7eb12189a36922bbe26a3be825d9a13788cfeb5 Author: VampireAchao <ac...@apache.org> AuthorDate: Tue Aug 20 16:04:25 2024 +0800 [Improve] Selector module adaptation namespace (#471) * fix * [Improve] adapt selector page namespace --------- Co-authored-by: ‘xcsnx’ <‘1192709...@qq.com’> --- src/models/common.js | 8 +++---- src/routes/Plugin/Common/RuleCopy.js | 6 ++++++ src/routes/Plugin/Common/SelectorCopy.js | 13 ++++++++++-- src/routes/Plugin/Common/index.js | 36 +++++++++++++++++++++++++------- src/services/api.js | 8 +++++-- 5 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/models/common.js b/src/models/common.js index 500841aa..466d350f 100644 --- a/src/models/common.js +++ b/src/models/common.js @@ -140,8 +140,8 @@ export default { }, *deleteSelector(params, { call, put }) { const { payload, fetchValue } = params; - const { list } = payload; - const json = yield call(deleteSelector, { list }); + const { list, namespaceId } = payload; + const json = yield call(deleteSelector, { list, namespaceId }); if (json.code === 200) { message.success( getIntlContent("SHENYU.COMMON.RESPONSE.DELETE.SUCCESS"), @@ -238,8 +238,8 @@ export default { *reload(params, { put }) { const { fetchValue } = params; - const { pluginId, currentPage, pageSize } = fetchValue; - const payload = { pluginId, currentPage, pageSize }; + const { pluginId, currentPage, pageSize, namespaceId } = fetchValue; + const payload = { pluginId, currentPage, pageSize, namespaceId }; yield put({ type: "fetchSelector", payload }); }, diff --git a/src/routes/Plugin/Common/RuleCopy.js b/src/routes/Plugin/Common/RuleCopy.js index a00eb91d..c18c2c0d 100644 --- a/src/routes/Plugin/Common/RuleCopy.js +++ b/src/routes/Plugin/Common/RuleCopy.js @@ -17,6 +17,7 @@ import React, { Component } from "react"; import { Modal, TreeSelect } from "antd"; +import { connect } from "dva"; import { getPluginDropDownList, getAllSelectors, @@ -25,6 +26,9 @@ import { } from "../../../services/api"; import { getIntlContent } from "../../../utils/IntlUtils"; +@connect(({ global }) => ({ + currentNamespaceId: global.currentNamespaceId, +})) class RuleCopy extends Component { constructor(props) { super(props); @@ -40,6 +44,7 @@ class RuleCopy extends Component { } getAllRule = async () => { + const { currentNamespaceId } = this.props; const { code: pluginCode, data: pluginList = [] } = await getPluginDropDownList(); const { @@ -48,6 +53,7 @@ class RuleCopy extends Component { } = await getAllSelectors({ currentPage: 1, pageSize: 9999, + namespaceId: currentNamespaceId, }); const { code: ruleCode, diff --git a/src/routes/Plugin/Common/SelectorCopy.js b/src/routes/Plugin/Common/SelectorCopy.js index 92799f45..6f8142dc 100644 --- a/src/routes/Plugin/Common/SelectorCopy.js +++ b/src/routes/Plugin/Common/SelectorCopy.js @@ -17,6 +17,7 @@ import React, { Component } from "react"; import { Modal, TreeSelect } from "antd"; +import { connect } from "dva"; import { getPluginDropDownList, getAllSelectors, @@ -24,6 +25,9 @@ import { } from "../../../services/api"; import { getIntlContent } from "../../../utils/IntlUtils"; +@connect(({ global }) => ({ + currentNamespaceId: global.currentNamespaceId, +})) class SelectorCopy extends Component { constructor(props) { super(props); @@ -39,6 +43,7 @@ class SelectorCopy extends Component { } getAllSelectors = async () => { + const { currentNamespaceId } = this.props; const { code: pluginCode, data: pluginList = [] } = await getPluginDropDownList(); const { @@ -47,6 +52,7 @@ class SelectorCopy extends Component { } = await getAllSelectors({ currentPage: 1, pageSize: 9999, + namespaceId: currentNamespaceId, }); const pluginMap = {}; const selectorTree = []; @@ -86,12 +92,15 @@ class SelectorCopy extends Component { }; handleOk = async () => { - const { onOk } = this.props; + const { onOk, currentNamespaceId } = this.props; const { value } = this.state; this.setState({ loading: true, }); - const { data = {} } = await findSelector({ id: value }); + const { data = {} } = await findSelector({ + id: value, + namespaceId: currentNamespaceId, + }); this.setState({ loading: false, }); diff --git a/src/routes/Plugin/Common/index.js b/src/routes/Plugin/Common/index.js index 79788564..40799a96 100755 --- a/src/routes/Plugin/Common/index.js +++ b/src/routes/Plugin/Common/index.js @@ -83,8 +83,8 @@ export default class Common extends Component { const preId = prevProps.match.params.id; const newId = this.props.match.params.id; const { selectorPage, selectorPageSize } = this.state; + const { dispatch, plugins, currentNamespaceId } = this.props; if (newId !== preId) { - const { dispatch } = this.props; dispatch({ type: "common/resetData", }); @@ -102,6 +102,11 @@ export default class Common extends Component { }); } } + if (prevProps.currentNamespaceId !== currentNamespaceId) { + if (plugins) { + this.getAllSelectors(selectorPage, selectorPageSize, plugins); + } + } } /* eslint-enable no-unused-vars */ @@ -113,7 +118,7 @@ export default class Common extends Component { } getAllSelectors = (page, pageSize, plugins) => { - const { dispatch } = this.props; + const { dispatch, currentNamespaceId } = this.props; const { selectorName } = this.state; let name = this.props.match.params ? this.props.match.params.id : ""; const tempPlugin = this.getPlugin(plugins, name); @@ -127,6 +132,7 @@ export default class Common extends Component { pageSize, pluginId: tempPluginId, name: selectorName, + namespaceId: currentNamespaceId, }, }); this.setState({ selectorSelectedRowKeys: [] }); @@ -199,7 +205,7 @@ export default class Common extends Component { addSelector = () => { const { selectorPage, selectorPageSize } = this.state; - const { dispatch, plugins } = this.props; + const { dispatch, plugins, currentNamespaceId } = this.props; let name = this.props.match.params ? this.props.match.params.id : ""; const plugin = this.getPlugin(plugins, name); const { id: pluginId, config } = plugin; @@ -241,11 +247,13 @@ export default class Common extends Component { pluginId, ...selector, upstreams: upstreamsWithProps, + namespaceId: currentNamespaceId, }, fetchValue: { pluginId, currentPage: selectorPage, pageSize: selectorPageSize, + namespaceId: currentNamespaceId, }, callback: (selectorId) => { this.addDiscoveryUpstream({ @@ -280,11 +288,16 @@ export default class Common extends Component { handleOk={(selector) => { dispatch({ type: "common/addSelector", - payload: { pluginId, ...selector }, + payload: { + pluginId, + ...selector, + namespaceId: currentNamespaceId, + }, fetchValue: { pluginId, currentPage: selectorPage, pageSize: selectorPageSize, + namespaceId: currentNamespaceId, }, callback: () => { this.closeModal(); @@ -470,7 +483,7 @@ export default class Common extends Component { }; editSelector = (record) => { - const { dispatch, plugins } = this.props; + const { dispatch, plugins, currentNamespaceId } = this.props; const { selectorPage, selectorPageSize } = this.state; let name = this.props.match.params ? this.props.match.params.id : ""; const plugin = this.getPlugin(plugins, name); @@ -483,6 +496,7 @@ export default class Common extends Component { type: "common/fetchSeItem", payload: { id, + namespaceId: currentNamespaceId, }, callback: (selector) => { if (isDiscovery) { @@ -541,11 +555,13 @@ export default class Common extends Component { pluginId, ...values, id, + namespaceId: currentNamespaceId, }, fetchValue: { pluginId, currentPage: selectorPage, pageSize: selectorPageSize, + namespaceId: currentNamespaceId, }, callback: () => { const { @@ -603,11 +619,13 @@ export default class Common extends Component { pluginId, ...values, id, + namespaceId: currentNamespaceId, }, fetchValue: { pluginId, currentPage: selectorPage, pageSize: selectorPageSize, + namespaceId: currentNamespaceId, }, callback: () => { this.closeModal(); @@ -624,7 +642,7 @@ export default class Common extends Component { }; enableSelector = ({ list, enabled }) => { - const { dispatch, plugins } = this.props; + const { dispatch, plugins, currentNamespaceId } = this.props; const { selectorPage, selectorPageSize } = this.state; let name = this.props.match.params ? this.props.match.params.id : ""; const plugin = this.getPlugin(plugins, name); @@ -634,11 +652,13 @@ export default class Common extends Component { payload: { list, enabled, + namespaceId: currentNamespaceId, }, fetchValue: { pluginId, currentPage: selectorPage, pageSize: selectorPageSize, + namespaceId: currentNamespaceId, }, }); }; @@ -666,7 +686,7 @@ export default class Common extends Component { }; deleteSelector = (record) => { - const { dispatch, plugins } = this.props; + const { dispatch, plugins, currentNamespaceId } = this.props; const { selectorPage, selectorPageSize } = this.state; let name = this.props.match.params ? this.props.match.params.id : ""; const pluginId = this.getPluginId(plugins, name); @@ -674,11 +694,13 @@ export default class Common extends Component { type: "common/deleteSelector", payload: { list: [record.id], + namespaceId: currentNamespaceId, }, fetchValue: { pluginId, currentPage: selectorPage, pageSize: selectorPageSize, + namespaceId: currentNamespaceId, }, }); }; diff --git a/src/services/api.js b/src/services/api.js index 5c66e5eb..da693db5 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -429,7 +429,10 @@ export async function addSelector(params) { export async function deleteSelector(params) { return request(`${baseUrl}/selector/batch`, { method: `DELETE`, - body: [...params.list], + body: { + ids: [...params.list], + namespaceId: params.namespaceId, + }, }); } @@ -450,6 +453,7 @@ export async function enableSelector(params) { body: { ids: params.list, enabled: params.enabled, + namespaceId: params.namespaceId, }, }); } @@ -463,7 +467,7 @@ export async function getAllSelectors(params) { /* get single selector */ export async function findSelector(params) { - return request(`${baseUrl}/selector/${params.id}`, { + return request(`${baseUrl}/selector/${params.id}/${params.namespaceId}`, { method: `GET`, }); }