From 2a3c046b550f87edd01cc987065984b80f501bca Mon Sep 17 00:00:00 2001
From: Debayan Ghosh <66942246+debayangg@users.noreply.github.com>
Date: Thu, 4 Jan 2024 21:05:35 +0530
Subject: [PATCH] [JENKINS-71435] Make empty properties clickable (#1648)
Change `DetailsTableModel` to display '-' for issues with blank properties.
---
.../analysis/core/model/DetailsTableModel.java | 8 ++++++--
.../analysis/core/model/DetailsTableModelTest.java | 11 +++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/DetailsTableModel.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/DetailsTableModel.java
index e11d2cf069..ba505066ab 100644
--- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/DetailsTableModel.java
+++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/DetailsTableModel.java
@@ -247,7 +247,7 @@ protected String formatSeverity(final Severity severity) {
}
/**
- * Formats the text of the specified property column. T he text actually is a link to the UI representation of
+ * Formats the text of the specified property column. The text actually is a link to the UI representation of
* the property.
*
* @param property
@@ -258,7 +258,11 @@ protected String formatSeverity(final Severity severity) {
* @return the formatted column
*/
protected String formatProperty(final String property, final String value) {
- return String.format("%s", property, value.hashCode(), render(value));
+ String renderedValue = render(value);
+ if (StringUtils.isBlank(value)) {
+ renderedValue = "-";
+ }
+ return String.format("%s", property, value.hashCode(), renderedValue);
}
/**
diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/DetailsTableModelTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/DetailsTableModelTest.java
index e3d7aa58c7..35959d66fb 100644
--- a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/DetailsTableModelTest.java
+++ b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/DetailsTableModelTest.java
@@ -36,6 +36,17 @@ void shouldCreateSortableFileName() {
createExpectedFileName(issue), "/path/to/file-1:0000015");
}
+ @Test
+ void shouldReturnClickableProperties() {
+ try (IssueBuilder builder = new IssueBuilder()) {
+ builder.setCategory("");
+ Issue issue = builder.build();
+ TableRow model = createRow(issue);
+ assertThat(model.formatProperty("category", issue.getCategory()))
+ .isEqualTo("-");
+ }
+ }
+
private TableRow createRow(final Issue issue) {
return new TableRow(createAgeBuilder(), createFileNameRenderer(), i -> DESCRIPTION, issue,
createJenkinsFacade());