Skip to content

Commit

Permalink
folder path in route fixed (#1066)
Browse files Browse the repository at this point in the history
* fixed

* fix search redirects

Co-authored-by: Michael Yankelev <myankelev@gmail.com>
Co-authored-by: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com>
  • Loading branch information
3 people authored May 31, 2021
1 parent 248aa77 commit af17b2a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FilesList from "./views/FilesList"
import { CONTENT_TYPES } from "../../../Utils/Constants"
import DragAndDrop from "../../../Contexts/DnDContext"
import { useHistory, useLocation, useToaster } from "@chainsafe/common-components"
import { getParentPathFromFilePath } from "../../../Utils/pathUtils"
import { getArrayOfPaths, getParentPathFromFilePath, getURISafePathFromArray } from "../../../Utils/pathUtils"
import { ROUTE_LINKS } from "../../FilesRoutes"
import { t } from "@lingui/macro"
import { FileBrowserContext } from "../../../Contexts/FileBrowserContext"
Expand Down Expand Up @@ -75,9 +75,9 @@ const SearchFileBrowser: React.FC<IFileBrowserModuleProps> = ({ controls = false
const searchEntry = getSearchEntry(cid)
if (searchEntry) {
if (searchEntry.content.content_type === CONTENT_TYPES.Directory) {
redirect(ROUTE_LINKS.Drive(searchEntry.path))
redirect(ROUTE_LINKS.Drive(getURISafePathFromArray(getArrayOfPaths(searchEntry.path))))
} else {
redirect(ROUTE_LINKS.Drive(getParentPathFromFilePath(searchEntry.path)))
redirect(ROUTE_LINKS.Drive(getURISafePathFromArray(getArrayOfPaths(getParentPathFromFilePath(searchEntry.path)))))
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/files-ui/src/Components/Modules/SearchModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import clsx from "clsx"
import { ROUTE_LINKS } from "../FilesRoutes"
import { useFiles, BucketType, SearchEntry } from "../../Contexts/FilesContext"
import { CONTENT_TYPES } from "../../Utils/Constants"
import { getParentPathFromFilePath } from "../../Utils/pathUtils"
import { getArrayOfPaths, getParentPathFromFilePath, getURISafePathFromArray } from "../../Utils/pathUtils"
import { t, Trans } from "@lingui/macro"
import { CSFTheme } from "../../Themes/types"
import { useFilesApi } from "@chainsafe/common-contexts"
import { trimChar } from "../../Utils/pathUtils"

export interface SearchParams {
bucketType: BucketType
Expand Down Expand Up @@ -222,13 +223,13 @@ const SearchModule: React.FC<ISearchModule> = ({
)

const onSearchEntryClickFolder = (searchEntry: SearchEntry) => {
redirect(ROUTE_LINKS.Drive(searchEntry.path))
redirect(ROUTE_LINKS.Drive(getURISafePathFromArray(getArrayOfPaths(searchEntry.path))))
setSearchQuery("")
setSearchActive(false)
}

const onSearchEntryClickFile = (searchEntry: SearchEntry) => {
redirect(ROUTE_LINKS.Drive(getParentPathFromFilePath(searchEntry.path)))
redirect(ROUTE_LINKS.Drive(getURISafePathFromArray(getArrayOfPaths(getParentPathFromFilePath(searchEntry.path)))))
setSearchQuery("")
setSearchActive(false)
}
Expand Down Expand Up @@ -343,3 +344,4 @@ const SearchModule: React.FC<ISearchModule> = ({
}

export default SearchModule

2 changes: 1 addition & 1 deletion packages/files-ui/src/Utils/pathUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// trims a string at both ends for a character
function trimChar(str: string, char: string) {
export function trimChar(str: string, char: string) {
char = char.charAt(0)
if (str.charAt(0) === char) {
str = str.substr(1, str.length - 1)
Expand Down

0 comments on commit af17b2a

Please sign in to comment.