From 29533675000e0e1ebef49e14a9958e8428a24b18 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Mon, 27 Feb 2023 10:29:13 +0100 Subject: [PATCH] Hide internal properties The Structurizr DSL library introduced element/relationship identifiers as properties recently. Hide those for the site generation since we are not really interested in presenting them to users. Note that at the time of committing they still appear on the generated diagrams, though that has already been addressed upstream in com.structurizr:structurizr-export and will be fixed with a library update once a new version has been released. --- .../site/generatr/StructurizrUtilities.kt | 3 +++ .../model/SoftwareSystemHomePageViewModel.kt | 5 +++-- .../SoftwareSystemHomePageViewModelTest.kt | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt index 67043ced..c880f463 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt @@ -11,6 +11,9 @@ val Model.includedSoftwareSystems: List val SoftwareSystem.includedSoftwareSystem get() = this.location != Location.External +val SoftwareSystem.includedProperties + get() = this.properties.filterNot { (name, _) -> name == "structurizr.dsl.identifier" } + fun SoftwareSystem.hasDecisions() = documentation.decisions.isNotEmpty() fun SoftwareSystem.hasDocumentationSections() = documentation.sections.size >= 2 diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModel.kt index e8ad170e..54b286d1 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModel.kt @@ -1,12 +1,13 @@ package nl.avisi.structurizr.site.generatr.site.model import com.structurizr.model.SoftwareSystem +import nl.avisi.structurizr.site.generatr.includedProperties import nl.avisi.structurizr.site.generatr.site.GeneratorContext class SoftwareSystemHomePageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) : SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.HOME) { - val hasProperties = softwareSystem.properties.any() - val propertiesTable = createPropertiesTableViewModel(softwareSystem.properties) + val hasProperties = softwareSystem.includedProperties.any() + val propertiesTable = createPropertiesTableViewModel(softwareSystem.includedProperties) val content = markdownToHtml(this, softwareSystem.info(), generatorContext.svgFactory) private fun SoftwareSystem.info() = documentation.sections diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt index 9812b6d8..d1d4f4e2 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt @@ -84,4 +84,22 @@ class SoftwareSystemHomePageViewModelTest : ViewModelTest() { .isEqualTo(createPropertiesTableViewModel(softwareSystem.properties)) } } + + @Test + fun `internal properties present`() { + val generatorContext = generatorContext() + val softwareSystem: SoftwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system") + .apply { + description = "It's a system." + addProperty("structurizr.dsl.identifier", "id") + } + val viewModel = SoftwareSystemHomePageViewModel(generatorContext, softwareSystem) + + assertThat(viewModel) + .all { + prop(SoftwareSystemHomePageViewModel::hasProperties).isEqualTo(false) + prop(SoftwareSystemHomePageViewModel::propertiesTable) + .isEqualTo(createPropertiesTableViewModel(mapOf())) + } + } }