From 0a7c3a3f3663637b359eb1606cc43bf47b98bfdd Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Thu, 23 Jun 2022 14:51:15 +0800 Subject: [PATCH] feat: support quota info when create security group rule 1. Show quota info when create security group rule 2. Add left quota check when create security group rule Change-Id: Iab21d57e4e2fd5c3973281256d0aa79d438a2e8c --- .../Detail/Rule/actions/Create.jsx | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/pages/network/containers/SecurityGroup/Detail/Rule/actions/Create.jsx b/src/pages/network/containers/SecurityGroup/Detail/Rule/actions/Create.jsx index 2122d849..c68b6cc6 100644 --- a/src/pages/network/containers/SecurityGroup/Detail/Rule/actions/Create.jsx +++ b/src/pages/network/containers/SecurityGroup/Detail/Rule/actions/Create.jsx @@ -16,6 +16,7 @@ import { inject, observer } from 'mobx-react'; import { ModalAction } from 'containers/Action'; import globalSecurityGroupRuleStore from 'stores/neutron/security-rule'; import globalSecurityGroupStore from 'stores/neutron/security-group'; +import globalProjectStore from 'stores/keystone/project'; import { ipProtocols } from 'resources/neutron/security-group-rule'; import { has } from 'lodash'; import { cidrAllValidate } from 'utils/validate'; @@ -41,9 +42,13 @@ export class Create extends ModalAction { } init() { + this.state.quota = {}; + this.state.quotaLoading = true; this.store = globalSecurityGroupRuleStore; this.groupStore = globalSecurityGroupStore; + this.projectStore = globalProjectStore; this.getAllGroups(); + this.getQuota(); } static policy = 'create_security_group_rule'; @@ -62,6 +67,45 @@ export class Create extends ModalAction { })); } + static get disableSubmit() { + const { neutronQuota: { security_group_rule: { left = 0 } = {} } = {} } = + globalProjectStore; + return left === 0; + } + + static get showQuota() { + return true; + } + + get showQuota() { + return true; + } + + async getQuota() { + const result = await this.projectStore.fetchProjectNeutronQuota(); + const { security_group_rule: 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: 'security_group_rule', + title: t('Security Group Rule'), + }; + return [data]; + } + get defaultRules() { return { custom_tcp: {