From 8d7ed1d7c20580fa7d85dae31aed96d492a7247f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 1 Jul 2021 19:23:45 +0200 Subject: [PATCH] rm double func, check for name & id on remove, fix effect --- apps/remix-ide/src/app/panels/file-panel.js | 14 ++------------ .../file-explorer/src/lib/file-explorer.tsx | 17 ++++++++++++----- .../file-explorer/src/lib/types/index.ts | 2 +- .../workspace/src/lib/remix-ui-workspace.tsx | 3 +++ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 0e212793d0..4e4769baad 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -108,7 +108,7 @@ 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.removedMenuItems = this.removedMenuItems.filter(menuItem => item.id !== menuItem.id) this.renderComponent() } @@ -116,20 +116,13 @@ module.exports = class Filepanel extends ViewPlugin { this.registeredMenuItems = this.registeredMenuItems.filter((item) => { if (item.id !== plugin.name || item.sticky === true) return true else { - this.removedMenuItems.push(item.id) + this.removedMenuItems.push(item) return false } }) this.renderComponent() } - removePluginActions (plugin) { - this.registeredMenuItems = this.registeredMenuItems.filter((item) => { - return item.id !== plugin.name || item.sticky === true - }) - this.renderComponent() - } - async getCurrentWorkspace () { return await this.request.getCurrentWorkspace() } @@ -212,9 +205,6 @@ module.exports = class Filepanel extends ViewPlugin { } }) }) - - const self = this - this.appManager.on('manager', 'pluginDeactivated', self.removePluginActions.bind(this)) } 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 d3a858f539..a5cbfb205f 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -208,7 +208,7 @@ export const FileExplorer = (props: FileExplorerProps) => { if (removedContextMenuItems) { removeMenuItems(removedContextMenuItems) } - }, [removedContextMenuItems]) + }, [contextMenuItems]) useEffect(() => { if (displayInput) { @@ -285,7 +285,15 @@ export const FileExplorer = (props: FileExplorerProps) => { multiselect: false }]) } else { - removeMenuItems(['paste']) + removeMenuItems([{ + id: 'paste', + name: 'Paste', + type: ['folder', 'file'], + path: [], + extension: [], + pattern: [], + multiselect: false + }]) } }, [canPaste]) @@ -298,10 +306,9 @@ export const FileExplorer = (props: FileExplorerProps) => { }) } - const removeMenuItems = (ids: string[]) => { + const removeMenuItems = (items: MenuItems) => { setState(prevState => { - const actions = prevState.actions.filter(({ id }) => ids.findIndex(value => value === id) === -1) - + const actions = prevState.actions.filter(({ id, name }) => items.findIndex(item => id === item.id && name === item.name) === -1) return { ...prevState, actions } }) } 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 7e3f1ac7dc..61fcb4d752 100644 --- a/libs/remix-ui/file-explorer/src/lib/types/index.ts +++ b/libs/remix-ui/file-explorer/src/lib/types/index.ts @@ -9,7 +9,7 @@ export interface FileExplorerProps { plugin: any, focusRoot: boolean, contextMenuItems: MenuItems, - removedContextMenuItems: string[], + removedContextMenuItems: MenuItems, displayInput?: boolean, externalUploads?: EventTarget & HTMLInputElement, } diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 6a85a0febf..d974eca5a3 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -21,6 +21,7 @@ export interface WorkspaceProps { request: any // api request, workspaces: any, registeredMenuItems: [] // menu items + removedMenuItems: [] initialWorkspace: string } @@ -409,6 +410,7 @@ export const Workspace = (props: WorkspaceProps) => { plugin={props.plugin} focusRoot={state.reset} contextMenuItems={props.registeredMenuItems} + removedContextMenuItems={props.removedMenuItems} displayInput={state.displayNewFile} externalUploads={state.uploadFileEvent} /> @@ -426,6 +428,7 @@ export const Workspace = (props: WorkspaceProps) => { plugin={props.plugin} focusRoot={state.reset} contextMenuItems={props.registeredMenuItems} + removedContextMenuItems={props.removedMenuItems} /> }