From 1e7636283ff8706aa197bdd9a66492584fe2e8e3 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Wed, 25 Jan 2023 13:52:36 +0200 Subject: [PATCH] ToggleTypesWidget (#2983) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements ToggleTypeWidget Refactored HealthWidget to it's own component Signed-off-by: andreas-unleash ## About the changes Closes # ### Important files ![Screenshot 2023-01-25 at 11 38 07](https://user-images.githubusercontent.com/104830839/214531944-c7007192-e93f-48fc-8ee1-f44930f873d2.png) ## Discussion points Signed-off-by: andreas-unleash --- .../Project/ProjectInfo/HealthWidget.tsx | 34 ++++++++ .../Project/ProjectInfo/ProjectInfo.styles.ts | 17 ++++ .../Project/ProjectInfo/ProjectInfo.tsx | 41 ++++------ .../Project/ProjectInfo/ToggleTypesWidget.tsx | 81 +++++++++++++++++++ .../project/Project/ProjectOverview.tsx | 3 +- 5 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 frontend/src/component/project/Project/ProjectInfo/HealthWidget.tsx create mode 100644 frontend/src/component/project/Project/ProjectInfo/ToggleTypesWidget.tsx diff --git a/frontend/src/component/project/Project/ProjectInfo/HealthWidget.tsx b/frontend/src/component/project/Project/ProjectInfo/HealthWidget.tsx new file mode 100644 index 0000000000..4f7752030a --- /dev/null +++ b/frontend/src/component/project/Project/ProjectInfo/HealthWidget.tsx @@ -0,0 +1,34 @@ +import { + StyledArrowIcon, + StyledDivInfoContainer, + StyledDivPercentageContainer, + StyledLink, + StyledParagraphEmphasizedText, + StyledParagraphSubtitle, + StyledSpanLinkText, +} from './ProjectInfo.styles'; +import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle'; + +interface IHealthWidgetProps { + projectId: string; + health: number; +} +export const HealthWidget = ({ projectId, health }: IHealthWidgetProps) => { + return ( + + + + + + Overall health rating + + + {health}% + + + view more + + + + ); +}; diff --git a/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.styles.ts b/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.styles.ts index 94e495114a..a91b1339c7 100644 --- a/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.styles.ts +++ b/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.styles.ts @@ -51,6 +51,17 @@ export const StyledParagraphSubtitle = styled('p')(({ theme }) => ({ marginBottom: theme.spacing(2), })); +export const StyledParagraphGridRow = styled('div')(({ theme }) => ({ + display: 'grid', + gridGap: theme.spacing(2), + gridTemplateColumns: '10% 70% 20%', + margin: theme.spacing(1, 2, 1, 2), + fontSize: theme.fontSizes.smallBody, + color: theme.palette.tertiary.dark, + textAlign: 'left', + alignItems: 'center', +})); + export const StyledParagraphEmphasizedText = styled('p')(({ theme }) => ({ fontSize: '1.5rem', marginBottom: theme.spacing(2), @@ -60,6 +71,12 @@ export const StyledParagraphEmphasizedText = styled('p')(({ theme }) => ({ }, })); +export const StyledCount = styled('p')(({ theme }) => ({ + fontSize: '1.2rem', + fontWeight: 'bold', + color: theme.palette.text.primary, +})); + export const StyledSpanLinkText = styled('p')(({ theme }) => ({ [theme.breakpoints.down('md')]: { display: 'none', diff --git a/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.tsx b/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.tsx index 105f8f276d..c711887418 100644 --- a/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.tsx +++ b/frontend/src/component/project/Project/ProjectInfo/ProjectInfo.tsx @@ -1,28 +1,34 @@ import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; -import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; -import { DEFAULT_PROJECT_ID } from '../../../../hooks/api/getters/useDefaultProject/useDefaultProjectId'; +import { DEFAULT_PROJECT_ID } from 'hooks/api/getters/useDefaultProject/useDefaultProjectId'; import { + StyledArrowIcon, StyledDivContainer, StyledDivInfoContainer, - StyledDivPercentageContainer, - StyledParagraphSubtitle, - StyledParagraphEmphasizedText, StyledLink, + StyledParagraphEmphasizedText, + StyledParagraphSubtitle, StyledSpanLinkText, - StyledArrowIcon, } from './ProjectInfo.styles'; +import { IFeatureToggleListItem } from '../../../../interfaces/featureToggle'; +import { HealthWidget } from './HealthWidget'; +import { ToggleTypesWidget } from './ToggleTypesWidget'; interface IProjectInfoProps { id: string; memberCount: number; - featureCount: number; + features: IFeatureToggleListItem[]; health: number; description?: string; } -const ProjectInfo = ({ id, memberCount, health }: IProjectInfoProps) => { +const ProjectInfo = ({ + id, + memberCount, + health, + features, +}: IProjectInfoProps) => { const { uiConfig } = useUiConfig(); let link = `/admin/users`; @@ -34,23 +40,7 @@ const ProjectInfo = ({ id, memberCount, health }: IProjectInfoProps) => { return ( ); diff --git a/frontend/src/component/project/Project/ProjectInfo/ToggleTypesWidget.tsx b/frontend/src/component/project/Project/ProjectInfo/ToggleTypesWidget.tsx new file mode 100644 index 0000000000..62c57fc534 --- /dev/null +++ b/frontend/src/component/project/Project/ProjectInfo/ToggleTypesWidget.tsx @@ -0,0 +1,81 @@ +import { IFeatureToggleListItem } from '../../../../interfaces/featureToggle'; +import { useMemo } from 'react'; +import { + StyledCount, + StyledDivInfoContainer, + StyledParagraphGridRow, + StyledParagraphSubtitle, +} from './ProjectInfo.styles'; +import { getFeatureTypeIcons } from 'utils/getFeatureTypeIcons'; + +export interface IToggleTypesWidgetProps { + features: IFeatureToggleListItem[]; +} + +export const ToggleTypesWidget = ({ features }: IToggleTypesWidgetProps) => { + const { release, experiment, operational, kill, permission } = + useMemo(() => { + const release = + features?.filter(feature => feature.type === 'release') + .length || 0; + const experiment = + features?.filter(feature => feature.type === 'experiment') + .length || 0; + const operational = + features?.filter(feature => feature.type === 'operational') + .length || 0; + const kill = + features?.filter(feature => feature.type === 'kill-switch') + .length || 0; + const permission = + features?.filter(feature => feature.type === 'permission') + .length || 0; + + return { + release, + experiment, + operational, + kill, + permission, + }; + }, [features]); + + const ReleaseToggleIcon = getFeatureTypeIcons('release'); + const ExperimentToggleIcon = getFeatureTypeIcons('experiment'); + const OperationalToggleIcon = getFeatureTypeIcons('operational'); + const KillToggleIcon = getFeatureTypeIcons('kill-switch'); + const PermissionToggleIcon = getFeatureTypeIcons('permission'); + + return ( + + + Toggle types used + + + +
Release
+ {release} +
+ + +
Experiment
+ {experiment} +
+ + +
Operational
+ {operational} +
+ + +
Kill switch
+ {kill} +
+ + +
Permission
+ {permission} +
+
+ ); +}; diff --git a/frontend/src/component/project/Project/ProjectOverview.tsx b/frontend/src/component/project/Project/ProjectOverview.tsx index 8dfa58bb57..31908223b5 100644 --- a/frontend/src/component/project/Project/ProjectOverview.tsx +++ b/frontend/src/component/project/Project/ProjectOverview.tsx @@ -8,7 +8,6 @@ import { usePageTitle } from 'hooks/usePageTitle'; import { useRequiredPathParam } from 'hooks/useRequiredPathParam'; import { useLastViewedProject } from '../../../hooks/useLastViewedProject'; import { useEffect } from 'react'; -import { StatusBox } from './ProjectStatus/StatusBox'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import { ProjectStatus } from './ProjectStatus/ProjectStatus'; @@ -53,7 +52,7 @@ const ProjectOverview = () => { description={description} memberCount={members} health={health} - featureCount={features?.length} + features={features} />