Skip to content

Commit d3198e9

Browse files
somebody1234farmaazon
authored andcommitted
Add back root directory for Trash category (#12802)
- Add back root directory for Trash category # Important Notes None
1 parent d28a027 commit d3198e9

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

app/gui/src/dashboard/hooks/backendBatchedHooks.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @file Hooks to do batched backend operations. */
22
import { backendQueryOptions, mutationOptions } from '#/hooks/backendHooks'
3+
import type { TrashCategory } from '#/layouts/CategorySwitcher/Category'
34
import { getMessageOrToString } from '#/utilities/error'
45
import { useMutationState, type Mutation, type QueryClient } from '@tanstack/react-query'
56
import {
@@ -295,11 +296,15 @@ export function useMoveAssetsMutationState<Result>(
295296
}
296297

297298
/** Get a list of all items in the trash. */
298-
export async function getAllTrashedItems(queryClient: QueryClient, backend: Backend) {
299+
export async function getAllTrashedItems(
300+
queryClient: QueryClient,
301+
backend: Backend,
302+
category: TrashCategory,
303+
) {
299304
return await queryClient.ensureQueryData(
300305
backendQueryOptions(backend, 'listDirectory', [
301306
{
302-
parentId: null,
307+
parentId: category.homeDirectoryId,
303308
labels: null,
304309
filterBy: FilterBy.trashed,
305310
recentProjects: false,

app/gui/src/dashboard/layouts/AssetsTable.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ function AssetsTable(props: AssetsTableProps) {
258258
const addAssetsLabelsMutation = useMutationCallback(addAssetsLabelsMutationOptions(backend))
259259
const removeAssetsLabelsMutation = useMutationCallback(removeAssetsLabelsMutationOptions(backend))
260260

261-
const { currentDirectoryId, setCurrentDirectoryId } = useDirectoryIds({
261+
const { queryDirectoryId, currentDirectoryId, setCurrentDirectoryId } = useDirectoryIds({
262262
category,
263263
})
264264
const listDirectoryRefetchInterval = useListDirectoryRefetchInterval()
265265
const { data: assets = [] } = useSuspenseQuery({
266266
...listDirectoryQueryOptions({
267267
backend,
268-
parentId: currentDirectoryId,
268+
parentId: queryDirectoryId,
269269
category,
270270
refetchInterval: listDirectoryRefetchInterval,
271271
}),
@@ -1264,6 +1264,11 @@ function AssetsTable(props: AssetsTableProps) {
12641264
: getText('assetsDropFilesDescription', droppedFilesCount)
12651265
: getText('assetsDropzoneDescription')
12661266

1267+
const specialEmptyText =
1268+
query.query !== '' ? getText('noFilesMatchTheCurrentFilters')
1269+
: currentDirectoryId !== category.homeDirectoryId ? getText('thisFolderIsEmpty')
1270+
: null
1271+
12671272
const table = (
12681273
<div className="flex flex-none flex-col">
12691274
<table className="isolate table-fixed border-collapse rounded-rows">
@@ -1277,16 +1282,10 @@ function AssetsTable(props: AssetsTableProps) {
12771282
<td colSpan={columns.length} className="h-table-row bg-transparent">
12781283
<Text className="px-cell-x placeholder" disableLineHeightCompensation>
12791284
{category.type === 'trash' ?
1280-
query.query !== '' ?
1281-
getText('noFilesMatchTheCurrentFilters')
1282-
: getText('yourTrashIsEmpty')
1285+
(specialEmptyText ?? getText('yourTrashIsEmpty'))
12831286
: category.type === 'recent' ?
1284-
query.query !== '' ?
1285-
getText('noFilesMatchTheCurrentFilters')
1286-
: getText('youHaveNoRecentProjects')
1287-
: query.query !== '' ?
1288-
getText('noFilesMatchTheCurrentFilters')
1289-
: getText('youHaveNoFiles')}
1287+
(specialEmptyText ?? getText('youHaveNoRecentProjects'))
1288+
: (specialEmptyText ?? getText('youHaveNoFiles'))}
12901289
</Text>
12911290
</td>
12921291
</tr>

app/gui/src/dashboard/layouts/Drive/Categories/Category.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const TRASH_CATEGORY_SCHEMA = z
5757
.object({
5858
type: z.literal('trash'),
5959
id: z.literal('trash'),
60-
homeDirectoryId: z.null(),
60+
homeDirectoryId: DIRECTORY_ID_SCHEMA,
6161
})
6262
.merge(EACH_CATEGORY_SCHEMA)
6363
.readonly()

app/gui/src/dashboard/layouts/Drive/Categories/categoriesHooks.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ import { useUser } from '#/providers/AuthProvider'
1818
import { useEventCallback } from '#/hooks/eventCallbackHooks'
1919
import { useOffline } from '#/hooks/offlineHooks'
2020
import { useSearchParamsState } from '#/hooks/searchParamsStateHooks'
21-
import { useBackend, useLocalBackend } from '#/providers/BackendProvider'
21+
import { useBackend, useLocalBackend, useRemoteBackend } from '#/providers/BackendProvider'
2222
import { useLocalStorageState } from '#/providers/LocalStorageProvider'
2323
import { useText } from '#/providers/TextProvider'
2424
import type Backend from '#/services/Backend'
2525
import { Path, type DirectoryId } from '#/services/Backend'
2626
import { newDirectoryId } from '#/services/LocalBackend'
27+
import { organizationIdToDirectoryId } from '#/services/RemoteBackend'
2728
import { getFileName } from '#/utilities/fileInfo'
2829
import LocalStorage from '#/utilities/LocalStorage'
30+
import { useSuspenseQuery } from '@tanstack/react-query'
2931
import type { ReactNode } from 'react'
3032
import { createContext, useContext } from 'react'
3133
import invariant from 'tiny-invariant'
@@ -85,6 +87,13 @@ export type CloudCategoryResult = ReturnType<typeof useCloudCategoryList>
8587
export function useCloudCategoryList() {
8688
const user = useUser()
8789
const { getText } = useText()
90+
const backend = useRemoteBackend()
91+
const { data: organization } = useSuspenseQuery({
92+
queryKey: [backend.type, 'getOrganization'],
93+
queryFn: () => backend.getOrganization(),
94+
})
95+
const organizationRootDirectoryId =
96+
organization != null ? organizationIdToDirectoryId(organization.id) : user.rootDirectoryId
8897

8998
const cloudCategory: CloudCategory = {
9099
type: 'cloud',
@@ -107,7 +116,7 @@ export function useCloudCategoryList() {
107116
id: 'trash',
108117
label: getText('trashCategory'),
109118
icon: Trash2Icon,
110-
homeDirectoryId: null,
119+
homeDirectoryId: organizationRootDirectoryId,
111120
}
112121

113122
const predefinedCloudCategories: AnyCloudCategory[] = [

app/gui/src/dashboard/layouts/Drive/directoryIdsHooks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ export function useDirectoryIds(options: UseDirectoryIdsOptions) {
1313
const { category } = options
1414
const user = useUser()
1515
const rootDirectoryId = category.homeDirectoryId ?? user.rootDirectoryId
16-
const currentDirectoryId = useCurrentDirectoryId().current ?? rootDirectoryId
16+
/** The id of the directory to use in the "list directory" query. */
17+
const queryDirectoryId = useCurrentDirectoryId().current ?? category.homeDirectoryId
18+
const currentDirectoryId = queryDirectoryId ?? rootDirectoryId
1719
const parentDirectoryId = useCurrentDirectoryId().parent ?? rootDirectoryId
1820
const setCurrentDirectoryId = useSetCurrentDirectoryId()
1921

2022
return {
2123
setCurrentDirectoryId,
2224
rootDirectoryId,
25+
queryDirectoryId,
2326
currentDirectoryId,
2427
parentDirectoryId,
2528
} as const

app/gui/src/dashboard/pages/dashboard/Drive/DriveBar/DriveBarToolbar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { useEventCallback } from '#/hooks/eventCallbackHooks'
3535
import { useOffline } from '#/hooks/offlineHooks'
3636
import { AssetPanelToggle } from '#/layouts/AssetPanel'
3737
import AssetSearchBar from '#/layouts/AssetSearchBar'
38+
import type { TrashCategory } from '#/layouts/CategorySwitcher/Category'
3839
import {
3940
canTransferBetweenCategories,
4041
isCloudCategory,
@@ -314,7 +315,7 @@ export function DriveBarToolbar(props: DriveBarToolbarProps) {
314315
interface TrashFolderToolbarProps extends PropsWithChildren {
315316
readonly shouldBeDisabled: boolean
316317
readonly backend: Backend
317-
readonly category: Category
318+
readonly category: TrashCategory
318319
}
319320

320321
/**
@@ -327,7 +328,7 @@ function TrashFolderToolbar(props: TrashFolderToolbarProps) {
327328
const rootDirectoryQueryOptions = listDirectoryQueryOptions({
328329
backend,
329330
category,
330-
parentId: null,
331+
parentId: category.homeDirectoryId,
331332
refetchInterval: null,
332333
})
333334

@@ -340,7 +341,7 @@ function TrashFolderToolbar(props: TrashFolderToolbarProps) {
340341
const deleteAssetsMutation = useMutationCallback(deleteAssetsMutationOptions(backend))
341342

342343
const clearTrash = useEventCallback(async () => {
343-
const allTrashedItems = await getAllTrashedItems(queryClient, backend)
344+
const allTrashedItems = await getAllTrashedItems(queryClient, backend, category)
344345
await deleteAssetsMutation([allTrashedItems.map((item) => item.id), true])
345346
})
346347

0 commit comments

Comments
 (0)