Skip to content

Commit

Permalink
picker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanad94 committed Nov 19, 2023
1 parent 26ae568 commit d70f185
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const usePickerHelper = ({ contextPath, selectionRoots, repository }: Ref
)

setHelperPaths(fulfilledResults)
console.log(fulfilledResults)
setIsLoading(false)
setIsAncestorOfRoot(isContextPathInTree)
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions packages/sn-pickers-react/src/components/picker/picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const Picker: React.FunctionComponent<PickerProps<GenericContent>> = (pro
const handleJumpToCurrentPath = (path: string) => {
setMode(PickerModes.TREE)
setTerm('')
console.log('handleJumpToCurrentPath', path, navigationPath)
setNavigationPath(path)

Check warning on line 139 in packages/sn-pickers-react/src/components/picker/picker.tsx

View check run for this annotation

Codecov / codecov/patch

packages/sn-pickers-react/src/components/picker/picker.tsx#L136-L139

Added lines #L136 - L139 were not covered by tests
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export const loadItems = async <T extends GenericContentWithIsParent>({
parentODataOptions,
parentId ?? (items?.[0] ? undefined : PathHelper.getParentPath(path)),
)

console.log(parentResult)
if (!parentResult) {
return items
}
Expand Down
14 changes: 10 additions & 4 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, Repository } from '@sensenet/client-core'
import { ConstantContent, ODataParams, ODataResponse, 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 Down Expand Up @@ -61,20 +61,24 @@ export const useTreePicker = <T extends GenericContentWithIsParent = GenericCont
setIsLoading(true)

if (path === virtualRootPath && roots) {
const result = await Promise.all(
const promises = await Promise.allSettled(
roots.map((root) =>
repository.load({
idOrPath: root,
oDataOptions: options.itemsODataOptions,
}),
),
)
return setItems(result.map((item) => ({ ...item.d, isParent: false })))
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 })))

Check warning on line 76 in packages/sn-pickers-react/src/hooks/use-tree-picker.ts

View check run for this annotation

Codecov / codecov/patch

packages/sn-pickers-react/src/hooks/use-tree-picker.ts#L76

Added line #L76 was not covered by tests
}

const result = await loadItems({
path: navigationPath || path,
loadParent: !roots?.includes(path),
loadParent: !roots?.includes(navigationPath || path),
repository,
parentId,
itemsODataOptions: options.itemsODataOptions,
Expand All @@ -83,6 +87,8 @@ export const useTreePicker = <T extends GenericContentWithIsParent = GenericCont
})

if ((roots?.length ?? 0) > 1 && roots?.includes(path)) {
console.log('roots', roots)

result.unshift({
...(ConstantContent.EMPTY_CONTENT as T),
isParent: true,
Expand Down

0 comments on commit d70f185

Please sign in to comment.