Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sorting header for mobile file browser #1786

Merged
merged 15 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/common-components/src/Icons/icons/Sort.icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from "react"
import createSvgIcon from "../createSvgIcon"
import { ReactComponent as SortSvg } from "../svgs/sort.svg"

export { SortSvg }

export default createSvgIcon(<SortSvg />)
1 change: 1 addition & 0 deletions packages/common-components/src/Icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export { default as SearchIcon, SearchSvg } from "./icons/Search.icon"
export { default as SettingIcon, SettingSvg } from "./icons/Setting.icon"
export { default as ShareAltIcon, ShareAltSvg } from "./icons/ShareAlt.icon"
export { default as StarIcon, StarSvg } from "./icons/Star.icon"
export { default as SortIcon, SortSvg } from "./icons/Sort.icon"
export { default as SunIcon, SunSvg } from "./icons/Sun.icon"
export { default as TableIcon, TableSvg } from "./icons/Table.icon"
export { default as UpdateIcon, UpdateSvg } from "./icons/Update.icon"
Expand Down
1 change: 1 addition & 0 deletions packages/common-components/src/Icons/svgs/sort.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
GridIcon,
TableIcon,
UploadSvg,
PlusCircleSvg
PlusCircleSvg,
SortIcon,
CheckIcon
} from "@chainsafe/common-components"
import { useState } from "react"
import { useMemo } from "react"
Expand Down Expand Up @@ -52,6 +54,7 @@ import SharedUsers from "../../../Elements/SharedUsers"
import Menu from "../../../../UI-components/Menu"
import SharingExplainerModal from "../../../SharingExplainerModal"
import { useSharingExplainerModalFlag } from "../hooks/useSharingExplainerModalFlag"
import { ListItemIcon, ListItemText } from "@material-ui/core"

const baseOperations: FileOperation[] = ["download", "info", "preview", "share"]
const readerOperations: FileOperation[] = [...baseOperations, "report"]
Expand Down Expand Up @@ -415,6 +418,14 @@ const FilesList = ({ isShared = false }: Props) => {
}
}

const toggleSortDirection = () => {
if (direction === "ascend") {
setDirection("descend")
} else {
setDirection("ascend")
}
}

