Skip to content

Commit

Permalink
fix double slash (#2106)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Yankelev <12774278+FSM1@users.noreply.github.com>
  • Loading branch information
Tbaut and FSM1 authored Apr 22, 2022
1 parent 9e5ff4e commit 8f2fc0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ interface IUploadFileModuleProps {
const UploadFileModule = ({ modalOpen, close }: IUploadFileModuleProps) => {
const classes = useStyles()
const [isDoneDisabled, setIsDoneDisabled] = useState(true)
const { uploadFiles } = useFiles()
const { currentPath, refreshContents, bucket } = useFileBrowser()
const { storageSummary } = useFiles()
const { storageSummary, uploadFiles } = useFiles()

const UploadSchema = useMemo(() => object().shape({
files: array().required(t`Please select a file to upload`)
Expand All @@ -105,10 +104,13 @@ const UploadFileModule = ({ modalOpen, close }: IUploadFileModuleProps) => {

const onSubmit = useCallback(async (values: {files: Array<File & {path: string}>}, helpers) => {
if (!bucket) return

helpers.setSubmitting(true)

try {
close()
const paths = [...new Set(values.files.map(f => f.path.substring(0, f.path.lastIndexOf("/"))))]

paths.forEach(async p => {
const filesToUpload = values.files.filter((f => f.path.substring(0, f.path.lastIndexOf("/")) === p))
await uploadFiles(bucket, filesToUpload, getPathWithFile(currentPath, p))
Expand All @@ -124,17 +126,15 @@ const UploadFileModule = ({ modalOpen, close }: IUploadFileModuleProps) => {
const formik = useFormik({
initialValues: { files: [] },
validationSchema: UploadSchema,
onSubmit: onSubmit
onSubmit
})

return (
<CustomModal
active={modalOpen}
closePosition="none"
maxWidth="sm"
injectedClass={{
inner: classes.modalInner
}}
injectedClass={{ inner: classes.modalInner }}
>
<FormikProvider value={formik}>
<Form
Expand Down
13 changes: 10 additions & 3 deletions packages/files-ui/src/Utils/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ export function getURISafePathFromArray(arrayOfPaths: string[]): string {
// /path/to/somewhere + 1.txt -> /path/to/somewhere/1.txt
// /path/to/somewhere/ + 1.txt -> /path/to/somewhere/1.txt
export function getPathWithFile(path: string, fileName: string) {

// make sure the file name doesn't start with a /
// otherwise remove it
const nameToUse = fileName.startsWith("/")
? fileName.substring(1)
: fileName

return path === "/"
? `/${fileName}`
? `/${nameToUse}`
: path[path.length - 1] === "/"
? `${path}${fileName}`
: `${path}/${fileName}`
? `${path}${nameToUse}`
: `${path}/${nameToUse}`
}

// Removes a parent element
Expand Down

0 comments on commit 8f2fc0f

Please sign in to comment.