1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

ToggleTypesWidget (#2983)

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>
This commit is contained in:
andreas-unleash 2023-01-25 13:52:36 +02:00 committed by GitHub
parent decb7f320d
commit 1e7636283f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 149 additions and 27 deletions

View File

@ -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>
);
};

View File

@ -51,6 +51,17 @@ export const StyledParagraphSubtitle = styled('p')(({ theme }) => ({
marginBottom: theme.spacing(2), 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 }) => ({ export const StyledParagraphEmphasizedText = styled('p')(({ theme }) => ({
fontSize: '1.5rem', fontSize: '1.5rem',
marginBottom: theme.spacing(2), 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 }) => ({ export const StyledSpanLinkText = styled('p')(({ theme }) => ({
[theme.breakpoints.down('md')]: { [theme.breakpoints.down('md')]: {
display: 'none', display: 'none',

View File

@ -1,28 +1,34 @@
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; 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 { import {
StyledArrowIcon,
StyledDivContainer, StyledDivContainer,
StyledDivInfoContainer, StyledDivInfoContainer,
StyledDivPercentageContainer,
StyledParagraphSubtitle,
StyledParagraphEmphasizedText,
StyledLink, StyledLink,
StyledParagraphEmphasizedText,
StyledParagraphSubtitle,
StyledSpanLinkText, StyledSpanLinkText,
StyledArrowIcon,
} from './ProjectInfo.styles'; } from './ProjectInfo.styles';
import { IFeatureToggleListItem } from '../../../../interfaces/featureToggle';
import { HealthWidget } from './HealthWidget';
import { ToggleTypesWidget } from './ToggleTypesWidget';
interface IProjectInfoProps { interface IProjectInfoProps {
id: string; id: string;
memberCount: number; memberCount: number;
featureCount: number; features: IFeatureToggleListItem[];
health: number; health: number;
description?: string; description?: string;
} }
const ProjectInfo = ({ id, memberCount, health }: IProjectInfoProps) => { const ProjectInfo = ({
id,
memberCount,
health,
features,
}: IProjectInfoProps) => {
const { uiConfig } = useUiConfig(); const { uiConfig } = useUiConfig();
let link = `/admin/users`; let link = `/admin/users`;
@ -34,23 +40,7 @@ const ProjectInfo = ({ id, memberCount, health }: IProjectInfoProps) => {
return ( return (
<aside> <aside>
<StyledDivContainer> <StyledDivContainer>
<StyledDivInfoContainer> <HealthWidget projectId={id} health={health} />
<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>
<ConditionallyRender <ConditionallyRender
condition={id !== DEFAULT_PROJECT_ID} condition={id !== DEFAULT_PROJECT_ID}
show={ show={
@ -70,6 +60,7 @@ const ProjectInfo = ({ id, memberCount, health }: IProjectInfoProps) => {
</StyledDivInfoContainer> </StyledDivInfoContainer>
} }
/> />
<ToggleTypesWidget features={features} />
</StyledDivContainer> </StyledDivContainer>
</aside> </aside>
); );

View File

@ -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>
);
};

View File

@ -8,7 +8,6 @@ import { usePageTitle } from 'hooks/usePageTitle';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam'; import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { useLastViewedProject } from '../../../hooks/useLastViewedProject'; import { useLastViewedProject } from '../../../hooks/useLastViewedProject';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { StatusBox } from './ProjectStatus/StatusBox';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { ProjectStatus } from './ProjectStatus/ProjectStatus'; import { ProjectStatus } from './ProjectStatus/ProjectStatus';
@ -53,7 +52,7 @@ const ProjectOverview = () => {
description={description} description={description}
memberCount={members} memberCount={members}
health={health} health={health}
featureCount={features?.length} features={features}
/> />
<StyledContentContainer> <StyledContentContainer>
<ConditionallyRender <ConditionallyRender