// Previews
const setNextPreview = () => {
if (
Expand Down Expand Up @@ -882,7 +893,7 @@ const FilesList = ({ isShared = false }: Props) => {
className={clsx(loadingCurrentPath && classes.fadeOutLoading)}
testId="home"
>
{desktop && (
{desktop ? (
<TableHead>
<TableRow type="grid"
className={classes.tableRow}>
Expand Down Expand Up @@ -928,6 +939,69 @@ const FilesList = ({ isShared = false }: Props) => {
<TableHeadCell>{/* Menu */}</TableHeadCell>
</TableRow>
</TableHead>
) : (
<TableHead>
<TableRow type="grid"
className={classes.tableRow}>
<TableHeadCell>
{/* Checkbox */}
</TableHeadCell>
<TableHeadCell
align='left'
onSortChange={toggleSortDirection}
sortButtons
sortDirection={direction}
>
{t`Name`}
</TableHeadCell>
<TableHeadCell align='right'>
<Menu
testId='fileDropdown'
icon={<SortIcon className={classes.dropdownIcon} />}
options={[{
contents: (
<ListItemText inset>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to use the material imports here if we want to get rid of the dependency in Files ultimately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It saves us from having to reimplement the inset prop. This would just be an update of where the component is imported from, once we actually move forward with the upgrade.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe yeah that'll probably be on me, hence my complaints 😅

<b><Trans>Sort By:</Trans></b>
</ListItemText>
)
}, {
contents: (
<>
{column === "name" && <ListItemIcon>
<CheckIcon />
</ListItemIcon>}
<ListItemText inset={column !== "name"}>
<Trans>Name</Trans>
</ListItemText>
</>
),
onClick: () => setColumn("name")
}, {
contents: (
<>
{column === "date_uploaded" && <ListItemIcon><CheckIcon /></ListItemIcon>}
<ListItemText inset={column !== "date_uploaded"}>
<Trans>Date Uploaded</Trans>
</ListItemText>
</>
),
onClick: () => setColumn("date_uploaded")
}, {
contents: (
<>
{column === "size" && <ListItemIcon><CheckIcon /></ListItemIcon>}
<ListItemText inset={column !== "size"}>
<Trans>Size</Trans>
</ListItemText>
</>
),
onClick: () => setColumn("size")
}]}
style={{ focusVisible: classes.focusVisible }}
/>
</TableHeadCell>
</TableRow>
</TableHead>
)}
<TableBody>
{items.map((file, index) => (
Expand Down
12 changes: 9 additions & 3 deletions packages/files-ui/src/UI-components/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { useState, ReactNode, useMemo } from "react"
import { Menu as MaterialMenu, MenuItem } from "@material-ui/core"
import { Menu as MaterialMenu, MenuItem, PopoverOrigin } from "@material-ui/core"
import { makeStyles, createStyles } from "@chainsafe/common-theme"
import clsx from "clsx"
import { useCallback } from "react"
import { CSFTheme } from "../Themes/types"

interface Option {
contents: ReactNode
inset?: boolean
testId?: string
onClick?: () => void
}

Expand All @@ -22,6 +24,8 @@ interface Props {
options: Option[]
style?: CustomClasses
testId?: string
anchorOrigin?: PopoverOrigin
transformOrigin?: PopoverOrigin
}

const useStyles = makeStyles(({ constants }: CSFTheme) => {
Expand All @@ -40,7 +44,7 @@ const useStyles = makeStyles(({ constants }: CSFTheme) => {
}
})})

export default function Menu({ icon, options, style, testId }: Props) {
export default function Menu({ icon, options, style, testId, anchorOrigin, transformOrigin }: Props) {
const [anchorEl, setAnchorEl] = useState(null)
const open = useMemo(() => Boolean(anchorEl), [anchorEl])
const classes = useStyles()
Expand Down Expand Up @@ -68,12 +72,14 @@ export default function Menu({ icon, options, style, testId }: Props) {
open={open}
onClose={handleClose}
PopoverClasses={{ paper: classes.paper, root: style?.root }}
anchorOrigin={anchorOrigin}
transformOrigin={transformOrigin}
>
{options.map((option, index) => (
<MenuItem
key={index}
onClick={() => {
handleClose()
option.onClick && handleClose()
option.onClick && option.onClick()
}}
focusVisibleClassName={clsx(style?.focusVisible)}
Expand Down
6 changes: 6 additions & 0 deletions packages/files-ui/src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ msgstr ""
msgid "Data restored successfully"
msgstr ""

msgid "Date Uploaded"
msgstr ""

msgid "Date uploaded"
msgstr "Hochgeladen am"

Expand Down Expand Up @@ -706,6 +709,9 @@ msgstr "Etwas ist schief gelaufen!"
msgid "Something went wrong. We couldn't upload your file"
msgstr "Es ist etwas schief gelaufen. Wir konnten Ihre Datei nicht hochladen"

msgid "Sort By:"
msgstr ""

msgid "Start Upload"
msgstr "Hochladen starten"

Expand Down
6 changes: 6 additions & 0 deletions packages/files-ui/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ msgstr "Data moved to bin successfully"
msgid "Data restored successfully"
msgstr "Data restored successfully"

msgid "Date Uploaded"
msgstr "Date Uploaded"

msgid "Date uploaded"
msgstr "Date uploaded"

Expand Down Expand Up @@ -709,6 +712,9 @@ msgstr "Something went wrong!"
msgid "Something went wrong. We couldn't upload your file"
msgstr "Something went wrong. We couldn't upload your file"

msgid "Sort By:"
msgstr "Sort By:"

msgid "Start Upload"
msgstr "Start Upload"

Expand Down
6 changes: 6 additions & 0 deletions packages/files-ui/src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ msgstr ""
msgid "Data restored successfully"
msgstr ""

msgid "Date Uploaded"
msgstr ""

msgid "Date uploaded"
msgstr "Fecha de subida"

Expand Down Expand Up @@ -710,6 +713,9 @@ msgstr ""
msgid "Something went wrong. We couldn't upload your file"
msgstr "Algo salió mal. No pudimos subir tu archivo"

msgid "Sort By:"
msgstr ""

msgid "Start Upload"
msgstr "Iniciar la subida"

Expand Down
6 changes: 6 additions & 0 deletions packages/files-ui/src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ msgstr "Les données ont été déplacées vers la poubelle avec succès"
msgid "Data restored successfully"
msgstr "Données restaurées avec succès"

msgid "Date Uploaded"
msgstr ""

msgid "Date uploaded"
msgstr "Téléversé le"

Expand Down Expand Up @@ -710,6 +713,9 @@ msgstr "Quelque chose a mal tourné !"
msgid "Something went wrong. We couldn't upload your file"
msgstr "Un problème est survenu. Nous n’avons pas pu téléverser votre fichier"

msgid "Sort By:"
msgstr ""

msgid "Start Upload"
msgstr "Démarrer le téléversement"

Expand Down
6 changes: 6 additions & 0 deletions packages/files-ui/src/locales/no/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ msgstr ""
msgid "Data restored successfully"
msgstr ""

msgid "Date Uploaded"
msgstr ""

msgid "Date uploaded"
msgstr "Dato opplastet"

Expand Down Expand Up @@ -706,6 +709,9 @@ msgstr "Noe gikk galt."
msgid "Something went wrong. We couldn't upload your file"
msgstr ""

msgid "Sort By:"
msgstr ""

msgid "Start Upload"
msgstr ""

Expand Down