import { styled, Typography } from '@mui/material';
import type { FC } from 'react';
import { Link } from 'react-router-dom';
import Lightbulb from '@mui/icons-material/LightbulbOutlined';
import type { PersonalDashboardProjectDetailsSchemaInsights } from 'openapi';
import { ActionBox } from './ActionBox.tsx';
import { useFlag } from '@unleash/proxy-client-react';
const PercentageScore = styled('span')(({ theme }) => ({
fontWeight: theme.typography.fontWeightBold,
}));
const ConnectedSdkProject: FC<{ project: string }> = ({ project }) => {
return (
<>
This project already has connected SDKs and existing feature
flags.
Create a new feature flag
{' '}
or go to the{' '}
go to the project
{' '}
to work with existing flags
>
);
};
type HealthTrend = 'consistent' | 'improved' | 'declined' | 'unknown';
const determineProjectHealthTrend = (
insights: PersonalDashboardProjectDetailsSchemaInsights,
): HealthTrend => {
const { avgHealthCurrentWindow, avgHealthPastWindow } = insights;
if (avgHealthCurrentWindow === null || avgHealthPastWindow === null) {
return 'unknown';
}
if (avgHealthCurrentWindow > avgHealthPastWindow) {
return 'improved';
}
if (avgHealthCurrentWindow < avgHealthPastWindow) {
return 'declined';
}
return 'consistent';
};
const ProjectHealthMessage: FC<{
trend: HealthTrend;
insights: PersonalDashboardProjectDetailsSchemaInsights;
project: string;
}> = ({ trend, insights, project }) => {
const healthToTechDebtEnabled = useFlag('healthToTechDebt');
const { avgHealthCurrentWindow, avgHealthPastWindow, health } = insights;
const improveMessage = healthToTechDebtEnabled
? 'Remember to archive your stale feature flags to keep the technical debt low.'
: 'Remember to archive your stale feature flags to keep the project health growing.';
const keepDoingMessage =
'This indicates that you are doing a good job of archiving your feature flags.';
const avgCurrentTechnicalDebt = 100 - (avgHealthCurrentWindow ?? 0);
const avgPastTechnicalDebt = 100 - (avgHealthPastWindow ?? 0);
if (trend === 'improved') {
if (healthToTechDebtEnabled) {
return (
<>
On average, your project technical debt went down from{' '}
{avgPastTechnicalDebt}%
{' '}
to{' '}
{avgCurrentTechnicalDebt}%
{' '}
during the last 4 weeks.
{keepDoingMessage}
>
);
}
return (
<>
On average, your project health went up from{' '}
{avgHealthPastWindow}% to{' '}
{avgHealthCurrentWindow}%{' '}
during the last 4 weeks.
{keepDoingMessage}
>
);
}
if (trend === 'declined') {
if (healthToTechDebtEnabled) {
return (
<>
On average, your project technical debt went up from{' '}
{avgPastTechnicalDebt}%
{' '}
to{' '}
{avgCurrentTechnicalDebt}%
{' '}
during the last 4 weeks.
{improveMessage}
>
);
}
return (
<>
On average, your project health went down from{' '}
{avgHealthPastWindow}% to{' '}
{avgHealthCurrentWindow}%{' '}
during the last 4 weeks.
{improveMessage}
>
);
}
if (trend === 'consistent') {
if (healthToTechDebtEnabled) {
return (
<>
On average, your project technical debt has remained at{' '}
{avgCurrentTechnicalDebt}%
{' '}
during the last 4 weeks.
{keepDoingMessage}
>
);
}
return (
<>
On average, your project health has remained at{' '}
{avgHealthCurrentWindow}%{' '}
during the last 4 weeks.
{avgHealthCurrentWindow && avgHealthCurrentWindow >= 75
? keepDoingMessage
: improveMessage}
>
);
}
if (trend === 'unknown') {
if (healthToTechDebtEnabled) {
return (
<>
Your current project technical debt is{' '}
{avgCurrentTechnicalDebt}%
.
{improveMessage}
>
);
}
return (
<>
Your current health score is{' '}
{health}%.
{health >= 75 ? keepDoingMessage : improveMessage}
>
);
}
return ;
};
export const ProjectSetupComplete: FC<{
project: string;
insights: PersonalDashboardProjectDetailsSchemaInsights;
}> = ({ project, insights }) => {
const healthToTechDebtEnabled = useFlag('healthToTechDebt');
const projectHealthTrend = determineProjectHealthTrend(insights);
return (
{healthToTechDebtEnabled
? 'Technical debt'
: 'Project health'}
>
}
>
{projectHealthTrend !== 'unknown' && (
View more insights
)}
);
};