Skip to content

Commit

Permalink
ToggleTypesWidget (#2983)
Browse files Browse the repository at this point in the history
Implements ToggleTypeWidget

Refactored HealthWidget to it's own component

Signed-off-by: andreas-unleash <andreas@getunleash.ai>

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->

![Screenshot 2023-01-25 at 11 38
07](https://user-images.githubusercontent.com/104830839/214531944-c7007192-e93f-48fc-8ee1-f44930f873d2.png)

## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
  • Loading branch information
andreas-unleash committed Jan 25, 2023
1 parent decb7f3 commit 1e76362
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 27 deletions.
@@ -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 (
<StyledDivInfoContainer>
<StyledDivPercentageContainer>
<PercentageCircle percentage={health} />
</StyledDivPercentageContainer>
<StyledParagraphSubtitle data-loading>
Overall health rating
</StyledParagraphSubtitle>
<StyledParagraphEmphasizedText data-loading>
{health}%
</StyledParagraphEmphasizedText>
<StyledLink data-loading to={`/projects/${projectId}/health`}>
<StyledSpanLinkText data-loading>view more </StyledSpanLinkText>
<StyledArrowIcon data-loading />
</StyledLink>
</StyledDivInfoContainer>
);
};
Expand Up @@ -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),
Expand All @@ -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',
Expand Down
41 changes: 16 additions & 25 deletions 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`;
Expand All @@ -34,23 +40,7 @@ const ProjectInfo = ({ id, memberCount, health }: IProjectInfoProps) => {
return (
<aside>
<StyledDivContainer>
<StyledDivInfoContainer>
<StyledDivPercentageContainer>
<PercentageCircle percentage={health} />
</StyledDivPercentageContainer>
<StyledParagraphSubtitle data-loading>
Overall health rating
</StyledParagraphSubtitle>
<StyledParagraphEmphasizedText data-loading>
{health}%
</StyledParagraphEmphasizedText>
<StyledLink data-loading to={`/projects/${id}/health`}>
<StyledSpanLinkText data-loading>
view more{' '}
</StyledSpanLinkText>
<StyledArrowIcon data-loading />
</StyledLink>
</StyledDivInfoContainer>
<HealthWidget projectId={id} health={health} />
<ConditionallyRender
condition={id !== DEFAULT_PROJECT_ID}
show={
Expand All @@ -70,6 +60,7 @@ const ProjectInfo = ({ id, memberCount, health }: IProjectInfoProps) => {
</StyledDivInfoContainer>
}
/>
<ToggleTypesWidget features={features} />
</StyledDivContainer>
</aside>
);
Expand Down
@@ -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 (
<StyledDivInfoContainer>
<StyledParagraphSubtitle data-loading>
Toggle types used
</StyledParagraphSubtitle>
<StyledParagraphGridRow data-loading>
<ReleaseToggleIcon fontSize="inherit" data-loading />
<div>Release</div>
<StyledCount>{release}</StyledCount>
</StyledParagraphGridRow>
<StyledParagraphGridRow data-loading>
<ExperimentToggleIcon fontSize="inherit" data-loading />
<div>Experiment</div>
<StyledCount>{experiment}</StyledCount>
</StyledParagraphGridRow>
<StyledParagraphGridRow data-loading>
<OperationalToggleIcon fontSize="inherit" data-loading />
<div>Operational</div>
<StyledCount>{operational}</StyledCount>
</StyledParagraphGridRow>
<StyledParagraphGridRow data-loading>
<KillToggleIcon fontSize="inherit" data-loading />
<div>Kill switch</div>
<StyledCount>{kill}</StyledCount>
</StyledParagraphGridRow>
<StyledParagraphGridRow data-loading>
<PermissionToggleIcon fontSize="inherit" data-loading />
<div>Permission</div>
<StyledCount>{permission}</StyledCount>
</StyledParagraphGridRow>
</StyledDivInfoContainer>
);
};
3 changes: 1 addition & 2 deletions frontend/src/component/project/Project/ProjectOverview.tsx
Expand Up @@ -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';
Expand Down Expand Up @@ -53,7 +52,7 @@ const ProjectOverview = () => {
description={description}
memberCount={members}
health={health}
featureCount={features?.length}
features={features}
/>
<StyledContentContainer>
<ConditionallyRender
Expand Down

0 comments on commit 1e76362

Please sign in to comment.