Skip to content

Commit

Permalink
fix: show loading features only when loading is happening (#6817)
Browse files Browse the repository at this point in the history
Previously, the dummy data would persist when there is no data coming
from the API. This causes us to display dummy data in the dora metrics
table which is not correct. This PR fixes that by only showing the
loading features when we are actually loading.
  • Loading branch information
FredrikOseberg committed Apr 10, 2024
1 parent 70eb463 commit 7f1c46a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ test('Show outdated SDKs and apps using them', async () => {
<Routes>
<Route
path={'/projects/:projectId'}
element={<LeadTimeForChanges leadTime={leadTime} />}
element={
<LeadTimeForChanges leadTime={leadTime} loading={false} />
}
/>
</Routes>,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,21 @@ const resolveDoraMetrics = (input: number) => {

interface ILeadTimeForChangesProps {
leadTime: ProjectDoraMetricsSchema;
loading: boolean;
}

export const LeadTimeForChanges = ({ leadTime }: ILeadTimeForChangesProps) => {
const loadingLeadTimeFeatures = [
{ name: 'feature1', timeToProduction: 0 },
{ name: 'feature2', timeToProduction: 0 },
{ name: 'feature3', timeToProduction: 0 },
{ name: 'feature4', timeToProduction: 0 },
{ name: 'feature5', timeToProduction: 2 },
];

export const LeadTimeForChanges = ({
leadTime,
loading,
}: ILeadTimeForChangesProps) => {
const columns = useMemo(
() => [
{
Expand Down Expand Up @@ -157,7 +169,7 @@ export const LeadTimeForChanges = ({ leadTime }: ILeadTimeForChangesProps) => {
disableSortBy: true,
},
],
[JSON.stringify(leadTime.features)],
[JSON.stringify(leadTime.features), loading],
);

const initialState = useMemo(
Expand Down Expand Up @@ -185,7 +197,7 @@ export const LeadTimeForChanges = ({ leadTime }: ILeadTimeForChangesProps) => {
} = useTable(
{
columns: columns as any[],
data: leadTime.features,
data: loading ? loadingLeadTimeFeatures : leadTime.features,
initialState,
autoResetGlobalFilter: false,
autoResetSortBy: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const ProjectInsights = () => {
<ProjectHealth health={data.health} />
</MediumWideContainer>
<WideContainer>
<LeadTimeForChanges leadTime={data.leadTime} />
<LeadTimeForChanges
leadTime={data.leadTime}
loading={loading}
/>
</WideContainer>
<NarrowContainer>
<FlagTypesUsed featureTypeCounts={data.featureTypeCounts} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ const placeholderData: ProjectInsightsSchema = {
],
leadTime: {
projectAverage: 0,
features: [
{ name: 'feature1', timeToProduction: 0 },
{ name: 'feature2', timeToProduction: 0 },
{ name: 'feature3', timeToProduction: 0 },
{ name: 'feature4', timeToProduction: 0 },
{ name: 'feature5', timeToProduction: 2 },
],
features: [],
},
health: {
rating: 0,
Expand Down

0 comments on commit 7f1c46a

Please sign in to comment.