fix saving and loading gist workspace/folder

pull/4550/head
yann300 9 months ago
parent 3aaa6446ee
commit 9f15938a0a
  1. 15
      apps/remix-ide/src/app/panels/file-panel.js
  2. 4
      apps/remix-ide/src/app/tabs/locales/en/filePanel.json
  3. 2
      libs/remix-core-plugin/src/lib/gist-handler.ts
  4. 18
      libs/remix-ui/workspace/src/lib/actions/index.ts
  5. 12
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  6. 26
      libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx
  7. 4
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  8. 8
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  9. 7
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  10. 11
      libs/remix-ui/workspace/src/lib/utils/index.ts

@ -46,6 +46,7 @@ const profile = {
'loadTemplate', 'loadTemplate',
'clone', 'clone',
'isExpanded', 'isExpanded',
'isGist'
], ],
events: ['setWorkspace', 'workspaceRenamed', 'workspaceDeleted', 'workspaceCreated'], events: ['setWorkspace', 'workspaceRenamed', 'workspaceDeleted', 'workspaceCreated'],
icon: 'assets/img/fileManager.webp', icon: 'assets/img/fileManager.webp',
@ -131,6 +132,20 @@ module.exports = class Filepanel extends ViewPlugin {
}) })
} }
/**
* return the gist id if the current workspace is a gist workspace, otherwise returns null
* @argument {String} workspaceName - the name of the workspace to check against. default to the current workspace.
* @returns {string} gist id or null
*/
isGist (workspaceName) {
workspaceName = workspaceName || this.currentWorkspaceMetadata && this.currentWorkspaceMetadata.name
const isGist = workspaceName.startsWith('gist')
if (isGist) {
return workspaceName.split(' ')[1]
}
return null
}
getCurrentWorkspace() { getCurrentWorkspace() {
return this.currentWorkspaceMetadata return this.currentWorkspaceMetadata
} }

@ -62,10 +62,10 @@
"filePanel.compileForNahmii": "Compile for Nahmii", "filePanel.compileForNahmii": "Compile for Nahmii",
"filePanel.createNewFile": "Create new file", "filePanel.createNewFile": "Create new file",
"filePanel.createNewFolder": "Create new folder", "filePanel.createNewFolder": "Create new folder",
"filePanel.publishToGist": "Publish all files to GitHub gist", "filePanel.publishToGist": "Publish workspace to GitHub gist",
"filePanel.uploadFile": "Upload files", "filePanel.uploadFile": "Upload files",
"filePanel.uploadFolder": "Upload folder", "filePanel.uploadFolder": "Upload folder",
"filePanel.updateGist": "Update the current [gist] explorer", "filePanel.updateGist": "Publish workspace to GitHub gist",
"filePanel.viewAllBranches": "View all branches", "filePanel.viewAllBranches": "View all branches",
"filePanel.createBranch": "Create branch", "filePanel.createBranch": "Create branch",
"filePanel.switchBranches": "Switch branches", "filePanel.switchBranches": "Switch branches",

