Skip to content

Commit

Permalink
fix: allow void and Promises for action function (context menu)
Browse files Browse the repository at this point in the history
  • Loading branch information
masterprog-cmd committed Sep 25, 2024
1 parent 7433a90 commit d6d18d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ const contextMenuSelectedItems = ({
}): ListItemMenu<DriveItemData> => [
{
name: `${selectedItems.length} ${t('contextMenu.itemsSelected')}`,
action: () => ({}),
action: () => {},
disabled: () => {
return true;
},
},
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveItemMenuItem(moveItems),
getDownloadMenuItem(downloadItems),
{ name: '', action: () => false, separator: true },
Expand Down Expand Up @@ -178,13 +178,13 @@ const contextMenuDriveNotSharedLink = ({
}): ListItemMenu<DriveItemData> => [
shareLinkMenuItem(shareLink),
getCopyLinkMenuItem(getLink),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
openPreview && getOpenPreviewMenuItem(openPreview),
showDetailsMenuItem(showDetails),
getRenameMenuItem(renameItem),
getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -207,12 +207,12 @@ const contextMenuDriveFolderNotSharedLink = ({
}): ListItemMenu<DriveItemData> => [
shareLinkMenuItem(shareLink),
getCopyLinkMenuItem(getLink),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
showDetailsMenuItem(showDetails),
getRenameMenuItem(renameItem),
getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -236,13 +236,13 @@ const contextMenuDriveItemShared = ({
moveToTrash: (item: DriveItemData | (ListShareLinksItem & { code: string })) => void;
}): ListItemMenu<DriveItemData | (ListShareLinksItem & { code: string })> => [
...[manageLinkAccessMenuItem(openShareAccessSettings), getCopyLinkMenuItem(copyLink)],
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
openPreview && getOpenPreviewMenuItem(openPreview),
showDetailsMenuItem(showDetails),
getRenameMenuItem(renameItem),
getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -264,12 +264,12 @@ const contextMenuDriveFolderShared = ({
moveToTrash: (item: DriveItemData | (ListShareLinksItem & { code: string })) => void;
}): ListItemMenu<DriveItemData | (ListShareLinksItem & { code: string })> => [
...[manageLinkAccessMenuItem(openShareAccessSettings), getCopyLinkMenuItem(copyLink)],
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
showDetailsMenuItem(showDetails),
getRenameMenuItem(renameItem),
getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -281,7 +281,7 @@ const contextMenuMultipleSharedView = ({
moveToTrash: (item: ListShareLinksItem) => void;
}): ListItemMenu<ListShareLinksItem> => [
getDownloadMenuItem(downloadItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -296,7 +296,7 @@ const contextMenuTrashItems = ({
}): ListItemMenu<DriveItemData> => [
openPreview && getOpenPreviewMenuItem(openPreview),
getRestoreMenuItem(restoreItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getDeletePermanentlyMenuItem(deletePermanently),
];

Expand All @@ -308,7 +308,7 @@ const contextMenuTrashFolder = ({
deletePermanently: (item: DriveItemData) => void;
}): ListItemMenu<DriveItemData> => [
getRestoreMenuItem(restoreItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getDeletePermanentlyMenuItem(deletePermanently),
];

Expand All @@ -320,7 +320,7 @@ const contextMenuMultipleSelectedTrashItems = ({
deletePermanently: (item: DriveItemData) => void;
}): ListItemMenu<DriveItemData> => [
getRestoreMenuItem(restoreItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getDeletePermanentlyMenuItem(deletePermanently),
];

Expand All @@ -337,9 +337,7 @@ const contextMenuBackupItems = ({
action: () => {
onDeviceDeleted(selectedDevices);
},
disabled: () => {
return false;
},
disabled: () => false,
},
];

Expand All @@ -351,7 +349,7 @@ const contextMenuSelectedBackupItems = ({
onDeleteSelectedItems: () => Promise<void>;
}): ListItemMenu<unknown> => [
getDownloadMenuItem(onDownloadSelectedItems),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
{
name: t('drive.dropdown.delete'),
icon: Trash,
Expand Down Expand Up @@ -397,7 +395,7 @@ const contextMenuDriveItemSharedAFS = ({
renameItem && getRenameMenuItem(renameItem),
moveItem && getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
moveToTrash && { name: '', action: () => false, separator: true },
moveToTrash && { name: '', action: () => {}, separator: true },
moveToTrash && getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -419,12 +417,12 @@ const contextMenuDriveFolderSharedAFS = ({
moveToTrash?: (item: any) => void;
}): ListItemMenu<any> => [
openShareAccessSettings && manageLinkAccessMenuItem(openShareAccessSettings),
openShareAccessSettings && { name: '', action: () => false, separator: true },
openShareAccessSettings && { name: '', action: () => {}, separator: true },
showDetailsMenuItem(showDetails),
renameItem && getRenameMenuItem(renameItem),
moveItem && getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
moveToTrash && { name: '', action: () => false, separator: true },
moveToTrash && { name: '', action: () => {}, separator: true },
moveToTrash && getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -436,7 +434,7 @@ const contextMenuMultipleSharedViewAFS = ({
moveToTrash?: (item: AdvancedSharedItem) => void;
}): ListItemMenu<AdvancedSharedItem> => [
getDownloadMenuItem(downloadItem),
moveToTrash && { name: '', action: () => false, separator: true },
moveToTrash && { name: '', action: () => {}, separator: true },
moveToTrash && getMoveToTrashMenuItem(moveToTrash),
];

Expand All @@ -462,12 +460,12 @@ const contextMenuWorkspaceFolder = ({
shareLinkMenuItem(shareLink),
getCopyLinkMenuItem(getLink),
shareWithTeamMenuItem(shareWithTeam),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
showDetailsMenuItem(showDetails),
getRenameMenuItem(renameItem),
getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveToTrashMenuItem(moveToTrash),
];

Expand Down Expand Up @@ -495,13 +493,13 @@ const contextMenuWorkspaceFile = ({
shareLinkMenuItem(shareLink),
getCopyLinkMenuItem(getLink),
shareWithTeamMenuItem(shareWithTeam),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
openPreview && getOpenPreviewMenuItem(openPreview),
showDetailsMenuItem(showDetails),
getRenameMenuItem(renameItem),
getMoveItemMenuItem(moveItem),
getDownloadMenuItem(downloadItem),
{ name: '', action: () => false, separator: true },
{ name: '', action: () => {}, separator: true },
getMoveToTrashMenuItem(moveToTrash),
];

Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ListItemMenu<T> = Array<
keyboardShortcutIcon?: React.ForwardRefExoticComponent<{ size?: number | string }>;
keyboardShortcutText?: string;
};
action: (target: T) => void;
action: (target: T) => void | Promise<void>;
disabled?: (target: T) => boolean;
}
| undefined
Expand Down

0 comments on commit d6d18d7

Please sign in to comment.