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:
parent
fa3a66492d
commit
38aee3b1c7
|
@ -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 = () => {
|
||||||
|
|
|
@ -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
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue