Remove unused code and fix conflicts

pull/5370/head
ioedeveloper 2 years ago committed by Aniket
parent daa183610d
commit 00989259e2
  1. 72
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
  2. 256
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  3. 4
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -2,9 +2,7 @@ import React, { useEffect, useState, useRef, SyntheticEvent } from 'react' // es
import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line
import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line
import { FileExplorerContextMenu } from './file-explorer-context-menu' // eslint-disable-line import { FileExplorerContextMenu } from './file-explorer-context-menu' // eslint-disable-line
import { FileExplorerProps, MenuItems, FileExplorerState, WorkSpaceState } from '../types' import { FileExplorerProps, WorkSpaceState } from '../types'
import { customAction } from '@remixproject/plugin-api'
import { contextMenuActions } from '../utils'
import '../css/file-explorer.css' import '../css/file-explorer.css'
import { checkSpecialChars, extractNameFromKey, extractParentFromKey, joinPath } from '@remix-ui/helper' import { checkSpecialChars, extractNameFromKey, extractParentFromKey, joinPath } from '@remix-ui/helper'
@ -15,7 +13,7 @@ import { ROOT_PATH } from '../utils/constants'
export const FileExplorer = (props: FileExplorerProps) => { export const FileExplorer = (props: FileExplorerProps) => {
const { name, contextMenuItems, removedContextMenuItems, files, workspaceState, toGist, addMenuItems, const { name, contextMenuItems, removedContextMenuItems, files, workspaceState, toGist, addMenuItems,
removeMenuItems, handleContextMenu, handleNewFileInput, handleNewFolderInput, uploadFile, fileState } = props removeMenuItems, handleContextMenu, handleNewFileInput, handleNewFolderInput, uploadFile, uploadFolder, fileState } = props
const [state, setState] = useState<WorkSpaceState>( workspaceState) const [state, setState] = useState<WorkSpaceState>( workspaceState)
const treeRef = useRef<HTMLDivElement>(null) const treeRef = useRef<HTMLDivElement>(null)
@ -100,46 +98,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
} }
const downloadPath = async (path: string) => {
try {
props.dispatchDownloadPath(path)
} catch (error) {
props.modal('Download Failed', 'Unexpected error while downloading: ' + typeof error === 'string' ? error : error.message, 'Close', async () => {})
}
}
const uploadFile = (target) => {
const parentFolder = getFocusedFolder()
const expandPath = [...new Set([...props.expandPath, parentFolder])]
props.dispatchHandleExpandPath(expandPath)
props.dispatchUploadFile(target, parentFolder)
}
const uploadFolder = (target) => {
const parentFolder = getFocusedFolder()
const expandPath = [...new Set([...props.expandPath, parentFolder])]
props.dispatchHandleExpandPath(expandPath)
props.dispatchUploadFolder(target, parentFolder)
}
const copyFile = (src: string, dest: string) => {
try {
props.dispatchCopyFile(src, dest)
} catch (error) {
props.modal('Copy File Failed', 'Unexpected error while copying file: ' + src, 'Close', async () => {})
}
}
const copyFolder = (src: string, dest: string) => {
try {
props.dispatchCopyFolder(src, dest)
} catch (error) {
props.modal('Copy Folder Failed', 'Unexpected error while copying folder: ' + src, 'Close', async () => {})
}
}
const publishToGist = (path?: string, type?: string) => { const publishToGist = (path?: string, type?: string) => {
props.modal('Create a public gist', `Are you sure you want to anonymously publish all your files in the ${name} workspace as a public gist on github.com?`, 'OK', () => toGist(path, type), 'Cancel', () => {}) props.modal('Create a public gist', `Are you sure you want to anonymously publish all your files in the ${name} workspace as a public gist on github.com?`, 'OK', () => toGist(path, type), 'Cancel', () => {})
} }
@ -311,38 +269,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
key={index} key={index}
showIconsMenu={props.showIconsMenu} showIconsMenu={props.showIconsMenu}
hideIconsMenu={props.hideIconsMenu} hideIconsMenu={props.hideIconsMenu}
/>) />)
} }
</TreeView> </TreeView>
</div> </div>
</TreeViewItem> </TreeViewItem>
</TreeView> </TreeView>
{ state.showContextMenu &&
<FileExplorerContextMenu
actions={props.focusElement.length > 1 ? state.actions.filter(item => item.multiselect) : state.actions.filter(item => !item.multiselect)}
hideContextMenu={hideContextMenu}
createNewFile={handleNewFileInput}
createNewFolder={handleNewFolderInput}
deletePath={deletePath}
downloadPath={downloadPath}
renamePath={editModeOn}
runScript={runScript}
copy={handleCopyClick}
paste={handlePasteClick}
copyFileName={handleCopyFileNameClick}
copyPath={handleCopyFilePathClick}
emit={emitContextMenuEvent}
pageX={state.focusContext.x}
pageY={state.focusContext.y}
path={state.focusContext.element}
type={state.focusContext.type}
focus={props.focusElement}
pushChangesToGist={pushChangesToGist}
publishFolderToGist={publishFolderToGist}
publishFileToGist={publishFileToGist}
/>
}
</div> </div>
</Drag> </Drag>
) )

