From 221a4a62804b088f9506835d4e77c116cbb71054 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 17 Jan 2025 10:50:10 -0700 Subject: [PATCH] finalize permission popup Co-Authored-By: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- .../_CollectionIndividualHeader.tsx | 5 +- .../PermissionGroupSelectedPopup.tsx | 55 +++++++++++++++++-- ...PermissionListPermissionGroupContainer.tsx | 24 ++++---- .../_PermissionPermissionGroup/config.tsx | 10 ++++ .../BusterInfiniteList/BusterInfiniteList.tsx | 36 ++++++------ .../BusterList/BusterListRowComponent.tsx | 44 +++++++++++---- .../BusterListRowComponentSelector.tsx | 5 +- .../list/BusterList/BusterListVirtua.tsx | 16 +++++- .../components/list/BusterList/interfaces.ts | 1 + 9 files changed, 140 insertions(+), 56 deletions(-) create mode 100644 web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/config.tsx diff --git a/web/src/app/app/collections/[collectionId]/_CollectionIndividualHeader.tsx b/web/src/app/app/collections/[collectionId]/_CollectionIndividualHeader.tsx index c9b8cb3c5..81509cf7b 100644 --- a/web/src/app/app/collections/[collectionId]/_CollectionIndividualHeader.tsx +++ b/web/src/app/app/collections/[collectionId]/_CollectionIndividualHeader.tsx @@ -8,7 +8,6 @@ import { useIndividualCollection } from '@/context/Collections'; import { Breadcrumb, Button, Dropdown, MenuProps } from 'antd'; -import { BreadcrumbSeperator } from '@/components'; import Link from 'next/link'; import { useAppLayoutContextSelector } from '@/context/BusterAppLayout'; import { BusterRoutes } from '@/routes'; @@ -19,10 +18,10 @@ import { ShareMenu } from '../../_components/ShareMenu'; import { BusterCollection } from '@/api/buster-rest/collection'; import { BusterShareAssetType } from '@/api/buster-rest'; import { Text } from '@/components'; - import { useAntToken } from '@/styles/useAntToken'; -import { measureTextWidth } from '@/utils'; import { useMemoizedFn } from 'ahooks'; +import { BreadcrumbSeperator } from '@/components/breadcrumb'; +import { measureTextWidth } from '@/utils/canvas'; export const CollectionsIndividualHeader: React.FC<{}> = () => { const selectedThreadId = useBusterThreadsContextSelector((x) => x.selectedThreadId); diff --git a/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionGroupSelectedPopup.tsx b/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionGroupSelectedPopup.tsx index 70e5c979f..2df574bce 100644 --- a/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionGroupSelectedPopup.tsx +++ b/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionGroupSelectedPopup.tsx @@ -1,11 +1,16 @@ import { BusterListSelectedOptionPopupContainer } from '@/components/list'; -import { Button } from 'antd'; -import React from 'react'; +import { Button, Dropdown, MenuProps } from 'antd'; +import React, { useMemo } from 'react'; +import { PERMISSION_GROUP_ASSIGNED_OPTIONS } from './config'; +import { useMemoizedFn } from 'ahooks'; +import { useDatasetUpdatePermissionGroups } from '@/api/buster-rest'; +import { AppMaterialIcons } from '@/components/icons'; export const PermissionGroupSelectedPopup: React.FC<{ selectedRowKeys: string[]; + datasetId: string; onSelectChange: (selectedRowKeys: string[]) => void; -}> = React.memo(({ selectedRowKeys, onSelectChange }) => { +}> = React.memo(({ selectedRowKeys, onSelectChange, datasetId }) => { return ( ]} @@ -26,6 +32,45 @@ PermissionGroupSelectedPopup.displayName = 'PermissionGroupSelectedPopup'; const PermissionGroupAssignButton: React.FC<{ selectedRowKeys: string[]; onSelectChange: (selectedRowKeys: string[]) => void; -}> = ({ selectedRowKeys, onSelectChange }) => { - return ; + datasetId: string; +}> = ({ selectedRowKeys, onSelectChange, datasetId }) => { + const { mutateAsync: updatePermissionGroups, isPending } = + useDatasetUpdatePermissionGroups(datasetId); + + const onClickItem = useMemoizedFn(async (assigned: boolean) => { + try { + await updatePermissionGroups( + selectedRowKeys.map((id) => ({ + id, + assigned + })) + ); + onSelectChange([]); + } catch (error) { + // + } + }); + + const menu: MenuProps = useMemo(() => { + return { + items: PERMISSION_GROUP_ASSIGNED_OPTIONS.map((option) => ({ + label: option.label, + key: option.value ? 'true' : 'false', + icon: option.value ? ( + + ) : ( + + ), + onClick: () => { + onClickItem(option.value); + } + })) + }; + }, []); + + return ( + + + + ); }; diff --git a/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionListPermissionGroupContainer.tsx b/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionListPermissionGroupContainer.tsx index 2ac24299b..b6329118c 100644 --- a/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionListPermissionGroupContainer.tsx +++ b/web/src/app/app/datasets/[datasetId]/permissions/_PermissionPermissionGroup/PermissionListPermissionGroupContainer.tsx @@ -10,6 +10,7 @@ import React, { useMemo, useState } from 'react'; import { Text } from '@/components/text'; import { PermissionGroupSelectedPopup } from './PermissionGroupSelectedPopup'; import { BusterInfiniteList } from '@/components/list/BusterInfiniteList'; +import { PERMISSION_GROUP_ASSIGNED_OPTIONS } from './config'; export const PermissionListPermissionGroupContainer: React.FC<{ filteredPermissionGroups: ListPermissionGroupsResponse[]; @@ -121,11 +122,13 @@ export const PermissionListPermissionGroupContainer: React.FC<{ selectedRowKeys={selectedRowKeys} onSelectChange={setSelectedRowKeys} emptyState={} + useRowClickSelectChange={true} /> -
+
@@ -149,18 +152,7 @@ const PermissionGroupInfoCell = React.memo(({ name }: { name: string }) => { }); PermissionGroupInfoCell.displayName = 'PermissionGroupInfoCell'; -const options = [ - { - label: 'Assigned', - value: true - }, - { - label: 'Not Assigned', - value: false - } -]; - -const PermissionGroupAssignedCell = React.memo( +export const PermissionGroupAssignedCell = React.memo( ({ id, assigned, @@ -172,9 +164,13 @@ const PermissionGroupAssignedCell = React.memo( }) => { return (