mirror of https://github.com/buster-so/buster.git
update copy for sharing
This commit is contained in:
parent
f99cbfb69f
commit
5a0cb079e3
|
@ -1,5 +1,5 @@
|
|||
import React, { useMemo } from 'react';
|
||||
import { ShareRole } from '@/api/asset_interfaces';
|
||||
import { ShareAssetType, ShareRole } from '@/api/asset_interfaces';
|
||||
import { DropdownItem, DropdownLabel } from '@/components/ui/dropdown';
|
||||
import { Paragraph, Text } from '@/components/ui/typography';
|
||||
import { useMemoizedFn } from '@/hooks';
|
||||
|
@ -15,11 +15,12 @@ export const AccessDropdown: React.FC<{
|
|||
showRemove?: boolean;
|
||||
shareLevel?: ShareRole | null;
|
||||
onChangeShareLevel?: (level: ShareRole | null) => void;
|
||||
}> = ({ shareLevel, showRemove = true, className = '', onChangeShareLevel }) => {
|
||||
assetType: ShareAssetType;
|
||||
}> = ({ shareLevel, showRemove = true, className = '', onChangeShareLevel, assetType }) => {
|
||||
const disabled = useMemo(() => canEdit(shareLevel), [shareLevel]);
|
||||
|
||||
const items = useMemo(() => {
|
||||
const baseItems: DropdownItem<DropdownValue>[] = [...standardItems];
|
||||
const baseItems: DropdownItem<DropdownValue>[] = [...(itemsRecord[assetType] || [])];
|
||||
|
||||
if (showRemove) {
|
||||
baseItems.push({
|
||||
|
@ -32,7 +33,7 @@ export const AccessDropdown: React.FC<{
|
|||
...item,
|
||||
selected: item.value === shareLevel
|
||||
}));
|
||||
}, [showRemove, shareLevel]);
|
||||
}, [showRemove, shareLevel, assetType]);
|
||||
|
||||
const selectedLabel = useMemo(() => {
|
||||
const selectedItem = items.find((item) => item.selected) || OWNER_ITEM;
|
||||
|
@ -92,7 +93,25 @@ export const AccessDropdown: React.FC<{
|
|||
);
|
||||
};
|
||||
|
||||
const standardItems: DropdownItem<ShareRole>[] = [
|
||||
const metricItems: DropdownItem<ShareRole>[] = [
|
||||
{
|
||||
value: ShareRole.FULL_ACCESS,
|
||||
label: 'Full access',
|
||||
secondaryLabel: 'Can edit and share with others.'
|
||||
},
|
||||
{
|
||||
value: ShareRole.CAN_EDIT,
|
||||
label: 'Can edit',
|
||||
secondaryLabel: 'Can edit but not share with others.'
|
||||
},
|
||||
{
|
||||
value: ShareRole.CAN_VIEW,
|
||||
label: 'Can view',
|
||||
secondaryLabel: 'Can view asset but not edit.'
|
||||
}
|
||||
];
|
||||
|
||||
const dashboardItems: DropdownItem<ShareRole>[] = [
|
||||
{
|
||||
value: ShareRole.FULL_ACCESS,
|
||||
label: 'Full access',
|
||||
|
@ -111,10 +130,35 @@ const standardItems: DropdownItem<ShareRole>[] = [
|
|||
{
|
||||
value: ShareRole.CAN_VIEW,
|
||||
label: 'Can view',
|
||||
secondaryLabel: 'Can view asset but not edit.'
|
||||
secondaryLabel: 'Can view dashboard and metrics but not edit.'
|
||||
}
|
||||
];
|
||||
|
||||
const collectionItems: DropdownItem<ShareRole>[] = [
|
||||
{
|
||||
value: ShareRole.FULL_ACCESS,
|
||||
label: 'Full access',
|
||||
secondaryLabel: 'Can edit and share with others.'
|
||||
},
|
||||
{
|
||||
value: ShareRole.CAN_EDIT,
|
||||
label: 'Can edit',
|
||||
secondaryLabel: 'Can edit but not share with others.'
|
||||
},
|
||||
{
|
||||
value: ShareRole.CAN_VIEW,
|
||||
label: 'Can view',
|
||||
secondaryLabel: 'Can view assets but not edit.'
|
||||
}
|
||||
];
|
||||
|
||||
const itemsRecord: Record<ShareAssetType, DropdownItem<ShareRole>[]> = {
|
||||
[ShareAssetType.DASHBOARD]: dashboardItems,
|
||||
[ShareAssetType.METRIC]: metricItems,
|
||||
[ShareAssetType.COLLECTION]: collectionItems,
|
||||
[ShareAssetType.CHAT]: collectionItems
|
||||
};
|
||||
|
||||
const OWNER_ITEM: DropdownItem<DropdownValue> = {
|
||||
value: ShareRole.OWNER,
|
||||
label: 'Owner',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Avatar } from '@/components/ui/avatar';
|
||||
import { AccessDropdown } from './AccessDropdown';
|
||||
import React from 'react';
|
||||
import { ShareRole } from '@/api/asset_interfaces';
|
||||
import { ShareAssetType, ShareRole } from '@/api/asset_interfaces';
|
||||
import { Text } from '@/components/ui/typography';
|
||||
import { useMemoizedFn } from '@/hooks';
|
||||
|
||||
|
@ -10,7 +10,8 @@ export const IndividualSharePerson: React.FC<{
|
|||
email: string;
|
||||
role: ShareRole;
|
||||
onUpdateShareRole: (email: string, role: ShareRole | null) => void;
|
||||
}> = React.memo(({ name, onUpdateShareRole, email, role }) => {
|
||||
assetType: ShareAssetType;
|
||||
}> = React.memo(({ name, onUpdateShareRole, email, role, assetType }) => {
|
||||
const isSameEmailName = name === email;
|
||||
|
||||
const onChangeShareLevel = useMemoizedFn((v: ShareRole | null) => {
|
||||
|
@ -36,7 +37,12 @@ export const IndividualSharePerson: React.FC<{
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<AccessDropdown shareLevel={role} showRemove={true} onChangeShareLevel={onChangeShareLevel} />
|
||||
<AccessDropdown
|
||||
shareLevel={role}
|
||||
showRemove={true}
|
||||
onChangeShareLevel={onChangeShareLevel}
|
||||
assetType={assetType}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -177,6 +177,7 @@ const ShareMenuContentShare: React.FC<ShareMenuContentBodyProps> = React.memo(
|
|||
className="absolute top-[50%] right-[10px] -translate-y-1/2"
|
||||
shareLevel={defaultPermissionLevel}
|
||||
onChangeShareLevel={onChangeAccessDropdown}
|
||||
assetType={assetType}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
@ -197,6 +198,7 @@ const ShareMenuContentShare: React.FC<ShareMenuContentBodyProps> = React.memo(
|
|||
key={permission.email}
|
||||
{...permission}
|
||||
onUpdateShareRole={onUpdateShareRole}
|
||||
assetType={assetType}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue