diff --git a/.changeset/gold-jeans-lay.md b/.changeset/gold-jeans-lay.md new file mode 100644 index 0000000000..41b76dfbf0 --- /dev/null +++ b/.changeset/gold-jeans-lay.md @@ -0,0 +1,5 @@ +--- +'@oriflame/backstage-plugin-score-card': minor +--- + +Configure display policies to hide/show owner and kind columns diff --git a/plugins/score-card/config.d.ts b/plugins/score-card/config.d.ts index a47cb2d63d..18b8797bf5 100644 --- a/plugins/score-card/config.d.ts +++ b/plugins/score-card/config.d.ts @@ -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 diff --git a/plugins/score-card/src/components/ScoreCardTable/ScoreCardTable.tsx b/plugins/score-card/src/components/ScoreCardTable/ScoreCardTable.tsx index f292df2e5d..0de307c573 100644 --- a/plugins/score-card/src/components/ScoreCardTable/ScoreCardTable.tsx +++ b/plugins/score-card/src/components/ScoreCardTable/ScoreCardTable.tsx @@ -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 => @@ -97,8 +107,8 @@ export const ScoreTable = ({ title, scores }: ScoreTableProps) => { ) : null, - }, - ]; + }); + } if ( displayPolicies.reviewer === DisplayPolicy.Always || diff --git a/plugins/score-card/src/config/DisplayConfig.test.ts b/plugins/score-card/src/config/DisplayConfig.test.ts index 2d143a4328..af4f4d6704 100644 --- a/plugins/score-card/src/config/DisplayConfig.test.ts +++ b/plugins/score-card/src/config/DisplayConfig.test.ts @@ -22,17 +22,29 @@ 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, }, ], [ @@ -40,13 +52,55 @@ describe('display config', () => { { 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 } }); diff --git a/plugins/score-card/src/config/DisplayConfig.ts b/plugins/score-card/src/config/DisplayConfig.ts index 608e561316..88a9fdfaa3 100644 --- a/plugins/score-card/src/config/DisplayConfig.ts +++ b/plugins/score-card/src/config/DisplayConfig.ts @@ -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, diff --git a/plugins/score-card/src/config/types.ts b/plugins/score-card/src/config/types.ts index a20b47f26c..79bf37000a 100644 --- a/plugins/score-card/src/config/types.ts +++ b/plugins/score-card/src/config/types.ts @@ -21,6 +21,8 @@ export enum DisplayPolicy { } export interface DisplayPolicies { + kind: DisplayPolicy, + owner: DisplayPolicy, reviewer: DisplayPolicy; reviewDate: DisplayPolicy; }