Skip to content

Commit

Permalink
tooltip and remove virtualRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanad94 committed Nov 21, 2023
1 parent 6aee70d commit f56c767
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 45 deletions.
37 changes: 20 additions & 17 deletions packages/sn-pickers-react/src/components/picker/picker-helper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CircularProgress, Link } from '@material-ui/core'
import { CircularProgress, Link, Tooltip } from '@material-ui/core'
import { Repository } from '@sensenet/client-core'
import React, { memo } from 'react'
import { usePickerHelper } from './picker-helper.hook'
Expand Down Expand Up @@ -51,28 +51,31 @@ export const PickerHelper = ({

return (
<div style={containerStyle}>
{isAncestorOfRoot && (
<Link
data-test="current-content"
variant="body2"
onClick={() => handleJumpToCurrentPath(contextPath || '')}
className={styles}>
{currentContentText || 'Current Content'}
</Link>
{isAncestorOfRoot && contextPath && (
<Tooltip title={contextPath}>
<Link
data-test="current-content"
variant="body2"
onClick={() => handleJumpToCurrentPath(contextPath)}
className={styles}>
{currentContentText || 'Current Content'}
</Link>
</Tooltip>
)}

{helperPaths.length > 0 && (
<div data-test="path-helpers">
{helperPaths.map((path) => {
return (
<Link
key={path.Path}
data-test={`path-helper-${path.Path}`}
variant="body2"
onClick={() => handleJumpToCurrentPath(path.Path)}
className={styles}>
{path.DisplayName || path.Name}
</Link>
<Tooltip key={path.Path} title={path.Path}>
<Link
data-test={`path-helper-${path.Path}`}
variant="body2"
onClick={() => handleJumpToCurrentPath(path.Path)}
className={styles}>
{path.DisplayName || path.Name}
</Link>
</Tooltip>
)
})}
</div>
Expand Down
29 changes: 1 addition & 28 deletions packages/sn-pickers-react/src/hooks/use-tree-picker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConstantContent, ODataParams, ODataResponse, Repository } from '@sensenet/client-core'
import { ODataParams, Repository } from '@sensenet/client-core'
import { AsyncReturnValue, PathHelper } from '@sensenet/client-utils'
import { GenericContent } from '@sensenet/default-content-types'
import { useCallback, useEffect, useMemo, useState } from 'react'
Expand All @@ -10,8 +10,6 @@ interface State {
parentId: number | undefined
}

const virtualRootPath = '!VirtualRoot!'

const setParentIdAndPath = <T extends GenericContent>(node: T, parent?: T) => {
return parent && parent.Id === node.Id
? { parentId: parent.ParentId, path: parent.Path }
Expand Down Expand Up @@ -60,22 +58,6 @@ export const useTreePicker = <T extends GenericContentWithIsParent = GenericCont
try {
setIsLoading(true)

if (path === virtualRootPath && roots && navigationPath === virtualRootPath) {
const promises = await Promise.allSettled(
roots.map((root) =>
repository.load({
idOrPath: root,
oDataOptions: options.itemsODataOptions,
}),
),
)
const fulfilledResults: GenericContent[] = promises
.filter((result) => result.status === 'fulfilled')
.map((result) => (result as PromiseFulfilledResult<ODataResponse<GenericContent>>).value.d)

return setItems(fulfilledResults.map((item) => ({ ...item, isParent: false })))
}

const result = await loadItems({
path: navigationPath || path,
loadParent: !roots?.includes(navigationPath || path),
Expand All @@ -86,15 +68,6 @@ export const useTreePicker = <T extends GenericContentWithIsParent = GenericCont
abortController,
})

if ((roots?.length ?? 0) > 1 && (roots?.includes(path) || roots?.includes(navigationPath!))) {
result.unshift({
...(ConstantContent.EMPTY_CONTENT as T),
isParent: true,
IsFolder: true,
Path: virtualRootPath,
})
}

setItems(result)
} catch (e) {
if (!abortController.signal.aborted) {
Expand Down

0 comments on commit f56c767

Please sign in to comment.