Skip to content

Commit

Permalink
fix: don't delete any rendering layouts and keep the order of existin…
Browse files Browse the repository at this point in the history
…g rendering layouts even when overwrite-layouts is enabled
  • Loading branch information
micha91 committed Sep 5, 2024
1 parent 9519a51 commit 47e476b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
17 changes: 15 additions & 2 deletions capella2polarion/converters/document_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,19 @@ def update_mixed_authority_document(
document, session.headings, text_work_item_provider
)

def _update_rendering_layouts(
self,
document: polarion_api.Document,
rendering_layouts: list[polarion_api.RenderingLayout],
):
"""Keep existing work item layouts in their original order."""
document.rendering_layouts = document.rendering_layouts or []
for rendering_layout in rendering_layouts:
index = polarion_html_helper.get_layout_index(
"section", document.rendering_layouts, rendering_layout.type
)
document.rendering_layouts[index] = rendering_layout

def _get_and_customize_doc(
self,
project_id: str | None,
Expand All @@ -359,11 +372,11 @@ def _get_and_customize_doc(
old_doc, text_work_items = self.existing_documents.get(
(project_id, space, name), (None, [])
)
if old_doc:
if old_doc is not None:
if title:
old_doc.title = title
if self.overwrite_layouts:
old_doc.rendering_layouts = rendering_layouts
self._update_rendering_layouts(old_doc, rendering_layouts)
if self.overwrite_heading_numbering:
old_doc.outline_numbering = heading_numbering

Expand Down
17 changes: 14 additions & 3 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ def existing_documents() -> polarion_repo.DocumentRepository:
value=MIXED_AUTHORITY_DOCUMENT.read_text("utf-8"),
),
rendering_layouts=[
polarion_api.RenderingLayout(
"text", "paragraph", type="text"
),
polarion_api.RenderingLayout(
"Class", "paragraph", type="class"
)
),
],
),
[],
Expand Down Expand Up @@ -461,7 +464,7 @@ def test_render_all_documents_partially_successfully(
)
assert (
len(projects_data[None].updated_docs[1].document.rendering_layouts)
== 1
== 2
)
assert (
projects_data[None].updated_docs[0].document.outline_numbering is None
Expand Down Expand Up @@ -540,7 +543,15 @@ def test_render_all_documents_overwrite_headings_layouts(
updated_docs = projects_data[None].updated_docs

assert len(updated_docs[0].document.rendering_layouts) == 2
assert len(updated_docs[1].document.rendering_layouts) == 2
assert len(updated_docs[1].document.rendering_layouts) == 3
assert updated_docs[1].document.rendering_layouts[0].type == "text"
assert updated_docs[1].document.rendering_layouts[1].type == "class"
assert (
"tree_view_diagram"
in updated_docs[1]
.document.rendering_layouts[1]
.properties.fields_at_end
)
assert updated_docs[0].document.outline_numbering is False
assert updated_docs[1].document.outline_numbering is False

Expand Down

0 comments on commit 47e476b

Please sign in to comment.