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

Expand parent directories of opened projects #11947

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4c5729f
Expand parent directories of opened projects
somebody1234 Dec 26, 2024
edddae0
Fix expanding local directories
somebody1234 Dec 26, 2024
8269f4e
Automatically expand "Users" or "Teams" root directory as appropriate
somebody1234 Dec 30, 2024
e5259d5
Fix errors
somebody1234 Dec 30, 2024
7b96344
Merge branch 'develop' into wip/sb/expand-parent-directories
somebody1234 Dec 30, 2024
b2b361b
Only expand ancestors of initially launched projects once
somebody1234 Dec 31, 2024
e943fe1
WIP: Separate ancestor lists for each Drive sidebar category
somebody1234 Dec 31, 2024
2cee8ea
Fix errors
somebody1234 Jan 2, 2025
68000a7
Merge branch 'develop' into wip/sb/expand-parent-directories
somebody1234 Jan 3, 2025
364c3af
Fix errors
somebody1234 Jan 3, 2025
1df6478
Fix bugs
somebody1234 Jan 3, 2025
21b3489
Remove obsolete test
somebody1234 Jan 3, 2025
6adda38
Replace `category` with `categoryType` in `listDirectoryQueryOptions`
somebody1234 Jan 6, 2025
eca7931
Move logic for computing ancestors from `Dashboard.tsx` to individual…
somebody1234 Jan 7, 2025
0fa64ce
Extract computing initial expanded directories to a function
somebody1234 Jan 7, 2025
17eb1df
Compute initial expanded directories in initial value store instead o…
somebody1234 Jan 7, 2025
356cfec
Fix cyclic dependencies between stores
somebody1234 Jan 8, 2025
d01fc61
Fix errors
somebody1234 Jan 8, 2025
3091835
Expand full path to directory when clicking on breadcrumb
somebody1234 Jan 8, 2025
8f4032e
Remove `useSetExpandedDirectories`
somebody1234 Jan 8, 2025
58d59ec
Add `useIsDirectoryExpanded`
somebody1234 Jan 8, 2025
6bcfaf7
WIP: Re-add `DriveProvider.test`
somebody1234 Jan 8, 2025
98727bf
WIP: Fix `DriveProvider.test`
somebody1234 Jan 8, 2025
a7f81ae
Fix unnecessary dependencies of `DriveProvider`
somebody1234 Jan 8, 2025
4602cc6
help
somebody1234 Jan 8, 2025
afdc27b
WIP: Fix `DriveProvider.test`
somebody1234 Jan 8, 2025
71a1b8c
Fix `DriveProvider.test`
somebody1234 Jan 8, 2025
ffc6e15
Fix type errors
somebody1234 Jan 8, 2025
42fa910
Merge branch 'develop' into wip/sb/expand-parent-directories
somebody1234 Jan 9, 2025
25a05ca
Fix errors
somebody1234 Jan 9, 2025
571a60b
Fix integration tests
somebody1234 Jan 9, 2025
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
121 changes: 120 additions & 1 deletion app/gui/src/dashboard/pages/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ import * as backendModule from '#/services/Backend'
import * as localBackendModule from '#/services/LocalBackend'
import * as projectManager from '#/services/ProjectManager'

import { listDirectoryQueryOptions } from '#/hooks/backendHooks'
import { useSyncRef } from '#/hooks/syncRefHooks'
import { useCategoriesAPI } from '#/layouts/Drive/Categories/categoriesHooks'
import { useDriveStore, useSetExpandedDirectoryIds } from '#/providers/DriveProvider'
import { userGroupIdToDirectoryId } from '#/services/RemoteBackend'
import { TEAMS_DIRECTORY_ID, USERS_DIRECTORY_ID } from '#/services/remoteBackendPaths'
import { baseName } from '#/utilities/fileInfo'
import { tryFindSelfPermission } from '#/utilities/permissions'
import { STATIC_QUERY_OPTIONS } from '#/utilities/reactQuery'
import * as sanitizedEventTargets from '#/utilities/sanitizedEventTargets'
import { usePrefetchQuery } from '@tanstack/react-query'
import { usePrefetchQuery, useQueryClient } from '@tanstack/react-query'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
import { DashboardTabPanels } from './DashboardTabPanels'

