Skip to content

Commit

Permalink
[ISSUE alibaba#12017] Update the frontend of the console by using the…
Browse files Browse the repository at this point in the history
… Console API for other section

* Update the request path

* Update the request parameters

* Update the return values
  • Loading branch information
RickonZhang0929 committed Oct 14, 2024
1 parent 92e4845 commit 2cace4e
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 52 deletions.
1 change: 1 addition & 0 deletions console-ui/src/pages/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Login extends React.Component {
}
login(values)
.then(res => {
res= res.data;
localStorage.setItem('token', JSON.stringify(res));
this.props.history.push('/');
})
Expand Down
12 changes: 7 additions & 5 deletions console-ui/src/pages/NameSpace/NameSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class NameSpace extends React.Component {
request({
type: 'get',
beforeSend() {},
url: 'v1/console/namespaces',
url: 'v3/console/core/namespace/list',
success: res => {
if (res.code === 200) {
if (res.code === 0) {
const data = res.data || [];
window.namespaceList = data;

Expand Down Expand Up @@ -113,11 +113,12 @@ class NameSpace extends React.Component {
const { namespaceDetails, namespaceName, namespaceID, configuration, description } = locale;
const { namespace } = record; // 获取ak,sk
request({
url: `v1/console/namespaces?show=all&namespaceId=${namespace}`,
url: `v3/console/core/namespace?namespaceId=${namespace}`,
beforeSend: () => {
this.openLoading();
},
success: res => {
res = res.data;
if (res !== null) {
Dialog.alert({
style: { width: '500px' },
Expand Down Expand Up @@ -182,11 +183,12 @@ class NameSpace extends React.Component {
</div>
),
onOk: () => {
const url = `v1/console/namespaces?namespaceId=${record.namespace}`;
const url = `v3/console/core/namespace?namespaceId=${record.namespace}`;
request({
url,
type: 'delete',
success: res => {
res = res.data;
const _payload = {};
_payload.title = configurationManagement;
if (res === true) {
Expand All @@ -210,7 +212,7 @@ class NameSpace extends React.Component {
refreshNameSpace() {
request({
type: 'get',
url: 'v1/console/namespaces',
url: 'v3/console/core/namespace',
success: res => {
if (res.code === 200) {
window.namespaceList = res.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EditClusterDialog extends React.Component {
} = this.state.editCluster;
request({
method: 'PUT',
url: 'v1/ns/cluster',
url: 'v3/console/ns/service/cluster',
data: {
serviceName,
clusterName: name,
Expand All @@ -81,7 +81,7 @@ class EditClusterDialog extends React.Component {
dataType: 'text',
beforeSend: () => openLoading(),
success: res => {
if (res !== 'ok') {
if (res.data !== 'ok') {
Message.error(res);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EditInstanceDialog extends React.Component {
const { ip, port, ephemeral, weight, enabled, metadataText } = this.state.editInstance;
request({
method: 'PUT',
url: 'v1/ns/instance',
url: 'v3/console/ns/instance',
data: {
serviceName,
clusterName,
Expand All @@ -84,7 +84,7 @@ class EditInstanceDialog extends React.Component {
dataType: 'text',
beforeSend: () => openLoading(),
success: res => {
if (res !== 'ok') {
if (res.data !== 'ok') {
Message.error(res);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EditServiceDialog extends React.Component {
if (!this.validator({ name, protectThreshold })) return;
request({
method: isCreate ? 'POST' : 'PUT',
url: 'v1/ns/service',
url: 'v3/console/ns/service',
data: {
serviceName: name,
groupName: groupName || 'DEFAULT_GROUP',
Expand All @@ -97,7 +97,7 @@ class EditServiceDialog extends React.Component {
dataType: 'text',
beforeSend: () => this.setState({ loading: true }),
success: res => {
if (res !== 'ok') {
if (res.data !== 'ok') {
Message.error(res);
return;
}
Expand All @@ -107,7 +107,7 @@ class EditServiceDialog extends React.Component {
this.props.getServiceDetail();
}
},
error: res => Message.error(res.responseText || res.statusText),
error: res => Message.error(res.data.responseText || res.data.statusText),
complete: () => this.setState({ loading: false }),
});
this.hide();
Expand Down Expand Up @@ -136,9 +136,9 @@ class EditServiceDialog extends React.Component {
getSelectorTypes() {
request({
method: 'GET',
url: 'v1/ns/service/selector/types',
url: 'v3/console/ns/service/selector/types',
success: response => {
if (response.code !== 200) {
if (response.code !== 0) {
Message.error(response.message);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class InstanceTable extends React.Component {
if (!clusterName) return;
const { pageSize, pageNum } = this.state;
request({
url: 'v1/ns/catalog/instances',
url: 'v3/console/ns/instance/list',
data: {
serviceName,
clusterName,
Expand All @@ -78,7 +78,7 @@ class InstanceTable extends React.Component {
pageNo: pageNum,
},
beforeSend: () => this.openLoading(),
success: instance => this.setState({ instance }),
success: ({ data: instance }) => this.setState({ instance }),
complete: () => this.closeLoading(),
});
}
Expand All @@ -93,7 +93,7 @@ class InstanceTable extends React.Component {
const { clusterName, serviceName, groupName } = this.props;
request({
method: 'PUT',
url: 'v1/ns/instance',
url: 'v3/console/ns/instance',
data: {
serviceName,
clusterName,
Expand All @@ -107,7 +107,7 @@ class InstanceTable extends React.Component {
},
dataType: 'text',
beforeSend: () => this.openLoading(),
success: () => {
success: ({ data }) => {
const newVal = Object.assign({}, instance);
newVal.list[index].enabled = !enabled;
this.setState({ instance: newVal });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class ServiceDetail extends React.Component {
getServiceDetail() {
const { serviceName, groupName } = this.state;
request({
url: `v1/ns/catalog/service?serviceName=${serviceName}&groupName=${groupName}`,
url: `v3/console/ns/service?serviceName=${serviceName}&groupName=${groupName}`,
beforeSend: () => this.openLoading(),
success: ({ clusters = [], service = {} }) => this.setState({ service, clusters }),
success: ({ data: { clusters = [], service = {} } }) => this.setState({ service, clusters }),
error: e => Message.error(e.responseText || 'error'),
complete: () => this.closeLoading(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class ServiceList extends React.Component {
});
this.openLoading();
request({
url: `v1/ns/catalog/services?${parameter.join('&')}`,
success: ({ count = 0, serviceList = [] } = {}) => {
url: `v3/console/ns/service/list?${parameter.join('&')}`,
success: ({ data: { count = 0, serviceList = [] } = {} }) => {
this.setState({
dataSource: serviceList,
total: count,
Expand Down Expand Up @@ -158,17 +158,17 @@ class ServiceList extends React.Component {
onOk: () => {
request({
method: 'DELETE',
url: `v1/ns/service?serviceName=${service.name}&groupName=${service.groupName}`,
url: `v3/console/ns/service?serviceName=${service.name}&groupName=${service.groupName}`,
dataType: 'text',
beforeSend: () => this.openLoading(),
success: res => {
if (res !== 'ok') {
if (res.data !== 'ok') {
Message.error(res);
return;
}
this.queryServiceList();
},
error: res => Message.error(res.responseText || res.statusText),
error: res => Message.error(res.data.responseText || res.data.statusText),
complete: () => this.closeLoading(),
});
},
Expand Down
26 changes: 13 additions & 13 deletions console-ui/src/reducers/authority.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,87 +51,87 @@ const successMsg = res => {
* @param {*} params
*/
const getUsers = params => dispatch =>
request.get('v1/auth/users', { params }).then(data => dispatch({ type: USER_LIST, data }));
request.get('v3/auth/user/list', { params }).then(data => dispatch({ type: USER_LIST, data: data.data }));

/**
* 创建用户
* @param {*} param0
*/
const createUser = ([username, password]) =>
request.post('v1/auth/users', { username, password }).then(res => successMsg(res));
request.post('v3/auth/user', { username, password }).then(res => successMsg(res));

/**
* 通过username 模糊匹配
* @param {*} param0
*/
const searchUsers = username =>
request.get('v1/auth/users/search', { params: { username } }).then(res => successMsg(res));
request.get('v3/auth/user/search', { params: { username } }).then(res => successMsg(res.data));

/**
* 删除用户
* @param {*} username
*/
const deleteUser = username =>
request.delete('v1/auth/users', { params: { username } }).then(res => successMsg(res));
request.delete('v3/auth/user', { params: { username } }).then(res => successMsg(res));

/**
* 重置密码
* @param {*} param0
*/
const passwordReset = ([username, newPassword]) =>
request.put('v1/auth/users', { username, newPassword }).then(res => successMsg(res));
request.put('v3/auth/user', { username, newPassword }).then(res => successMsg(res));

/**
* 角色列表
* @param {*} params
*/

const getRoles = params => dispatch =>
request.get('v1/auth/roles', { params }).then(data => dispatch({ type: ROLE_LIST, data }));
request.get('v3/auth/role/list', { params }).then(data => dispatch({ type: ROLE_LIST, data: data.data }));

/**
* 通过username 模糊匹配
* @param {*} param0
*/
const searchRoles = role =>
request.get('v1/auth/roles/search', { params: { role } }).then(res => successMsg(res));
request.get('v3/auth/role/search', { params: { role } }).then(res => successMsg(res.data));

/**
* 创建角色
* @param {*} param0
*/
const createRole = ([role, username]) =>
request.post('v1/auth/roles', { role, username }).then(res => successMsg(res));
request.post('v3/auth/role', { role, username }).then(res => successMsg(res));

/**
* 删除角色
* @param {*} param0
*/
const deleteRole = role =>
request.delete('v1/auth/roles', { params: role }).then(res => successMsg(res));
request.delete('v3/auth/role', { params: role }).then(res => successMsg(res));

/**
* 权限列表
* @param {*} params
*/
const getPermissions = params => dispatch =>
request
.get('v1/auth/permissions', { params })
.then(data => dispatch({ type: PERMISSIONS_LIST, data }));
.get('v3/auth/permission/list', { params })
.then(data => dispatch({ type: PERMISSIONS_LIST, data: data.data }));

/**
* 给角色添加权限
* @param {*} param0
*/
const createPermission = ([role, resource, action]) =>
request.post('v1/auth/permissions', { role, resource, action }).then(res => successMsg(res));
request.post('v3/auth/permission', { role, resource, action }).then(res => successMsg(res));

/**
* 删除权限
* @param {*} param0
*/
const deletePermission = permission =>
request.delete('v1/auth/permissions', { params: permission }).then(res => successMsg(res));
request.delete('v3/auth/permission', { params: permission }).then(res => successMsg(res));

export default (state = initialState, action) => {
switch (action.type) {
Expand Down
10 changes: 5 additions & 5 deletions console-ui/src/reducers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const initialState = {
* 用户登录
* @param {*} param0
*/
const login = user => request.post('v1/auth/users/login', user);
const admin = user => request.post('v1/auth/users/admin', user);
const login = user => request.post('v3/auth/user/login', user);
const admin = user => request.post('v3/auth/user/admin', user);

/**
* 单独在login处调用 获取提示信息
*/
const guide = () => request.get('v1/console/server/guide');
const guide = () => request.get('v3/console/server/guide');

/**
* 单独在login调用 判断是否可以登陆
Expand Down Expand Up @@ -82,7 +82,7 @@ const getState = () => dispatch =>

const getNotice = () => dispatch =>
request
.get('v1/console/server/announcement?language=' + localStorage.getItem(LANGUAGE_KEY))
.get('v3/console/server/announcement?language=' + localStorage.getItem(LANGUAGE_KEY))
.then(res => {
dispatch({
type: GET_NOTICE,
Expand All @@ -102,7 +102,7 @@ const getNotice = () => dispatch =>

const getGuide = () => dispatch =>
request
.get('v1/console/server/guide')
.get('v3/console/server/guide')
.then(res => {
dispatch({
type: SERVER_GUIDE,
Expand Down
8 changes: 4 additions & 4 deletions console-ui/src/reducers/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const initialState = {

const getConfigs = params => dispatch =>
request
.get('v1/cs/configs', { params })
.then(data => dispatch({ type: GET_CONFIGURATION, data }));
.get('v3/console/cs/config/list', { params })
.then(data => dispatch({ type: GET_CONFIGURATION, data: data.data }));

const getConfigsV2 = params => dispatch =>
request
.get('v2/cs/config/searchDetail', { params })
.then(data => dispatch({ type: GET_CONFIGURATION, data }));
.get('v3/console/cs/config/searchDetail', { params })
.then(data => dispatch({ type: GET_CONFIGURATION, data: data.data }));

export default (state = initialState, action) => {
switch (action.type) {
Expand Down
4 changes: 2 additions & 2 deletions console-ui/src/reducers/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const initialState = {
};

const getNamespaces = params => dispatch =>
request.get('v1/console/namespaces', { params }).then(response => {
request.get('v3/console/core/namespace/list', { params }).then(response => {
const { code, data } = response;
dispatch({
type: GET_NAMESPACES,
data: code === 200 ? data : [],
data: code === 0 ? data : [],
});
});

Expand Down
4 changes: 2 additions & 2 deletions console-ui/src/reducers/subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const initialState = {
};

const getSubscribers = params => dispatch =>
request.get('v1/ns/service/subscribers', { params }).then(data => {
request.get('v3/console/ns/service/subscribers', { params }).then(data => {
dispatch({
type: GET_SUBSCRIBERS,
data,
data: data.data,
});
});
const removeSubscribers = () => dispatch => dispatch({ type: REMOVE_SUBSCRIBERS });
Expand Down
Loading

0 comments on commit 2cace4e

Please sign in to comment.