feat: support quota info when instance snapshot create volume

1. Support quota info when instance snapshot create volume
2. Disable click submit button when the given type's left quota is insufficient

Change-Id: I2665b5285b7e93324fec7b02bbf095cf9fad3b9f
This commit is contained in:
Jingwei.Zhang 2022-07-18 15:04:56 +08:00
parent d3ffb6264d
commit c6eaddabe6

View File

@ -17,6 +17,14 @@ import { toJS } from 'mobx';
import { ModalAction } from 'containers/Action'; import { ModalAction } from 'containers/Action';
import globalVolumeStore from 'stores/cinder/volume'; import globalVolumeStore from 'stores/cinder/volume';
import { InstanceSnapshotStore } from 'stores/glance/instance-snapshot'; import { InstanceSnapshotStore } from 'stores/glance/instance-snapshot';
import {
getQuotaInfo,
checkQuotaDisable,
fetchQuota,
setCreateVolumeType,
onVolumeSizeChange,
onVolumeTypeChange,
} from 'resources/cinder/volume';
export class CreateVolume extends ModalAction { export class CreateVolume extends ModalAction {
static id = 'create'; static id = 'create';
@ -42,6 +50,22 @@ export class CreateVolume extends ModalAction {
static allowed = () => Promise.resolve(true); static allowed = () => Promise.resolve(true);
static get disableSubmit() {
return checkQuotaDisable();
}
static get showQuota() {
return true;
}
get showQuota() {
return true;
}
get quotaInfo() {
return getQuotaInfo(this);
}
async getVolumeTypes() { async getVolumeTypes() {
const { id } = this.item; const { id } = this.item;
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -53,6 +77,7 @@ export class CreateVolume extends ModalAction {
const typeItem = this.volumeTypes.find((it) => it.label === volumeType); const typeItem = this.volumeTypes.find((it) => it.label === volumeType);
if (typeItem) { if (typeItem) {
this.volumeType = typeItem.value; this.volumeType = typeItem.value;
setCreateVolumeType(volumeType);
} }
this.updateFormValue('volume_type', this.volumeType); this.updateFormValue('volume_type', this.volumeType);
} }
@ -60,9 +85,11 @@ export class CreateVolume extends ModalAction {
async getMinSize() { async getMinSize() {
const { id } = this.item; const { id } = this.item;
if (this.snapshot && this.snapshot.volume_size) { if (this.snapshot && this.snapshot.volume_size) {
fetchQuota(this, this.minSize);
return; return;
} }
await this.snapshotStore.fetchDetail({ id }); await this.snapshotStore.fetchDetail({ id });
fetchQuota(this, this.minSize);
this.updateDefaultValue(); this.updateDefaultValue();
} }
@ -134,6 +161,7 @@ export class CreateVolume extends ModalAction {
min: this.minSize, min: this.minSize,
extra: `${t('Min size')}: ${this.minSize}GiB`, extra: `${t('Min size')}: ${this.minSize}GiB`,
required: true, required: true,
onChange: onVolumeSizeChange,
}, },
{ {
name: 'more', name: 'more',
@ -147,6 +175,7 @@ export class CreateVolume extends ModalAction {
options: this.volumeTypes, options: this.volumeTypes,
placeholder: t('Please select volume type'), placeholder: t('Please select volume type'),
hidden: !more, hidden: !more,
onChange: onVolumeTypeChange,
}, },
]; ];
} }