// =================
Expand All @@ -76,6 +82,7 @@ export default function Dashboard(props: DashboardProps) {
<CategoriesProvider onCategoryChange={resetAssetTableState}>
<EventListProvider>
<ProjectsProvider>
<OpenedProjectsParentsExpander />
<DashboardInner {...props} />
</ProjectsProvider>
</EventListProvider>
Expand Down Expand Up @@ -308,3 +315,115 @@ function DashboardInner(props: DashboardProps) {
</Page>
)
}

/** Expand the list of parents for opened projects. */
function OpenedProjectsParentsExpander() {
const queryClient = useQueryClient()
const remoteBackend = backendProvider.useRemoteBackend()
const localBackend = backendProvider.useLocalBackend()
const categoriesAPI = useCategoriesAPI()
const category = categoriesAPI.category
const driveStore = useDriveStore()
const launchedProjects = useLaunchedProjects()
const setExpandedDirectoryIds = useSetExpandedDirectoryIds()
const launchedProjectsRef = useSyncRef(launchedProjects)
const { user } = authProvider.useFullUserSession()

React.useEffect(() => {
const userGroupDirectoryIds = new Set(
(user.userGroups ?? EMPTY_ARRAY).map(userGroupIdToDirectoryId),
)

switch (category.type) {
case 'cloud':
case 'team':
case 'user': {
const relevantProjects = launchedProjectsRef.current.filter(
(project) => project.type === backendModule.BackendType.remote,
)
const promises = relevantProjects.map((project) =>
queryClient.ensureQueryData(
listDirectoryQueryOptions({
backend: remoteBackend,
parentId: project.parentId,
category,
}),
),
)
void Promise.allSettled(promises)
.then((projects) =>
projects.flatMap((directoryResult, i) => {
const projectInfo = relevantProjects[i]
const project =
projectInfo && directoryResult.status === 'fulfilled' ?
directoryResult.value
.filter(backendModule.assetIsProject)
.find((asset) => asset.id === projectInfo.id)
: null
return project ? [project] : []
}),
)
.then((projects) => {
const expandedDirectoryIds = new Set(driveStore.getState().expandedDirectoryIds)
for (const project of projects) {
const parents = project.parentsPath.split('/').filter(backendModule.isDirectoryId)
const rootDirectoryId = parents[0]
if ((rootDirectoryId && userGroupDirectoryIds.has(rootDirectoryId)) ?? false) {
expandedDirectoryIds.add(TEAMS_DIRECTORY_ID)
} else {
expandedDirectoryIds.add(USERS_DIRECTORY_ID)
}
for (const parent of parents) {
expandedDirectoryIds.add(parent)
}
}
setExpandedDirectoryIds([...expandedDirectoryIds])
})
break
}
case 'local':
case 'local-directory': {
if (!localBackend) {
break
}
const rootPath = 'rootPath' in category ? category.rootPath : localBackend.rootPath()
const relevantProjects = launchedProjectsRef.current.filter(
(project) => project.type === backendModule.BackendType.local,
)
const expandedDirectoryIds = new Set(driveStore.getState().expandedDirectoryIds)
for (const project of relevantProjects) {
const path = localBackendModule.extractTypeAndId(project.parentId).id
const strippedPath = path.replace(`${rootPath}/`, '')
if (strippedPath !== path) {
let parentPath = String(rootPath)
const parents = strippedPath.split('/')
for (const parent of parents) {
parentPath += `/${parent}`
expandedDirectoryIds.add(
localBackendModule.newDirectoryId(backendModule.Path(parentPath)),
)
}
}
}
setExpandedDirectoryIds([...expandedDirectoryIds])
break
}
case 'recent':
case 'trash': {
// Ignored - directories should not be expanded here.
break
}
}
}, [
category,
driveStore,
launchedProjectsRef,
localBackend,
queryClient,
remoteBackend,
setExpandedDirectoryIds,
user.userGroups,
MrFlashAccount marked this conversation as resolved.
Show resolved Hide resolved
])

return null
}
Loading