Skip to content

Commit

Permalink
reference picker bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanad94 committed Nov 20, 2023
1 parent d70f185 commit c69709f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CircularProgress, Link } from '@material-ui/core'
import { Repository } from '@sensenet/client-core'
import React from 'react'
import React, { memo } from 'react'
import { usePickerHelper } from './picker-helper.hook'

type ReferenceFieldHelperProps = {
Expand Down Expand Up @@ -80,4 +80,5 @@ export const PickerHelper = ({
</div>
)
}
export default PickerHelper

export default memo(PickerHelper, (prevProps, nextProps) => prevProps.contextPath === nextProps.contextPath)
12 changes: 8 additions & 4 deletions packages/sn-pickers-react/src/components/picker/picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@ export const Picker: React.FunctionComponent<PickerProps<GenericContent>> = (pro
}, [term, props.repository, props.selectionRoots])

const handleJumpToCurrentPath = (path: string) => {
setMode(PickerModes.TREE)
setTerm('')
console.log('handleJumpToCurrentPath', path, navigationPath)
setNavigationPath(path)

Check warning on line 136 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

Added line #L136 was not covered by tests

if (term?.length && term.length > 0) {
debouncedQuery('')

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#L138-L139

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

if (mode !== PickerModes.TREE) {
setMode(PickerModes.TREE)

Check warning on line 143 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#L142-L143

Added lines #L142 - L143 were not covered by tests
}
}

return (
Expand Down Expand Up @@ -167,7 +172,6 @@ export const Picker: React.FunctionComponent<PickerProps<GenericContent>> = (pro
onChange={(ev) => {
debouncedQuery(ev.target.value)
}}
value={term}
/>
<ShowSelectedButton
className={classes.showSelected}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export const loadItems = async <T extends GenericContentWithIsParent>({
parentId ?? (items?.[0] ? undefined : PathHelper.getParentPath(path)),
)

console.log(parentResult)
if (!parentResult) {
return items
}
Expand Down
6 changes: 2 additions & 4 deletions packages/sn-pickers-react/src/hooks/use-tree-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const useTreePicker = <T extends GenericContentWithIsParent = GenericCont
try {
setIsLoading(true)

if (path === virtualRootPath && roots) {
if (path === virtualRootPath && roots && navigationPath === virtualRootPath) {
const promises = await Promise.allSettled(
roots.map((root) =>
repository.load({
Expand All @@ -86,9 +86,7 @@ export const useTreePicker = <T extends GenericContentWithIsParent = GenericCont
abortController,
})

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

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

0 comments on commit c69709f

Please sign in to comment.