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