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

renterd file explorer modes #485

Merged
merged 3 commits into from
Feb 14, 2024
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
5 changes: 5 additions & 0 deletions .changeset/late-numbers-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/react-renterd': minor
---

Added useObjectList.
5 changes: 5 additions & 0 deletions .changeset/short-clocks-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The file explorer now has a global mode that shows a flat list of files from across all directories in a bucket.
5 changes: 5 additions & 0 deletions .changeset/silent-pots-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The file health indicator now show the percentage inline.
5 changes: 5 additions & 0 deletions .changeset/wise-socks-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The file explorer global mode now allows you to sort across all files in a bucket.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
import { useObject } from '@siafoundation/react-renterd'
import { cx } from 'class-variance-authority'
import { sortBy } from '@technically/lodash'
import { computeSlabContractSetShards } from '../../../../contexts/files/health'
import { ObjectData } from '../../../../contexts/files/types'
import { computeSlabContractSetShards } from '../../../../lib/health'
import { ObjectData } from '../../../../contexts/filesManager/types'
import { useHealthLabel } from '../../../../hooks/useHealthLabel'
import { bucketAndKeyParamsFromPath } from '../../../../contexts/files/paths'
import { bucketAndKeyParamsFromPath } from '../../../../lib/paths'

export function FilesHealthColumnContents({
path,
Expand Down
24 changes: 15 additions & 9 deletions apps/renterd/components/Files/Columns/FilesHealthColumn/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HoverCard, LoadingDots, Text } from '@siafoundation/design-system'
import { ObjectData } from '../../../../contexts/files/types'
import { ObjectData } from '../../../../contexts/filesManager/types'
import { useHealthLabel } from '../../../../hooks/useHealthLabel'
import { FilesHealthColumnContents } from './FilesHealthColumnContents'

Expand All @@ -11,7 +11,7 @@ export function FilesHealthColumn(props: ObjectData) {
size,
isDirectory,
})

