mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	chore: handle edge cases (#8719)
Handle a couple edge cases related to project lifecycle metrics: 1. If the average time spent was less than a day, we'd show "0 days". Now we show "less than a day" instead. 2. If the number of flags grows very large, it'd start pushing out the lifecycle icon. Instead, we now format in nicely. Before:   After:  
This commit is contained in:
		
							parent
							
								
									3bc9fe9a9a
								
							
						
					
					
						commit
						42198cee83
					
				@ -4,8 +4,7 @@ import { useProjectStatus } from 'hooks/api/getters/useProjectStatus/useProjectS
 | 
				
			|||||||
import useLoading from 'hooks/useLoading';
 | 
					import useLoading from 'hooks/useLoading';
 | 
				
			||||||
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
 | 
					import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
 | 
				
			||||||
import type { FC } from 'react';
 | 
					import type { FC } from 'react';
 | 
				
			||||||
import { Link } from 'react-router-dom';
 | 
					import { PrettifyLargeNumber } from 'component/common/PrettifyLargeNumber/PrettifyLargeNumber';
 | 
				
			||||||
 | 
					 | 
				
			||||||
const LifecycleBox = styled('li')(({ theme }) => ({
 | 
					const LifecycleBox = styled('li')(({ theme }) => ({
 | 
				
			||||||
    padding: theme.spacing(2),
 | 
					    padding: theme.spacing(2),
 | 
				
			||||||
    borderRadius: theme.shape.borderRadiusExtraLarge,
 | 
					    borderRadius: theme.shape.borderRadiusExtraLarge,
 | 
				
			||||||
@ -31,7 +30,7 @@ const Counter = styled('span')({
 | 
				
			|||||||
    justifyContent: 'space-between',
 | 
					    justifyContent: 'space-between',
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const BigNumber = styled('span')(({ theme }) => ({
 | 
					const BigText = styled('span')(({ theme }) => ({
 | 
				
			||||||
    fontSize: `calc(2 * ${theme.typography.body1.fontSize})`,
 | 
					    fontSize: `calc(2 * ${theme.typography.body1.fontSize})`,
 | 
				
			||||||
}));
 | 
					}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,10 +47,6 @@ const NoData = styled('span')({
 | 
				
			|||||||
    fontWeight: 'normal',
 | 
					    fontWeight: 'normal',
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const LinkNoUnderline = styled(Link)({
 | 
					 | 
				
			||||||
    textDecoration: 'none',
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const AverageDaysStat: FC<{ averageDays?: number | null }> = ({
 | 
					const AverageDaysStat: FC<{ averageDays?: number | null }> = ({
 | 
				
			||||||
    averageDays,
 | 
					    averageDays,
 | 
				
			||||||
}) => {
 | 
					}) => {
 | 
				
			||||||
@ -60,6 +55,9 @@ const AverageDaysStat: FC<{ averageDays?: number | null }> = ({
 | 
				
			|||||||
            return <NoData>No data</NoData>;
 | 
					            return <NoData>No data</NoData>;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (averageDays < 1) {
 | 
				
			||||||
 | 
					            return 'less than a day';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        return `${averageDays} days`;
 | 
					        return `${averageDays} days`;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
@ -72,6 +70,18 @@ const AverageDaysStat: FC<{ averageDays?: number | null }> = ({
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const BigNumber: FC<{ value?: number }> = ({ value }) => {
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <BigText data-loading-project-lifecycle-summary>
 | 
				
			||||||
 | 
					            <PrettifyLargeNumber
 | 
				
			||||||
 | 
					                value={value ?? 0}
 | 
				
			||||||
 | 
					                threshold={1000}
 | 
				
			||||||
 | 
					                precision={1}
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					        </BigText>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const ProjectLifecycleSummary = () => {
 | 
					export const ProjectLifecycleSummary = () => {
 | 
				
			||||||
    const projectId = useRequiredPathParam('projectId');
 | 
					    const projectId = useRequiredPathParam('projectId');
 | 
				
			||||||
    const { data, loading } = useProjectStatus(projectId);
 | 
					    const { data, loading } = useProjectStatus(projectId);
 | 
				
			||||||
@ -85,9 +95,9 @@ export const ProjectLifecycleSummary = () => {
 | 
				
			|||||||
            <LifecycleBox>
 | 
					            <LifecycleBox>
 | 
				
			||||||
                <p>
 | 
					                <p>
 | 
				
			||||||
                    <Counter>
 | 
					                    <Counter>
 | 
				
			||||||
                        <BigNumber data-loading-project-lifecycle-summary>
 | 
					                        <BigNumber
 | 
				
			||||||
                            {data?.lifecycleSummary.initial.currentFlags ?? 0}
 | 
					                            value={data?.lifecycleSummary.initial.currentFlags}
 | 
				
			||||||
                        </BigNumber>
 | 
					                        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <FeatureLifecycleStageIcon
 | 
					                        <FeatureLifecycleStageIcon
 | 
				
			||||||
                            aria-hidden='true'
 | 
					                            aria-hidden='true'
 | 
				
			||||||
@ -103,9 +113,9 @@ export const ProjectLifecycleSummary = () => {
 | 
				
			|||||||
            <LifecycleBox>
 | 
					            <LifecycleBox>
 | 
				
			||||||
                <p>
 | 
					                <p>
 | 
				
			||||||
                    <Counter>
 | 
					                    <Counter>
 | 
				
			||||||
                        <BigNumber data-loading-project-lifecycle-summary>
 | 
					                        <BigNumber
 | 
				
			||||||
                            {data?.lifecycleSummary.preLive.currentFlags ?? 0}
 | 
					                            value={data?.lifecycleSummary.preLive.currentFlags}
 | 
				
			||||||
                        </BigNumber>
 | 
					                        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <FeatureLifecycleStageIcon
 | 
					                        <FeatureLifecycleStageIcon
 | 
				
			||||||
                            aria-hidden='true'
 | 
					                            aria-hidden='true'
 | 
				
			||||||
@ -121,9 +131,9 @@ export const ProjectLifecycleSummary = () => {
 | 
				
			|||||||
            <LifecycleBox>
 | 
					            <LifecycleBox>
 | 
				
			||||||
                <p>
 | 
					                <p>
 | 
				
			||||||
                    <Counter>
 | 
					                    <Counter>
 | 
				
			||||||
                        <BigNumber data-loading-project-lifecycle-summary>
 | 
					                        <BigNumber
 | 
				
			||||||
                            {data?.lifecycleSummary.live.currentFlags ?? 0}
 | 
					                            value={data?.lifecycleSummary.live.currentFlags}
 | 
				
			||||||
                        </BigNumber>
 | 
					                        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <FeatureLifecycleStageIcon
 | 
					                        <FeatureLifecycleStageIcon
 | 
				
			||||||
                            aria-hidden='true'
 | 
					                            aria-hidden='true'
 | 
				
			||||||
@ -139,9 +149,11 @@ export const ProjectLifecycleSummary = () => {
 | 
				
			|||||||
            <LifecycleBox>
 | 
					            <LifecycleBox>
 | 
				
			||||||
                <p>
 | 
					                <p>
 | 
				
			||||||
                    <Counter>
 | 
					                    <Counter>
 | 
				
			||||||
                        <BigNumber data-loading-project-lifecycle-summary>
 | 
					                        <BigNumber
 | 
				
			||||||
                            {data?.lifecycleSummary.completed.currentFlags ?? 0}
 | 
					                            value={
 | 
				
			||||||
                        </BigNumber>
 | 
					                                data?.lifecycleSummary.completed.currentFlags
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <FeatureLifecycleStageIcon
 | 
					                        <FeatureLifecycleStageIcon
 | 
				
			||||||
                            aria-hidden='true'
 | 
					                            aria-hidden='true'
 | 
				
			||||||
@ -157,9 +169,9 @@ export const ProjectLifecycleSummary = () => {
 | 
				
			|||||||
            <LifecycleBox>
 | 
					            <LifecycleBox>
 | 
				
			||||||
                <p>
 | 
					                <p>
 | 
				
			||||||
                    <Counter>
 | 
					                    <Counter>
 | 
				
			||||||
                        <BigNumber data-loading-project-lifecycle-summary>
 | 
					                        <BigNumber
 | 
				
			||||||
                            {data?.lifecycleSummary.archived.currentFlags ?? 0}
 | 
					                            value={data?.lifecycleSummary.archived.currentFlags}
 | 
				
			||||||
                        </BigNumber>
 | 
					                        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <FeatureLifecycleStageIcon
 | 
					                        <FeatureLifecycleStageIcon
 | 
				
			||||||
                            aria-hidden='true'
 | 
					                            aria-hidden='true'
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user