From e75e405350364cb3beaaf567a6181841cf1261c1 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sat, 2 Sep 2023 00:29:43 +0100 Subject: [PATCH 01/18] sort root level files and folders by name --- .../workspace/src/lib/reducers/workspace.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 1058dfb8a40..386215f8b38 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -933,12 +933,29 @@ const removeInputField = ( return files } +const sortDirectoriesFetched = (folderStructure: any) => { + if(!folderStructure) return + +} + +const sortFilesFetched = (folderStructure: any) => { + // eslint-disable-next-line prefer-const + let newResult = _.fromPairs(_.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name)) + let target = {} + Object.assign(target, newResult) + const result = { '/': target } + target = null + newResult = null + return result +} + // IDEA: Modify function to remove blank input field without fetching content const fetchDirectoryContent = ( state: BrowserState, payload: {fileTree; path: string; type?: 'file' | 'folder'}, deletePath?: string ): {[x: string]: Record} => { + if (!payload.fileTree) return state.mode === 'browser' ? state.browser.files @@ -986,6 +1003,7 @@ const fetchDirectoryContent = ( ) } } + files = sortFilesFetched(files) return files } } else { @@ -993,6 +1011,7 @@ const fetchDirectoryContent = ( let files = normalize(payload.fileTree, ROOT_PATH, payload.type) files = _.merge(files, state.localhost.files[ROOT_PATH]) if (deletePath) delete files[deletePath] + return {[ROOT_PATH]: files} } else { let files = state.localhost.files @@ -1012,6 +1031,8 @@ const fetchDirectoryContent = ( } } files = _.setWith(files, _path, prevFiles, Object) + const newFiles = sortFilesFetched(files) + console.log({ newFiles }) } else { files = { [payload.path]: normalize( @@ -1021,7 +1042,8 @@ const fetchDirectoryContent = ( ) } } - return files + const newFiles = sortFilesFetched(files) + return newFiles } } } From 0dbc448ae9e0dbadbaa65ba84b02b9fcd6f18e55 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 11 Sep 2023 10:35:56 +0100 Subject: [PATCH 02/18] add sorting icon --- .../src/lib/components/file-explorer-menu.tsx | 4 ++-- .../src/lib/components/file-explorer.tsx | 17 +++++++++++++++-- .../workspace/src/lib/reducers/workspace.ts | 8 +------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx index bb9ef8b94f0..19e079a7094 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx @@ -72,7 +72,7 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => { {props.title} - + {state.menuItems.map(({action, title, icon, placement}, index) => { if (action === 'uploadFile') { return ( @@ -160,6 +160,6 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => { ) -} +}// add tooltip to sort icon. then wireup logic to sort files by name ascending/descending export default FileExplorerMenu 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 70ebf688980..9ce1c3b0793 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -6,11 +6,12 @@ import {FileExplorerContextMenu} from './file-explorer-context-menu' // eslint-d import {FileExplorerProps, WorkSpaceState} from '../types' import '../css/file-explorer.css' -import {checkSpecialChars, extractNameFromKey, extractParentFromKey, joinPath} from '@remix-ui/helper' +import {CustomTooltip, checkSpecialChars, extractNameFromKey, extractParentFromKey, joinPath} from '@remix-ui/helper' // eslint-disable-next-line @typescript-eslint/no-unused-vars import {FileRender} from './file-render' import {Drag} from '@remix-ui/drag-n-drop' import {ROOT_PATH} from '../utils/constants' +import { FormattedMessage } from 'react-intl' export const FileExplorer = (props: FileExplorerProps) => { const intl = useIntl() @@ -323,7 +324,7 @@ export const FileExplorer = (props: FileExplorerProps) => { id="treeViewItem" controlBehaviour={true} label={ -
+
{ uploadFile={uploadFile} uploadFolder={uploadFolder} /> + + + + } + > + console.log('sorting clicked')}> + +
} expand={true} diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 386215f8b38..ade890f6af9 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -933,11 +933,6 @@ const removeInputField = ( return files } -const sortDirectoriesFetched = (folderStructure: any) => { - if(!folderStructure) return - -} - const sortFilesFetched = (folderStructure: any) => { // eslint-disable-next-line prefer-const let newResult = _.fromPairs(_.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name)) @@ -955,7 +950,7 @@ const fetchDirectoryContent = ( payload: {fileTree; path: string; type?: 'file' | 'folder'}, deletePath?: string ): {[x: string]: Record} => { - + console.trace() if (!payload.fileTree) return state.mode === 'browser' ? state.browser.files @@ -1003,7 +998,6 @@ const fetchDirectoryContent = ( ) } } - files = sortFilesFetched(files) return files } } else { From 6ae75b8693be4209afa1f1c8c5252b6c5235f85c Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 11 Sep 2023 11:39:20 +0100 Subject: [PATCH 03/18] add state to sort icon --- .../workspace/src/lib/components/file-explorer.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 9ce1c3b0793..88e1d15fbc1 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -31,7 +31,10 @@ export const FileExplorer = (props: FileExplorerProps) => { uploadFolder, fileState } = props + const sortIconDesc = 'fa fa-sort-alpha-desc justify-end' + const sortIconAsc = 'fa fa-sort-alpha-up justify-end' const [state, setState] = useState(workspaceState) + const [sortIcon, setSortIcon] = useState(sortIconDesc) const treeRef = useRef(null) useEffect(() => { @@ -343,7 +346,10 @@ export const FileExplorer = (props: FileExplorerProps) => { tooltipClasses="text-nowrap" tooltipText={} > - console.log('sorting clicked')}> + { + console.log('sorting clicked') + sortIcon === sortIconDesc ? setSortIcon(sortIconAsc) : setSortIcon(sortIconDesc) + }}>
From f8a0b35a2020f18eeae33bbadb0ef7745d20eef1 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 11 Sep 2023 14:07:18 +0100 Subject: [PATCH 04/18] add ascending and descending as options --- libs/remix-ui/workspace/src/lib/reducers/workspace.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index ade890f6af9..50c1fd508f1 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -933,9 +933,10 @@ const removeInputField = ( return files } -const sortFilesFetched = (folderStructure: any) => { +const sortFilesFetched = (folderStructure: any, direction?: 'asc' | 'desc') => { // eslint-disable-next-line prefer-const - let newResult = _.fromPairs(_.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name)) + let newResult = _.fromPairs( + direction && direction === 'desc' ? _.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name).reverse() : _.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name)) let target = {} Object.assign(target, newResult) const result = { '/': target } From f29aa4222737c9b2b2092f6097c284d6962e747e Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 11 Sep 2023 22:59:16 +0100 Subject: [PATCH 05/18] add types for sort function --- libs/remix-ui/workspace/src/lib/actions/index.ts | 4 +++- .../workspace/src/lib/components/file-explorer.tsx | 3 +++ libs/remix-ui/workspace/src/lib/contexts/index.ts | 5 +++-- .../workspace/src/lib/providers/FileSystemProvider.tsx | 6 ++++++ libs/remix-ui/workspace/src/lib/reducers/workspace.ts | 7 ++----- libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx | 2 ++ libs/remix-ui/workspace/src/lib/types/index.ts | 3 ++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index e34b9db4177..f7c5098426b 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -126,7 +126,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. }else{ _paq.push(['trackEvent', 'Storage', 'error', `Workspace in localstorage not found: ${localStorage.getItem("currentWorkspace")}`]) await basicWorkspaceInit(workspaces, workspaceProvider) - } + } } else { await basicWorkspaceInit(workspaces, workspaceProvider) } @@ -142,9 +142,11 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. } export const fetchDirectory = async (path: string) => { + console.trace() const provider = plugin.fileManager.currentFileProvider() const promise = new Promise((resolve) => { provider.resolveDirectory(path, (error, fileTree) => { + console.log({ fileTree }) if (error) console.error(error) resolve(fileTree) 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 88e1d15fbc1..e398bdea9e8 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -36,6 +36,7 @@ export const FileExplorer = (props: FileExplorerProps) => { const [state, setState] = useState(workspaceState) const [sortIcon, setSortIcon] = useState(sortIconDesc) const treeRef = useRef(null) + console.log({ props }) useEffect(() => { if (contextMenuItems) { @@ -172,6 +173,7 @@ export const FileExplorer = (props: FileExplorerProps) => { } const handleClickFolder = async (path: string, type: 'folder' | 'file' | 'gist') => { + console.log({ state, props }) if (state.ctrlKey) { if (props.focusElement.findIndex((item) => item.key === path) !== -1) { const focusElement = props.focusElement.filter((item) => item.key !== path) @@ -349,6 +351,7 @@ export const FileExplorer = (props: FileExplorerProps) => { { console.log('sorting clicked') sortIcon === sortIconDesc ? setSortIcon(sortIconAsc) : setSortIcon(sortIconDesc) + props.dispatchDirectoriesSort(files[ROOT_PATH]) }}>
diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index d0b578d85e8..5eb61aa8a1f 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -1,6 +1,7 @@ import { customAction } from '@remixproject/plugin-api' import { createContext, SyntheticEvent } from 'react' import { BrowserState } from '../reducers/workspace' +import { FileType } from '../types' export const FileSystemContext = createContext<{ fs: BrowserState, @@ -13,6 +14,7 @@ export const FileSystemContext = createContext<{ dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, opts?, initGitRepo?: boolean) => Promise, toast: (toasterMsg: string) => void, dispatchFetchWorkspaceDirectory: (path: string) => Promise, + dispatchDirectoriesSort: (files: { [x: string]: Record } | any, direction?: 'asc' | 'desc') => Promise, dispatchSwitchToWorkspace: (name: string) => Promise, dispatchRenameWorkspace: (oldName: string, workspaceName: string) => Promise, dispatchDeleteWorkspace: (workspaceName: string) => Promise, @@ -47,5 +49,4 @@ export const FileSystemContext = createContext<{ dispatchCreateSlitherGithubAction: () => Promise dispatchCreateHelperScripts: (script: string) => Promise }>(null) - - \ No newline at end of file + diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index 13adb71235f..1a534a0e81f 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -76,6 +76,11 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await fetchDirectory(path) } + const dispatchDirectoriesSort = async (files: any, path?: string, direction?: 'asc' | 'desc') => { + const result = await fetchDirectory(files.path ?? path) + console.log(result) + } + const dispatchAddInputField = async (path: string, type: 'file' | 'folder') => { await addInputField(type, path) } @@ -305,6 +310,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => { toast, dispatchInitWorkspace, dispatchFetchDirectory, + dispatchDirectoriesSort, dispatchAddInputField, dispatchRemoveInputField, dispatchCreateWorkspace, diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 50c1fd508f1..9cec5c880c8 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -951,7 +951,7 @@ const fetchDirectoryContent = ( payload: {fileTree; path: string; type?: 'file' | 'folder'}, deletePath?: string ): {[x: string]: Record} => { - console.trace() + // console.trace() if (!payload.fileTree) return state.mode === 'browser' ? state.browser.files @@ -1026,8 +1026,6 @@ const fetchDirectoryContent = ( } } files = _.setWith(files, _path, prevFiles, Object) - const newFiles = sortFilesFetched(files) - console.log({ newFiles }) } else { files = { [payload.path]: normalize( @@ -1037,8 +1035,7 @@ const fetchDirectoryContent = ( ) } } - const newFiles = sortFilesFetched(files) - return newFiles + return files } } } 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 5d2932ab347..b165cc006a3 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -1018,6 +1018,7 @@ export function Workspace() { dispatchHandleClickFile={global.dispatchHandleClickFile} dispatchSetFocusElement={global.dispatchSetFocusElement} dispatchFetchDirectory={global.dispatchFetchDirectory} + dispatchDirectoriesSort={global.dispatchDirectoriesSort} dispatchRemoveInputField={global.dispatchRemoveInputField} dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} @@ -1076,6 +1077,7 @@ export function Workspace() { dispatchHandleClickFile={global.dispatchHandleClickFile} dispatchSetFocusElement={global.dispatchSetFocusElement} dispatchFetchDirectory={global.dispatchFetchDirectory} + dispatchDirectoriesSort={global.dispatchDirectoriesSort} dispatchRemoveInputField={global.dispatchRemoveInputField} dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index 5ded4df7d48..7776ec86d11 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -108,6 +108,7 @@ export interface FileExplorerProps { dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise, dispatchSetFocusElement: (elements: { key: string, type: 'file' | 'folder' | 'gist' }[]) => Promise, dispatchFetchDirectory:(path: string) => Promise, + dispatchDirectoriesSort: (files: { [x: string]: Record } | any, direction?: 'asc' | 'desc') => Promise, dispatchRemoveInputField:(path: string) => Promise, dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise, dispatchHandleExpandPath: (paths: string[]) => Promise, @@ -202,4 +203,4 @@ export type FileFocusContextType = { export type CopyElementType = { key: string type: 'folder' | 'gist' | 'file' | 'workspace' -} \ No newline at end of file +} From ec94107d1178263eaea20981295c771debc2efeb Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 14 Sep 2023 18:47:07 +0100 Subject: [PATCH 06/18] initial sorting fixed --- apps/remix-ide/src/app/files/fileManager.ts | 2 +- .../workspace/src/lib/actions/index.ts | 1 - .../workspace/src/lib/actions/payload.ts | 8 ++-- .../workspace/src/lib/actions/workspace.ts | 8 ++-- .../src/lib/components/file-explorer.tsx | 18 ++++---- .../workspace/src/lib/contexts/index.ts | 3 +- .../src/lib/providers/FileSystemProvider.tsx | 10 +---- .../workspace/src/lib/reducers/workspace.ts | 42 +++++++++---------- .../workspace/src/lib/remix-ui-workspace.tsx | 29 ++++++++++--- .../remix-ui/workspace/src/lib/types/index.ts | 9 +++- 10 files changed, 75 insertions(+), 55 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index e24680e91fa..ca4d6eab285 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -713,7 +713,7 @@ class FileManager extends Plugin { } try { // This make sure dependencies are loaded in the editor context. - // This ensure monaco is aware of deps artifacts, so it can provide basic features like "go to" symbols. + // This ensure monaco is aware of deps artifacts, so it can provide basic features like "go to" symbols. await this.editor.handleTypeScriptDependenciesOf(file, content, path => this.readFile(path), path => this.exists(path)) } catch (e) { console.log('unable to handle TypeScript dependencies of', file) diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index f7c5098426b..2e762c07193 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -142,7 +142,6 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. } export const fetchDirectory = async (path: string) => { - console.trace() const provider = plugin.fileManager.currentFileProvider() const promise = new Promise((resolve) => { provider.resolveDirectory(path, (error, fileTree) => { diff --git a/libs/remix-ui/workspace/src/lib/actions/payload.ts b/libs/remix-ui/workspace/src/lib/actions/payload.ts index ea804ce2d17..a8d5e168be4 100644 --- a/libs/remix-ui/workspace/src/lib/actions/payload.ts +++ b/libs/remix-ui/workspace/src/lib/actions/payload.ts @@ -140,17 +140,17 @@ export const fetchWorkspaceDirectoryError = (error: any) => { } } -export const fetchWorkspaceDirectoryRequest = (promise: Promise) => { +export const fetchWorkspaceDirectoryRequest = (promise: Promise, direction?: 'asc' | 'desc') => { return { type: 'FETCH_WORKSPACE_DIRECTORY_REQUEST', - payload: promise + payload: { promise, direction } } } -export const fetchWorkspaceDirectorySuccess = (path: string, fileTree) => { +export const fetchWorkspaceDirectorySuccess = (path: string, fileTree, direction?: 'asc' | 'desc') => { return { type: 'FETCH_WORKSPACE_DIRECTORY_SUCCESS', - payload: { path, fileTree } + payload: { path, fileTree, direction } } } diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 37652f1b049..bfa484a23e1 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -266,7 +266,7 @@ export const workspaceExists = async (name: string) => { return await browserProvider.exists(workspacePath) } -export const fetchWorkspaceDirectory = async (path: string) => { +export const fetchWorkspaceDirectory = async (path: string, direction?: 'asc' | 'desc') => { if (!path) return const provider = plugin.fileManager.currentFileProvider() const promise = new Promise((resolve) => { @@ -277,9 +277,9 @@ export const fetchWorkspaceDirectory = async (path: string) => { }) }) - dispatch(fetchWorkspaceDirectoryRequest(promise)) + dispatch(fetchWorkspaceDirectoryRequest(promise, direction)) promise.then((fileTree) => { - dispatch(fetchWorkspaceDirectorySuccess(path, fileTree)) + dispatch(fetchWorkspaceDirectorySuccess(path, fileTree, direction)) }).catch((error) => { dispatch(fetchWorkspaceDirectoryError({ error })) }) @@ -683,7 +683,7 @@ const scriptsRef = { 'etherscan': etherscanScripts } export const createHelperScripts = async (script: string) => { - + if (!scriptsRef[script]) return await scriptsRef[script](plugin) plugin.call('notification', 'toast', 'scripts added in the "scripts" folder') 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 e398bdea9e8..ee92730dc96 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -20,6 +20,10 @@ export const FileExplorer = (props: FileExplorerProps) => { contextMenuItems, removedContextMenuItems, files, + sortIconDesc, + sortIconAsc, + sortIcon, + setSortIcon, workspaceState, toGist, addMenuItems, @@ -31,12 +35,8 @@ export const FileExplorer = (props: FileExplorerProps) => { uploadFolder, fileState } = props - const sortIconDesc = 'fa fa-sort-alpha-desc justify-end' - const sortIconAsc = 'fa fa-sort-alpha-up justify-end' const [state, setState] = useState(workspaceState) - const [sortIcon, setSortIcon] = useState(sortIconDesc) const treeRef = useRef(null) - console.log({ props }) useEffect(() => { if (contextMenuItems) { @@ -349,9 +349,13 @@ export const FileExplorer = (props: FileExplorerProps) => { tooltipText={} > { - console.log('sorting clicked') - sortIcon === sortIconDesc ? setSortIcon(sortIconAsc) : setSortIcon(sortIconDesc) - props.dispatchDirectoriesSort(files[ROOT_PATH]) + if(sortIcon === sortIconAsc) { + setSortIcon(sortIconDesc) + props.setTriggerSort('desc') + } else { + setSortIcon(sortIconAsc) + props.setTriggerSort('asc') + } }}> diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 5eb61aa8a1f..ebf04c47a95 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -13,8 +13,7 @@ export const FileSystemContext = createContext<{ dispatchRemoveInputField:(path: string) => Promise, dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, opts?, initGitRepo?: boolean) => Promise, toast: (toasterMsg: string) => void, - dispatchFetchWorkspaceDirectory: (path: string) => Promise, - dispatchDirectoriesSort: (files: { [x: string]: Record } | any, direction?: 'asc' | 'desc') => Promise, + dispatchFetchWorkspaceDirectory: (path: string, direction?: 'asc' | 'desc') => Promise, dispatchSwitchToWorkspace: (name: string) => Promise, dispatchRenameWorkspace: (oldName: string, workspaceName: string) => Promise, dispatchDeleteWorkspace: (workspaceName: string) => Promise, diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index 1a534a0e81f..78d4afc89e5 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -76,11 +76,6 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await fetchDirectory(path) } - const dispatchDirectoriesSort = async (files: any, path?: string, direction?: 'asc' | 'desc') => { - const result = await fetchDirectory(files.path ?? path) - console.log(result) - } - const dispatchAddInputField = async (path: string, type: 'file' | 'folder') => { await addInputField(type, path) } @@ -93,8 +88,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await createWorkspace(workspaceName, workspaceTemplateName, opts, null, null, initGitRepo) } - const dispatchFetchWorkspaceDirectory = async (path: string) => { - await fetchWorkspaceDirectory(path) + const dispatchFetchWorkspaceDirectory = async (path: string, direction?: 'asc' | 'desc') => { + await fetchWorkspaceDirectory(path, direction) } const dispatchSwitchToWorkspace = async (name: string) => { @@ -310,7 +305,6 @@ export const FileSystemProvider = (props: WorkspaceProps) => { toast, dispatchInitWorkspace, dispatchFetchDirectory, - dispatchDirectoriesSort, dispatchAddInputField, dispatchRemoveInputField, dispatchCreateWorkspace, diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 9cec5c880c8..908cd15691d 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -10,6 +10,7 @@ interface Action { export interface BrowserState { browser: { currentWorkspace: string + sort?: 'asc' | 'desc', workspaces: { name: string isGitRepo: boolean @@ -71,6 +72,7 @@ export interface BrowserState { export const browserInitialState: BrowserState = { browser: { currentWorkspace: '', + sort: null, workspaces: [], files: {}, expandPath: [], @@ -255,12 +257,13 @@ export const browserReducer = (state = browserInitialState, action: Action) => { } case 'FETCH_WORKSPACE_DIRECTORY_SUCCESS': { - const payload = action.payload as {path: string; fileTree} + const payload = action.payload as {path: string; fileTree, direction?: 'asc' | 'desc'} return { ...state, browser: { ...state.browser, + sort: payload.direction ?? 'asc', files: state.mode === 'browser' ? fetchWorkspaceDirectoryContent(state, payload) @@ -934,15 +937,9 @@ const removeInputField = ( } const sortFilesFetched = (folderStructure: any, direction?: 'asc' | 'desc') => { - // eslint-disable-next-line prefer-const - let newResult = _.fromPairs( - direction && direction === 'desc' ? _.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name).reverse() : _.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name)) - let target = {} - Object.assign(target, newResult) - const result = { '/': target } - target = null - newResult = null - return result + const newResult = direction && direction === 'desc' ? _.fromPairs(_.sortBy(_.toPairs(folderStructure), (x: any) => x[0]).reverse()) + : _.fromPairs(_.sortBy(_.toPairs(folderStructure), (x: any) => x[0])) + return Object.assign({}, newResult) } // IDEA: Modify function to remove blank input field without fetching content @@ -951,14 +948,13 @@ const fetchDirectoryContent = ( payload: {fileTree; path: string; type?: 'file' | 'folder'}, deletePath?: string ): {[x: string]: Record} => { - // console.trace() if (!payload.fileTree) return state.mode === 'browser' ? state.browser.files : state[state.mode].files if (state.mode === 'browser') { if (payload.path === ROOT_PATH) { - let files = normalize(payload.fileTree, ROOT_PATH, payload.type) + let files = normalize(payload.fileTree, ROOT_PATH, payload.type, state) files = _.merge(files, state.browser.files[ROOT_PATH]) if (deletePath) delete files[deletePath] return {[ROOT_PATH]: files} @@ -979,7 +975,7 @@ const fetchDirectoryContent = ( if (prevFiles) { prevFiles.child = _.merge( - normalize(payload.fileTree, payload.path, payload.type), + normalize(payload.fileTree, payload.path, payload.type, state), prevFiles.child ) if (deletePath) { @@ -995,7 +991,8 @@ const fetchDirectoryContent = ( [payload.path]: normalize( payload.fileTree, payload.path, - payload.type + payload.type, + state ) } } @@ -1015,7 +1012,7 @@ const fetchDirectoryContent = ( if (prevFiles) { prevFiles.child = _.merge( - normalize(payload.fileTree, payload.path, payload.type), + normalize(payload.fileTree, payload.path, payload.type, state), prevFiles.child ) if (deletePath) { @@ -1031,7 +1028,8 @@ const fetchDirectoryContent = ( [payload.path]: normalize( payload.fileTree, payload.path, - payload.type + payload.type, + state ) } } @@ -1044,7 +1042,7 @@ const fetchWorkspaceDirectoryContent = ( state: BrowserState, payload: {fileTree; path: string} ): {[x: string]: Record} => { - const files = normalize(payload.fileTree, ROOT_PATH) + const files = normalize(payload.fileTree, ROOT_PATH, null, state) return {[ROOT_PATH]: files} } @@ -1052,10 +1050,11 @@ const fetchWorkspaceDirectoryContent = ( const normalize = ( filesList, directory?: string, - newInputType?: 'folder' | 'file' + newInputType?: 'folder' | 'file', + state?: BrowserState ): Record => { - const folders = {} - const files = {} + let folders = {} + let files = {} Object.keys(filesList || {}).forEach((key) => { key = key.replace(/^\/|\/$/g, '') // remove first and last slash @@ -1099,7 +1098,8 @@ const normalize = ( type: 'file' } } - + folders = sortFilesFetched(folders, state.browser.sort) + files = sortFilesFetched(files, state.browser.sort) return Object.assign({}, folders, files) } 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 b165cc006a3..a7ef6341c31 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -8,10 +8,13 @@ import './css/remix-ui-workspace.css' import {ROOT_PATH, TEMPLATE_NAMES} from './utils/constants' import {HamburgerMenu} from './components/workspace-hamburger' -import {MenuItems, WorkSpaceState} from './types' +import {FileType, MenuItems, WorkSpaceState} from './types' import {contextMenuActions} from './utils' import FileExplorerContextMenu from './components/file-explorer-context-menu' import {customAction} from '@remixproject/plugin-api' +import * as _ from 'lodash' + + const _paq = (window._paq = window._paq || []) @@ -46,9 +49,11 @@ export function Workspace() { const initGitRepoRef = useRef() const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter((branch) => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : [] const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null - + const sortIconDesc = 'fa fa-sort-alpha-desc justify-end' + const sortIconAsc = 'fa fa-sort-alpha-up justify-end' + const [sortIcon, setSortIcon] = useState(sortIconDesc) + const [triggerSort, setTriggerSort] = useState<'asc' | 'desc'>(null) const [canPaste, setCanPaste] = useState(false) - const [state, setState] = useState({ ctrlKey: false, newFileName: '', @@ -126,6 +131,10 @@ export function Workspace() { } }, [global.fs.browser.currentWorkspace, global.fs.localhost.sharedFolder, global.fs.mode]) + useEffect(() => { + global.dispatchFetchWorkspaceDirectory(ROOT_PATH, triggerSort) + }, [triggerSort]) + useEffect(() => { if (global.fs.browser.currentWorkspace && !global.fs.browser.workspaces.find(({name}) => name === global.fs.browser.currentWorkspace)) { if (global.fs.browser.workspaces.length > 0) { @@ -994,6 +1003,12 @@ export function Workspace() { contextMenuItems={global.fs.browser.contextMenu.registeredMenuItems} removedContextMenuItems={global.fs.browser.contextMenu.removedMenuItems} files={global.fs.browser.files} + triggerSort={triggerSort} + setTriggerSort={setTriggerSort} + sortIcon={sortIcon} + sortIconAsc={sortIconAsc} + sortIconDesc={sortIconDesc} + setSortIcon={setSortIcon} workspaceState={state} expandPath={global.fs.browser.expandPath} focusEdit={global.fs.focusEdit} @@ -1018,7 +1033,6 @@ export function Workspace() { dispatchHandleClickFile={global.dispatchHandleClickFile} dispatchSetFocusElement={global.dispatchSetFocusElement} dispatchFetchDirectory={global.dispatchFetchDirectory} - dispatchDirectoriesSort={global.dispatchDirectoriesSort} dispatchRemoveInputField={global.dispatchRemoveInputField} dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} @@ -1052,6 +1066,12 @@ export function Workspace() { contextMenuItems={global.fs.localhost.contextMenu.registeredMenuItems} removedContextMenuItems={global.fs.localhost.contextMenu.removedMenuItems} files={global.fs.localhost.files} + triggerSort={triggerSort} + setTriggerSort={setTriggerSort} + sortIcon={sortIcon} + sortIconAsc={sortIconAsc} + sortIconDesc={sortIconDesc} + setSortIcon={setSortIcon} fileState={[]} workspaceState={state} expandPath={global.fs.localhost.expandPath} @@ -1077,7 +1097,6 @@ export function Workspace() { dispatchHandleClickFile={global.dispatchHandleClickFile} dispatchSetFocusElement={global.dispatchSetFocusElement} dispatchFetchDirectory={global.dispatchFetchDirectory} - dispatchDirectoriesSort={global.dispatchDirectoriesSort} dispatchRemoveInputField={global.dispatchRemoveInputField} dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index 7776ec86d11..224f5731188 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -89,6 +89,12 @@ export interface FileExplorerProps { hideIconsMenu: React.Dispatch>, showIconsMenu: boolean, focusElement: { key: string, type: 'file' | 'folder' | 'gist' }[], + setSortIcon: React.Dispatch>, + triggerSort: 'asc' | 'desc' | null, + setTriggerSort: React.Dispatch>, + sortIcon: string, + sortIconAsc: string, + sortIconDesc: string, dispatchCreateNewFile: (path: string, rootDir: string) => Promise, // eslint-disable-next-line no-undef modal:(title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, @@ -108,7 +114,6 @@ export interface FileExplorerProps { dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise, dispatchSetFocusElement: (elements: { key: string, type: 'file' | 'folder' | 'gist' }[]) => Promise, dispatchFetchDirectory:(path: string) => Promise, - dispatchDirectoriesSort: (files: { [x: string]: Record } | any, direction?: 'asc' | 'desc') => Promise, dispatchRemoveInputField:(path: string) => Promise, dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise, dispatchHandleExpandPath: (paths: string[]) => Promise, @@ -203,4 +208,4 @@ export type FileFocusContextType = { export type CopyElementType = { key: string type: 'folder' | 'gist' | 'file' | 'workspace' -} + } From a30c8bb6fb8430ee69a96e157399c46b53fc0670 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 14 Sep 2023 22:31:34 +0100 Subject: [PATCH 07/18] fix formatting of test file. modify css selector of new file --- apps/remix-ide-e2e/src/commands/addFile.ts | 2 +- .../src/tests/stressEditor.test.ts | 232 +++++++++--------- 2 files changed, 117 insertions(+), 117 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 08e9ff6d5b0..9108e677407 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('span > span[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) diff --git a/apps/remix-ide-e2e/src/tests/stressEditor.test.ts b/apps/remix-ide-e2e/src/tests/stressEditor.test.ts index 5e44c8d200d..fa30bc46864 100644 --- a/apps/remix-ide-e2e/src/tests/stressEditor.test.ts +++ b/apps/remix-ide-e2e/src/tests/stressEditor.test.ts @@ -22,166 +22,166 @@ module.exports = { }) } const fillContent = (content, mul) => { - let localContent = content - mul = 3 * mul - for (let k = 0 ; k < mul; k++) { - localContent += content - } - return localContent + let localContent = content + mul = 3 * mul + for (let k = 0 ; k < mul; k++) { + localContent += content + } + return localContent } browser.clickLaunchIcon('filePanel') - .perform((done) => { + .perform((done) => { const i = 0 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 1 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 2 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 3 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 4 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 5 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 6 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 7 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 8 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }).perform((done) => { + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }).perform((done) => { const i = 9 const localContent = fillContent(content, i) contents[i] = localContent const name = 'test_' + i + '.sol' browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') - .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) - .sendKeys('*[data-id$="/blank"] .remixui_items', name) - .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) - .getText('.remix_ui_terminal_block', (result) => { - console.log(result) - }) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) - .setEditorValue(localContent) - done() - }) - .pause(10000) + .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) + .sendKeys('*[data-id$="/blank"] .remixui_items', name) + .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) + .getText('.remix_ui_terminal_block', (result) => { + console.log(result) + }) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) + .setEditorValue(localContent) + done() + }) + .pause(10000) .refreshPage() .perform(done => checkContent(0, done)) .perform(done => checkContent(1, done)) @@ -202,12 +202,12 @@ const content = ` pragma solidity >=0.7.0 <0.9.0; -/** +/** * @title Ballot * @dev Implements voting process along with vote delegation| */ contract Ballot { - + struct Voter { uint weight; // weight is accumulated by delegation bool voted; // if true, that person already voted @@ -216,7 +216,7 @@ contract Ballot { } struct Proposal { - // If you can limit the length to a certain number of bytes, + // If you can limit the length to a certain number of bytes, // always use one of bytes1 to bytes32 because they are much cheaper bytes32 name; // short name (up to 32 bytes) uint voteCount; // number of accumulated votes @@ -230,7 +230,7 @@ contract Ballot { function () test { - /** + /** * @dev Create a new ballot to choose one of 'proposalNames'. * @param proposalNames names of proposals */ @@ -248,8 +248,8 @@ function () test { })); } } - - /** + + /** * @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. * @param voter address of voter */ @@ -312,7 +312,7 @@ function () test { proposals[proposal].voteCount += sender.weight; } - /** + /** * @dev Computes the winning proposal taking all previous votes into account. * @return winningProposal_ index of winning proposal in the proposals array */ @@ -328,7 +328,7 @@ function () test { } } - /** + /** * @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then * @return winnerName_ the name of the winner */ From 476bbc9f02665db588e6cd5b888c61f0741d8839 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 14 Sep 2023 23:03:08 +0100 Subject: [PATCH 08/18] e2e --- apps/remix-ide-e2e/src/commands/addFile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 9108e677407..7a74dba1932 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('span > span[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('span[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) From ffce38768ae548308cd84fba53a1d28bb2ef9aca Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Fri, 15 Sep 2023 10:04:57 +0100 Subject: [PATCH 09/18] move sort icon --- libs/remix-ui/workspace/src/lib/components/file-explorer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ee92730dc96..02265622724 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -339,7 +339,7 @@ export const FileExplorer = (props: FileExplorerProps) => { uploadFile={uploadFile} uploadFolder={uploadFolder} /> - + Date: Fri, 15 Sep 2023 23:37:37 +0100 Subject: [PATCH 10/18] fix selector --- apps/remix-ide-e2e/src/commands/addFile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 7a74dba1932..4421381c100 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('span[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('*[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) From 7d72103682ebb5871ad161cd30ba6f6f95b873de Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sat, 16 Sep 2023 00:47:21 +0100 Subject: [PATCH 11/18] add data-ids to fix e2e --- apps/remix-ide-e2e/src/commands/addFile.ts | 2 +- .../workspace/src/lib/components/file-explorer-menu.tsx | 2 +- libs/remix-ui/workspace/src/lib/components/file-explorer.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 4421381c100..d31f953f737 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('*[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('*[data-id="spanContaining"] > *[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx index 19e079a7094..714bf43f78c 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx @@ -72,7 +72,7 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => { {props.title} - + {state.menuItems.map(({action, title, icon, placement}, index) => { if (action === 'uploadFile') { return ( 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 02265622724..b653cc7eeb3 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -329,7 +329,7 @@ export const FileExplorer = (props: FileExplorerProps) => { id="treeViewItem" controlBehaviour={true} label={ -
+
Date: Sat, 16 Sep 2023 01:10:19 +0100 Subject: [PATCH 12/18] modify selector --- apps/remix-ide-e2e/src/commands/addFile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index d31f953f737..bfef787a766 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('*[data-id="spanContaining"] > *[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('span[data-id="spanContaining"] > span[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) From ff4a41aca4480dbabd20d36e59d6277c6628347d Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sat, 16 Sep 2023 13:29:52 +0100 Subject: [PATCH 13/18] use id in selector --- apps/remix-ide-e2e/src/commands/addFile.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index bfef787a766..97cc8ef284a 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,8 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('span[data-id="spanContaining"] > span[data-id="fileExplorerNewFilecreateNewFile"]') + // browser.click('*[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('#createNewFile') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) From 38a9713d7d33d65e8637fcb5f8d8b3e26679d641 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sat, 16 Sep 2023 13:50:32 +0100 Subject: [PATCH 14/18] e2e --- apps/remix-ide-e2e/src/commands/addFile.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 97cc8ef284a..7a74dba1932 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,8 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - // browser.click('*[data-id="fileExplorerNewFilecreateNewFile"]') - browser.click('#createNewFile') + browser.click('span[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) From d9b9afb046addb6a0a173b959a5520358cf0fe72 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 18 Sep 2023 09:51:32 +0100 Subject: [PATCH 15/18] simplify selector for addFile command --- apps/remix-ide-e2e/src/commands/addFile.ts | 3 ++- libs/remix-ui/workspace/src/lib/components/file-explorer.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 7a74dba1932..d4d4b585b0b 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,8 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('span[data-id="fileExplorerNewFilecreateNewFile"]') + // browser.click('span[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('#fileExplorerMenuContainer > span#createNewFile') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) 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 b653cc7eeb3..a6b3454372c 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -329,7 +329,7 @@ export const FileExplorer = (props: FileExplorerProps) => { id="treeViewItem" controlBehaviour={true} label={ -
+
Date: Mon, 18 Sep 2023 11:32:29 +0100 Subject: [PATCH 16/18] revert selector --- apps/remix-ide-e2e/src/commands/addFile.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index d4d4b585b0b..4421381c100 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,8 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - // browser.click('span[data-id="fileExplorerNewFilecreateNewFile"]') - browser.click('#fileExplorerMenuContainer > span#createNewFile') + browser.click('*[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) From f9fa3d28a8744bd7043e8a7e345875c6162511d7 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 18 Sep 2023 12:33:06 +0100 Subject: [PATCH 17/18] remove asterisk --- apps/remix-ide-e2e/src/commands/addFile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 4421381c100..08e9ff6d5b0 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -43,7 +43,7 @@ function addFile(browser: NightwatchBrowser, name: string, content: NightwatchCo done() }) } else { - browser.click('*[data-id="fileExplorerNewFilecreateNewFile"]') + browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') .waitForElementContainsText('*[data-id$="/blank"]', '', 60000) .sendKeys('*[data-id$="/blank"] .remixui_items', name) .sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER) From 3cd34e105f6dc2b3b633036381f12e19524d7672 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 18 Sep 2023 13:07:07 +0100 Subject: [PATCH 18/18] fix null reference crashing ide during e2e --- .../workspace/src/lib/reducers/workspace.ts | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 908cd15691d..bbc6773991f 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -954,7 +954,7 @@ const fetchDirectoryContent = ( : state[state.mode].files if (state.mode === 'browser') { if (payload.path === ROOT_PATH) { - let files = normalize(payload.fileTree, ROOT_PATH, payload.type, state) + let files = normalize(payload.fileTree, state, ROOT_PATH, payload.type) files = _.merge(files, state.browser.files[ROOT_PATH]) if (deletePath) delete files[deletePath] return {[ROOT_PATH]: files} @@ -975,7 +975,7 @@ const fetchDirectoryContent = ( if (prevFiles) { prevFiles.child = _.merge( - normalize(payload.fileTree, payload.path, payload.type, state), + normalize(payload.fileTree, state, payload.path, payload.type), prevFiles.child ) if (deletePath) { @@ -990,9 +990,9 @@ const fetchDirectoryContent = ( files = { [payload.path]: normalize( payload.fileTree, + state, payload.path, - payload.type, - state + payload.type ) } } @@ -1000,7 +1000,7 @@ const fetchDirectoryContent = ( } } else { if (payload.path === ROOT_PATH) { - let files = normalize(payload.fileTree, ROOT_PATH, payload.type) + let files = normalize(payload.fileTree, state, ROOT_PATH, payload.type) files = _.merge(files, state.localhost.files[ROOT_PATH]) if (deletePath) delete files[deletePath] @@ -1012,7 +1012,7 @@ const fetchDirectoryContent = ( if (prevFiles) { prevFiles.child = _.merge( - normalize(payload.fileTree, payload.path, payload.type, state), + normalize(payload.fileTree, state, payload.path, payload.type), prevFiles.child ) if (deletePath) { @@ -1027,9 +1027,9 @@ const fetchDirectoryContent = ( files = { [payload.path]: normalize( payload.fileTree, + state, payload.path, payload.type, - state ) } } @@ -1042,16 +1042,16 @@ const fetchWorkspaceDirectoryContent = ( state: BrowserState, payload: {fileTree; path: string} ): {[x: string]: Record} => { - const files = normalize(payload.fileTree, ROOT_PATH, null, state) + const files = normalize(payload.fileTree, state, ROOT_PATH, null) return {[ROOT_PATH]: files} } const normalize = ( filesList, + state: BrowserState, directory?: string, - newInputType?: 'folder' | 'file', - state?: BrowserState + newInputType?: 'folder' | 'file' ): Record => { let folders = {} let files = {} @@ -1098,8 +1098,9 @@ const normalize = ( type: 'file' } } - folders = sortFilesFetched(folders, state.browser.sort) - files = sortFilesFetched(files, state.browser.sort) + + folders = sortFilesFetched(folders, state.browser?.sort) + files = sortFilesFetched(files, state.browser?.sort) return Object.assign({}, folders, files) }