Skip to content

Commit d1ff372

Browse files
committed
Refactor parent select options to remove visual indenting and streamline data structure. Update Twig template to handle depth-based indentation for improved clarity in dropdowns.
1 parent da07301 commit d1ff372

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/backend/controllers/pages.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,21 @@ class Pages {
102102
}
103103

104104
/**
105-
* Ordered pages for the parent `<select>` with visual nesting (indent = depth).
105+
* Ordered pages for the parent `<select>` with nesting depth (indent in the template).
106106
*
107107
* @param excludePageId - when editing, exclude this page and its descendants (same as groupByParent)
108108
*/
109109
public static async getParentSelectOptions(
110110
excludePageId?: EntityId
111-
): Promise<Array<{ page: Page; depth: number; indent: string }>> {
111+
): Promise<Array<{ page: Page; depth: number }>> {
112112
const { pages, pagesMap } = excludePageId
113113
? await this.groupByParentWithMap(excludePageId)
114114
: await this.groupByParentWithMap('' as EntityId);
115-
const indentUnit = '\u00a0\u00a0';
116115

117-
return pages.map((page) => {
118-
const depth = Pages.computePageDepth(page, pagesMap);
119-
120-
return { page, depth, indent: indentUnit.repeat(depth) };
121-
});
116+
return pages.map((page) => ({
117+
page,
118+
depth: Pages.computePageDepth(page, pagesMap),
119+
}));
122120
}
123121

124122
/**

src/backend/views/pages/form.twig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
{% set _page = entry.page %}
3131
{% if toString(_page._id) != toString(currentPageId) %}
3232
<option value="{{ toString(_page._id) }}" {{ page is not empty and toString(page._parent) == toString(_page._id) ? 'selected' : ''}}>
33-
{{- entry.indent -}}{{- _page.title -}}
33+
{%- if entry.depth > 0 -%}
34+
{%- for _ in 1..entry.depth %}&nbsp;&nbsp;{% endfor -%}
35+
{%- endif -%}
36+
{{- _page.title|striptags -}}
3437
</option>
3538
{% endif %}
3639
{% endfor %}
@@ -42,7 +45,7 @@
4245
<select id="above" name="above">
4346
<option value="0">—</option>
4447
{% for _page in parentsChildrenOrdered %}
45-
<option value="{{ toString(_page._id) }}">{{ _page.title }}</option>
48+
<option value="{{ toString(_page._id) }}">{{ _page.title|striptags }}</option>
4649
{% endfor %}
4750
</select>
4851
</div>

0 commit comments

Comments
 (0)