Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(score-cards): Configure display policies to hide/show columns #296

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-jeans-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@oriflame/backstage-plugin-score-card': minor
---

Configure display policies to hide/show owner and kind columns
10 changes: 10 additions & 0 deletions plugins/score-card/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export interface Config {
*/
jsonDataUrl?: string;
display?: {
/**
* Whether to display the kind column in the score card table.
* @visibility frontend
*/
kind?: string;
/**
* Whether to display the owner column in the score card table.
* @visibility frontend
*/
owner?: string;
/**
* Whether to display the reviewer column in the score card table.
* @visibility frontend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,24 @@ export const ScoreTable = ({ title, scores }: ScoreTableProps) => {
);
},
},
{
];

if (displayPolicies.kind === DisplayPolicy.Always) {
columns.push({
title: 'Kind',
field: 'entityRef.kind',
render: entityScore => {
return <>{entityScore.entityRef.kind}</>;
},
},
{
});
}

if (
displayPolicies.owner === DisplayPolicy.Always ||
(displayPolicies.owner === DisplayPolicy.IfDataPresent &&
scores.some(s => !!s.owner))
) {
columns.push({
title: 'Owner',
field: 'owner.name',
render: entityScore =>
Expand All @@ -97,8 +107,8 @@ export const ScoreTable = ({ title, scores }: ScoreTableProps) => {
</EntityRefLink>
</>
) : null,
},
];
});
}

if (
displayPolicies.reviewer === DisplayPolicy.Always ||
Expand Down
62 changes: 58 additions & 4 deletions plugins/score-card/src/config/DisplayConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,85 @@ describe('display config', () => {
it.each([
[
{ reviewer: 'always', reviewDate: 'always' },
{ reviewer: DisplayPolicy.Always, reviewDate: DisplayPolicy.Always },
{
reviewer: DisplayPolicy.Always,
reviewDate: DisplayPolicy.Always,
owner: DisplayPolicy.Always,
kind: DisplayPolicy.Always,
},
],
[
{ reviewer: 'never', reviewDate: 'never' },
{ reviewer: DisplayPolicy.Never, reviewDate: DisplayPolicy.Never },
{
reviewer: DisplayPolicy.Never,
reviewDate: DisplayPolicy.Never,
owner: DisplayPolicy.Always,
kind: DisplayPolicy.Always,
},
],
[
{ reviewer: 'if-data-present', reviewDate: 'if-data-present' },
{
reviewer: DisplayPolicy.IfDataPresent,
reviewDate: DisplayPolicy.IfDataPresent,
owner: DisplayPolicy.Always,
kind: DisplayPolicy.Always,
},
],
[
{ reviewDate: 'if-data-present' },
{
reviewer: DisplayPolicy.Always,
reviewDate: DisplayPolicy.IfDataPresent,
owner: DisplayPolicy.Always,
kind: DisplayPolicy.Always,
},
],
[
{ reviewer: 'never' },
{ reviewer: DisplayPolicy.Never, reviewDate: DisplayPolicy.Always },
{
reviewer: DisplayPolicy.Never,
reviewDate: DisplayPolicy.Always,
owner: DisplayPolicy.Always,
kind: DisplayPolicy.Always,
},
],
[
{ owner: 'never' },
{
reviewer: DisplayPolicy.Always,
reviewDate: DisplayPolicy.Always,
owner: DisplayPolicy.Never,
kind: DisplayPolicy.Always,
},
],
[
{ owner: 'if-data-present' },
{
reviewer: DisplayPolicy.Always,
reviewDate: DisplayPolicy.Always,
owner: DisplayPolicy.IfDataPresent,
kind: DisplayPolicy.Always,
},
],
[
{ kind: 'never' },
{
reviewer: DisplayPolicy.Always,
reviewDate: DisplayPolicy.Always,
owner: DisplayPolicy.Always,
kind: DisplayPolicy.Never,
},
],
[
{},
{
reviewer: DisplayPolicy.Always,
reviewDate: DisplayPolicy.Always,
owner: DisplayPolicy.Always,
kind: DisplayPolicy.Always,
}
],
[{}, { reviewer: DisplayPolicy.Always, reviewDate: DisplayPolicy.Always }],
])('gets expected display policies from config', (policies, expected) => {
const mockConfig = new MockConfigApi({ scorecards: { display: policies } });

Expand Down
6 changes: 6 additions & 0 deletions plugins/score-card/src/config/DisplayConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export class DisplayConfig {
reviewer:
(displayConfig?.getOptionalString('reviewer') as DisplayPolicy) ??
DisplayPolicy.Always,
owner:
(displayConfig?.getOptionalString('owner') as DisplayPolicy) ??
DisplayPolicy.Always,
kind:
(displayConfig?.getOptionalString('kind') as DisplayPolicy) ??
DisplayPolicy.Always,
reviewDate:
(displayConfig?.getOptionalString('reviewDate') as DisplayPolicy) ??
DisplayPolicy.Always,
Expand Down
2 changes: 2 additions & 0 deletions plugins/score-card/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum DisplayPolicy {
}

export interface DisplayPolicies {
kind: DisplayPolicy,
owner: DisplayPolicy,
reviewer: DisplayPolicy;
reviewDate: DisplayPolicy;
}