Skip to content

Commit

Permalink
[Improve] Selector module adaptation namespace (#471)
Browse files Browse the repository at this point in the history
* fix

* [Improve] adapt selector page namespace

---------

Co-authored-by: ‘xcsnx’ <‘[email protected]’>
  • Loading branch information
VampireAchao and ‘xcsnx’ authored Aug 20, 2024
1 parent c34cec1 commit d7eb121
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/models/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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 });
},

Expand Down
6 changes: 6 additions & 0 deletions src/routes/Plugin/Common/RuleCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import React, { Component } from "react";
import { Modal, TreeSelect } from "antd";
import { connect } from "dva";
import {
getPluginDropDownList,
getAllSelectors,
Expand All @@ -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);
Expand All @@ -40,6 +44,7 @@ class RuleCopy extends Component {
}

getAllRule = async () => {
const { currentNamespaceId } = this.props;
const { code: pluginCode, data: pluginList = [] } =
await getPluginDropDownList();
const {
Expand All @@ -48,6 +53,7 @@ class RuleCopy extends Component {
} = await getAllSelectors({
currentPage: 1,
pageSize: 9999,
namespaceId: currentNamespaceId,
});
const {
code: ruleCode,
Expand Down
13 changes: 11 additions & 2 deletions src/routes/Plugin/Common/SelectorCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

import React, { Component } from "react";
import { Modal, TreeSelect } from "antd";
import { connect } from "dva";
import {
getPluginDropDownList,
getAllSelectors,
findSelector,
} from "../../../services/api";
import { getIntlContent } from "../../../utils/IntlUtils";

@connect(({ global }) => ({
currentNamespaceId: global.currentNamespaceId,
}))
class SelectorCopy extends Component {
constructor(props) {
super(props);
Expand All @@ -39,6 +43,7 @@ class SelectorCopy extends Component {
}

getAllSelectors = async () => {
const { currentNamespaceId } = this.props;
const { code: pluginCode, data: pluginList = [] } =
await getPluginDropDownList();
const {
Expand All @@ -47,6 +52,7 @@ class SelectorCopy extends Component {
} = await getAllSelectors({
currentPage: 1,
pageSize: 9999,
namespaceId: currentNamespaceId,
});
const pluginMap = {};
const selectorTree = [];
Expand Down Expand Up @@ -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,
});
Expand Down
36 changes: 29 additions & 7 deletions src/routes/Plugin/Common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand All @@ -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 */

Expand All @@ -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);
Expand All @@ -127,6 +132,7 @@ export default class Common extends Component {
pageSize,
pluginId: tempPluginId,
name: selectorName,
namespaceId: currentNamespaceId,
},
});
this.setState({ selectorSelectedRowKeys: [] });
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -483,6 +496,7 @@ export default class Common extends Component {
type: "common/fetchSeItem",
payload: {
id,
namespaceId: currentNamespaceId,
},
callback: (selector) => {
if (isDiscovery) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -634,11 +652,13 @@ export default class Common extends Component {
payload: {
list,
enabled,
namespaceId: currentNamespaceId,
},
fetchValue: {
pluginId,
currentPage: selectorPage,
pageSize: selectorPageSize,
namespaceId: currentNamespaceId,
},
});
};
Expand Down Expand Up @@ -666,19 +686,21 @@ 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);
dispatch({
type: "common/deleteSelector",
payload: {
list: [record.id],
namespaceId: currentNamespaceId,
},
fetchValue: {
pluginId,
currentPage: selectorPage,
pageSize: selectorPageSize,
namespaceId: currentNamespaceId,
},
});
};
Expand Down
8 changes: 6 additions & 2 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
}

Expand All @@ -450,6 +453,7 @@ export async function enableSelector(params) {
body: {
ids: params.list,
enabled: params.enabled,
namespaceId: params.namespaceId,
},
});
}
Expand All @@ -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`,
});
}
Expand Down

0 comments on commit d7eb121

Please sign in to comment.