2025-02-02 12:53:01 +08:00
|
|
|
import type {
|
2025-01-11 07:10:50 +08:00
|
|
|
ListPermissionGroupsResponse,
|
2025-02-02 12:53:01 +08:00
|
|
|
ListPermissionUsersResponse
|
|
|
|
} from '@/api/asset_interfaces';
|
|
|
|
import { useDatasetUpdatePermissionUsers } from '@/api/buster_rest/datasets';
|
2025-01-24 01:20:01 +08:00
|
|
|
import {
|
|
|
|
BusterListColumn,
|
|
|
|
BusterListRowItem,
|
|
|
|
EmptyStateList,
|
|
|
|
InfiniteListContainer
|
2025-02-20 10:53:49 +08:00
|
|
|
} from '@/components/ui/list';
|
|
|
|
import { BusterInfiniteList } from '@/components/ui/list/BusterInfiniteList';
|
2025-01-11 07:10:50 +08:00
|
|
|
import { useMemoizedFn } from 'ahooks';
|
|
|
|
import { Select } from 'antd';
|
|
|
|
import React, { useMemo, useState } from 'react';
|
2025-01-18 03:10:23 +08:00
|
|
|
import { PermissionUsersSelectedPopup } from './PermissionUsersSelectedPopup';
|
|
|
|
import { PERMISSION_USERS_OPTIONS } from './config';
|
2025-01-18 11:20:47 +08:00
|
|
|
import { BusterRoutes, createBusterRoute } from '@/routes';
|
2025-03-01 03:05:32 +08:00
|
|
|
import { ListUserItem } from '@/components/features/list';
|
2025-01-11 07:10:50 +08:00
|
|
|
|
|
|
|
export const PermissionListUsersContainer: React.FC<{
|
|
|
|
filteredPermissionUsers: ListPermissionUsersResponse[];
|
|
|
|
datasetId: string;
|
|
|
|
}> = React.memo(({ filteredPermissionUsers, datasetId }) => {
|
2025-01-15 01:30:13 +08:00
|
|
|
const { mutateAsync: updatePermissionUsers } = useDatasetUpdatePermissionUsers(datasetId);
|
2025-01-11 07:10:50 +08:00
|
|
|
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
|
|
|
|
|
|
|
const numberOfPermissionUsers = filteredPermissionUsers.length;
|
|
|
|
|
|
|
|
const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }) => {
|
|
|
|
updatePermissionUsers([params]);
|
|
|
|
});
|
|
|
|
|
|
|
|
const columns: BusterListColumn[] = useMemo(
|
|
|
|
() => [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
width: 270,
|
|
|
|
render: (name: string, user: ListPermissionUsersResponse) => {
|
2025-01-21 06:32:59 +08:00
|
|
|
return <ListUserItem name={name} email={user.email} />;
|
2025-01-11 07:10:50 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Assigned',
|
|
|
|
dataIndex: 'assigned',
|
|
|
|
render: (assigned: boolean, permissionGroup: ListPermissionGroupsResponse) => {
|
|
|
|
return (
|
|
|
|
<div className="flex justify-end">
|
|
|
|
<PermissionGroupAssignedCell
|
|
|
|
id={permissionGroup.id}
|
|
|
|
assigned={assigned}
|
|
|
|
onSelect={onSelectAssigned}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
const { cannotQueryPermissionUsers, canQueryPermissionUsers } = useMemo(() => {
|
|
|
|
const result: {
|
|
|
|
cannotQueryPermissionUsers: BusterListRowItem[];
|
|
|
|
canQueryPermissionUsers: BusterListRowItem[];
|
|
|
|
} = filteredPermissionUsers.reduce<{
|
|
|
|
cannotQueryPermissionUsers: BusterListRowItem[];
|
|
|
|
canQueryPermissionUsers: BusterListRowItem[];
|
|
|
|
}>(
|
|
|
|
(acc, permissionUser) => {
|
2025-01-18 11:20:47 +08:00
|
|
|
const user: BusterListRowItem = {
|
|
|
|
id: permissionUser.id,
|
|
|
|
data: permissionUser,
|
|
|
|
link: createBusterRoute({
|
|
|
|
route: BusterRoutes.APP_SETTINGS_USERS_ID,
|
|
|
|
userId: permissionUser.id
|
|
|
|
})
|
|
|
|
};
|
2025-01-11 07:10:50 +08:00
|
|
|
if (permissionUser.assigned) {
|
2025-01-18 11:20:47 +08:00
|
|
|
acc.canQueryPermissionUsers.push(user);
|
2025-01-11 07:10:50 +08:00
|
|
|
} else {
|
2025-01-18 11:20:47 +08:00
|
|
|
acc.cannotQueryPermissionUsers.push(user);
|
2025-01-11 07:10:50 +08:00
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cannotQueryPermissionUsers: [] as BusterListRowItem[],
|
|
|
|
canQueryPermissionUsers: [] as BusterListRowItem[]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return result;
|
|
|
|
}, [filteredPermissionUsers]);
|
|
|
|
|
|
|
|
const rows = useMemo(
|
2025-01-24 01:20:01 +08:00
|
|
|
() => [
|
|
|
|
{
|
|
|
|
id: 'header-assigned',
|
|
|
|
data: {},
|
|
|
|
hidden: canQueryPermissionUsers.length === 0,
|
|
|
|
rowSection: {
|
|
|
|
title: 'Assigned',
|
|
|
|
secondaryTitle: canQueryPermissionUsers.length.toString()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
...canQueryPermissionUsers,
|
|
|
|
{
|
|
|
|
id: 'header-not-assigned',
|
|
|
|
data: {},
|
|
|
|
hidden: cannotQueryPermissionUsers.length === 0,
|
|
|
|
rowSection: {
|
|
|
|
title: 'Not Assigned',
|
|
|
|
secondaryTitle: cannotQueryPermissionUsers.length.toString()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
...cannotQueryPermissionUsers
|
|
|
|
],
|
2025-01-11 07:10:50 +08:00
|
|
|
[canQueryPermissionUsers, cannotQueryPermissionUsers, numberOfPermissionUsers]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2025-01-18 12:28:49 +08:00
|
|
|
<InfiniteListContainer
|
2025-01-18 03:10:23 +08:00
|
|
|
popupNode={
|
|
|
|
<PermissionUsersSelectedPopup
|
|
|
|
datasetId={datasetId}
|
|
|
|
selectedRowKeys={selectedRowKeys}
|
|
|
|
onSelectChange={setSelectedRowKeys}
|
|
|
|
/>
|
|
|
|
}>
|
2025-01-11 07:10:50 +08:00
|
|
|
<BusterInfiniteList
|
|
|
|
columns={columns}
|
|
|
|
rows={rows}
|
|
|
|
showHeader={false}
|
|
|
|
showSelectAll={false}
|
|
|
|
selectedRowKeys={selectedRowKeys}
|
|
|
|
onSelectChange={setSelectedRowKeys}
|
2025-01-18 11:20:47 +08:00
|
|
|
useRowClickSelectChange={false}
|
2025-01-24 01:20:01 +08:00
|
|
|
emptyState={<EmptyStateList text="No users found" />}
|
2025-01-11 07:10:50 +08:00
|
|
|
/>
|
2025-01-18 12:28:49 +08:00
|
|
|
</InfiniteListContainer>
|
2025-01-11 07:10:50 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
PermissionListUsersContainer.displayName = 'PermissionListUsersContainer';
|
|
|
|
|
2025-01-18 03:10:23 +08:00
|
|
|
const PermissionGroupAssignedCell: React.FC<{
|
|
|
|
id: string;
|
|
|
|
assigned: boolean;
|
|
|
|
onSelect: (value: { id: string; assigned: boolean }) => void;
|
|
|
|
}> = ({ id, assigned, onSelect }) => {
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
options={PERMISSION_USERS_OPTIONS}
|
|
|
|
value={assigned}
|
|
|
|
popupMatchSelectWidth
|
|
|
|
onSelect={(value) => {
|
|
|
|
onSelect({ id, assigned: value });
|
|
|
|
}}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|