const displayPercent = `${(displayHealth * 100).toFixed(0)}%`
if (isDirectory) {
if (name === '..') {
return null
Expand All @@ -22,15 +22,18 @@ export function FilesHealthColumn(props: ObjectData) {
openDelay: 100,
}}
trigger={
<Text color={color} className="flex cursor-pointer">
{icon}
</Text>
<div className="flex items-center gap-1 cursor-pointer">
<Text color={color}>{icon}</Text>
<Text color="verySubtle" size="12">
{displayPercent}
</Text>
</div>
}
>
<div className="z-10 flex flex-col -mx-1 overflow-hidden">
<div className="flex justify-between gap-2 py-0.5 px-2">
<Text size="12">{label}</Text>
<Text size="12">{(displayHealth * 100).toFixed(0)}%</Text>
<Text size="12">{displayPercent}</Text>
</div>
</div>
</HoverCard>
Expand All @@ -47,9 +50,12 @@ export function FilesHealthColumn(props: ObjectData) {
openDelay: 100,
}}
trigger={
<Text color={color} className="flex cursor-pointer">
{icon}
</Text>
<div className="flex items-center gap-1 cursor-pointer">
<Text color={color}>{icon}</Text>
<Text color="verySubtle" size="12">
{displayPercent}
</Text>
</div>
}
>
{/* important to separate contents so that each row does not trigger 1+n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@siafoundation/design-system'
import { Copy16 } from '@siafoundation/react-icons'
import { useObject } from '@siafoundation/react-renterd'
import { bucketAndKeyParamsFromPath } from '../../../contexts/files/paths'
import { bucketAndKeyParamsFromPath } from '../../../lib/paths'

type Props = {
path: string
Expand Down
9 changes: 5 additions & 4 deletions apps/renterd/components/Files/FileContextMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ import {
Filter16,
Edit16,
} from '@siafoundation/react-icons'
import { useFiles } from '../../../contexts/files'
import { useFileDelete } from '../useFileDelete'
import { CopyMetadataMenuItem } from './CopyMetadataMenuItem'
import { getFilename } from '../../../contexts/files/paths'
import { getFilename } from '../../../lib/paths'
import { useDialog } from '../../../contexts/dialog'
import { useFilesManager } from '../../../contexts/filesManager'

type Props = {
path: string
}

export function FileContextMenu({ path }: Props) {
const { downloadFiles, getFileUrl, navigateToFile } = useFiles()
const { downloadFiles, getFileUrl, navigateToFileDirectory } =
useFilesManager()
const deleteFile = useFileDelete()
const { openDialog } = useDialog()

Expand Down Expand Up @@ -68,7 +69,7 @@ export function FileContextMenu({ path }: Props) {
<DropdownMenuLabel>Filter</DropdownMenuLabel>
<DropdownMenuItem
onSelect={() => {
navigateToFile(path)
navigateToFileDirectory(path)
}}
>
<DropdownMenuLeftSlot>
Expand Down
66 changes: 0 additions & 66 deletions apps/renterd/components/Files/FilesBreadcrumbMenu.tsx

This file was deleted.

20 changes: 20 additions & 0 deletions apps/renterd/components/Files/FilesBreadcrumbMenuMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LinkButton } from '@siafoundation/design-system'
import { Earth16, Folder16 } from '@siafoundation/react-icons'
import { useFilesManager } from '../../contexts/filesManager'

export function FilesBreadcrumbMenuMode() {
const { switchViewModeUrl, activeViewMode } = useFilesManager()

return (
<LinkButton
href={switchViewModeUrl}
tip={
activeViewMode === 'directory'
? 'Viewing directory explorer'
: 'Viewing all bucket files'
}
>
{activeViewMode === 'directory' ? <Folder16 /> : <Earth16 />}
</LinkButton>
)
}
11 changes: 6 additions & 5 deletions apps/renterd/components/Files/FilesCmd/FilesSearchCmd/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CommandGroup, CommandItemSearch } from '../../../CmdRoot/Item'
import { Page } from '../../../CmdRoot/types'
import { useObjectSearch } from '@siafoundation/react-renterd'
import { isDirectory } from '../../../../contexts/files/paths'
import { useFiles } from '../../../../contexts/files'
import { isDirectory } from '../../../../lib/paths'
import { Text } from '@siafoundation/design-system'
import { Document16, FolderIcon } from '@siafoundation/react-icons'
import { FileSearchEmpty } from './FileSearchEmpty'
import { useFilesManager } from '../../../../contexts/filesManager'

export const filesSearchPage = {
namespace: 'files/search',
Expand All @@ -27,14 +27,15 @@ export function FilesSearchCmd({
beforeSelect?: () => void
afterSelect?: () => void
}) {
const { activeBucket, navigateToFile } = useFiles()
const { activeBucketName: activeBucket, navigateToFileDirectory } =
useFilesManager()
const onSearchPage = currentPage?.namespace === filesSearchPage.namespace
const results = useObjectSearch({
disabled: !onSearchPage,
params: {
bucket: activeBucket || 'default',
key: debouncedSearch,
skip: 0,
offset: 0,
limit: 10,
},
config: {
Expand All @@ -61,7 +62,7 @@ export function FilesSearchCmd({
key={path}
onSelect={() => {
beforeSelect()
navigateToFile(path)
navigateToFileDirectory(path)
afterSelect()
}}
value={path}
Expand Down
12 changes: 8 additions & 4 deletions apps/renterd/components/Files/FilesFilterDirectoryMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Button, Separator, TextField } from '@siafoundation/design-system'
import { useEffect, useState } from 'react'
import { useFiles } from '../../../contexts/files'
import { useDebounce } from 'use-debounce'
import { Close16 } from '@siafoundation/react-icons'
import { useFilesManager } from '../../../contexts/filesManager'

export function FilesFilterDirectoryMenu() {
const { filters, setFilter, removeFilter } = useFiles()
type Props = {
placeholder?: string
}

export function FilesFilterDirectoryMenu({ placeholder }: Props) {
const { filters, setFilter, removeFilter } = useFilesManager()
const [search, setSearch] = useState('')
const [debouncedSearch] = useDebounce(search, 500)

Expand Down Expand Up @@ -36,7 +40,7 @@ export function FilesFilterDirectoryMenu() {
<TextField
variant="ghost"
focus="none"
placeholder="Filter files in current directory"
placeholder={placeholder || 'Filter files in current directory'}
value={search}
onChange={(e) => setSearch(e.currentTarget.value)}
className="w-full !pl-0"
Expand Down
7 changes: 5 additions & 2 deletions apps/renterd/components/Files/FilesSearchMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { useDialog } from '../../../contexts/dialog'
import { useRouter } from 'next/router'
import { routes } from '../../../config/routes'
import { useContracts } from '../../../contexts/contracts'
import { FilesSearchCmd, filesSearchPage } from '../FilesCmd/FilesSearchCmd'
import {
FilesSearchCmd,
filesSearchPage,
} from '../../Files/FilesCmd/FilesSearchCmd'
import { useDebounce } from 'use-debounce'
import { FileSearchEmpty } from '../FilesCmd/FilesSearchCmd/FileSearchEmpty'
import { FileSearchEmpty } from '../../Files/FilesCmd/FilesSearchCmd/FileSearchEmpty'

type Props = {
panel?: boolean
Expand Down
62 changes: 0 additions & 62 deletions apps/renterd/components/Files/FilesStatsMenu/index.tsx

This file was deleted.

Loading
Loading