From 4dcd0fbd6a14fec408e3c391935c8ea5ab72e1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Vasconcellos?= Date: Fri, 23 Jun 2023 13:40:31 -0300 Subject: [PATCH] [ENG-791] Open location directory in native file explorer (#1007) Open folder in native file explorer - Remove verbose console.log --- .../app/$libraryId/Explorer/ContextMenu.tsx | 41 +++++++++++-------- .../client/src/hooks/useLibraryContext.tsx | 5 +-- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/interface/app/$libraryId/Explorer/ContextMenu.tsx b/interface/app/$libraryId/Explorer/ContextMenu.tsx index 2e7c2cf07..38a0fa84d 100644 --- a/interface/app/$libraryId/Explorer/ContextMenu.tsx +++ b/interface/app/$libraryId/Explorer/ContextMenu.tsx @@ -1,6 +1,6 @@ import { Clipboard, FileX, Image, Plus, Repeat, Share, ShieldCheck } from 'phosphor-react'; import { PropsWithChildren, useMemo } from 'react'; -import { useLibraryMutation } from '@sd/client'; +import { useBridgeQuery, useLibraryContext, useLibraryMutation, useLibraryQuery } from '@sd/client'; import { ContextMenu as CM, ModifierKeys } from '@sd/ui'; import { showAlertDialog } from '~/components'; import { getExplorerStore, useExplorerStore, useOperatingSystem } from '~/hooks'; @@ -11,7 +11,6 @@ import { useExplorerSearchParams } from './util'; export const OpenInNativeExplorer = () => { const os = useOperatingSystem(); const keybind = keybindForOs(os); - const platform = usePlatform(); const osFileBrowserName = useMemo(() => { if (os === 'macOS') { @@ -19,24 +18,34 @@ export const OpenInNativeExplorer = () => { } else if (os === 'windows') { return 'Explorer'; } else { - return 'File manager'; + return 'file manager'; } }, [os]); + const { openPath } = usePlatform(); + + let { locationId } = useExplorerStore(); + if (locationId == null) locationId = -1; + + const { library } = useLibraryContext(); + const { data: node } = useBridgeQuery(['nodeState']); + const { data: location } = useLibraryQuery(['locations.get', locationId]); + const [{ path: subPath }] = useExplorerSearchParams(); + + // Disable for remote nodes, as opening directories in a remote node is a more complex task + if (!(openPath && location?.path && node?.id && library.config.node_id === node.id)) + return null; + const path = location.path + (subPath ? subPath : ''); + return ( <> - {platform.openPath && ( - { - alert('TODO: Open in FS'); - // console.log('TODO', store.contextMenuActiveItem); - // platform.openPath!('/Users/oscar/Desktop'); // TODO: Work out the file path from the backend - }} - disabled - /> - )} + openPath(path)} + /> + + ); }; @@ -57,8 +66,6 @@ export default (props: PropsWithChildren) => { - - { - console.log('locations.online', d); - setOnlineLocations(d); - } + onData: (d) => setOnlineLocations(d) }); return (