added the ability to find the current pages highest ancestor and allow the tree view to expand inclusively to it

This commit is contained in:
SlowRobot 2022-07-22 01:08:38 +10:00 committed by SlowRobot
parent 62221196e7
commit f600ac9f7e
3 changed files with 18 additions and 15 deletions

View File

@ -148,7 +148,7 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean, con
const ancestorPages: IPage[] = buildPageAncestors(pages, currentPageId).reverse(); const ancestorPages: IPage[] = buildPageAncestors(pages, currentPageId).reverse();
const childrenPages: IPage[] = buildPageChildren(pages, currentPageId); const childrenPages: IPage[] = buildPageChildren(pages, currentPageId);
const treeLink: INavLink = buildHierarchy(pages); const treeLink: INavLink = buildHierarchy(pages, currentPageId);
// dispatch the GET_ALL action // dispatch the GET_ALL action
pagesDispatch({ pagesDispatch({
@ -253,16 +253,19 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean, con
return childPages; return childPages;
} }
function buildHierarchy(allPages: IPage[]): INavLink { function buildHierarchy(allPages: IPage[], pageId: number): INavLink {
function recurse(id: number, l: number): INavLink { function recurse(id: number, l: number, ancestorPages: IPage[]): INavLink {
var item: IPage = allPages.filter(i => i.id === id)[0]; var item: IPage = allPages.filter(i => i.id === id)[0];
var links: INavLink[] = []; var links: INavLink[] = [];
links = links.concat(allPages.filter(i => i.parentPageId === id).map(it => recurse(it.id, (l+1)))); 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 >= l }; 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 = () => { const addParentPageField = () => {

View File

@ -79,10 +79,10 @@ export default class PageHierarchyWebPart extends BaseWebPart<IPageHierarchyWebP
Really only used for workbench mode when we cannot get a page id for the current page. Really only used for workbench mode when we cannot get a page id for the current page.
We'll allow user to test with a property and also using mock data allow them to navigate when on local host with a querystring We'll allow user to test with a property and also using mock data allow them to navigate when on local host with a querystring
*/ */
private getDebugPageId() : number { private getDebugPageId(): number {
let queryParms = new UrlQueryParameterCollection(window.location.href); let queryParms = new UrlQueryParameterCollection(window.location.href);
let debugPageId = this.properties.debugPageId; let debugPageId = this.properties.debugPageId;
if(queryParms.getValue(Parameters.DEBUGPAGEID)) { debugPageId = Number(queryParms.getValue(Parameters.DEBUGPAGEID)); } if (queryParms.getValue(Parameters.DEBUGPAGEID)) { debugPageId = Number(queryParms.getValue(Parameters.DEBUGPAGEID)); }
return debugPageId; return debugPageId;
} }
@ -162,7 +162,7 @@ export default class PageHierarchyWebPart extends BaseWebPart<IPageHierarchyWebP
value: this.properties.treeFrom, value: this.properties.treeFrom,
label: strings.PropertyPane_Label_TreeFrom, label: strings.PropertyPane_Label_TreeFrom,
description: strings.PropertyPane_Description_TreeFrom, description: strings.PropertyPane_Description_TreeFrom,
minValue: 1, minValue: 0,
disabled: false disabled: false
}), }),
this.properties.pagesToDisplay === PagesToDisplay.Tree && PropertyFieldNumber('treeExpandTo', { this.properties.pagesToDisplay === PagesToDisplay.Tree && PropertyFieldNumber('treeExpandTo', {
@ -170,7 +170,7 @@ export default class PageHierarchyWebPart extends BaseWebPart<IPageHierarchyWebP
value: this.properties.treeExpandTo, value: this.properties.treeExpandTo,
label: strings.PropertyPane_Label_TreeExpandTo, label: strings.PropertyPane_Label_TreeExpandTo,
description: strings.PropertyPane_Description_TreeExpandTo, description: strings.PropertyPane_Description_TreeExpandTo,
minValue: 1, minValue: 0,
disabled: false disabled: false
}) })
] ]

View File

@ -1,4 +1,4 @@
define([], function() { define([], function () {
return { return {
"Configuration_Placeholder_IconText": "Configure Page Hierarchy Web Part", "Configuration_Placeholder_IconText": "Configure Page Hierarchy Web Part",
"Configuration_Placeholder_Description": "Please configure the web part.", "Configuration_Placeholder_Description": "Please configure the web part.",
@ -22,8 +22,8 @@ define([], function() {
"PropertyPane_Label_DebugPageId": "Debug Page Id", "PropertyPane_Label_DebugPageId": "Debug Page Id",
"PropertyPane_Label_VersionInfo": "Version: ", "PropertyPane_Label_VersionInfo": "Version: ",
"PropertyPane_Description_DebugPageId": "Provide a valid page list item id to see how the web part would render for it", "PropertyPane_Description_DebugPageId": "Provide a valid page list item id to see how the web part would render for it",
"PropertyPane_Description_TreeFrom": "Please provide the page id for the root of the tree to render", "PropertyPane_Description_TreeFrom": "Please provide the page id for the root of the tree to render. Entering zero will start the tree at the current pages highest ancestor",
"PropertyPane_Label_TreeExpandTo": "Default Expand the Tree To Level", "PropertyPane_Label_TreeExpandTo": "Default Expand the Tree To Level",
"PropertyPane_Description_TreeExpandTo": "By default expand the tree to this level" "PropertyPane_Description_TreeExpandTo": "By default expand the tree to this level. Entering zero will inclusively expand the tree along the ancestor path of the current page"
} }
}); });