diff --git a/samples/react-pages-hierarchy/README.md b/samples/react-pages-hierarchy/README.md index 1bbb25bd1..d9d66c122 100644 --- a/samples/react-pages-hierarchy/README.md +++ b/samples/react-pages-hierarchy/README.md @@ -49,6 +49,7 @@ Solution|Author(s) --------|--------- react-pages-hierarchy|[Bo George](https://github.com/bogeorge) ([@bo_george](https://twitter.com/bo_george)) react-pages-hierarchy|[Nick Brown](https://github.com/techienickb) ([@techienickb](https://twitter.com/techienickb)) +react-pages-hierarchy|[SlowRobot](https://github.com/SlowRobot) ## Version history @@ -57,6 +58,7 @@ Version|Date|Comments 1.0|April 30, 2020|Initial release 1.2|March 24, 2022|Updated to SPFX v1.14 and PnP packages to v3 1.3|March 31, 2022|Added a Tree View +1.4|July 29, 2022|Updated Tree View Functionality ## Minimal path to awesome diff --git a/samples/react-pages-hierarchy/assets/sample.json b/samples/react-pages-hierarchy/assets/sample.json index 202327a32..60252a274 100644 --- a/samples/react-pages-hierarchy/assets/sample.json +++ b/samples/react-pages-hierarchy/assets/sample.json @@ -9,7 +9,7 @@ "This web part allows users to create a faux page hierarchy in their pages library and use it for page-to-page navigation." ], "creationDateTime": "2020-04-30", - "updateDateTime": "2022-03-31", + "updateDateTime": "2022-07-29", "products": [ "SharePoint" ], diff --git a/samples/react-pages-hierarchy/config/package-solution.json b/samples/react-pages-hierarchy/config/package-solution.json index 1b7ab52bc..76f720164 100644 --- a/samples/react-pages-hierarchy/config/package-solution.json +++ b/samples/react-pages-hierarchy/config/package-solution.json @@ -51,4 +51,4 @@ "paths": { "zippedPackage": "solution/react-pages-hierarchy.sppkg" } -} +} \ No newline at end of file diff --git a/samples/react-pages-hierarchy/package-lock.json b/samples/react-pages-hierarchy/package-lock.json index 821a63e32..6778fc2ff 100644 --- a/samples/react-pages-hierarchy/package-lock.json +++ b/samples/react-pages-hierarchy/package-lock.json @@ -3882,6 +3882,16 @@ "msal": "1.4.13", "msalLegacy": "npm:msal@1.4.12", "tslib": "~1.10.0" + }, + "dependencies": { + "msalLegacy": { + "version": "npm:msal@1.4.12", + "resolved": "https://registry.npmjs.org/msal/-/msal-1.4.12.tgz", + "integrity": "sha512-gjupwQ6nvNL6mZkl5NIXyUmZhTiEMRu5giNdgHMh8l5EPOnV2Xj6nukY1NIxFacSTkEYUSDB47Pej9GxDYf+1w==", + "requires": { + "tslib": "^1.9.3" + } + } } }, "@microsoft/sp-listview-extensibility": { @@ -18736,14 +18746,6 @@ "tslib": "^1.9.3" } }, - "msalLegacy": { - "version": "npm:msal@1.4.12", - "resolved": "https://registry.npmjs.org/msal/-/msal-1.4.12.tgz", - "integrity": "sha512-gjupwQ6nvNL6mZkl5NIXyUmZhTiEMRu5giNdgHMh8l5EPOnV2Xj6nukY1NIxFacSTkEYUSDB47Pej9GxDYf+1w==", - "requires": { - "tslib": "^1.9.3" - } - }, "multicast-dns": { "version": "6.2.3", "resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-6.2.3.tgz", diff --git a/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts b/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts index 6fe0edebf..55f48d184 100644 --- a/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts +++ b/samples/react-pages-hierarchy/src/apiHooks/usePageApi.ts @@ -148,7 +148,7 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean, con const ancestorPages: IPage[] = buildPageAncestors(pages, currentPageId).reverse(); const childrenPages: IPage[] = buildPageChildren(pages, currentPageId); - const treeLink: INavLink = buildHierarchy(pages); + const treeLink: INavLink = buildHierarchy(pages, currentPageId); // dispatch the GET_ALL action pagesDispatch({ @@ -253,16 +253,19 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean, con return childPages; } - function buildHierarchy(allPages: IPage[]): INavLink { - function recurse(id: number, l: number): INavLink { + function buildHierarchy(allPages: IPage[], pageId: number): INavLink { + function recurse(id: number, l: number, ancestorPages: IPage[]): INavLink { var item: IPage = allPages.filter(i => i.id === id)[0]; - + var links: INavLink[] = []; - links = links.concat(allPages.filter(i => i.parentPageId === id).map(it => recurse(it.id, (l+1)))); - - return { name: item.title, url: item.url, key: item.id.toString(), links: links, isExpanded: treeExpandTo >= l }; + links = links.concat(allPages.filter(i => i.parentPageId === id).map(it => recurse(it.id, l ? l + 1 : l, ancestorPages))); + + return { name: item.title, url: item.url, key: item.id.toString(), links: links, isExpanded: treeExpandTo ? (treeExpandTo >= l) : (ancestorPages.find(f => f.id === id) ? true : false) }; } - return recurse(treeTop, 1); + + const ancestorPages: IPage[] = buildPageAncestors(allPages, pageId).reverse(); + + return recurse(treeTop ? treeTop : ancestorPages[0].id, treeExpandTo ? 1 : treeExpandTo, ancestorPages); } const addParentPageField = () => { diff --git a/samples/react-pages-hierarchy/src/webparts/pagehierarchy/PageHierarchyWebPart.ts b/samples/react-pages-hierarchy/src/webparts/pagehierarchy/PageHierarchyWebPart.ts index 35625fc17..c9b3f3f2e 100644 --- a/samples/react-pages-hierarchy/src/webparts/pagehierarchy/PageHierarchyWebPart.ts +++ b/samples/react-pages-hierarchy/src/webparts/pagehierarchy/PageHierarchyWebPart.ts @@ -79,10 +79,10 @@ export default class PageHierarchyWebPart extends BaseWebPart