Only render the first primary link of the check result prominently
Change-Id: I501eebdf09b8194a742685c881b4463695d5e54f
diff --git a/polygerrit-ui/app/api/checks.ts b/polygerrit-ui/app/api/checks.ts
index e74eee1..c737da0 100644
--- a/polygerrit-ui/app/api/checks.ts
+++ b/polygerrit-ui/app/api/checks.ts
@@ -424,8 +424,6 @@
url: string;
tooltip?: string;
/**
- * TODO: Maybe drop this property? Do we really need it?
- *
* Primary links will get a more prominent treatment in the UI, e.g. being
* always visible in the results table or also showing up in the change page
* summary of checks.
diff --git a/polygerrit-ui/app/elements/checks/gr-checks-results.ts b/polygerrit-ui/app/elements/checks/gr-checks-results.ts
index b77912d..9efb699 100644
--- a/polygerrit-ui/app/elements/checks/gr-checks-results.ts
+++ b/polygerrit-ui/app/elements/checks/gr-checks-results.ts
@@ -53,6 +53,8 @@
hasCompletedWithoutResults,
iconForCategory,
iconForLink,
+ otherLinks,
+ primaryLink,
primaryRunAction,
tooltipForLink,
} from '../../services/checks/checks-util';
@@ -306,7 +308,7 @@
</td>
<td class="summaryCol">
<div class="summary-cell">
- ${(this.result.links?.slice(0, 1) ?? []).map(this.renderLink)}
+ ${this.renderLink(primaryLink(this.result))}
${this.renderSummary(this.result.summary)}
<div class="message" @click="${this.toggleExpanded}">
${this.isExpanded ? '' : this.result.message}
@@ -396,12 +398,13 @@
}
renderLinks() {
- const links = (this.result?.links ?? []).slice(1);
+ const links = otherLinks(this.result);
if (links.length === 0) return;
return html`<div class="links">${links.map(this.renderLink)}</div>`;
}
- renderLink(link: Link) {
+ renderLink(link?: Link) {
+ if (!link) return;
const tooltipText = link.tooltip ?? tooltipForLink(link.icon);
return html`<a href="${link.url}" target="_blank"
><iron-icon
diff --git a/polygerrit-ui/app/services/checks/checks-util.ts b/polygerrit-ui/app/services/checks/checks-util.ts
index 7eb2a5d..981a1f6 100644
--- a/polygerrit-ui/app/services/checks/checks-util.ts
+++ b/polygerrit-ui/app/services/checks/checks-util.ts
@@ -21,6 +21,7 @@
CheckResult as CheckResultApi,
LinkIcon,
RunStatus,
+ Link,
} from '../../api/checks';
import {assertNever} from '../../utils/common-util';
import {CheckResult, CheckRun} from './checks-model';
@@ -308,3 +309,15 @@
internalResultId: 'fake',
};
}
+
+export function primaryLink(result?: CheckResultApi): Link | undefined {
+ const links = result?.links ?? [];
+ return links.find(link => link.primary);
+}
+
+export function otherLinks(result?: CheckResultApi): Link[] {
+ const primary = primaryLink(result);
+ const links = result?.links ?? [];
+ // Just filter the one primary link, not all primary links.
+ return links.filter(link => link !== primary);
+}