From 58f526c453d4965107f415c2a5d0d5e1885a81ff Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Thu, 1 Jul 2021 16:07:03 +0100 Subject: [PATCH] Implement removal of context menu items --- apps/remix-ide/src/app/panels/file-panel.js | 10 +++- .../file-explorer/src/lib/file-explorer.tsx | 52 +++---------------- .../file-explorer/src/lib/types/index.ts | 3 +- 3 files changed, 17 insertions(+), 48 deletions(-) diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 90cde523d6..a8abde0d66 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -60,6 +60,7 @@ module.exports = class Filepanel extends ViewPlugin { this.gitHandle = new GitHandle() this.hardhatHandle = new HardhatHandle() this.registeredMenuItems = [] + this.removedMenuItems = [] this.request = {} this.workspaces = [] this.initialWorkspace = null @@ -89,6 +90,7 @@ module.exports = class Filepanel extends ViewPlugin { request={this.request} workspaces={this.workspaces} registeredMenuItems={this.registeredMenuItems} + removedMenuItems={this.removedMenuItems} initialWorkspace={this.initialWorkspace} /> , this.el) @@ -106,12 +108,17 @@ module.exports = class Filepanel extends ViewPlugin { return o.id === item.id & o.name === item.name }).length) throw new Error(`Action ${item.name} already exists on ${item.id}`) this.registeredMenuItems = [...this.registeredMenuItems, item] + this.removedMenuItems = this.removedMenuItems.filter(id => item.id !== id) this.renderComponent() } removePluginActions (plugin) { this.registeredMenuItems = this.registeredMenuItems.filter((item) => { - return item.id !== plugin.name || item.sticky === true + if (item.id !== plugin.name || item.sticky === true) return true + else { + this.removedMenuItems.push(item.id) + return false + } }) this.renderComponent() } @@ -198,7 +205,6 @@ module.exports = class Filepanel extends ViewPlugin { } }) }) - } async createNewFile () { diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index d104a3e16c..d3a858f539 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -17,52 +17,8 @@ import './css/file-explorer.css' const queryParams = new QueryParams() -const initialActions = [{ - id: 'newFile', - name: 'New File', - type: ['folder'], - path: [], - extension: [], - pattern: [] -}, { - id: 'newFolder', - name: 'New Folder', - type: ['folder'], - path: [], - extension: [], - pattern: [] -}, { - id: 'rename', - name: 'Rename', - type: ['file', 'folder'], - path: [], - extension: [], - pattern: [] -}, { - id: 'delete', - name: 'Delete', - type: ['file', 'folder'], - path: [], - extension: [], - pattern: [] -}, { - id: 'pushChangesToGist', - name: 'Push changes to gist', - type: [], - path: [], - extension: [], - pattern: ['^browser/gists/([0-9]|[a-z])*$'] -}, { - id: 'run', - name: 'Run', - type: [], - path: [], - extension: ['.js'], - pattern: [] -}] - export const FileExplorer = (props: FileExplorerProps) => { - const { name, registry, plugin, focusRoot, contextMenuItems, displayInput, externalUploads } = props + const { name, registry, plugin, focusRoot, contextMenuItems, displayInput, externalUploads, removedContextMenuItems } = props const [state, setState] = useState({ focusElement: [{ key: '', @@ -248,6 +204,12 @@ export const FileExplorer = (props: FileExplorerProps) => { } }, [contextMenuItems]) + useEffect(() => { + if (removedContextMenuItems) { + removeMenuItems(removedContextMenuItems) + } + }, [removedContextMenuItems]) + useEffect(() => { if (displayInput) { handleNewFileInput() diff --git a/libs/remix-ui/file-explorer/src/lib/types/index.ts b/libs/remix-ui/file-explorer/src/lib/types/index.ts index 4aa1e97975..7e3f1ac7dc 100644 --- a/libs/remix-ui/file-explorer/src/lib/types/index.ts +++ b/libs/remix-ui/file-explorer/src/lib/types/index.ts @@ -9,8 +9,9 @@ export interface FileExplorerProps { plugin: any, focusRoot: boolean, contextMenuItems: MenuItems, + removedContextMenuItems: string[], displayInput?: boolean, - externalUploads?: EventTarget & HTMLInputElement + externalUploads?: EventTarget & HTMLInputElement, } export interface File {