remove items that are not sticky

targets
filip mertens 4 years ago
parent 41174d15da
commit 619a8f179e
  1. 4
      apps/remix-ide/src/app/panels/file-panel.js
  2. 43
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx

@ -73,6 +73,7 @@ module.exports = class Filepanel extends ViewPlugin {
} }
renderComponent () { renderComponent () {
console.log("render", this.registeredMenuItems)
ReactDOM.render( ReactDOM.render(
<Workspace <Workspace
createWorkspace={this.createWorkspace.bind(this)} createWorkspace={this.createWorkspace.bind(this)}
@ -112,8 +113,9 @@ module.exports = class Filepanel extends ViewPlugin {
removePluginActions (plugin) { removePluginActions (plugin) {
this.registeredMenuItems = this.registeredMenuItems.filter((item) => { this.registeredMenuItems = this.registeredMenuItems.filter((item) => {
return item.id !== plugin.name return item.id !== plugin.name || item.sticky === true
}) })
this.renderComponent()
} }
async getCurrentWorkspace () { async getCurrentWorkspace () {

@ -17,61 +17,63 @@ import './css/file-explorer.css'
const queryParams = new QueryParams() const queryParams = new QueryParams()
export const FileExplorer = (props: FileExplorerProps) => { const initialActions = [{
const { name, registry, plugin, focusRoot, contextMenuItems, displayInput, externalUploads } = props
const [state, setState] = useState({
focusElement: [{
key: '',
type: 'folder'
}],
focusPath: null,
files: [],
fileManager: null,
ctrlKey: false,
newFileName: '',
actions: [{
id: 'newFile', id: 'newFile',
name: 'New File', name: 'New File',
type: ['folder'], type: ['folder'],
path: [], path: [],
extension: [], extension: [],
pattern: [] pattern: []
}, { }, {
id: 'newFolder', id: 'newFolder',
name: 'New Folder', name: 'New Folder',
type: ['folder'], type: ['folder'],
path: [], path: [],
extension: [], extension: [],
pattern: [] pattern: []
}, { }, {
id: 'rename', id: 'rename',
name: 'Rename', name: 'Rename',
type: ['file', 'folder'], type: ['file', 'folder'],
path: [], path: [],
extension: [], extension: [],
pattern: [] pattern: []
}, { }, {
id: 'delete', id: 'delete',
name: 'Delete', name: 'Delete',
type: ['file', 'folder'], type: ['file', 'folder'],
path: [], path: [],
extension: [], extension: [],
pattern: [] pattern: []
}, { }, {
id: 'pushChangesToGist', id: 'pushChangesToGist',
name: 'Push changes to gist', name: 'Push changes to gist',
type: [], type: [],
path: [], path: [],
extension: [], extension: [],
pattern: ['^browser/gists/([0-9]|[a-z])*$'] pattern: ['^browser/gists/([0-9]|[a-z])*$']
}, { }, {
id: 'run', id: 'run',
name: 'Run', name: 'Run',
type: [], type: [],
path: [], path: [],
extension: ['.js'], extension: ['.js'],
pattern: [] pattern: []
}]
export const FileExplorer = (props: FileExplorerProps) => {
const { name, registry, plugin, focusRoot, contextMenuItems, displayInput, externalUploads } = props
const [state, setState] = useState({
focusElement: [{
key: '',
type: 'folder'
}], }],
focusPath: null,
files: [],
fileManager: null,
ctrlKey: false,
newFileName: '',
actions: initialActions,
focusContext: { focusContext: {
element: null, element: null,
x: null, x: null,
@ -173,10 +175,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
useEffect(() => { useEffect(() => {
if (contextMenuItems) { if (contextMenuItems) {
setState(prevState => { setState(prevState => {
// filter duplicate items return { ...prevState, actions: [...initialActions, ...contextMenuItems] }
const items = contextMenuItems.filter(({ name }) => prevState.actions.findIndex(action => action.name === name) === -1)
return { ...prevState, actions: [...prevState.actions, ...items] }
}) })
} }
}, [contextMenuItems]) }, [contextMenuItems])

Loading…
Cancel
Save