Skip to content

Commit

Permalink
feat(score-cards): Configure display policies to hide/show owner and …
Browse files Browse the repository at this point in the history
…kind columns
  • Loading branch information
orkhan-huseyn committed Dec 2, 2024
1 parent 1c844ea commit f014c40
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 9 deletions.
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
3 changes: 3 additions & 0 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ scaffolder:
scorecards:
jsonDataUrl: http://localhost:8090/plugins/score-card/sample-data/ #this is being served via http-server
wikiLinkTemplate: https://link-to-wiki/{id}
display:
owner: never
kind: never

catalog:
rules:
Expand Down
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;
}

0 comments on commit f014c40

Please sign in to comment.