@ -117,7 +117,7 @@ export class GistHandler extends Plugin {
const obj: StringByString = {} const obj: StringByString = {}
Object.keys(data.files).forEach((element) => { Object.keys(data.files).forEach((element) => {
const path = element.replace(/\.\.\./g, '/') const path = element.replace(/\.\.\./g, '/')
obj['/gist-' + gistId + '/' + path] = data.files[element] obj['/' + path] = data.files[element]
}) })
this.call('fileManager', 'setBatchFiles', obj, isElectron()? 'electron':'workspace', true, async (errorSavingFiles: any) => { this.call('fileManager', 'setBatchFiles', obj, isElectron()? 'electron':'workspace', true, async (errorSavingFiles: any) => {
if (errorSavingFiles) { if (errorSavingFiles) {

@ -225,14 +225,19 @@ export type SolidityConfiguration = {
runs: string runs: string
} }
export const publishToGist = async (path?: string, type?: string) => { export const publishToGist = async (path?: string) => {
// If 'id' is not defined, it is not a gist update but a creation so we have to take the files from the browser explorer. // If 'id' is not defined, it is not a gist update but a creation so we have to take the files from the browser explorer.
const folder = path || '/' const folder = path || '/'
try { try {
const name = await plugin.call('filePanel', 'getCurrentWorkspace') let id
const id = name && name.startsWith('gist ') ? name.split(' ')[1] : null if (path) {
// check if the current folder is a gist folder
id = await plugin.call('filePanel', 'isGist', extractNameFromKey(path))
} else {
// check if the current workspace is a gist workspace
id = await plugin.call('filePanel', 'isGist')
}
const packaged = await packageGistFiles(folder) const packaged = await packageGistFiles(folder)
// check for token // check for token
const config = plugin.registry.get('config').api const config = plugin.registry.get('config').api
@ -521,11 +526,6 @@ const packageGistFiles = async (directory) => {
if (/^\s+$/.test(content) || !content.length) { if (/^\s+$/.test(content) || !content.length) {
content = '// this line is added to create a gist. Empty file is not allowed.' content = '// this line is added to create a gist. Empty file is not allowed.'
} }
if (path.indexOf('gist-') === 0) {
path = path.split('/')
path.shift()
path = path.join('/')
}
path = path.replace(/\//g, '...') path = path.replace(/\//g, '...')
ret[path] = { content } ret[path] = { content }
}) })

@ -609,6 +609,7 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea
Object.keys(items) Object.keys(items)
.filter((item) => items[item].isDirectory) .filter((item) => items[item].isDirectory)
.map(async (folder) => { .map(async (folder) => {
const name = folder.replace(workspacesPath + '/', '')
const isGitRepo: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.git') const isGitRepo: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.git')
const hasGitSubmodules: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.gitmodules') const hasGitSubmodules: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.gitmodules')
if (isGitRepo) { if (isGitRepo) {
@ -618,17 +619,20 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea
branches = await getGitRepoBranches(folder) branches = await getGitRepoBranches(folder)
currentBranch = await getGitRepoCurrentBranch(folder) currentBranch = await getGitRepoCurrentBranch(folder)
return { return {
name: folder.replace(workspacesPath + '/', ''), name,
isGitRepo, isGitRepo,
branches, branches,
currentBranch, currentBranch,
hasGitSubmodules hasGitSubmodules,
isGist: null
} }
} else { } else {
const gistId = await plugin.call('filePanel', 'isGist', name)
return { return {
name: folder.replace(workspacesPath + '/', ''), name,
isGitRepo, isGitRepo,
hasGitSubmodules hasGitSubmodules,
isGist: gistId
} }
} }
}) })

@ -33,6 +33,13 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
placement: 'top', placement: 'top',
platforms:[appPlatformTypes.web] platforms:[appPlatformTypes.web]
}, },
{
action: 'updateGist',
title: 'Update the cdddurrent gist',
icon: 'fab fa-github',
placement: 'bottom-start',
platforms:[appPlatformTypes.web]
},
{ {
action: 'uploadFile', action: 'uploadFile',
title: 'Upload files into current workspace', title: 'Upload files into current workspace',
@ -46,13 +53,6 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
icon: 'far fa-folder-upload', icon: 'far fa-folder-upload',
placement: 'top', placement: 'top',
platforms:[appPlatformTypes.web] platforms:[appPlatformTypes.web]
},
{
action: 'updateGist',
title: 'Update the current [gist] explorer',
icon: 'fab fa-github',
placement: 'bottom-start',
platforms:[appPlatformTypes.web]
} }
].filter( ].filter(
(item) => (item) =>
@ -65,16 +65,6 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
}) })
const enableDirUpload = {directory: '', webkitdirectory: ''} const enableDirUpload = {directory: '', webkitdirectory: ''}
useEffect(() => {
const actions = {
updateGist: () => {}
}
setState((prevState) => {
return {...prevState, actions}
})
}, [])
return ( return (
(!global.fs.browser.isSuccessfulWorkspace ? null : (!global.fs.browser.isSuccessfulWorkspace ? null :
<> <>
@ -165,7 +155,7 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
props.createNewFile() props.createNewFile()
} else if (action === 'createNewFolder') { } else if (action === 'createNewFolder') {
props.createNewFolder() props.createNewFolder()
} else if (action === 'publishToGist') { } else if (action === 'publishToGist' || action == 'updateGist') {
props.publishToGist() props.publishToGist()
} else { } else {
state.actions[action]() state.actions[action]()

@ -117,8 +117,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await deleteAllWorkspaces() await deleteAllWorkspaces()
} }
const dispatchPublishToGist = async (path?: string, type?: string) => { const dispatchPublishToGist = async (path?: string) => {
await publishToGist(path, type) await publishToGist(path)
} }
const dispatchUploadFile = async (target?: SyntheticEvent, targetFolder?: string) => { const dispatchUploadFile = async (target?: SyntheticEvent, targetFolder?: string) => {

@ -17,6 +17,7 @@ export interface BrowserState {
name: string name: string
}[] }[]
currentBranch?: string currentBranch?: string
isGist: string
}[] }[]
files: {[x: string]: Record<string, FileType>} files: {[x: string]: Record<string, FileType>}
flatTree: FileType[] flatTree: FileType[]
@ -150,7 +151,6 @@ export const browserReducer = (state = browserInitialState, action: Actions) =>
case 'SET_WORKSPACES': { case 'SET_WORKSPACES': {
const payload = action.payload const payload = action.payload
return { return {
...state, ...state,
browser: { browser: {
@ -986,8 +986,7 @@ const removeInputField = (
isDirectory: true, isDirectory: true,
path, path,
name: extractNameFromKey(path), name: extractNameFromKey(path),
type: type: 'folder',
extractNameFromKey(path).indexOf('gist-') === 0 ? 'gist' : 'folder',
child: prevFiles ? prevFiles.child : {} child: prevFiles ? prevFiles.child : {}
}, },
Object Object
@ -1117,8 +1116,7 @@ const normalize = (
path, path,
name: extractNameFromKey(path), name: extractNameFromKey(path),
isDirectory: filesList[key].isDirectory, isDirectory: filesList[key].isDirectory,
type: type: 'folder'
extractNameFromKey(path).indexOf('gist-') === 0 ? 'gist' : 'folder'
} }
} else { } else {
files[extractNameFromKey(key)] = { files[extractNameFromKey(key)] = {

@ -32,6 +32,7 @@ export function Workspace() {
hasGitSubmodules?: boolean hasGitSubmodules?: boolean
branches?: {remote: any; name: string}[] branches?: {remote: any; name: string}[]
currentBranch?: string currentBranch?: string
isGist: string
}>(null) }>(null)
const [showDropdown, setShowDropdown] = useState<boolean>(false) const [showDropdown, setShowDropdown] = useState<boolean>(false)
const [showIconsMenu, hideIconsMenu] = useState<boolean>(false) const [showIconsMenu, hideIconsMenu] = useState<boolean>(false)
@ -73,7 +74,7 @@ export function Workspace() {
}, },
mouseOverElement: null, mouseOverElement: null,
showContextMenu: false, showContextMenu: false,
reservedKeywords: [ROOT_PATH, 'gist-'], reservedKeywords: [ROOT_PATH],
copyElement: [], copyElement: [],
dragStatus: false dragStatus: false
}) })
@ -922,7 +923,6 @@ export function Workspace() {
</> </>
) )
} }
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 <div
@ -1077,11 +1077,10 @@ export function Workspace() {
</div> </div>
)} )}
{!(global.fs.browser.isRequestingWorkspace || global.fs.browser.isRequestingCloning) && global.fs.mode === 'browser' && currentWorkspace !== NO_WORKSPACE && ( {!(global.fs.browser.isRequestingWorkspace || global.fs.browser.isRequestingCloning) && global.fs.mode === 'browser' && currentWorkspace !== NO_WORKSPACE && (
<FileExplorer <FileExplorer
fileState={global.fs.browser.fileState} fileState={global.fs.browser.fileState}
name={currentWorkspace} name={currentWorkspace}
menuItems={['createNewFile', 'createNewFolder', 'publishToGist', canUpload ? 'uploadFile' : '', canUpload ? 'uploadFolder' : '']} menuItems={['createNewFile', 'createNewFolder', selectedWorkspace && selectedWorkspace.isGist ? 'updateGist' : 'publishToGist', canUpload ? 'uploadFile' : '', canUpload ? 'uploadFolder' : '']}
contextMenuItems={global.fs.browser.contextMenu.registeredMenuItems} contextMenuItems={global.fs.browser.contextMenu.registeredMenuItems}
removedContextMenuItems={global.fs.browser.contextMenu.removedMenuItems} removedContextMenuItems={global.fs.browser.contextMenu.removedMenuItems}
files={global.fs.browser.files} files={global.fs.browser.files}

@ -112,16 +112,7 @@ export const contextMenuActions: MenuItems = [{
label: 'Load a Local File', label: 'Load a Local File',
group: 4, group: 4,
platform: appPlatformTypes.web platform: appPlatformTypes.web
}, { },{
id: 'publishToGist',
name: 'Push changes to gist',
type: ['folder', 'gist'],
multiselect: false,
label: 'Publish all to Gist',
group: 4,
platform: appPlatformTypes.web
},
{
id: 'publishWorkspace', id: 'publishWorkspace',
name: 'Publish Workspace to Gist', name: 'Publish Workspace to Gist',
type: ['workspace'], type: ['workspace'],

Loading…
Cancel
Save