From 84a6a8db9d48fad01741b63c74db1c3276e5cde4 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Tue, 15 Aug 2023 15:14:32 +0300 Subject: [PATCH] Web:Client:Plugin: fix context menu items for Images, Video, Files for file list and viewer --- .../src/pages/Home/MediaViewer/index.js | 16 ++--- packages/client/src/store/FilesStore.js | 69 +++++++++++-------- .../MediaViewer/MediaViewer.props.ts | 1 + .../common/components/MediaViewer/index.tsx | 13 ++++ 4 files changed, 64 insertions(+), 35 deletions(-) diff --git a/packages/client/src/pages/Home/MediaViewer/index.js b/packages/client/src/pages/Home/MediaViewer/index.js index 609ddcacf3..9ade7dfd19 100644 --- a/packages/client/src/pages/Home/MediaViewer/index.js +++ b/packages/client/src/pages/Home/MediaViewer/index.js @@ -253,17 +253,17 @@ export default inject( setIsSectionFilterLoading(param); }; - const { contextMenuItemsList } = pluginStore; + const { contextMenuItemsList, getContextMenuKeysByType } = pluginStore; + + const pluginContextMenuKeys = [ + ...(getContextMenuKeysByType() || []), + ...(getContextMenuKeysByType(PluginFileType.Image) || []), + ...(getContextMenuKeysByType(PluginFileType.Video) || []), + ]; const pluginContextMenuItems = contextMenuItemsList?.filter((i) => { - const { value } = i; - - if ( - value?.fileType?.includes(PluginFileType.Image) || - value?.fileType.includes(PluginFileType.Video) || - !value?.fileType - ) { + if (pluginContextMenuKeys.includes(i.key)) { return true; } diff --git a/packages/client/src/store/FilesStore.js b/packages/client/src/store/FilesStore.js index aad9569030..5738f7be6a 100644 --- a/packages/client/src/store/FilesStore.js +++ b/packages/client/src/store/FilesStore.js @@ -1949,40 +1949,55 @@ class FilesStore { // ]); // } - if (!isRecycleBinFolder) + if (!isRecycleBinFolder) { fileOptions = this.removeOptions(fileOptions, ["restore"]); - if (enablePlugins && !isRecycleBinFolder) { - const pluginFilesKeys = this.pluginStore.getContextMenuKeysByType( - PluginFileType.Files, - item.fileExst - ); + if (enablePlugins) { + if ( + !item.viewAccessability.MediaView && + !item.viewAccessability.ImageView + ) { + const pluginFilesKeys = this.pluginStore.getContextMenuKeysByType( + PluginFileType.Files, + item.fileExst + ); - pluginAllKeys && pluginAllKeys.forEach((key) => fileOptions.push(key)); - pluginFilesKeys && - pluginFilesKeys.forEach((key) => fileOptions.push(key)); - } + pluginAllKeys && + pluginAllKeys.forEach((key) => fileOptions.push(key)); + pluginFilesKeys && + pluginFilesKeys.forEach((key) => fileOptions.push(key)); + } - if (enablePlugins && item.viewAccessability.ImageView) { - const pluginFilesKeys = this.pluginStore.getContextMenuKeysByType( - PluginFileType.Image, - item.fileExst - ); + if ( + !item.viewAccessability.MediaView && + item.viewAccessability.ImageView + ) { + const pluginFilesKeys = this.pluginStore.getContextMenuKeysByType( + PluginFileType.Image, + item.fileExst + ); - pluginAllKeys && pluginAllKeys.forEach((key) => fileOptions.push(key)); - pluginFilesKeys && - pluginFilesKeys.forEach((key) => fileOptions.push(key)); - } + pluginAllKeys && + pluginAllKeys.forEach((key) => fileOptions.push(key)); + pluginFilesKeys && + pluginFilesKeys.forEach((key) => fileOptions.push(key)); + } - if (enablePlugins && item.viewAccessability.MediaView) { - const pluginFilesKeys = this.pluginStore.getContextMenuKeysByType( - PluginFileType.Video, - item.fileExst - ); + if ( + item.viewAccessability.MediaView && + !item.viewAccessability.ImageView + ) { + const pluginFilesKeys = this.pluginStore.getContextMenuKeysByType( + PluginFileType.Video, + item.fileExst + ); - pluginAllKeys && pluginAllKeys.forEach((key) => fileOptions.push(key)); - pluginFilesKeys && - pluginFilesKeys.forEach((key) => fileOptions.push(key)); + pluginAllKeys && + pluginAllKeys.forEach((key) => fileOptions.push(key)); + pluginFilesKeys && + pluginFilesKeys.forEach((key) => fileOptions.push(key)); + } + } } if (!this.canShareOwnerChange(item)) { diff --git a/packages/common/components/MediaViewer/MediaViewer.props.ts b/packages/common/components/MediaViewer/MediaViewer.props.ts index bd1f63e1a1..c6a20467d6 100644 --- a/packages/common/components/MediaViewer/MediaViewer.props.ts +++ b/packages/common/components/MediaViewer/MediaViewer.props.ts @@ -36,6 +36,7 @@ export interface MediaViewerProps { label: string; onClick: (id: number) => void; icon: string; + fileType?: ["video", "image"]; }; }[]; diff --git a/packages/common/components/MediaViewer/index.tsx b/packages/common/components/MediaViewer/index.tsx index 6b40e49f87..45725dc0d5 100644 --- a/packages/common/components/MediaViewer/index.tsx +++ b/packages/common/components/MediaViewer/index.tsx @@ -201,6 +201,19 @@ function MediaViewer({ props.onClose(); }; + if ( + item.value.fileType && + item.value.fileType.includes("image") && + !targetFile.viewAccessability.ImageView + ) + return; + if ( + item.value.fileType && + item.value.fileType.includes("video") && + !targetFile.viewAccessability.MediaView + ) + return; + model.push({ id: item.key, key: item.key,