Skip to content

Commit

Permalink
Fix Search Results bugs (#1004)
Browse files Browse the repository at this point in the history
* fix "invalid date" in search results closes #990

* clean up lint

* fix nav to folder closes #992

* ensure selection is cleared on navigate

* fix hook warning

* make sure that date values arent undefined
  • Loading branch information
FSM1 authored May 7, 2021
1 parent 958c148 commit 974053c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useMemo } from "react"
import { Crumb, useToaster } from "@chainsafe/common-components"
import { Crumb, useHistory, useToaster } from "@chainsafe/common-components"
import { useDrive } from "../../../Contexts/DriveContext"
import { getArrayOfPaths, getPathFromArray } from "../../../Utils/pathUtils"
import { IBulkOperations, IFilesBrowserModuleProps, IFilesTableBrowserProps } from "./types"
Expand All @@ -8,6 +8,7 @@ import { CONTENT_TYPES } from "../../../Utils/Constants"
import DragAndDrop from "../../../Contexts/DnDContext"
import { useQuery } from "../../../Utils/Helpers"
import { t } from "@lingui/macro"
import { ROUTE_LINKS } from "../../FilesRoutes"
import { useLocalStorage } from "@chainsafe/browser-storage-hooks"
import { DISMISSED_SURVEY_KEY } from "../../SurveyBanner"
import { useUser } from "@chainsafe/common-contexts"
Expand All @@ -29,6 +30,7 @@ const CSFFileBrowser: React.FC<IFilesBrowserModuleProps> = ({ controls = true }:
} = useDrive()

const queryPath = useQuery().get("path")
const { redirect } = useHistory()
const { localStorageGet, localStorageSet } = useLocalStorage()
const { profile } = useUser()
const showSurvey = localStorageGet(DISMISSED_SURVEY_KEY) === "false"
Expand Down Expand Up @@ -101,6 +103,13 @@ const CSFFileBrowser: React.FC<IFilesBrowserModuleProps> = ({ controls = true }:
}
}, [addToastMessage, uploadFiles])

const viewFolder = useCallback((cid: string) => {
const fileSystemItem = pathContents.find(f => f.cid === cid)
if (fileSystemItem && fileSystemItem.content_type === CONTENT_TYPES.Directory) {
redirect(ROUTE_LINKS.Home(`${currentPath}${fileSystemItem.name}`))
}
}, [currentPath, pathContents, redirect])

const bulkOperations: IBulkOperations = useMemo(() => ({
[CONTENT_TYPES.Directory]: ["move"],
[CONTENT_TYPES.File]: ["delete", "move"]
Expand All @@ -126,6 +135,7 @@ const CSFFileBrowser: React.FC<IFilesBrowserModuleProps> = ({ controls = true }:
downloadFile={downloadFile}
handleMove={handleMove}
handleRename={handleRename}
viewFolder={viewFolder}
handleUploadOnDrop={handleUploadOnDrop}
uploadsInProgress={uploadsInProgress}
loadingCurrentPath={loadingCurrentPath}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const FileInfoModal: React.FC<IFileInfoModuleProps> = ({
variant="body2"
component="p"
>
{dayjs.unix(fullFileInfo.content.created_at).format("DD MMM YYYY h:mm a")}
{fullFileInfo.content.created_at && dayjs.unix(fullFileInfo.content.created_at).format("DD MMM YYYY h:mm a")}
</Typography>
</div>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ const FileSystemItemRow: React.FC<IFileSystemItemRowProps> = ({
file,
files,
currentPath,
updateCurrentPath,
selected,
editing,
setEditing,
Expand All @@ -145,7 +144,6 @@ const FileSystemItemRow: React.FC<IFileSystemItemRowProps> = ({
setFileInfoPath,
handleSelect,
itemOperations,
resetSelectedFiles,
browserView
}) => {
const { cid, name, isFolder, content_type } = file
Expand Down Expand Up @@ -312,9 +310,8 @@ const FileSystemItemRow: React.FC<IFileSystemItemRowProps> = ({
}

const onFolderClick = useCallback(() => {
updateCurrentPath(`${currentPath}${name}`, undefined, true)
resetSelectedFiles()
}, [currentPath, name, resetSelectedFiles, updateCurrentPath])
viewFolder && viewFolder(cid)
}, [cid, viewFolder])

const onFileClick = useCallback(() => {
setPreviewFileIndex(files?.indexOf(file))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function FileSystemTableItem({
<>
<TableCell align="left">
{
dayjs.unix(created_at).format("DD MMM YYYY h:mm a")
created_at && dayjs.unix(created_at).format("DD MMM YYYY h:mm a")
}
</TableCell>
<TableCell align="left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ const FilesTableView = ({
setIsSurveyBannerVisible(false)
}, [setIsSurveyBannerVisible])

const handleViewFolder = useCallback((cid: string) => {
resetSelectedCids()
viewFolder && viewFolder(cid)
}, [viewFolder, resetSelectedCids])

return (
<article
className={clsx(classes.root, {
Expand Down Expand Up @@ -832,7 +837,7 @@ const FilesTableView = ({
}}
recoverFile={recoverFile}
downloadFile={downloadFile}
viewFolder={viewFolder}
viewFolder={handleViewFolder}
handleUploadOnDrop={handleUploadOnDrop}
setPreviewFileIndex={setPreviewFileIndex}
moveFile={() => {
Expand Down

0 comments on commit 974053c

Please sign in to comment.