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',
'clone',
'isExpanded',
'isGist'
],
events: ['setWorkspace', 'workspaceRenamed', 'workspaceDeleted', 'workspaceCreated'],
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() {
return this.currentWorkspaceMetadata
}

@ -62,10 +62,10 @@
"filePanel.compileForNahmii": "Compile for Nahmii",
"filePanel.createNewFile": "Create new file",
"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.uploadFolder": "Upload folder",
"filePanel.updateGist": "Update the current [gist] explorer",
"filePanel.updateGist": "Publish workspace to GitHub gist",
"filePanel.viewAllBranches": "View all branches",
"filePanel.createBranch": "Create branch",
"filePanel.switchBranches": "Switch branches",

@ -117,7 +117,7 @@ export class GistHandler extends Plugin {
const obj: StringByString = {}
Object.keys(data.files).forEach((element) => {
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) => {
if (errorSavingFiles) {

@ -225,14 +225,19 @@ export type SolidityConfiguration = {
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.
const folder = path || '/'
try {
const name = await plugin.call('filePanel', 'getCurrentWorkspace')
const id = name && name.startsWith('gist ') ? name.split(' ')[1] : null
let id
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)
// check for token
const config = plugin.registry.get('config').api
@ -521,11 +526,6 @@ const packageGistFiles = async (directory) => {
if (/^\s+$/.test(content) || !content.length) {
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, '...')
ret[path] = { content }
})

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

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

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

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

@ -32,6 +32,7 @@ export function Workspace() {
hasGitSubmodules?: boolean
branches?: {remote: any; name: string}[]
currentBranch?: string
isGist: string
}>(null)
const [showDropdown, setShowDropdown] = useState<boolean>(false)
const [showIconsMenu, hideIconsMenu] = useState<boolean>(false)
@ -73,7 +74,7 @@ export function Workspace() {
},
mouseOverElement: null,
showContextMenu: false,
reservedKeywords: [ROOT_PATH, 'gist-'],
reservedKeywords: [ROOT_PATH],
copyElement: [],
dragStatus: false
})
@ -922,7 +923,6 @@ export function Workspace() {
</>
)
}
return (
<div className="d-flex flex-column justify-content-between h-100">
<div
@ -1077,11 +1077,10 @@ export function Workspace() {
</div>
)}
{!(global.fs.browser.isRequestingWorkspace || global.fs.browser.isRequestingCloning) && global.fs.mode === 'browser' && currentWorkspace !== NO_WORKSPACE && (
<FileExplorer
fileState={global.fs.browser.fileState}
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}
removedContextMenuItems={global.fs.browser.contextMenu.removedMenuItems}
files={global.fs.browser.files}

@ -112,16 +112,7 @@ export const contextMenuActions: MenuItems = [{
label: 'Load a Local File',
group: 4,
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',
name: 'Publish Workspace to Gist',
type: ['workspace'],

Loading…
Cancel
Save