Skip to content
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 workspaces/scorecard/.changeset/hungry-mangos-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@red-hat-developer-hub/backstage-plugin-scorecard': patch
---

optimized how scorecard homepage is loaded
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import type { ComponentType, ReactElement } from 'react';
import { HomePageWidgetBlueprint } from '@backstage/plugin-home-react/alpha';
import type { RendererProps } from '@backstage/plugin-home-react';
import { ScorecardHomepageCardWithProvider } from '../../components/ScorecardHomepageSection';

const defaultCardLayout = {
width: {
Expand All @@ -31,38 +31,20 @@ const defaultCardLayout = {
},
} as const;

function AggregatedCardWithDeprecatedMetricIdContent() {
return <ScorecardHomepageCardWithProvider metricId="jira.openIssues" />;
}

function AggregatedCardWithDefaultAggregationContent() {
return <ScorecardHomepageCardWithProvider aggregationId="github.openPRs" />;
}

function AggregatedCardWithJiraOpenIssuesContent() {
return <ScorecardHomepageCardWithProvider aggregationId="openIssuesKpi" />;
}

function AggregatedCardWithGithubOpenPrsContent() {
return <ScorecardHomepageCardWithProvider aggregationId="openPrsKpi" />;
}

function AggregatedCardWithGithubFilecheckLicenseContent() {
return (
<ScorecardHomepageCardWithProvider aggregationId="licenseFileExistsKpi" />
);
}

function AggregatedCardWithGithubFilecheckCodeownersContent() {
return (
<ScorecardHomepageCardWithProvider aggregationId="filecheck.codeowners" />
);
}

function AggregatedCardWithGithubOpenPrsWeightedContent() {
return (
<ScorecardHomepageCardWithProvider aggregationId="openPrsWeightedKpi" />
);
function lazyScorecardWidget(
factory: (
ScorecardHomepageCardWithProvider: ComponentType<{
metricId?: string;
aggregationId?: string;
}>,
) => () => ReactElement,
) {
return async () => {
const { ScorecardHomepageCardWithProvider } = await import(
'../../components/ScorecardHomepageSection'
);
return { Content: factory(ScorecardHomepageCardWithProvider) };
};
}

function BorderlessHomeWidgetRenderer({ Content }: RendererProps) {
Expand All @@ -83,10 +65,10 @@ export const aggregatedCardWithDeprecatedMetricIdWidget =
componentProps: {
Renderer: BorderlessHomeWidgetRenderer,
},
components: () =>
Promise.resolve({
Content: AggregatedCardWithDeprecatedMetricIdContent,
}),
components: lazyScorecardWidget(
ScorecardHomepageCardWithProvider => () =>
<ScorecardHomepageCardWithProvider metricId="jira.openIssues" />,
),
},
});

Expand All @@ -104,10 +86,10 @@ export const aggregatedCardWithDefaultAggregationWidget =
componentProps: {
Renderer: BorderlessHomeWidgetRenderer,
},
components: () =>
Promise.resolve({
Content: AggregatedCardWithDefaultAggregationContent,
}),
components: lazyScorecardWidget(
ScorecardHomepageCardWithProvider => () =>
<ScorecardHomepageCardWithProvider aggregationId="github.openPRs" />,
),
},
});

Expand All @@ -125,10 +107,10 @@ export const aggregatedCardWithJiraOpenIssuesWidget =
componentProps: {
Renderer: BorderlessHomeWidgetRenderer,
},
components: () =>
Promise.resolve({
Content: AggregatedCardWithJiraOpenIssuesContent,
}),
components: lazyScorecardWidget(
ScorecardHomepageCardWithProvider => () =>
<ScorecardHomepageCardWithProvider aggregationId="openIssuesKpi" />,
),
},
});

Expand All @@ -146,10 +128,10 @@ export const aggregatedCardWithGithubOpenPrsWidget =
componentProps: {
Renderer: BorderlessHomeWidgetRenderer,
},
components: () =>
Promise.resolve({
Content: AggregatedCardWithGithubOpenPrsContent,
}),
components: lazyScorecardWidget(
ScorecardHomepageCardWithProvider => () =>
<ScorecardHomepageCardWithProvider aggregationId="openPrsKpi" />,
),
},
});

Expand All @@ -167,10 +149,12 @@ export const aggregatedCardWithGithubFilecheckLicenseWidget =
componentProps: {
Renderer: BorderlessHomeWidgetRenderer,
},
components: () =>
Promise.resolve({
Content: AggregatedCardWithGithubFilecheckLicenseContent,
}),
components: lazyScorecardWidget(
ScorecardHomepageCardWithProvider => () =>
(
<ScorecardHomepageCardWithProvider aggregationId="licenseFileExistsKpi" />
),
),
},
});

Expand All @@ -188,10 +172,12 @@ export const aggregatedCardWithGithubFilecheckCodeownersWidget =
componentProps: {
Renderer: BorderlessHomeWidgetRenderer,
},
components: () =>
Promise.resolve({
Content: AggregatedCardWithGithubFilecheckCodeownersContent,
}),
components: lazyScorecardWidget(
ScorecardHomepageCardWithProvider => () =>
(
<ScorecardHomepageCardWithProvider aggregationId="filecheck.codeowners" />
),
),
},
});

Expand All @@ -209,9 +195,11 @@ export const aggregatedCardWithGithubOpenPrsWeightedWidget =
componentProps: {
Renderer: BorderlessHomeWidgetRenderer,
},
components: () =>
Promise.resolve({
Content: AggregatedCardWithGithubOpenPrsWeightedContent,
}),
components: lazyScorecardWidget(
ScorecardHomepageCardWithProvider => () =>
(
<ScorecardHomepageCardWithProvider aggregationId="openPrsWeightedKpi" />
),
),
},
});
Loading