mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
fix: now issue count under application will show correctly (#6553)
Previously if multiple environments had same missing SDK, it was counted multiple times. Now it will take only unique.
This commit is contained in:
parent
2b2089f7b5
commit
1780fae022
@ -14,7 +14,7 @@ import Flag from '@mui/icons-material/Flag';
|
|||||||
import WarningAmberRounded from '@mui/icons-material/WarningAmberRounded';
|
import WarningAmberRounded from '@mui/icons-material/WarningAmberRounded';
|
||||||
import TimeAgo from 'react-timeago';
|
import TimeAgo from 'react-timeago';
|
||||||
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
import { getApplicationIssueMode } from './ApplicationIssues/ApplicationIssues';
|
import { getApplicationIssues } from './ApplicationIssues/ApplicationIssues';
|
||||||
|
|
||||||
const StyledTable = styled('table')(({ theme }) => ({
|
const StyledTable = styled('table')(({ theme }) => ({
|
||||||
fontSize: theme.fontSizes.smallerBody,
|
fontSize: theme.fontSizes.smallerBody,
|
||||||
@ -196,7 +196,7 @@ export const ApplicationChart = ({ data }: IApplicationChartProps) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const mode = getApplicationIssueMode(data);
|
const mode = getApplicationIssues(data);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width }}>
|
<Box sx={{ width }}>
|
||||||
|
@ -35,4 +35,40 @@ test('Display all application issues', async () => {
|
|||||||
);
|
);
|
||||||
await screen.findByText(`We detected the following outdated SDKs`);
|
await screen.findByText(`We detected the following outdated SDKs`);
|
||||||
await screen.findByText(`unleash-client-php:1.13.0`);
|
await screen.findByText(`unleash-client-php:1.13.0`);
|
||||||
|
await screen.findByText(`We detected 4 issues in this application`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Each SDK version should be displayed once', async () => {
|
||||||
|
const application: ApplicationOverviewSchema = {
|
||||||
|
projects: ['default'],
|
||||||
|
featureCount: 0,
|
||||||
|
environments: [
|
||||||
|
{
|
||||||
|
issues: {
|
||||||
|
missingFeatures: [],
|
||||||
|
outdatedSdks: ['unleash-client-php:1.13.0'],
|
||||||
|
},
|
||||||
|
sdks: [],
|
||||||
|
instanceCount: 0,
|
||||||
|
lastSeen: new Date().toISOString(),
|
||||||
|
name: 'development',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
issues: {
|
||||||
|
missingFeatures: [],
|
||||||
|
outdatedSdks: ['unleash-client-php:1.13.0'],
|
||||||
|
},
|
||||||
|
sdks: [],
|
||||||
|
instanceCount: 0,
|
||||||
|
lastSeen: new Date().toISOString(),
|
||||||
|
name: 'production',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
issues: {
|
||||||
|
missingStrategies: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
render(<ApplicationIssues application={application} />);
|
||||||
|
|
||||||
|
await screen.findByText(`We detected 1 issue in this application`);
|
||||||
});
|
});
|
||||||
|
@ -95,6 +95,17 @@ interface IOutdatedSDKsProps {
|
|||||||
sdks: string[];
|
sdks: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApplicationIssues =
|
||||||
|
| {
|
||||||
|
applicationMode: 'success';
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
applicationMode: 'warning';
|
||||||
|
issueCount: number;
|
||||||
|
outdatedSdks: string[];
|
||||||
|
missingFeatures: string[];
|
||||||
|
};
|
||||||
|
|
||||||
const FeaturesMissing = ({ features }: IFeaturesMissingProps) => {
|
const FeaturesMissing = ({ features }: IFeaturesMissingProps) => {
|
||||||
const { hasAccess } = useContext(AccessContext);
|
const { hasAccess } = useContext(AccessContext);
|
||||||
const length = features.length;
|
const length = features.length;
|
||||||
@ -186,38 +197,9 @@ const OutdatedSDKs = ({ sdks }: IOutdatedSDKsProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getApplicationIssueMode = (
|
export const getApplicationIssues = (
|
||||||
application: ApplicationOverviewSchema,
|
application: ApplicationOverviewSchema,
|
||||||
):
|
): ApplicationIssues => {
|
||||||
| {
|
|
||||||
applicationMode: 'success';
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
applicationMode: 'warning';
|
|
||||||
issueCount: number;
|
|
||||||
} => {
|
|
||||||
const issueCount =
|
|
||||||
application.issues.missingStrategies.length +
|
|
||||||
application.environments
|
|
||||||
.map(
|
|
||||||
(env) =>
|
|
||||||
env.issues.missingFeatures.length +
|
|
||||||
env.issues.outdatedSdks.length,
|
|
||||||
)
|
|
||||||
.reduce((sum, num) => sum + num, 0);
|
|
||||||
|
|
||||||
return {
|
|
||||||
issueCount,
|
|
||||||
applicationMode: issueCount > 0 ? 'warning' : 'success',
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ApplicationIssues = ({ application }: IApplicationIssuesProps) => {
|
|
||||||
const mode = getApplicationIssueMode(application);
|
|
||||||
|
|
||||||
if (mode.applicationMode === 'success') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const outdatedSdks = [
|
const outdatedSdks = [
|
||||||
...new Set(
|
...new Set(
|
||||||
application.environments.flatMap((env) => env.issues.outdatedSdks),
|
application.environments.flatMap((env) => env.issues.outdatedSdks),
|
||||||
@ -230,7 +212,26 @@ export const ApplicationIssues = ({ application }: IApplicationIssuesProps) => {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
const issueCount = mode.issueCount;
|
const issueCount =
|
||||||
|
outdatedSdks.length +
|
||||||
|
missingFeatures.length +
|
||||||
|
application.issues.missingStrategies.length;
|
||||||
|
|
||||||
|
return {
|
||||||
|
issueCount,
|
||||||
|
outdatedSdks,
|
||||||
|
missingFeatures,
|
||||||
|
applicationMode: issueCount > 0 ? 'warning' : 'success',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ApplicationIssues = ({ application }: IApplicationIssuesProps) => {
|
||||||
|
const mode = getApplicationIssues(application);
|
||||||
|
|
||||||
|
if (mode.applicationMode === 'success') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { issueCount, outdatedSdks, missingFeatures } = mode;
|
||||||
return (
|
return (
|
||||||
<WarningContainer>
|
<WarningContainer>
|
||||||
<WarningHeader>
|
<WarningHeader>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ReactNode, VFC, useState } from 'react';
|
import { ReactNode, VFC } from 'react';
|
||||||
import { useUiFlag } from 'hooks/useUiFlag';
|
import { useUiFlag } from 'hooks/useUiFlag';
|
||||||
import { useFeedback } from 'component/feedbackNew/useFeedback';
|
import { useFeedback } from 'component/feedbackNew/useFeedback';
|
||||||
import ReviewsOutlined from '@mui/icons-material/ReviewsOutlined';
|
import ReviewsOutlined from '@mui/icons-material/ReviewsOutlined';
|
||||||
@ -8,7 +8,6 @@ import {
|
|||||||
styled,
|
styled,
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
Box,
|
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
||||||
import { Badge } from 'component/common/Badge/Badge';
|
import { Badge } from 'component/common/Badge/Badge';
|
||||||
|
Loading…
Reference in New Issue
Block a user