From f50df3da8dbace6b347565bf17088e62525e41c2 Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Wed, 15 Sep 2021 16:07:37 +0800 Subject: [PATCH] feat: Refactor project list page 1. Refactor project list page 2. Remove useless func Change-Id: I65ae489bf29e61e9745a987c0a42d9aeafc97014 --- src/components/Tables/Base/index.jsx | 23 ------ .../identity/containers/Domain/index.jsx | 8 -- .../identity/containers/Project/index.jsx | 78 +++++++++---------- src/pages/identity/containers/Role/index.jsx | 8 -- 4 files changed, 35 insertions(+), 82 deletions(-) diff --git a/src/components/Tables/Base/index.jsx b/src/components/Tables/Base/index.jsx index 634dcab4..a5d9c85b 100644 --- a/src/components/Tables/Base/index.jsx +++ b/src/components/Tables/Base/index.jsx @@ -705,29 +705,6 @@ export default class BaseTable extends React.Component { ); } - - // if (searchType === 'keyword') { - // const placeholder = - // this.props.placeholder || t('Please input a keyword to find'); - - // return ( - //
- // - // {/* */} - //
- // ); - // } - // return null; return (
[ { title: t('Domain ID/Name'), diff --git a/src/pages/identity/containers/Project/index.jsx b/src/pages/identity/containers/Project/index.jsx index aec7d65e..6cd71faa 100644 --- a/src/pages/identity/containers/Project/index.jsx +++ b/src/pages/identity/containers/Project/index.jsx @@ -16,14 +16,18 @@ import React from 'react'; import { observer, inject } from 'mobx-react'; import { Divider, Badge, Tag, Tooltip } from 'antd'; import Base from 'containers/List'; -import globalProjectStore from 'stores/keystone/project'; -import { yesNoOptions, projectTagsColors } from 'utils/constants'; +import globalProjectStore, { ProjectStore } from 'stores/keystone/project'; +import { + yesNoOptions, + projectTagsColors, + emptyActionConfig, +} from 'utils/constants'; import actionConfigs from './actions'; import styles from './index.less'; export class Projects extends Base { init() { - this.store = globalProjectStore; + this.store = this.inDetailPage ? new ProjectStore() : globalProjectStore; } get tabs() { @@ -42,19 +46,23 @@ export class Projects extends Base { return false; } - getTableProps() { - const baseProps = Base.prototype.getTableProps.call(this); - return { - ...baseProps, - searchType: 'keyword', - }; + get inProject() { + const { pathname } = this.props.location; + return pathname.includes('project-admin'); } - getColumns = () => { - const { - match: { path }, - } = this.props; - const components = [ + get inUserDetail() { + const { pathname } = this.props.location; + return this.inDetailPage && pathname.includes('user-admin/detail'); + } + + get inUserGroupDetail() { + const { pathname } = this.props.location; + return this.inDetailPage && pathname.includes('user-group-admin/detail'); + } + + getColumns() { + const columns = [ { title: t('Project ID/Name'), dataIndex: 'name', @@ -64,17 +72,13 @@ export class Projects extends Base { title: t('Role'), dataIndex: 'projectRole', render: (roles, value) => { - const rolesAll = [...(roles || [])]; - if (value.groupProjectRole) { - rolesAll.push(...value.groupProjectRole); - } + const { groupProjectRole = [] } = value; + const rolesAll = [...(roles || []), ...(groupProjectRole || [])]; return (rolesAll || []).map((it) =>
{it}
); }, stringify: (roles, value) => { - const rolesAll = [...(roles || [])]; - if (value.groupProjectRole) { - rolesAll.push(...value.groupProjectRole); - } + const { groupProjectRole = [] } = value; + const rolesAll = [...(roles || []), ...(groupProjectRole || [])]; return (rolesAll || []).join(';'); }, }, @@ -154,26 +158,16 @@ export class Projects extends Base { }, ]; - if (path.indexOf('project-admin') >= 0) { - components.splice(1, 1); + if (this.inProject) { + return columns.filter((it) => it.dataIndex !== 'projectRole'); } - return components; - }; + return columns; + } get actionConfigs() { - const { - match: { path }, - } = this.props; - if ( - path.indexOf('user-admin/detail') >= 0 || - path.indexOf('user-group-admin/detail') >= 0 - ) { - return { - batchActions: [], - primaryActions: [], - rowActions: [], - }; + if (this.inUserDetail || this.inUserGroupDetail) { + return emptyActionConfig; } return actionConfigs; } @@ -202,15 +196,13 @@ export class Projects extends Base { async getData({ silent, ...params } = {}) { const { match } = this.props; - const { path } = match; + const { id } = match.params || {}; const newParams = { ...params }; silent && (this.list.silent = true); - if (path.indexOf('user-admin/detail') >= 0) { - const { id } = match.params; + if (this.inUserDetail) { newParams.userId = id; await this.store.fetchListInUserDetail(newParams); - } else if (path.indexOf('user-group-admin/detail') >= 0) { - const { id } = match.params; + } else if (this.inUserGroupDetail) { newParams.groupId = id; await this.store.fetchListInGroupDetail(newParams); } else { diff --git a/src/pages/identity/containers/Role/index.jsx b/src/pages/identity/containers/Role/index.jsx index 271e130e..1bd41ffd 100644 --- a/src/pages/identity/containers/Role/index.jsx +++ b/src/pages/identity/containers/Role/index.jsx @@ -41,14 +41,6 @@ export default class Role extends Base { return false; } - getTableProps() { - const baseProps = Base.prototype.getTableProps.call(this); - return { - ...baseProps, - searchType: 'keyword', - }; - } - getColumns = () => [ { title: t('Role Name'),