feat: support show quota info when create router

1. Support show quota info when create router
2. Disable click submit button when lef quota is zero
3. Update size of large modal with quota info

Change-Id: I8f651d58af0b3d7a5915116ea488bc70a3ed902d
This commit is contained in:
Jingwei.Zhang 2022-06-23 13:00:44 +08:00
parent b8caadf202
commit bf6c765fb1
3 changed files with 59 additions and 1 deletions

View File

@ -438,7 +438,7 @@ export class ActionButton extends Component {
case 'middle':
return 720 * multi;
case 'large':
return 1200 * multi;
return 1200;
default:
return 520 * multi;
}

View File

@ -16,6 +16,7 @@ import { inject, observer } from 'mobx-react';
import { RouterStore } from 'stores/neutron/router';
import { NetworkStore } from 'stores/neutron/network';
import globalNeutronStore from 'stores/neutron/neutron';
import globalProjectStore from 'stores/keystone/project';
import { ModalAction } from 'containers/Action';
import { has } from 'lodash';
import { networkStatus } from 'resources/neutron/network';
@ -30,9 +31,13 @@ export class Create extends ModalAction {
static title = t('Create Router');
init() {
this.state.quota = {};
this.state.quotaLoading = true;
this.store = new RouterStore();
this.networkStore = new NetworkStore();
this.projectStore = globalProjectStore;
this.fetchAzones();
this.getQuota();
}
get name() {
@ -60,6 +65,45 @@ export class Create extends ModalAction {
}));
}
static get disableSubmit() {
const { neutronQuota: { router: { left = 0 } = {} } = {} } =
globalProjectStore;
return left === 0;
}
static get showQuota() {
return true;
}
get showQuota() {
return true;
}
async getQuota() {
const result = await this.projectStore.fetchProjectNeutronQuota();
const { router: quota = {} } = result || {};
this.setState({
quota,
quotaLoading: false,
});
}
get quotaInfo() {
const { quota = {}, quotaLoading } = this.state;
if (quotaLoading) {
return [];
}
const { left = 0 } = quota;
const add = left === 0 ? 0 : 1;
const data = {
...quota,
add,
name: 'router',
title: t('Router'),
};
return [data];
}
get defaultValue() {
return {
openExternalNetwork: false,

View File

@ -26,6 +26,9 @@ export class ProjectStore extends Base {
@observable
novaQuota = {};
@observable
neutronQuota = {};
@observable
groupRoleList = [];
@ -465,6 +468,17 @@ export class ProjectStore extends Base {
this.novaQuota = novaQuota;
return novaQuota;
}
@action
async fetchProjectNeutronQuota(projectId) {
const result = await this.neutronQuotaClient.details(
projectId || this.currentProjectId
);
const { quota } = result;
const neutronQuota = this.updateQuotaData(quota);
this.neutronQuota = neutronQuota;
return neutronQuota;
}
}
const globalProjectStore = new ProjectStore();