From 949d7113f1fc13165f6f218d673630e292f3a050 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 5 Dec 2022 13:52:43 +0100 Subject: [PATCH] fix file type and context menu string. add function signature to interface. --- .../lib/components/file-explorer-context-menu.tsx | 10 +++++++++- .../workspace/src/lib/components/file-explorer.tsx | 13 +++++++++++++ libs/remix-ui/workspace/src/lib/types/index.ts | 2 ++ libs/remix-ui/workspace/src/lib/utils/index.ts | 6 +++--- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx index 7250f590c1..66432f6872 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx @@ -13,7 +13,7 @@ declare global { const _paq = window._paq = window._paq || [] //eslint-disable-line export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) => { - const { actions, createNewFile, createNewFolder, deletePath, renamePath, hideContextMenu, pushChangesToGist, publishFileToGist, publishFolderToGist, copy, paste, runScript, emit, pageX, pageY, path, type, focus, ...otherProps } = props + const { actions, createNewFile, createNewFolder, deletePath, renamePath, hideContextMenu, pushChangesToGist, publishFileToGist, publishFolderToGist, copy, copyFileName, copyPath, paste, runScript, emit, pageX, pageY, path, type, focus, ...otherProps } = props const contextMenuRef = useRef(null) const intl = useIntl() useEffect(() => { @@ -108,6 +108,14 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) => copy(path, type) _paq.push(['trackEvent', 'fileExplorer', 'contextMenu', 'copy']) break + case 'Copy name': + copyFileName(path, type) + _paq.push(['trackEvent', 'fileExplorer', 'contextMenu', 'copy']) + break + case 'Copy path': + copyPath(path, type) + _paq.push(['trackEvent', 'fileExplorer', 'contextMenu', 'copy']) + break case 'Paste': paste(path, type) _paq.push(['trackEvent', 'fileExplorer', 'contextMenu', 'paste']) diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx index 64f52d0630..a16b626f56 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -409,6 +409,17 @@ export const FileExplorer = (props: FileExplorerProps) => { props.dispatchHandleExpandPath(expandPath) } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const handleCopyFileNameClick = (path: string, _type: string) => { + const fileName = extractNameFromKey(path) + navigator.clipboard.writeText(fileName) + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const handleCopyFilePathClick = (path: string, _type: string) => { + navigator.clipboard.writeText(path) + } + const handleFileMove = (dest: string, src: string) => { try { props.dispatchMoveFile(src, dest) @@ -480,6 +491,8 @@ export const FileExplorer = (props: FileExplorerProps) => { runScript={runScript} copy={handleCopyClick} paste={handlePasteClick} + copyFileName={handleCopyFileNameClick} + copyPath={handleCopyFilePathClick} emit={emitContextMenuEvent} pageX={state.focusContext.x} pageY={state.focusContext.y} diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index 596682b87b..a0ef77c2e8 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -134,6 +134,8 @@ export interface FileExplorerContextMenuProps { onMouseOver?: (...args) => void, copy?: (path: string, type: string) => void, paste?: (destination: string, type: string) => void + copyFileName?: (path: string, type: string) => void + copyPath?: (path: string, type: string) => void } export interface FileExplorerState { diff --git a/libs/remix-ui/workspace/src/lib/utils/index.ts b/libs/remix-ui/workspace/src/lib/utils/index.ts index be6b09fd50..8a0762ae7f 100644 --- a/libs/remix-ui/workspace/src/lib/utils/index.ts +++ b/libs/remix-ui/workspace/src/lib/utils/index.ts @@ -56,14 +56,14 @@ export const contextMenuActions: MenuItems = [{ label: '' }, { id: 'copyFileName', - name: 'Copy file name', + name: 'Copy name', type: ['file'], multiselect: false, label: '' }, { id: 'copyFilePath', - name: 'Copy file path', - type: ['folder', 'file'], + name: 'Copy path', + type: ['file'], multiselect: false, label: '' }, {