Fixed duplicate new file

pull/5370/head
ioedeveloper 4 years ago
parent 624542e523
commit 0742681fa2
  1. 4
      .env
  2. 19
      apps/remix-ide-e2e/src/commands/addFile.ts
  3. 28
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx

@ -1,4 +1,4 @@
gist_token=ef5df4e3822bf121f1aee4616ea110309e2d49f5 gist_token=ef5df4e3822bf121f1aee4616ea110309e2d49f5
account_passphrase=<passphrase> account_passphrase=explain uniform adapt basic blue onion rebel pull rice erase volcano couple
account_password=<password> account_password=remix_is_cool
NODE_OPTIONS=--max-old-space-size=2048 NODE_OPTIONS=--max-old-space-size=2048

@ -15,20 +15,11 @@ class AddFile extends EventEmitter {
function addFile (browser: NightwatchBrowser, name: string, content: NightwatchContractContent, done: VoidFunction) { function addFile (browser: NightwatchBrowser, name: string, content: NightwatchContractContent, done: VoidFunction) {
browser.clickLaunchIcon('udapp').clickLaunchIcon('fileExplorers').click('.newFile') browser.clickLaunchIcon('udapp').clickLaunchIcon('fileExplorers').click('.newFile')
.waitForElementVisible('#modal-dialog') .pause(2000)
.perform((client, done) => { .keys(name)
browser.execute(function (fileName) { .keys(browser.Keys.ENTER)
if (fileName !== 'Untitled.sol') { .pause(1000)
document.querySelector('#modal-dialog #prompt_text').setAttribute('value', fileName) .click('[data-id="treeViewLitreeViewItembrowser/Greet.sol"]')
}
const elem = document.querySelector('#modal-footer-ok') as HTMLElement
elem.click()
}, [name], function (result) {
console.log(result)
done()
})
})
.setEditorValue(content.content) .setEditorValue(content.content)
.pause(1000) .pause(1000)
.perform(function () { .perform(function () {

@ -156,8 +156,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
filesProvider.event.register('fileRenamed', fileRenamed) filesProvider.event.register('fileRenamed', fileRenamed)
}, [state.files]) }, [state.files])
const resolveDirectory = async (folderPath, dir: File[]): Promise<File[]> => { const resolveDirectory = async (folderPath, dir: File[], isChild = false): Promise<File[]> => {
if ((extractParentFromKey(state.focusEdit.element) === name) && (dir.findIndex(({ path }) => path === state.focusEdit.element) === -1)) { if (!isChild && (state.focusEdit.element === 'browser/blank') && state.focusEdit.isNew && (dir.findIndex(({ path }) => path === 'browser/blank') === -1)) {
dir = state.focusEdit.type === 'file' ? [...dir, { dir = state.focusEdit.type === 'file' ? [...dir, {
path: state.focusEdit.element, path: state.focusEdit.element,
name: '', name: '',
@ -171,25 +171,21 @@ export const FileExplorer = (props: FileExplorerProps) => {
dir = await Promise.all(dir.map(async (file) => { dir = await Promise.all(dir.map(async (file) => {
if (file.path === folderPath) { if (file.path === folderPath) {
if ((extractParentFromKey(state.focusEdit.element) === folderPath) && state.focusEdit.isNew) { if ((extractParentFromKey(state.focusEdit.element) === folderPath) && state.focusEdit.isNew) {
if (file.child && (file.child.findIndex(({ path }) => path === state.focusEdit.element) === -1)) { file.child = state.focusEdit.type === 'file' ? [...await fetchDirectoryContent(folderPath), {
file.child = state.focusEdit.type === 'file' ? [...await fetchDirectoryContent(folderPath), { path: state.focusEdit.element,
path: state.focusEdit.element, name: '',
name: '', isDirectory: false
isDirectory: false }] : [{
}] : [{ path: state.focusEdit.element,
path: state.focusEdit.element, name: '',
name: '', isDirectory: true
isDirectory: true }, ...await fetchDirectoryContent(folderPath)]
}, ...await fetchDirectoryContent(folderPath)]
} else {
file.child = await fetchDirectoryContent(folderPath)
}
} else { } else {
file.child = await fetchDirectoryContent(folderPath) file.child = await fetchDirectoryContent(folderPath)
} }
return file return file
} else if (file.child) { } else if (file.child) {
file.child = await resolveDirectory(folderPath, file.child) file.child = await resolveDirectory(folderPath, file.child, true)
return file return file
} else { } else {
return file return file

Loading…
Cancel
Save