From 3da3eca1bdde0b6c5554bb42c20342ffec64bda0 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 7 Mar 2023 15:00:46 +0100 Subject: [PATCH] check available workspace name --- apps/remix-ide/src/app/panels/file-panel.js | 12 +++++++++++- .../src/lib/components/homeTabGetStarted.tsx | 7 ++++--- libs/remix-ui/workspace/src/lib/contexts/index.ts | 1 + .../src/lib/providers/FileSystemProvider.tsx | 1 + .../workspace/src/lib/remix-ui-workspace.tsx | 7 +++++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 2ff7a1da01..d088ffa367 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -30,7 +30,7 @@ const { SlitherHandle } = require('../files/slither-handle.js') const profile = { name: 'filePanel', displayName: 'File explorer', - methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace', 'setWorkspace', 'registerContextMenuItem', 'renameWorkspace', 'deleteWorkspace'], + methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getAvailableWorkspaceName', 'getWorkspaces', 'createWorkspace', 'setWorkspace', 'registerContextMenuItem', 'renameWorkspace', 'deleteWorkspace'], events: ['setWorkspace', 'workspaceRenamed', 'workspaceDeleted', 'workspaceCreated'], icon: 'assets/img/fileManager.webp', description: 'Remix IDE file explorer', @@ -94,6 +94,16 @@ module.exports = class Filepanel extends ViewPlugin { return this.workspaces } + getAvailableWorkspaceName (name) { + let index = 1 + let workspace = this.workspaces.find(workspace => workspace.name === name + ' - ' + index) + while (workspace) { + index++ + workspace = this.workspaces.find(workspace => workspace.name === name + ' - ' + index) + } + return name + ' - ' + index + } + setWorkspaces (workspaces) { this.workspaces = workspaces } diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx index ea349ca8cb..52e536dd27 100644 --- a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx @@ -60,9 +60,10 @@ function HomeTabGetStarted ({plugin}: HomeTabGetStartedProps) { const createWorkspace = async (templateName) => { await plugin.appManager.activatePlugin('filePanel') const timeStamp = Date.now() - const templateDisplayName = TEMPLATE_NAMES[templateName] - await plugin.call('filePanel', 'createWorkspace', templateDisplayName + " " + timeStamp, templateName) - await plugin.call('filePanel', 'setWorkspace', templateDisplayName + " " + timeStamp) + let templateDisplayName = TEMPLATE_NAMES[templateName] + templateDisplayName = await plugin.call('filePanale', 'getAvailableWorkspaceName', templateDisplayName) + await plugin.call('filePanel', 'createWorkspace', templateDisplayName, templateName) + await plugin.call('filePanel', 'setWorkspace', templateDisplayName) plugin.verticalIcons.select('filePanel') _paq.push(['trackEvent', 'hometab', 'homeGetStarted', templateName]) } diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 08c1fb7f41..04e91602ef 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -4,6 +4,7 @@ import { BrowserState } from '../reducers/workspace' export const FileSystemContext = createContext<{ fs: BrowserState, + plugin: any, modal:(title: string | JSX.Element, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, dispatchInitWorkspace:() => Promise, dispatchFetchDirectory:(path: 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 b57b10aed0..e05e92a7d2 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -255,6 +255,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => { const value = { fs, + plugin, modal, toast, dispatchInitWorkspace, 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 ba73fbf14c..43fefe1b2e 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -231,7 +231,10 @@ export function Workspace () { } else displayOzCustomRef.current.style.display = 'none' // @ts-ignore - workspaceCreateInput.current.value = `${TEMPLATE_NAMES[workspaceCreateTemplateInput.current.value || 'remixDefault']} ${Date.now()}` + let displayName = TEMPLATE_NAMES[(workspaceCreateTemplateInput.current && workspaceCreateTemplateInput.current.value) || 'remixDefault'] + displayName = global.plugin.getAvailableWorkspaceName(displayName) + // @ts-ignore + workspaceCreateInput.current.value = displayName } const handleTypingUrl = () => { @@ -348,7 +351,7 @@ export function Workspace () { - +