From 4acc62915a96842a0c998d6a194d8078b63f599f Mon Sep 17 00:00:00 2001 From: zhuyue Date: Thu, 30 Sep 2021 16:47:10 +0800 Subject: [PATCH] feat: add confirm & revert resize action add confirm & revert resize action Change-Id: I2f6efddfe5cd8902a9a38d4af26ef762fea77b4d --- src/locales/en.json | 4 ++ src/locales/zh.json | 4 ++ .../Instance/actions/ConfirmResize.jsx | 57 +++++++++++++++++++ .../Instance/actions/RevertResize.jsx | 50 ++++++++++++++++ .../containers/Instance/actions/index.jsx | 11 +++- 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/pages/compute/containers/Instance/actions/ConfirmResize.jsx create mode 100644 src/pages/compute/containers/Instance/actions/RevertResize.jsx diff --git a/src/locales/en.json b/src/locales/en.json index ec99f05e..b07ca38f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -275,6 +275,7 @@ "Confirm": "Confirm", "Confirm Config": "Confirm Config", "Confirm Password": "Confirm Password", + "Confirm Resize or Migrate": "Confirm Resize or Migrate", "Confirm Shared Key": "Confirm Shared Key", "Confirming Resize or Migrate": "Confirming Resize or Migrate", "Connect Subnet": "Connect Subnet", @@ -1344,6 +1345,7 @@ "Resume Instance": "Resume Instance", "Resuming": "Resuming", "Retyping": "Retyping", + "Revert Resize or Migrate": "Revert Resize or Migrate", "Revert Resize/Migrate": "Revert Resize/Migrate", "Reverting": "Reverting", "Reverting Resize or Migrate": "Reverting Resize or Migrate", @@ -1789,6 +1791,7 @@ "cinder services": "cinder services", "compute hosts": "compute hosts", "compute services": "compute services", + "confirm resize or migrate": "confirm resize or migrate", "connect subnet": "connect subnet", "create DSCP marking rule": "create DSCP marking rule", "create a new network/subnet": "create a new network/subnet", @@ -1930,6 +1933,7 @@ "remove router": "remove router", "resize": "resize", "resume instance": "resume instance", + "revert resize or migrate": "revert resize or migrate", "role": "role", "roles": "roles", "router": "router", diff --git a/src/locales/zh.json b/src/locales/zh.json index 184cdc20..d4dc581a 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -275,6 +275,7 @@ "Confirm": "确定", "Confirm Config": "确认配置", "Confirm Password": "确认密码", + "Confirm Resize or Migrate": "确认修改配置/迁移", "Confirm Shared Key": "确认共享密钥", "Confirming Resize or Migrate": "确认修改配置/迁移", "Connect Subnet": "连接子网", @@ -1344,6 +1345,7 @@ "Resume Instance": "恢复云主机", "Resuming": "恢复中", "Retyping": "修改类型中", + "Revert Resize or Migrate": "回滚修改配置/迁移", "Revert Resize/Migrate": "回滚修改配置/迁移", "Reverting": "恢复中", "Reverting Resize or Migrate": "正在回滚修改配置/迁移", @@ -1789,6 +1791,7 @@ "cinder services": "存储服务", "compute hosts": "计算节点", "compute services": "计算服务", + "confirm resize or migrate": "确认修改配置/迁移", "connect subnet": "连接子网", "create DSCP marking rule": "创建DSCP标记规则", "create a new network/subnet": "新建网络/子网", @@ -1930,6 +1933,7 @@ "remove router": "移除路由器", "resize": "更改配置", "resume instance": "恢复云主机", + "revert resize or migrate": "回滚修改配置/迁移", "role": "角色", "roles": "角色", "router": "路由器", diff --git a/src/pages/compute/containers/Instance/actions/ConfirmResize.jsx b/src/pages/compute/containers/Instance/actions/ConfirmResize.jsx new file mode 100644 index 00000000..0aacc816 --- /dev/null +++ b/src/pages/compute/containers/Instance/actions/ConfirmResize.jsx @@ -0,0 +1,57 @@ +// Copyright 2021 99cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { ConfirmAction } from 'containers/Action'; +import globalServerStore from 'stores/nova/instance'; + +export default class ConfirmResizeAction extends ConfirmAction { + get id() { + return 'confirm_resize_migrate'; + } + + get title() { + return t('Confirm Resize or Migrate'); + } + + get buttonText() { + return t('Confirm Resize or Migrate'); + } + + get actionName() { + return t('confirm resize or migrate'); + } + + policy = 'os_compute_api:servers:resize'; + + allowedCheckFunc = (item) => { + if (!item) { + return true; + } + return item.status.toLowerCase() === 'verify_resize'; + }; + + confirmContext = (data) => { + const name = this.getName(data); + return t(`${this.actionNameDisplay} (instance: {name})?`, { + name, + }); + }; + + onSubmit = (item) => { + const { id } = item || this.item; + return globalServerStore.update(id, { + confirmResize: null, + }); + }; +} diff --git a/src/pages/compute/containers/Instance/actions/RevertResize.jsx b/src/pages/compute/containers/Instance/actions/RevertResize.jsx new file mode 100644 index 00000000..8d6a7e6c --- /dev/null +++ b/src/pages/compute/containers/Instance/actions/RevertResize.jsx @@ -0,0 +1,50 @@ +// Copyright 2021 99cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { ConfirmAction } from 'containers/Action'; +import globalServerStore from 'stores/nova/instance'; + +export default class RevertResizeAction extends ConfirmAction { + get id() { + return 'revert_resize_migrate'; + } + + get title() { + return t('Revert Resize or Migrate'); + } + + get buttonText() { + return t('Revert Resize or Migrate'); + } + + get actionName() { + return t('revert resize or migrate'); + } + + policy = 'os_compute_api:servers:resize'; + + allowedCheckFunc = (item) => { + if (!item) { + return true; + } + return item.status.toLowerCase() === 'verify_resize'; + }; + + onSubmit = (item) => { + const { id } = item || this.item; + return globalServerStore.update(id, { + revertResize: null, + }); + }; +} diff --git a/src/pages/compute/containers/Instance/actions/index.jsx b/src/pages/compute/containers/Instance/actions/index.jsx index 80c55422..28d899fa 100644 --- a/src/pages/compute/containers/Instance/actions/index.jsx +++ b/src/pages/compute/containers/Instance/actions/index.jsx @@ -46,6 +46,8 @@ import LiveMigrate from './LiveMigrate'; import AssociateFip from './AssociateFip'; import ManageSecurityGroup from './ManageSecurityGroup'; import DeleteIronic from './DeleteIronic'; +import ConfirmResize from './ConfirmResize'; +import RevertResize from './RevertResize'; const statusActions = [ StartAction, @@ -72,7 +74,14 @@ const resourceActions = [ ManageSecurityGroup, ]; -const configActions = [Resize, ResizeOnline, ChangePassword, Rebuild]; +const configActions = [ + ConfirmResize, + RevertResize, + Resize, + ResizeOnline, + ChangePassword, + Rebuild, +]; const batchActions = [ StartAction,