From b3d0c9b1e6dcc0a3ccc47c46dfaeb3df4f79a907 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Wed, 20 Jul 2022 11:11:35 +0800 Subject: [PATCH] feat: support edit for trove instance 1. Support edit for trove instance 2. Fix the menu items name of trove instance 3. Fix the title of create trove instance Change-Id: If9448e8e20f547079e0ab6071d3828cf549e2173 --- src/layouts/menu.jsx | 6 +- src/locales/en.json | 4 +- src/locales/zh.json | 2 + .../containers/Instances/actions/Edit.jsx | 56 +++++++++++++++++++ .../Instances/actions/StepCreate/index.jsx | 6 +- .../containers/Instances/actions/index.jsx | 10 +++- src/resources/skyline/policy.js | 1 + 7 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 src/pages/database/containers/Instances/actions/Edit.jsx diff --git a/src/layouts/menu.jsx b/src/layouts/menu.jsx index 12796045..18746114 100644 --- a/src/layouts/menu.jsx +++ b/src/layouts/menu.jsx @@ -550,20 +550,20 @@ const renderMenu = (t) => { children: [ { path: '/database/instances', - name: t('Instances'), + name: t('Database Instance'), key: 'databaseInstances', level: 1, children: [ { path: /^\/database\/instances\/detail\/.[^/]+$/, - name: t('Instance Detail'), + name: t('Database Instance Detail'), key: 'databaseInstanceDetail', level: 2, routePath: '/database/instances/detail/:id', }, { path: '/database/instances/create', - name: t('Create Instance'), + name: t('Create Database Instance'), key: 'databaseInstanceCreate', level: 2, }, diff --git a/src/locales/en.json b/src/locales/en.json index f5f307b4..97da7ab6 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -460,6 +460,7 @@ "Create DNAT rule": "Create DNAT rule", "Create DSCP Marking Rule": "Create DSCP Marking Rule", "Create Database": "Create Database", + "Create Database Instance": "Create Database Instance", "Create Default Pool": "Create Default Pool", "Create Domain": "Create Domain", "Create Encryption": "Create Encryption", @@ -584,6 +585,7 @@ "Data Source Type": "Data Source Type", "Database": "Database", "Database Instance": "Database Instance", + "Database Instance Detail": "Database Instance Detail", "Database Name": "Database Name", "Database Port": "Database Port", "Database Service": "Database Service", @@ -2236,7 +2238,7 @@ "The instance deleted immediately cannot be restored": "The instance deleted immediately cannot be restored", "The instance has been locked. If you want to do more, please unlock it first.": "The instance has been locked. If you want to do more, please unlock it first.", "The instance is not shut down, unable to restore.": "The instance is not shut down, unable to restore.", - "The instance which is boot from volume will create snapshots for each mounted volumes": "The instance which is boot from volume will create snapshots for each mounted volumes", + "The instance which is boot from volume will create snapshots for each mounted volumes.": "The instance which is boot from volume will create snapshots for each mounted volumes.", "The instances in the affinity group are allocated to the same physical machine as much as possible, and when there are no more physical machines to allocate, the normal allocation strategy is returned.": "The instances in the affinity group are allocated to the same physical machine as much as possible, and when there are no more physical machines to allocate, the normal allocation strategy is returned.", "The instances in the affinity group are strictly allocated to the same physical machine. When there are no more physical machines to allocate, the allocation fails.": "The instances in the affinity group are strictly allocated to the same physical machine. When there are no more physical machines to allocate, the allocation fails.", "The instances in the anti-affinity group are allocated to different physical machines as much as possible. When there are no more physical machines to allocate, the normal allocation strategy is returned.": "The instances in the anti-affinity group are allocated to different physical machines as much as possible. When there are no more physical machines to allocate, the normal allocation strategy is returned.", diff --git a/src/locales/zh.json b/src/locales/zh.json index d3f15f8a..c7cb04ac 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -460,6 +460,7 @@ "Create DNAT rule": "创建DNAT规则", "Create DSCP Marking Rule": "创建DSCP标记规则", "Create Database": "创建数据库", + "Create Database Instance": "创建数据库实例", "Create Default Pool": "创建资源池", "Create Domain": "创建域", "Create Encryption": "创建加密", @@ -584,6 +585,7 @@ "Data Source Type": "数据源类型", "Database": "数据库", "Database Instance": "数据库实例", + "Database Instance Detail": "数据库实例详情", "Database Name": "数据库名称", "Database Port": "数据库端口", "Database Service": "数据库服务", diff --git a/src/pages/database/containers/Instances/actions/Edit.jsx b/src/pages/database/containers/Instances/actions/Edit.jsx new file mode 100644 index 00000000..d39b9179 --- /dev/null +++ b/src/pages/database/containers/Instances/actions/Edit.jsx @@ -0,0 +1,56 @@ +// 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 globalTroveInstanceStore from 'stores/trove/instances'; + +export class Edit extends ModalAction { + static id = 'edit-instance'; + + static title = t('Edit'); + + static buttonText = t('Edit'); + + static policy = 'instance:update'; + + static allowed() { + return Promise.resolve(true); + } + + get formItems() { + return [ + { + name: 'name', + label: t('Name'), + type: 'input', + required: true, + placeholder: t('Please input name'), + }, + ]; + } + + onSubmit = (values) => { + const { name } = values; + const body = { + instance: { + name, + }, + }; + const { id } = this.item; + return globalTroveInstanceStore.patch({ id }, body); + }; +} + +export default inject('rootStore')(observer(Edit)); diff --git a/src/pages/database/containers/Instances/actions/StepCreate/index.jsx b/src/pages/database/containers/Instances/actions/StepCreate/index.jsx index 6d232811..5e96c74c 100644 --- a/src/pages/database/containers/Instances/actions/StepCreate/index.jsx +++ b/src/pages/database/containers/Instances/actions/StepCreate/index.jsx @@ -25,9 +25,9 @@ export class StepCreate extends StepAction { this.store = globalInstancesStore; } - static id = 'create-instance'; + static id = 'create-database-instance'; - static title = t('Create Instance'); + static title = t('Create Database Instance'); static path = '/database/instances/create'; @@ -38,7 +38,7 @@ export class StepCreate extends StepAction { } get name() { - return t('Create Instance'); + return t('Create Database Instance'); } get listUrl() { diff --git a/src/pages/database/containers/Instances/actions/index.jsx b/src/pages/database/containers/Instances/actions/index.jsx index acad611f..7f531fea 100644 --- a/src/pages/database/containers/Instances/actions/index.jsx +++ b/src/pages/database/containers/Instances/actions/index.jsx @@ -13,13 +13,19 @@ // limitations under the License. import Delete from './Delete'; -import StepCreate from './StepCreate'; +import Create from './StepCreate'; +import Edit from './Edit'; const actionConfigs = { rowActions: { firstAction: Delete, + moreActions: [ + { + action: Edit, + }, + ], }, - primaryActions: [StepCreate], + primaryActions: [Create], batchActions: [Delete], }; diff --git a/src/resources/skyline/policy.js b/src/resources/skyline/policy.js index af30ea48..a7d9d06a 100644 --- a/src/resources/skyline/policy.js +++ b/src/resources/skyline/policy.js @@ -77,6 +77,7 @@ export const policyMap = { trove: [ 'instance:create', 'instance:delete', + 'instance:update', 'instance:backups', 'instance:resize', 'instance:extension',