From 7ba2adde768dc79ca2beaba75c3e33798cd15242 Mon Sep 17 00:00:00 2001 From: Tobias Blum Date: Thu, 11 May 2023 14:44:16 +0200 Subject: [PATCH] Use treeFrom/treeExpandTo settings only in "tree" mode Fix for https://github.com/pnp/sp-dev-fx-webparts/issues/3684 --- samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts | 2 +- .../pagehierarchy/components/Container/Container.tsx | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts b/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts index 6c4fca96d..3b34aa036 100644 --- a/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts +++ b/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts @@ -88,7 +88,7 @@ function pagesReducer(state: PagesState, action: Action): PagesState { } } -export function usePageApi(currentPageId: number, pageEditFinished: boolean, context: WebPartContext, treeTop: number, treeExpandTo: number): PageApi { +export function usePageApi(currentPageId: number, pageEditFinished: boolean, context: WebPartContext, treeTop?: number, treeExpandTo?: number): PageApi { const [pagesState, pagesDispatch] = useReducer(pagesReducer, { parentPageColumnExists: true, userCanManagePages: false, diff --git a/samples/react-pages-hierarchy/src/webparts/pagehierarchy/components/Container/Container.tsx b/samples/react-pages-hierarchy/src/webparts/pagehierarchy/components/Container/Container.tsx index 261baa65e..640570600 100644 --- a/samples/react-pages-hierarchy/src/webparts/pagehierarchy/components/Container/Container.tsx +++ b/samples/react-pages-hierarchy/src/webparts/pagehierarchy/components/Container/Container.tsx @@ -10,7 +10,10 @@ import { Placeholder } from "@pnp/spfx-controls-react/lib/Placeholder"; import { TreeLayout } from '../Layouts/TreeLayout'; export const Container: React.FunctionComponent = props => { - const pagesApi = usePageApi(props.currentPageId, props.pageEditFinished, props.context, props.treeFrom, props.treeExpandTo); + // Use props.treeFrom / treeExpandTo value from settings only in display mode "tree" + const treeFrom = (props.pagesToDisplay === PagesToDisplay.Tree) ? props.treeFrom : undefined; + const treeExpandTo = (props.pagesToDisplay === PagesToDisplay.Tree) ? props.treeExpandTo : undefined; + const pagesApi = usePageApi(props.currentPageId, props.pageEditFinished, props.context, treeFrom, treeExpandTo); let controlToRender = undefined; switch (props.pagesToDisplay) { case PagesToDisplay.Ancestors: