From 4a4ad26a499a64382ea0eb1e2b0ea837677ff09c Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Fri, 22 Apr 2022 17:27:10 +0800 Subject: [PATCH] fix: Fix create share group type 1. Add share types select when create share group type 2. Add share types column in share group type list page Change-Id: I729e8120fa2017b277ce6987508c1fc1eca75dc1 --- src/locales/en.json | 1 + src/locales/zh.json | 1 + .../ShareGroupType/actions/Create.jsx | 62 +++++++++++++++++-- .../share/containers/ShareGroupType/index.jsx | 8 +++ src/stores/manila/share-group-type.js | 21 +++++++ 5 files changed, 88 insertions(+), 5 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index c2570fcb..c2a366d9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1777,6 +1777,7 @@ "Share Server": "Share Server", "Share Type": "Share Type", "Share Type Detail": "Share Type Detail", + "Share Types": "Share Types", "Shared": "Shared", "Shared Image": "Shared Image", "Shared Network": "Shared Network", diff --git a/src/locales/zh.json b/src/locales/zh.json index e228d008..d74cbc36 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1777,6 +1777,7 @@ "Share Server": "共享服务器", "Share Type": "共享类型", "Share Type Detail": "共享类型详情", + "Share Types": "共享类型", "Shared": "共享", "Shared Image": "共享镜像", "Shared Network": "共享网络", diff --git a/src/pages/share/containers/ShareGroupType/actions/Create.jsx b/src/pages/share/containers/ShareGroupType/actions/Create.jsx index 4fa6a095..0e0670f8 100644 --- a/src/pages/share/containers/ShareGroupType/actions/Create.jsx +++ b/src/pages/share/containers/ShareGroupType/actions/Create.jsx @@ -15,6 +15,7 @@ import { inject, observer } from 'mobx-react'; import { ModalAction } from 'containers/Action'; import globalShareGroupTypeStore from '@/stores/manila/share-group-type'; +import globalShareTypeStore from '@/stores/manila/share-type'; import { projectTableOptions } from 'resources/project'; import { ProjectStore } from 'stores/keystone/project'; import { updateAddSelectValueToObj } from 'utils/index'; @@ -31,10 +32,16 @@ export class Create extends ModalAction { init() { this.store = globalShareGroupTypeStore; + this.typeStore = globalShareTypeStore; this.projectStore = new ProjectStore(); + this.getTypes(); this.getProjects(); } + getTypes() { + this.typeStore.fetchList({ is_public: 'all' }); + } + getProjects() { this.projectStore.fetchList(); } @@ -56,15 +63,19 @@ export class Create extends ModalAction { } get nameForStateUpdate() { - return ['isPublic']; + return ['is_public']; } get defaultValue() { return { is_public: true }; } + get shareTypes() { + return globalShareTypeStore.list.data || []; + } + get formItems() { - const { isPublic } = this.state; + const { is_public } = this.state; return [ { name: 'name', @@ -73,6 +84,37 @@ export class Create extends ModalAction { names: this.store.list.data.map((it) => it.name), required: true, }, + { + name: 'shareTypes', + label: t('Share Types'), + type: 'select-table', + required: true, + isMulti: true, + data: this.shareTypes, + isLoading: globalShareTypeStore.list.isLoading, + filterParams: [ + { + label: t('Name'), + name: 'name', + }, + ], + columns: [ + { + title: t('Name'), + dataIndex: 'name', + }, + { + title: t('Description'), + dataIndex: 'description', + valueRender: 'noValue', + }, + { + title: t('Public'), + dataIndex: 'is_public', + valueRender: 'yesNo', + }, + ], + }, { name: 'is_public', label: t('Public'), @@ -85,7 +127,7 @@ export class Create extends ModalAction { label: t('Access Control'), type: 'select-table', isMulti: true, - hidden: isPublic, + hidden: is_public, data: this.projects, isLoading: this.projectStore.list.isLoading, ...projectTableOptions, @@ -95,8 +137,18 @@ export class Create extends ModalAction { } onSubmit = (values) => { - const { is_public, accessControl = {}, extra = [], ...rest } = values; - const body = { is_public, ...rest }; + const { + is_public, + accessControl = {}, + extra = [], + shareTypes, + ...rest + } = values; + const body = { + is_public, + share_types: shareTypes.selectedRowKeys, + ...rest, + }; let projectIds = []; const extraSpecs = updateAddSelectValueToObj(extra); body.group_specs = extraSpecs; diff --git a/src/pages/share/containers/ShareGroupType/index.jsx b/src/pages/share/containers/ShareGroupType/index.jsx index d485e386..71b64149 100644 --- a/src/pages/share/containers/ShareGroupType/index.jsx +++ b/src/pages/share/containers/ShareGroupType/index.jsx @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import React from 'react'; import { observer, inject } from 'mobx-react'; import Base from 'containers/List'; import globalShareGroupTypeStore from '@/stores/manila/share-group-type'; @@ -56,6 +57,13 @@ export class ShareGroupType extends Base { dataIndex: 'is_public', valueRender: 'yesNo', }, + { + title: t('Share Types'), + dataIndex: 'shareTypes', + render: (value) => { + return (value || []).map((it) =>
{it.name}
); + }, + }, ]; } diff --git a/src/stores/manila/share-group-type.js b/src/stores/manila/share-group-type.js index 6775c90f..0c593941 100644 --- a/src/stores/manila/share-group-type.js +++ b/src/stores/manila/share-group-type.js @@ -24,6 +24,10 @@ export class ShareGroupTypeStore extends Base { return client.manila.shareGroupTypes; } + get shareTypeClient() { + return client.manila.types; + } + get paramsFunc() { return (params) => params; } @@ -41,6 +45,23 @@ export class ShareGroupTypeStore extends Base { return this.addProjectAccess(id, projectIds); } + async listDidFetch(items) { + if (!items.length) { + return items; + } + const result = await this.shareTypeClient.list({ is_public: 'all' }); + const { share_types: types = [] } = result; + return items.map((it) => { + const { share_types = [] } = it; + return { + ...it, + shareTypes: share_types.map((typeId) => + types.find((t) => t.id === typeId) + ), + }; + }); + } + @action update(id, data) { const body = {};