@ -7,7 +7,6 @@ import { FileSystemContext } from './contexts'
import './css/remix-ui-workspace.css' import './css/remix-ui-workspace.css'
import { ROOT_PATH, TEMPLATE_NAMES } from './utils/constants' import { ROOT_PATH, TEMPLATE_NAMES } from './utils/constants'
import { HamburgerMenu } from './components/workspace-hamburger' import { HamburgerMenu } from './components/workspace-hamburger'
import { CopyElementType, FileFocusContextType } from './types'
import { MenuItems, WorkSpaceState } from './types' import { MenuItems, WorkSpaceState } from './types'
import { contextMenuActions } from './utils' import { contextMenuActions } from './utils'
@ -42,10 +41,6 @@ export function Workspace () {
const initGitRepoRef = useRef<HTMLInputElement>() const initGitRepoRef = useRef<HTMLInputElement>()
const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : [] const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : []
const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null
const [focusContext, setFocusContext] = useState<FileFocusContextType>()
const [copyElement, setCopyElement] = useState<CopyElementType>()
const [contextType, setContextType] = useState<"file" | "folder">(null);
const [showContextMenu, setShowContextMenu] = useState(false)
const [canPaste, setCanPaste] = useState(false) const [canPaste, setCanPaste] = useState(false)
@ -365,6 +360,14 @@ export function Workspace () {
} }
const downloadPath = async (path: string) => {
try {
global.dispatchDownloadPath(path)
} catch (error) {
global.modal('Download Failed', 'Unexpected error while downloading: ' + typeof error === 'string' ? error : error.message, 'Close', async () => {})
}
}
const copyFile = (src: string, dest: string) => { const copyFile = (src: string, dest: string) => {
try { try {
global.dispatchCopyFile(src, dest) global.dispatchCopyFile(src, dest)
@ -405,6 +408,14 @@ export function Workspace () {
global.dispatchUploadFile(target, parentFolder) global.dispatchUploadFile(target, parentFolder)
} }
const uploadFolder = (target) => {
const parentFolder = getFocusedFolder()
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder])]
global.dispatchHandleExpandPath(expandPath)
global.dispatchUploadFolder(target, parentFolder)
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const handleCopyFileNameClick = (path: string, _type: string) => { const handleCopyFileNameClick = (path: string, _type: string) => {
const fileName = extractNameFromKey(path) const fileName = extractNameFromKey(path)
@ -656,231 +667,6 @@ export function Workspace () {
) )
} }
const handleCanCopy = (path: string, type: 'folder' | 'gist' | 'file') => {
setCopyElement({ key: path, type })
}
const handleCloseContextMenu = () => {
setShowContextMenu(false)
};
const workspaceMenuIcons = [
<CustomTooltip
placement="right"
tooltipId="createWorkspaceTooltip"
tooltipClasses="text-nowrap"
tooltipText={<FormattedMessage id='filePanel.workspace.create' />}
>
<div
data-id='workspaceCreate'
onClick={() => {
createWorkspace()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspaceCreate'])
hideIconsMenu(!showIconsMenu)
}}
key={`workspacesCreate-fe-ws`}
>
<span
hidden={currentWorkspace === LOCALHOST}
id='workspaceCreate'
data-id='workspaceCreate'
onClick={() => {
createWorkspace()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspaceCreate'])
hideIconsMenu(!showIconsMenu)
}}
className='far fa-plus pl-2'
>
</span>
<span className="pl-3"><FormattedMessage id='filePanel.create' /></span>
</div>
</CustomTooltip>,
<CustomTooltip
placement="right-start"
tooltipId="createWorkspaceTooltip"
tooltipClasses="text-nowrap"
tooltipText={<FormattedMessage id='filePanel.workspace.delete' />}
>
<div
data-id='workspaceDelete'
onClick={() => {
deleteCurrentWorkspace()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspaceDelete'])
hideIconsMenu(!showIconsMenu)
}}
key={`workspacesDelete-fe-ws`}
>
<span
hidden={currentWorkspace === LOCALHOST || currentWorkspace === NO_WORKSPACE}
id='workspaceDelete'
data-id='workspaceDelete'
onClick={() => {
deleteCurrentWorkspace()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspaceDelete'])
hideIconsMenu(!showIconsMenu)
}}
className='far fa-trash pl-2'
>
</span>
<span className="pl-3"><FormattedMessage id='filePanel.delete' /></span>
</div>
</CustomTooltip>,
<CustomTooltip
placement='right-start'
tooltipClasses="text-nowrap"
tooltipId="workspaceRenametooltip"
tooltipText={<FormattedMessage id='filePanel.workspace.rename' />}
>
<div onClick={() => {
renameCurrentWorkspace()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspaceRename'])
hideIconsMenu(!showIconsMenu)
}}
data-id='workspaceRename'
key={`workspacesRename-fe-ws`}
>
<span
hidden={currentWorkspace === LOCALHOST || currentWorkspace === NO_WORKSPACE}
id='workspaceRename'
data-id='workspaceRename'
onClick={() => {
renameCurrentWorkspace()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspaceRename'])
hideIconsMenu(!showIconsMenu)
}}
className='far fa-edit pl-2'>
</span>
<span className="pl-3"><FormattedMessage id='filePanel.rename' /></span>
</div>
</CustomTooltip>,
<Dropdown.Divider className="border mb-0 mt-0" />,
<CustomTooltip
placement="right-start"
tooltipId="cloneWorkspaceTooltip"
tooltipClasses="text-nowrap"
tooltipText={<FormattedMessage id='filePanel.workspace.clone' />}
>
<div
data-id='cloneGitRepository'
onClick={() => {
cloneGitRepository()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'cloneGitRepository'])
hideIconsMenu(!showIconsMenu)
}}
key={`cloneGitRepository-fe-ws`}
>
<span
hidden={currentWorkspace === LOCALHOST}
id='cloneGitRepository'
data-id='cloneGitRepository'
onClick={() => {
cloneGitRepository()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'cloneGitRepository'])
hideIconsMenu(!showIconsMenu)
}}
className='fab fa-github pl-2'
>
</span>
<span className="pl-3"><FormattedMessage id='filePanel.clone' /></span>
</div>
</CustomTooltip>,
<Dropdown.Divider className="border mt-0 mb-0 remixui_menuhr" style={{ pointerEvents: 'none' }}/>,
<CustomTooltip
placement="right-start"
tooltipId="createWorkspaceTooltip"
tooltipClasses="text-nowrap"
tooltipText={<FormattedMessage id='filePanel.workspace.download' />}
>
<div
data-id='workspacesDownload'
onClick={() => {
downloadWorkspaces()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspacesDownload'])
hideIconsMenu(!showIconsMenu)
}}
key={`workspacesDownload-fe-ws`}
>
<span
hidden={currentWorkspace === LOCALHOST || currentWorkspace === NO_WORKSPACE}
id='workspacesDownload'
data-id='workspacesDownload'
onClick={() => {
downloadWorkspaces()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspacesDownload'])
hideIconsMenu(!showIconsMenu)
}}
className='far fa-download pl-2 '
>
</span>
<span className="pl-3"><FormattedMessage id='filePanel.download' /></span>
</div>
</CustomTooltip>,
<CustomTooltip
placement="right-start"
tooltipId="createWorkspaceTooltip"
tooltipClasses="text-nowrap"
tooltipText={<FormattedMessage id='filePanel.workspace.restore' />}
>
<div
data-id='workspacesRestore'
onClick={() => {
restoreBackup()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspacesRestore'])
hideIconsMenu(!showIconsMenu)
}}
key={`workspacesRestore-fe-ws`}
>
<span
hidden={currentWorkspace === LOCALHOST}
id='workspacesRestore'
data-id='workspacesRestore'
onClick={() => {
restoreBackup()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'workspacesRestore'])
hideIconsMenu(!showIconsMenu)
}}
className='far fa-upload pl-2'
>
</span>
<span className="pl-3"><FormattedMessage id='filePanel.restore' /></span>
</div>
</CustomTooltip>,
<Dropdown.Divider className="border mt-0 mb-0 remixui_menuhr" style={{ pointerEvents: 'none' }}/>,
<CustomTooltip
placement="right-start"
tooltipId="createSolGHActionTooltip"
tooltipClasses="text-nowrap"
tooltipText={<FormattedMessage id='filePanel.workspace.solghaction' />}
>
<div
data-id='soliditygithubaction'
onClick={(e) => {
e.stopPropagation()
addGithubAction()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'addSolidityTesting'])
hideIconsMenu(!showIconsMenu)
}}
>
<span
hidden={currentWorkspace === LOCALHOST}
id='soliditygithubaction'
data-id='soliditygithubaction'
onClick={(e) => {
e.stopPropagation()
addGithubAction()
_paq.push(['trackEvent', 'fileExplorer', 'workspaceMenu', 'addSolidityTesting'])
hideIconsMenu(!showIconsMenu)
}}
className='fab fa-github pl-2'
>
</span>
<span className="pl-3">{<FormattedMessage id='filePanel.solghaction' />}</span>
</div>
</CustomTooltip>
]
return ( return (
<div className='d-flex flex-column justify-content-between h-100'> <div className='d-flex flex-column justify-content-between h-100'>
<div className='remixui_container overflow-auto' style={{ maxHeight: selectedWorkspace && selectedWorkspace.isGitRepo ? '95%' : '100%' }} onContextMenu={(e)=>{ <div className='remixui_container overflow-auto' style={{ maxHeight: selectedWorkspace && selectedWorkspace.isGitRepo ? '95%' : '100%' }} onContextMenu={(e)=>{
@ -1038,15 +824,13 @@ export function Workspace () {
dispatchHandleExpandPath={global.dispatchHandleExpandPath} dispatchHandleExpandPath={global.dispatchHandleExpandPath}
dispatchMoveFile={global.dispatchMoveFile} dispatchMoveFile={global.dispatchMoveFile}
dispatchMoveFolder={global.dispatchMoveFolder} dispatchMoveFolder={global.dispatchMoveFolder}
contextType={contextType}
closeContextMenu={handleCloseContextMenu}
dispatchCanCopy={handleCanCopy}
handleCopyClick={handleCopyClick} handleCopyClick={handleCopyClick}
handlePasteClick={handlePasteClick} handlePasteClick={handlePasteClick}
addMenuItems={addMenuItems} addMenuItems={addMenuItems}
removeMenuItems={removeMenuItems} removeMenuItems={removeMenuItems}
handleContextMenu={handleContextMenu} handleContextMenu={handleContextMenu}
uploadFile={uploadFile} uploadFile={uploadFile}
uploadFolder={uploadFolder}
getFocusedFolder={getFocusedFolder} getFocusedFolder={getFocusedFolder}
toGist={toGist} toGist={toGist}
editModeOn={editModeOn} editModeOn={editModeOn}
@ -1094,15 +878,13 @@ export function Workspace () {
dispatchHandleExpandPath={global.dispatchHandleExpandPath} dispatchHandleExpandPath={global.dispatchHandleExpandPath}
dispatchMoveFile={global.dispatchMoveFile} dispatchMoveFile={global.dispatchMoveFile}
dispatchMoveFolder={global.dispatchMoveFolder} dispatchMoveFolder={global.dispatchMoveFolder}
contextType={contextType}
closeContextMenu={handleCloseContextMenu}
dispatchCanCopy={handleCanCopy}
handleCopyClick={handleCopyClick} handleCopyClick={handleCopyClick}
handlePasteClick={handlePasteClick} handlePasteClick={handlePasteClick}
addMenuItems={addMenuItems} addMenuItems={addMenuItems}
removeMenuItems={removeMenuItems} removeMenuItems={removeMenuItems}
handleContextMenu={handleContextMenu} handleContextMenu={handleContextMenu}
uploadFile={uploadFile} uploadFile={uploadFile}
uploadFolder={uploadFolder}
getFocusedFolder={getFocusedFolder} getFocusedFolder={getFocusedFolder}
toGist={toGist} toGist={toGist}
editModeOn={editModeOn} editModeOn={editModeOn}
@ -1196,7 +978,7 @@ export function Workspace () {
publishFolderToGist={publishFolderToGist} publishFolderToGist={publishFolderToGist}
publishFileToGist={publishFileToGist} publishFileToGist={publishFileToGist}
uploadFile={uploadFile} uploadFile={uploadFile}
downloadPath={global.dispatchDownloadPath} downloadPath={downloadPath}
/> />
} }

@ -113,15 +113,13 @@ export interface FileExplorerProps {
dispatchHandleExpandPath: (paths: string[]) => Promise<void>, dispatchHandleExpandPath: (paths: string[]) => Promise<void>,
dispatchMoveFile: (src: string, dest: string) => Promise<void>, dispatchMoveFile: (src: string, dest: string) => Promise<void>,
dispatchMoveFolder: (src: string, dest: string) => Promise<void>, dispatchMoveFolder: (src: string, dest: string) => Promise<void>,
contextType?: 'file' | 'folder',
closeContextMenu?: () => void,
dispatchCanCopy?: (path: string, type: 'folder' | 'gist' | 'file') => void
handlePasteClick: (dest: string, destType: string) => void handlePasteClick: (dest: string, destType: string) => void
handleCopyClick: (path: string, type: 'folder' | 'gist' | 'file' | 'workspace') => void handleCopyClick: (path: string, type: 'folder' | 'gist' | 'file' | 'workspace') => void
addMenuItems: (items: MenuItems) => void addMenuItems: (items: MenuItems) => void
removeMenuItems: (items: MenuItems) => void removeMenuItems: (items: MenuItems) => void
handleContextMenu: (pageX: number, pageY: number, path: string, content: string, type: string) => void handleContextMenu: (pageX: number, pageY: number, path: string, content: string, type: string) => void
uploadFile: (target) => void uploadFile: (target) => void
uploadFolder: (target) => void
getFocusedFolder: () => string getFocusedFolder: () => string
editModeOn: (path: string, type: string, isNew: boolean) => void editModeOn: (path: string, type: string, isNew: boolean) => void
toGist: (path?: string, type?: string) => void toGist: (path?: string, type?: string) => void

Loading…
Cancel
Save