Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] fix: role and member users issues in clusters / workspaces / projects #4330

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import React, { useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import type { ListPageProps, Column, FormattedUser, FormattedRole } from '@ks-console/shared';
import {
Column,
FormattedUser,
formatTime,
hasPermission,
StatusIndicator,
Expand All @@ -18,7 +17,6 @@ import {
MemberModifyModal,
InviteMemberPayload,
EditMemberRoleValue,
FormattedRole,
useActionMenu,
ListPage,
useCommonActions,
Expand Down Expand Up @@ -51,7 +49,7 @@ function Members() {

const { isOpen: isCreateOpen, open: openCreate, close: closeCreate } = useDisclosure(false);
const { isOpen: isEditOpen, open: openEdit, close: closeEdit } = useDisclosure(false);
const { data: allUserList } = useAllUserListQuery();
const { data: allUserList, refetch: refetchAllUserList } = useAllUserListQuery();

const { del } = useCommonActions({
store: userStore,
Expand All @@ -78,14 +76,17 @@ function Members() {
action: 'view',
});

const { data: roles = [] } = useQuery<FormattedRole[]>(['clusterroles'], async () => {
const res = await fetchList({
...params,
limit: -1,
annotation: 'kubesphere.io/creator',
} as any);
return res.data;
});
const { data: roles = [], refetch: refetchRoles } = useQuery<FormattedRole[]>(
['clusterroles'],
async () => {
const res = await fetchList({
...params,
limit: -1,
annotation: 'kubesphere.io/creator',
} as any);
return res.data;
},
);

const { mutate: mutateEditUser, isLoading: isEditLoading } = useEditUserMutation(
{
Expand Down Expand Up @@ -254,7 +255,7 @@ function Members() {
description: t('INVITE_CLUSTER_MEMBER_DESC'),
};

const table = {
const table: { ref: typeof tableRef } & ListPageProps['table'] = {
ref: tableRef,
columns: columns,
tableName: 'members',
Expand All @@ -264,6 +265,10 @@ function Members() {
disableRowSelect: (row: any) => isCurrentUser(row),
toolbarRight: renderTableAction({}),
serverDataFormat: serverDataFormatter,
onRefresh: () => {
refetchAllUserList();
refetchRoles();
},
};

return (
Expand Down
43 changes: 24 additions & 19 deletions packages/console/src/pages/projects/containers/Members/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import React, { useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import type { ListPageProps, Column, FormattedUser, FormattedRole } from '@ks-console/shared';
import {
Column,
FormattedUser,
formatTime,
hasPermission,
StatusIndicator,
Expand All @@ -18,7 +17,6 @@ import {
MemberModifyModal,
InviteMemberPayload,
EditMemberRoleValue,
FormattedRole,
useActionMenu,
ListPage,
useCommonActions,
Expand All @@ -45,7 +43,7 @@ function Members() {
const params: Record<string, any> = useParams();
const [editUser, setEditUser] = useState<FormattedUser>();
const [rolesMap, setRolesMap] = useState<Record<string, string>>({});
const { data: allUserList } = useAllUserListQuery();
const { data: allUserList, refetch: refetchAllUserList } = useAllUserListQuery();

const { isOpen: isCreateOpen, open: openCreate, close: closeCreate } = useDisclosure(false);
const { isOpen: isEditOpen, open: openEdit, close: closeEdit } = useDisclosure(false);
Expand All @@ -63,19 +61,22 @@ function Members() {
action: 'view',
});

const { data: roles = [] } = useQuery<FormattedRole[]>(['memberRoles'], async () => {
const res = await fetchList({
...params,
limit: -1,
annotation: 'kubesphere.io/creator',
} as any);
const maps: Record<string, string> = {};
res.data.forEach((item: any) => {
maps[item.name] = item.aliasName ? `${item.aliasName}(${item.name})` : item.name;
});
setRolesMap(maps);
return res.data;
});
const { data: roles = [], refetch: refetchRoles } = useQuery<FormattedRole[]>(
['memberRoles'],
async () => {
const res = await fetchList({
...params,
limit: -1,
annotation: 'kubesphere.io/creator',
} as any);
const maps: Record<string, string> = {};
res.data.forEach((item: any) => {
maps[item.name] = item.aliasName ? `${item.aliasName}(${item.name})` : item.name;
});
setRolesMap(maps);
return res.data;
},
);

const { mutate: mutateEditUser, isLoading: isEditLoading } = useEditUserMutation(
{
Expand Down Expand Up @@ -239,9 +240,9 @@ function Members() {
description: t('PROJECT_MEMBER_DESC'),
};

const table = {
url: getResourceUrl(params),
const table: { ref: typeof tableRef } & ListPageProps['table'] = {
ref: tableRef,
url: getResourceUrl(params),
columns: columns,
tableName: 'members',
rowKey: 'name',
Expand All @@ -250,6 +251,10 @@ function Members() {
disableRowSelect: (row: any) => isCurrentUser(row),
toolbarRight: renderTableAction({}),
serverDataFormat: serverDataFormatter,
onRefresh: () => {
refetchAllUserList();
refetchRoles();
},
};

return (
Expand Down
43 changes: 24 additions & 19 deletions packages/console/src/pages/workspaces/containers/Members/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import React, { useRef, useState } from 'react';
import { Link, useParams } from 'react-router-dom';
import type { ListPageProps, Column, FormattedUser, FormattedRole } from '@ks-console/shared';
import {
Column,
FormattedUser,
formatTime,
hasPermission,
StatusIndicator,
Expand All @@ -18,7 +17,6 @@ import {
MemberModifyModal,
InviteMemberPayload,
EditMemberRoleValue,
FormattedRole,
useActionMenu,
ListPage,
useCommonActions,
Expand All @@ -45,7 +43,7 @@ function Members() {
const params: Record<string, any> = useParams();
const [editUser, setEditUser] = useState<FormattedUser>();
const [rolesMap, setRolesMap] = useState<Record<string, string>>({});
const { data: allUserList } = useAllUserListQuery();
const { data: allUserList, refetch: refetchAllUserList } = useAllUserListQuery();

const { isOpen: isCreateOpen, open: openCreate, close: closeCreate } = useDisclosure(false);
const { isOpen: isEditOpen, open: openEdit, close: closeEdit } = useDisclosure(false);
Expand All @@ -63,19 +61,22 @@ function Members() {
action: 'view',
});

const { data: roles = [] } = useQuery<FormattedRole[]>(['memberRoles'], async () => {
const res = await fetchList({
...params,
limit: -1,
annotation: 'kubesphere.io/creator',
} as any);
const maps: Record<string, string> = {};
res.data.forEach((item: any) => {
maps[item.name] = item.aliasName ? `${item.aliasName}(${item.name})` : item.name;
});
setRolesMap(maps);
return res.data;
});
const { data: roles = [], refetch: refetchRoles } = useQuery<FormattedRole[]>(
['memberRoles'],
async () => {
const res = await fetchList({
...params,
limit: -1,
annotation: 'kubesphere.io/creator',
} as any);
const maps: Record<string, string> = {};
res.data.forEach((item: any) => {
maps[item.name] = item.aliasName ? `${item.aliasName}(${item.name})` : item.name;
});
setRolesMap(maps);
return res.data;
},
);

const { mutate: mutateEditUser, isLoading: isEditLoading } = useEditUserMutation(
{
Expand Down Expand Up @@ -239,9 +240,9 @@ function Members() {
description: t('WORKSPACE_MEMBER_DESC'),
};

const table = {
url: getResourceUrl(params),
const table: { ref: typeof tableRef } & ListPageProps['table'] = {
ref: tableRef,
url: getResourceUrl(params),
columns: columns,
tableName: 'members',
rowKey: 'name',
Expand All @@ -250,6 +251,10 @@ function Members() {
disableRowSelect: (row: any) => isCurrentUser(row),
toolbarRight: renderTableAction({}),
serverDataFormat: serverDataFormatter,
onRefresh: () => {
refetchAllUserList();
refetchRoles();
},
};

return (
Expand Down
Loading
Loading