From bc39f976a32b948be09f8003079e9fc962e4a2ab Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Mon, 16 May 2022 10:36:49 +0800 Subject: [PATCH] feat: Support force-delete && reset-status share istance 1. Support force delete share instance 2. Support reset share instance status Change-Id: I4ddc2c8b023c92e02b3f40406c4342cbd7e4f2c5 --- src/locales/en.json | 2 + src/locales/zh.json | 2 + .../containers/ShareInstance/Detail/index.jsx | 5 ++ .../ShareInstance/actions/Delete.jsx | 42 +++++++++ .../ShareInstance/actions/ResetStatus.jsx | 89 +++++++++++++++++++ .../ShareInstance/actions/index.jsx | 31 +++++++ .../share/containers/ShareInstance/index.jsx | 5 ++ src/stores/manila/share-instance.js | 17 ++++ 8 files changed, 193 insertions(+) create mode 100644 src/pages/share/containers/ShareInstance/actions/Delete.jsx create mode 100644 src/pages/share/containers/ShareInstance/actions/ResetStatus.jsx create mode 100644 src/pages/share/containers/ShareInstance/actions/index.jsx diff --git a/src/locales/en.json b/src/locales/en.json index 7ee8cb51..e3501fc8 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -836,6 +836,8 @@ "Forbidden Project": "Forbidden Project", "Forbidden User": "Forbidden User", "Forbidden the domain will have a negative impact, all project and user in domain will be forbidden": "Forbidden the domain will have a negative impact, all project and user in domain will be forbidden", + "Force Delete": "Force Delete", + "Force Delete Share Instance": "Force Delete Share Instance", "Force release": "Force release", "Forced Shutdown": "Forced Shutdown", "Forced shutdown may result in data loss or file system damage. You can also take the initiative to shut down and perform operations.": "Forced shutdown may result in data loss or file system damage. You can also take the initiative to shut down and perform operations.", diff --git a/src/locales/zh.json b/src/locales/zh.json index 3b848a7a..0779c47e 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -836,6 +836,8 @@ "Forbidden Project": "禁用项目", "Forbidden User": "禁用用户", "Forbidden the domain will have a negative impact, all project and user in domain will be forbidden": "禁用域后,该域下面的项目和用户都会被禁止,用户将无法登陆", + "Force Delete": "强制删除", + "Force Delete Share Instance": "强制删除共享实例", "Force release": "强制释放", "Forced Shutdown": "强制关机", "Forced shutdown may result in data loss or file system damage. You can also take the initiative to shut down and perform operations.": "强制关机可能会导致数据丢失或文件系统损坏,您也可以主动关机后再进行操作。", diff --git a/src/pages/share/containers/ShareInstance/Detail/index.jsx b/src/pages/share/containers/ShareInstance/Detail/index.jsx index 03357354..87c8857e 100644 --- a/src/pages/share/containers/ShareInstance/Detail/index.jsx +++ b/src/pages/share/containers/ShareInstance/Detail/index.jsx @@ -17,6 +17,7 @@ import { ShareInstanceStore } from 'stores/manila/share-instance'; import Base from 'containers/TabDetail'; import { shareStatus } from 'resources/manila/share'; import BaseDetail from './BaseDetail'; +import actionConfigs from '../actions'; export class Detail extends Base { get name() { @@ -31,6 +32,10 @@ export class Detail extends Base { return this.getRoutePath('shareInstance'); } + get actionConfigs() { + return actionConfigs; + } + get detailInfos() { return [ { diff --git a/src/pages/share/containers/ShareInstance/actions/Delete.jsx b/src/pages/share/containers/ShareInstance/actions/Delete.jsx new file mode 100644 index 00000000..3d932eb2 --- /dev/null +++ b/src/pages/share/containers/ShareInstance/actions/Delete.jsx @@ -0,0 +1,42 @@ +// 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 globalShareInstanceStore from 'stores/manila/share-instance'; + +export default class Delete extends ConfirmAction { + get id() { + return 'delete'; + } + + get title() { + return t('Force Delete Share Instance'); + } + + get buttonType() { + return 'danger'; + } + + get buttonText() { + return t('Force Delete'); + } + + get actionName() { + return t('Force Delete Share Instance'); + } + + policy = 'manila:share_instance:force_delete'; + + onSubmit = (data) => globalShareInstanceStore.forceDelete(data); +} diff --git a/src/pages/share/containers/ShareInstance/actions/ResetStatus.jsx b/src/pages/share/containers/ShareInstance/actions/ResetStatus.jsx new file mode 100644 index 00000000..4eddc2ae --- /dev/null +++ b/src/pages/share/containers/ShareInstance/actions/ResetStatus.jsx @@ -0,0 +1,89 @@ +// 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 { inject, observer } from 'mobx-react'; +import { ModalAction } from 'containers/Action'; +import globalShareInstanceStore from 'stores/manila/share-instance'; +import { shareStatus } from 'resources/manila/share'; +import { getOptions } from 'utils/index'; + +export class ResetStatus extends ModalAction { + static id = 'reset'; + + static title = t('Reset Status'); + + get name() { + return t('Reset Status'); + } + + get defaultValue() { + const { id, status } = this.item; + const value = { + id, + oldStatus: shareStatus[status] || status, + }; + return value; + } + + get instanceName() { + return (this.item || {}).id; + } + + static policy = 'manila:share_instance:reset_status'; + + static allowed = () => Promise.resolve(true); + + get statusOptions() { + const statusList = ['available', 'error']; + const { status } = this.item; + const leftStatusList = statusList.filter((it) => it !== status); + const options = getOptions(shareStatus).filter((it) => + leftStatusList.includes(it.value) + ); + return options; + } + + get formItems() { + return [ + { + name: 'id', + label: t('Share Instance'), + type: 'label', + iconType: 'instance', + }, + { + name: 'oldStatus', + label: t('Current Status'), + type: 'label', + }, + { + name: 'status', + label: t('New Status'), + type: 'select', + options: this.statusOptions, + }, + ]; + } + + init() { + this.store = globalShareInstanceStore; + } + + onSubmit = (values) => { + const { id } = this.item; + return this.store.resetStatus(id, values); + }; +} + +export default inject('rootStore')(observer(ResetStatus)); diff --git a/src/pages/share/containers/ShareInstance/actions/index.jsx b/src/pages/share/containers/ShareInstance/actions/index.jsx new file mode 100644 index 00000000..9391cb9e --- /dev/null +++ b/src/pages/share/containers/ShareInstance/actions/index.jsx @@ -0,0 +1,31 @@ +// 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 Delete from './Delete'; +import ResetStatus from './ResetStatus'; + +const actionConfigs = { + rowActions: { + firstAction: Delete, + moreActions: [ + { + action: ResetStatus, + }, + ], + }, + primaryActions: [], + batchActions: [Delete], +}; + +export default actionConfigs; diff --git a/src/pages/share/containers/ShareInstance/index.jsx b/src/pages/share/containers/ShareInstance/index.jsx index f13fa168..fca2fdc9 100644 --- a/src/pages/share/containers/ShareInstance/index.jsx +++ b/src/pages/share/containers/ShareInstance/index.jsx @@ -16,6 +16,7 @@ import { observer, inject } from 'mobx-react'; import Base from 'containers/List'; import globalShareInstanceStore from 'stores/manila/share-instance'; import { shareStatus } from 'resources/manila/share'; +import actionConfigs from './actions'; export class ShareInstance extends Base { init() { @@ -34,6 +35,10 @@ export class ShareInstance extends Base { return false; } + get actionConfigs() { + return actionConfigs; + } + getColumns = () => [ { title: t('ID'), diff --git a/src/stores/manila/share-instance.js b/src/stores/manila/share-instance.js index 8f902cf0..b4657f9e 100644 --- a/src/stores/manila/share-instance.js +++ b/src/stores/manila/share-instance.js @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { action } from 'mobx'; import client from 'client'; import Base from 'stores/base'; @@ -32,6 +33,22 @@ export class ShareInstanceStore extends Base { item.exportLocations = export_locations; return item; } + + @action + forceDelete = ({ id }) => { + const body = { + force_delete: null, + }; + return this.submitting(this.client.action(id, body)); + }; + + @action + resetStatus(id, data) { + const body = { + reset_status: data, + }; + return this.submitting(this.client.action(id, body)); + } } const globalShareInstanceStore = new ShareInstanceStore();