renaming, tes special character

pull/5370/head
yann300 4 years ago
parent cfee4297b0
commit 485f3df347
  1. 8
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -22,6 +22,10 @@ export interface WorkspaceProps {
initialWorkspace: string initialWorkspace: string
} }
const hasSpecialChar = (value) => {
return value.match(/[:*?"<>\\'|]/) != null || value.match(/\//) != null
}
var canUpload = window.File || window.FileReader || window.FileList || window.Blob var canUpload = window.File || window.FileReader || window.FileList || window.Blob
export const Workspace = (props: WorkspaceProps) => { export const Workspace = (props: WorkspaceProps) => {
const LOCALHOST = ' - connect to localhost - ' const LOCALHOST = ' - connect to localhost - '
@ -152,10 +156,12 @@ export const Workspace = (props: WorkspaceProps) => {
} }
const modalMessage = (title: string, body: string) => { const modalMessage = (title: string, body: string) => {
setTimeout(() => { // wait for any previous modal a chance to close
modal(title, body, { modal(title, body, {
label: 'OK', label: 'OK',
fn: () => {} fn: () => {}
}, null) }, null)
}, 200)
} }
const workspaceRenameInput = useRef() const workspaceRenameInput = useRef()
@ -165,6 +171,8 @@ export const Workspace = (props: WorkspaceProps) => {
if (workspaceRenameInput.current === undefined) return if (workspaceRenameInput.current === undefined) return
// @ts-ignore: Object is possibly 'null'. // @ts-ignore: Object is possibly 'null'.
const workspaceName = workspaceRenameInput.current.value const workspaceName = workspaceRenameInput.current.value
if (hasSpecialChar(workspaceName)) return modalMessage('Workspace Rename', 'special characters are not allowed')
const workspacesPath = props.workspace.workspacesPath const workspacesPath = props.workspace.workspacesPath
await props.fileManager.rename('browser/' + workspacesPath + '/' + state.currentWorkspace, 'browser/' + workspacesPath + '/' + workspaceName) await props.fileManager.rename('browser/' + workspacesPath + '/' + state.currentWorkspace, 'browser/' + workspacesPath + '/' + workspaceName)
setWorkspace(workspaceName) setWorkspace(workspaceName)

Loading…
Cancel
Save