mirror of https://github.com/buster-so/buster.git
update owner items
This commit is contained in:
parent
8e6387d2a9
commit
a70b7c0ca6
|
@ -61,10 +61,6 @@ export type DashboardUpdateRequest = {
|
|||
add_to_collections?: string[];
|
||||
/** Collection IDs to remove the dashboard from */
|
||||
remove_from_collections?: string[];
|
||||
/** User IDs to remove access from */
|
||||
remove_users?: string[];
|
||||
/** Array of metric IDs associated with the dashboard */
|
||||
metrics?: string[];
|
||||
/** The file content of the dashboard */
|
||||
file?: string;
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ import { useMemoizedFn } from '@/hooks';
|
|||
import { Dropdown } from '@/components/ui/dropdown';
|
||||
import { ChevronDown } from '@/components/ui/icons/NucleoIconFilled';
|
||||
import { canEdit } from '@/lib/share';
|
||||
import { cn } from '@/lib/classMerge';
|
||||
|
||||
type DropdownValue = ShareRole | 'remove' | 'notShared';
|
||||
|
||||
|
@ -25,7 +26,7 @@ export const AccessDropdown: React.FC<{
|
|||
const disabled = useMemo(() => canEdit(shareLevel), [shareLevel]);
|
||||
|
||||
const items = useMemo(() => {
|
||||
const baseItems: DropdownItem<DropdownValue>[] = [...standardItems];
|
||||
const baseItems: DropdownItem<DropdownValue>[] = standardItems;
|
||||
|
||||
if (groupShare) {
|
||||
baseItems.push({
|
||||
|
@ -46,11 +47,12 @@ export const AccessDropdown: React.FC<{
|
|||
}, [groupShare, showRemove, shareLevel]);
|
||||
|
||||
const selectedLabel = useMemo(() => {
|
||||
const selectedItem = items.find((item) => item.selected);
|
||||
if (!selectedItem) return 'No shared';
|
||||
const selectedItem = items.find((item) => item.selected) || OWNER_ITEM;
|
||||
|
||||
const { value } = selectedItem;
|
||||
|
||||
console.log(selectedItem, shareLevel);
|
||||
|
||||
// Using a type-safe switch to handle all ShareRole values
|
||||
switch (value) {
|
||||
case ShareRole.FULL_ACCESS:
|
||||
|
@ -62,13 +64,11 @@ export const AccessDropdown: React.FC<{
|
|||
case ShareRole.CAN_VIEW:
|
||||
return 'Can view';
|
||||
case ShareRole.OWNER:
|
||||
return 'Full access';
|
||||
return 'Owner';
|
||||
case 'remove':
|
||||
return 'Remove';
|
||||
case 'notShared':
|
||||
return 'Not shared';
|
||||
default:
|
||||
return typeof selectedItem.label === 'string' ? selectedItem.label : 'Selected';
|
||||
}
|
||||
}, [items]);
|
||||
|
||||
|
@ -83,6 +83,7 @@ export const AccessDropdown: React.FC<{
|
|||
return (
|
||||
<Dropdown
|
||||
items={items}
|
||||
disabled={disabled}
|
||||
footerContent={<FooterContent />}
|
||||
footerClassName="p-0!"
|
||||
onSelect={onSelectMenuItem}
|
||||
|
@ -93,9 +94,13 @@ export const AccessDropdown: React.FC<{
|
|||
<Text
|
||||
variant="secondary"
|
||||
size="xs"
|
||||
className={`flex! cursor-pointer items-center! space-x-1 ${className}`}>
|
||||
className={cn('flex! items-center! space-x-1', !disabled && 'cursor-pointer', className)}>
|
||||
<span className="truncate">{selectedLabel}</span>
|
||||
<span className="text-2xs">{!disabled && <ChevronDown />}</span>
|
||||
{!disabled && (
|
||||
<span className="text-2xs text-icon-color">
|
||||
<ChevronDown />
|
||||
</span>
|
||||
)}
|
||||
</Text>
|
||||
</Dropdown>
|
||||
);
|
||||
|
@ -124,6 +129,12 @@ const standardItems: DropdownItem<ShareRole>[] = [
|
|||
}
|
||||
];
|
||||
|
||||
const OWNER_ITEM: DropdownItem<DropdownValue> = {
|
||||
value: ShareRole.OWNER,
|
||||
label: 'Owner',
|
||||
secondaryLabel: 'Owner of the asset.'
|
||||
};
|
||||
|
||||
const FooterContent = React.memo(() => {
|
||||
return (
|
||||
<div className="bg-item-hover flex justify-center overflow-hidden rounded-b p-2 px-2.5">
|
||||
|
|
|
@ -192,7 +192,7 @@ const ShareMenuContentShare: React.FC<ShareMenuContentBodyProps> = React.memo(
|
|||
)}
|
||||
|
||||
{hasIndividualPermissions && (
|
||||
<div className="flex flex-col space-y-2 overflow-hidden px-3">
|
||||
<div className="flex flex-col space-y-2 overflow-hidden">
|
||||
{individual_permissions?.map((permission) => (
|
||||
<IndividualSharePerson
|
||||
key={permission.email}
|
||||
|
|
|
@ -65,6 +65,7 @@ export interface DropdownProps<T = string> extends DropdownMenuProps {
|
|||
contentClassName?: string;
|
||||
footerClassName?: string;
|
||||
sideOffset?: number;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface DropdownContentProps<T = string>
|
||||
|
@ -95,7 +96,8 @@ export const DropdownBase = <T,>({
|
|||
modal,
|
||||
sideOffset,
|
||||
footerClassName = '',
|
||||
showIndex = false
|
||||
showIndex = false,
|
||||
disabled = false
|
||||
}: DropdownProps<T>) => {
|
||||
return (
|
||||
<DropdownMenu
|
||||
|
@ -104,7 +106,7 @@ export const DropdownBase = <T,>({
|
|||
onOpenChange={onOpenChange}
|
||||
dir={dir}
|
||||
modal={modal}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<DropdownMenuTrigger asChild disabled={disabled}>
|
||||
<span className="dropdown-trigger">{children}</span>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
|
|
Loading…
Reference in New Issue