-
Notifications
You must be signed in to change notification settings - Fork 89
PR title: Fix deep page nesting in sidebar, prev/next order, and parent dropdown indent #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
66ffd4f
56d8a79
9c9de40
da07301
d1ff372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,42 @@ class Pages { | |
| return pagesMap; | ||
| } | ||
|
|
||
| /** | ||
| * Depth in parent chain: 0 for root pages, +1 per ancestor below root (for select indent). | ||
| */ | ||
| private static computePageDepth(page: Page, pagesMap: Map<string, Page>): number { | ||
| let depth = 0; | ||
| let cur: Page | undefined = page; | ||
|
|
||
| while (cur?._parent && !isEqualIds(cur._parent, '0' as EntityId)) { | ||
| depth++; | ||
| cur = pagesMap.get(cur._parent.toString()); | ||
| } | ||
|
|
||
| return depth; | ||
| } | ||
|
|
||
| /** | ||
| * Ordered pages for the parent `<select>` with visual nesting (indent = depth). | ||
| * | ||
| * @param excludePageId - when editing, exclude this page and its descendants (same as groupByParent) | ||
| */ | ||
| public static async getParentSelectOptions( | ||
| excludePageId?: EntityId | ||
| ): Promise<Array<{ page: Page; depth: number; indent: string }>> { | ||
| const pages = excludePageId | ||
| ? await this.groupByParent(excludePageId) | ||
| : await this.groupByParent(); | ||
| const pagesMap = await this.getPagesMap(); | ||
| const indentUnit = '\u00a0\u00a0'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seem like it is a presentation-specific logic, and should not be stored in a data model. |
||
|
|
||
| return pages.map((page) => { | ||
| const depth = Pages.computePageDepth(page, pagesMap); | ||
|
|
||
| return { page, depth, indent: indentUnit.repeat(depth) }; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Group all pages by their parents | ||
| * If the pageId is passed, it excludes passed page from result pages | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| {% set is_leaf = node.children is not defined or node.children is empty %} | ||
| <section class="docs-sidebar__section{{ nested ? ' docs-sidebar__section--nested' : '' }}{{ is_leaf ? ' docs-sidebar__section--leaf' : '' }}" data-id="{{ node._id }}"> | ||
| <a class="docs-sidebar__section-title-wrapper" | ||
| href="{{ node.uri ? '/' ~ node.uri : '/page/' ~ node._id }}" | ||
| > | ||
| <div class="docs-sidebar__section-title {{ page is defined and toString(page._id) == toString(node._id) ? 'docs-sidebar__section-title--active' : '' }}"> | ||
| <span> | ||
| {{ node.title | striptags }} | ||
| </span> | ||
| {% if node.children is defined and node.children is not empty %} | ||
| <button type="button" class="docs-sidebar__section-toggler" aria-label="Toggle section"> | ||
| {{ svg('arrow-up') }} | ||
| </button> | ||
| {% endif %} | ||
| </div> | ||
| </a> | ||
| {% if node.children is defined and node.children is not empty %} | ||
| <ul class="docs-sidebar__section-list docs-sidebar__section-list--nested"> | ||
| {% for child in node.children %} | ||
| <li> | ||
| {% include 'components/sidebar-section.twig' with { node: child, nested: true } %} | ||
| </li> | ||
| {% endfor %} | ||
| </ul> | ||
| {% endif %} | ||
| </section> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,14 +26,11 @@ | |
| {% endif %} | ||
| <select id="parent" name="parent"> | ||
| <option value="0">Root</option> | ||
| {% for _page in pagesAvailableGrouped %} | ||
| {% for entry in parentSelectOptions %} | ||
| {% set _page = entry.page %} | ||
| {% if toString(_page._id) != toString(currentPageId) %} | ||
| <option value="{{ toString(_page._id) }}" {{ page is not empty and toString(page._parent) == toString(_page._id) ? 'selected' : ''}}> | ||
| {% if _page._parent != "0" %} | ||
| | ||
| | ||
| {% endif %} | ||
| {{ _page.title }} | ||
| {{- entry.indent -}}{{- _page.title -}} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please, add "strip tags" filter to the title to prevent xss |
||
| </option> | ||
| {% endif %} | ||
| {% endfor %} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.