From 1ab6cf9b348acb68898a4c20f3bdf5f470fdf685 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Thu, 15 Jul 2021 14:56:35 +0800 Subject: [PATCH] fix: Add error status for volume and polyfill allSettled 1. Add error status for update status in volume 2. Add allSettled polyfill Change-Id: I4d2cb54b3f4d57ce40806978c20191c101e864c0 --- src/components/Tables/Base/ActionButton/index.jsx | 4 ++-- src/locales/en.json | 2 +- src/locales/zh.json | 2 +- .../containers/Volume/actions/Create/index.jsx | 3 ++- .../containers/Volume/actions/UpdateStatus.jsx | 3 ++- src/utils/index.js | 13 +++++++++++++ 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/components/Tables/Base/ActionButton/index.jsx b/src/components/Tables/Base/ActionButton/index.jsx index e91343c6..ff505cf1 100644 --- a/src/components/Tables/Base/ActionButton/index.jsx +++ b/src/components/Tables/Base/ActionButton/index.jsx @@ -20,7 +20,7 @@ import Confirm from 'components/Confirm'; import PropTypes from 'prop-types'; import Notify from 'components/Notify'; import classnames from 'classnames'; -import { firstUpperCase } from 'utils/index'; +import { firstUpperCase, allSettled } from 'utils'; import styles from './index.less'; function getDefaultMsg(action, data) { @@ -323,7 +323,7 @@ class ActionButton extends Component { const promises = data.map((it, index) => onSubmit(it, containerProps, isBatch, index, data) ); - const results = Promise.allSettled(promises); + const results = allSettled(promises); results.then((res) => { const failedDatas = res .map((it, idx) => { diff --git a/src/locales/en.json b/src/locales/en.json index 80fc0b25..77d634b2 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -483,7 +483,7 @@ "Disk Info": "Disk Info", "Disk Tag": "Disk Tag", "Disk size is limited by the min disk of flavor, image, etc.": "Disk size is limited by the min disk of flavor, image, etc.", - "Do not reset the normally mounted volume to the \"available\" or \"maintenance\" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the \"detach\" operation.": "Do not reset the normally mounted volume to the \"available\" or \"maintenance\" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the \"detach\" operation.", + "Do not reset the normally mounted volume to the \"available\"、\"maintenance\" or \"error\" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the \"detach\" operation.": "Do not reset the normally mounted volume to the \"available\"、\"maintenance\" or \"error\" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the \"detach\" operation.", "Do not set with a backend": "Do not set with a backend", "Docker": "Docker", "Domain": "Domain", diff --git a/src/locales/zh.json b/src/locales/zh.json index 5aac4bd9..0dd1c357 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -483,7 +483,7 @@ "Disk Info": "硬盘信息", "Disk Tag": "硬盘标签", "Disk size is limited by the min disk of flavor, image, etc.": "根磁盘大小受云主机类型、镜像等的最小磁盘限制。", - "Do not reset the normally mounted volume to the \"available\" or \"maintenance\" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the \"detach\" operation.": "请勿将正常的挂载中的云硬盘重置为“可用”或“维护”状态。重置状态并不会将云硬盘从云主机上卸载下来。如果您需要将云硬盘从云主机上移除,请进入相应项目的控制台使用“解绑”操作。", + "Do not reset the normally mounted volume to the \"available\"、\"maintenance\" or \"error\" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the \"detach\" operation.": "请勿将正常的挂载中的云硬盘重置为“可用”、“维护”或”错误“状态。重置状态并不会将云硬盘从云主机上卸载下来。如果您需要将云硬盘从云主机上移除,请进入相应项目的控制台使用“解绑”操作。", "Do not set with a backend": "不设置后端", "Docker": "Docker", "Domain": "域", diff --git a/src/pages/storage/containers/Volume/actions/Create/index.jsx b/src/pages/storage/containers/Volume/actions/Create/index.jsx index ac79bdcf..0f742caf 100644 --- a/src/pages/storage/containers/Volume/actions/Create/index.jsx +++ b/src/pages/storage/containers/Volume/actions/Create/index.jsx @@ -35,6 +35,7 @@ import { canImageCreateInstance, } from 'resources/image'; import { volumeTypeSelectProps } from 'resources/volume-type'; +import { allSettled } from 'utils'; import styles from './index.less'; @inject('rootStore') @@ -568,7 +569,7 @@ export default class Create extends FormAction { if (count === 1) { return this.volumeStore.create(volume); } - return Promise.allSettled( + return allSettled( new Array(count).fill(count).map((_, index) => { const body = { ...volume, diff --git a/src/pages/storage/containers/Volume/actions/UpdateStatus.jsx b/src/pages/storage/containers/Volume/actions/UpdateStatus.jsx index 8284bfc1..2c8e594d 100644 --- a/src/pages/storage/containers/Volume/actions/UpdateStatus.jsx +++ b/src/pages/storage/containers/Volume/actions/UpdateStatus.jsx @@ -42,7 +42,7 @@ export default class UpdateStatus extends ModalAction { get tips() { return t( - 'Do not reset the normally mounted volume to the "available" or "maintenance" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the "detach" operation.' + 'Do not reset the normally mounted volume to the "available"、"maintenance" or "error" status. The reset state does not remove the volume from the instance. If you need to remove the volume from the instance, please go to the console of the corresponding project and use the "detach" operation.' ); } @@ -50,6 +50,7 @@ export default class UpdateStatus extends ModalAction { const statusList = [ { value: 'available', label: t('Available') }, { value: 'maintenance', label: t('Maintained') }, + { value: 'error', label: t('Error') }, ]; return [ { diff --git a/src/utils/index.js b/src/utils/index.js index 219c5837..ec176e49 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -271,3 +271,16 @@ export const unescapeHtml = (message) => { }; export const isAdminPage = (url) => url && url.indexOf('admin') >= 0; + +export const allSettled = (promises) => { + if (!Promise.allSettled) { + return Promise.all( + promises.map((promise) => + promise + .then((value) => ({ status: 'fulfilled', value })) + .catch((reason) => ({ status: 'rejected', reason })) + ) + ); + } + return Promise.allSettled(promises); +};