fix: Fix for project tag filter & switch project

1. fix for project tag filter
2. can not switch to project that disabled

Change-Id: I82805e2d408de21c8026c59f90a9a1addd823d67
This commit is contained in:
zhuyue 2021-09-01 16:48:58 +08:00
parent e4de1c12b3
commit b2f798a359
2 changed files with 23 additions and 12 deletions

View File

@ -14,8 +14,8 @@
import { inject, observer } from 'mobx-react'; import { inject, observer } from 'mobx-react';
import { ModalAction } from 'containers/Action'; import { ModalAction } from 'containers/Action';
import { toJS } from 'mobx';
import { allCanReadPolicy } from 'resources/policy'; import { allCanReadPolicy } from 'resources/policy';
import globalUserStore from 'stores/keystone/user';
@inject('rootStore') @inject('rootStore')
@observer @observer
@ -26,7 +26,14 @@ export default class ProjectSelect extends ModalAction {
static buttonText = ' '; static buttonText = ' ';
init() {} init() {
this.getAllUserProjects();
}
async getAllUserProjects() {
await globalUserStore.getUserProjects();
this.updateDefaultValue();
}
get name() { get name() {
return t('Switch Project'); return t('Switch Project');
@ -73,16 +80,15 @@ export default class ProjectSelect extends ModalAction {
} }
get projects() { get projects() {
const { projects = {} } = this.user || {};
const { projectName } = this.state; const { projectName } = this.state;
const items = Object.keys(toJS(projects) || {}) const { data: projects } = globalUserStore.userProjects;
.map((key) => { const items = projects
const { name, domain_id } = projects[key]; .map((project) => {
const { id, ...rest } = project;
return { return {
id: key, id,
projectId: key, projectId: id,
name, ...rest,
domain_id,
}; };
}) })
.filter((it) => { .filter((it) => {
@ -102,6 +108,7 @@ export default class ProjectSelect extends ModalAction {
return { return {
project: { project: {
selectedRowKeys: [projectId], selectedRowKeys: [projectId],
selectedRows: this.projects.filter((i) => i.id === projectId),
}, },
}; };
} }
@ -113,6 +120,8 @@ export default class ProjectSelect extends ModalAction {
label: t('Owned Project'), label: t('Owned Project'),
type: 'select-table', type: 'select-table',
datas: this.projects, datas: this.projects,
isLoading: globalUserStore.userProjects.isLoading,
disabledFunc: (record) => !record.enabled,
filterParams: [ filterParams: [
{ {
label: t('Project Name'), label: t('Project Name'),

View File

@ -195,8 +195,10 @@ export default class Projects extends Base {
{ {
label: t('Tags'), label: t('Tags'),
name: 'tags', name: 'tags',
filterFunc: (val, filterVal) => filterFunc: (val, filterVal) => {
val.some((tag) => tag.includes(filterVal)), const lFilterVal = filterVal.toLowerCase();
return val.some((tag) => tag.toLowerCase().includes(lFilterVal));
},
}, },
]; ];
} }