1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-17 01:17:29 +02:00

Refactor: Project Overview fetching (#3035)

This commit is contained in:
Tymoteusz Czech 2023-02-07 08:57:28 +01:00 committed by GitHub
parent 74e657ecdf
commit 0656fddbc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 33 deletions

View File

@ -51,7 +51,7 @@ export const StyledInnerContainer = styled('div')(({ theme }) => ({
alignItems: 'start', alignItems: 'start',
})); }));
export const StyledProjectTitle = styled('h2')(({ theme }) => ({ export const StyledProjectTitle = styled('span')(({ theme }) => ({
margin: 0, margin: 0,
width: '100%', width: '100%',
fontSize: theme.fontSizes.mainHeader, fontSize: theme.fontSizes.mainHeader,

View File

@ -11,6 +11,8 @@ import {
import { useProjectChangeRequests } from 'hooks/api/getters/useProjectChangeRequests/useProjectChangeRequests'; import { useProjectChangeRequests } from 'hooks/api/getters/useProjectChangeRequests/useProjectChangeRequests';
import { WidgetFooterLink } from './WidgetFooterLink'; import { WidgetFooterLink } from './WidgetFooterLink';
const LOADING_LABEL = 'change-requests-widget';
interface IChangeRequestsWidgetProps { interface IChangeRequestsWidgetProps {
projectId: string; projectId: string;
} }
@ -60,6 +62,7 @@ const ChangeRequestsLabel = () => (
variant="body2" variant="body2"
color="text.secondary" color="text.secondary"
lineHeight={1} lineHeight={1}
data-loading={LOADING_LABEL}
> >
change requests change requests
</Typography> </Typography>
@ -69,7 +72,7 @@ export const ChangeRequestsWidget: FC<IChangeRequestsWidgetProps> = ({
projectId, projectId,
}) => { }) => {
const { changeRequests, loading } = useProjectChangeRequests(projectId); const { changeRequests, loading } = useProjectChangeRequests(projectId);
const loadingRef = useLoading(loading); const loadingRef = useLoading(loading, `[data-loading="${LOADING_LABEL}"]`);
const toBeApplied = changeRequests?.filter( const toBeApplied = changeRequests?.filter(
(changeRequest: IChangeRequest) => changeRequest?.state === 'Approved' (changeRequest: IChangeRequest) => changeRequest?.state === 'Approved'
).length; ).length;
@ -86,7 +89,9 @@ export const ChangeRequestsWidget: FC<IChangeRequestsWidgetProps> = ({
> >
<StyledSubtitle>To be applied</StyledSubtitle> <StyledSubtitle>To be applied</StyledSubtitle>
<StyledChangeRequestStatusInfo> <StyledChangeRequestStatusInfo>
<StyledApprovedCount>{toBeApplied}</StyledApprovedCount>{' '} <StyledApprovedCount data-loading={LOADING_LABEL}>
{toBeApplied || 0}
</StyledApprovedCount>{' '}
<ChangeRequestsLabel /> <ChangeRequestsLabel />
</StyledChangeRequestStatusInfo> </StyledChangeRequestStatusInfo>
</StyledChangeBox> </StyledChangeBox>
@ -95,8 +100,8 @@ export const ChangeRequestsWidget: FC<IChangeRequestsWidgetProps> = ({
> >
<StyledSubtitle>To be reviewed</StyledSubtitle> <StyledSubtitle>To be reviewed</StyledSubtitle>
<StyledChangeRequestStatusInfo> <StyledChangeRequestStatusInfo>
<StyledInReviewCount> <StyledInReviewCount data-loading={LOADING_LABEL}>
{toBeReviewed} {toBeReviewed || 0}
</StyledInReviewCount>{' '} </StyledInReviewCount>{' '}
<ChangeRequestsLabel /> <ChangeRequestsLabel />
</StyledChangeRequestStatusInfo> </StyledChangeRequestStatusInfo>

View File

@ -1,5 +1,5 @@
import { Box, styled, useMediaQuery, useTheme } from '@mui/material'; import { Box, styled, useMediaQuery, useTheme } from '@mui/material';
import { ProjectStatsSchema } from 'openapi/models/projectStatsSchema'; import type { ProjectStatsSchema } from 'openapi/models/projectStatsSchema';
import type { IFeatureToggleListItem } from 'interfaces/featureToggle'; import type { IFeatureToggleListItem } from 'interfaces/featureToggle';
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';
@ -12,6 +12,7 @@ import { ChangeRequestsWidget } from './ChangeRequestsWidget';
import { flexRow } from 'themes/themeStyles'; import { flexRow } from 'themes/themeStyles';
import { LegacyHealthWidget } from './LegacyHealthWidget'; import { LegacyHealthWidget } from './LegacyHealthWidget';
import { LegacyProjectMembersWidget } from './LegacyProjectMembersWidget'; import { LegacyProjectMembersWidget } from './LegacyProjectMembersWidget';
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
interface IProjectInfoProps { interface IProjectInfoProps {
id: string; id: string;
@ -50,8 +51,10 @@ const ProjectInfo = ({
const { uiConfig, isEnterprise } = useUiConfig(); const { uiConfig, isEnterprise } = useUiConfig();
const theme = useTheme(); const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
const { isChangeRequestConfiguredInAnyEnv } = useChangeRequestsEnabled(id);
const showChangeRequestsWidget = isEnterprise(); const showChangeRequestsWidget =
isEnterprise() && isChangeRequestConfiguredInAnyEnv();
const showProjectMembersWidget = id !== DEFAULT_PROJECT_ID; const showProjectMembersWidget = id !== DEFAULT_PROJECT_ID;
const fitMoreColumns = const fitMoreColumns =
(!showChangeRequestsWidget && !showProjectMembersWidget) || (!showChangeRequestsWidget && !showProjectMembersWidget) ||

View File

@ -83,12 +83,11 @@ export const ToggleTypesWidget = ({ features }: IToggleTypesWidgetProps) => {
<StyledProjectInfoWidgetContainer <StyledProjectInfoWidgetContainer
sx={{ padding: theme => theme.spacing(3) }} sx={{ padding: theme => theme.spacing(3) }}
> >
<StyledWidgetTitle data-loading> <StyledWidgetTitle>Toggle types used</StyledWidgetTitle>
Toggle types used
</StyledWidgetTitle>
{Object.keys(featureTypeStats).map(type => ( {Object.keys(featureTypeStats).map(type => (
<ToggleTypesRow <ToggleTypesRow
type={type} type={type}
key={type}
Icon={getFeatureTypeIcons(type)} Icon={getFeatureTypeIcons(type)}
count={ count={
featureTypeStats[type as keyof typeof featureTypeStats] featureTypeStats[type as keyof typeof featureTypeStats]

View File

@ -8,7 +8,7 @@ const StyledTypographyHeader = styled(Typography)(({ theme }) => ({
marginBottom: theme.spacing(2.5), marginBottom: theme.spacing(2.5),
})); }));
const StyledTypographyCount = styled(Typography)(({ theme }) => ({ const StyledTypographyCount = styled(Box)(({ theme }) => ({
fontSize: theme.fontSizes.largeHeader, fontSize: theme.fontSizes.largeHeader,
})); }));

View File

@ -1,7 +1,6 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { formatApiPath } from 'utils/formatPath'; import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler'; import handleErrorResponses from '../httpErrorResponseHandler';
import useUiConfig from '../useUiConfig/useUiConfig';
import { useEnterpriseSWR } from '../useEnterpriseSWR/useEnterpriseSWR'; import { useEnterpriseSWR } from '../useEnterpriseSWR/useEnterpriseSWR';
const fetcher = (path: string) => { const fetcher = (path: string) => {

View File

@ -2,11 +2,11 @@ import { createRef, useLayoutEffect } from 'react';
type refElement = HTMLDivElement; type refElement = HTMLDivElement;
const useLoading = (loading: boolean) => { const useLoading = (loading: boolean, selector = '[data-loading=true]') => {
const ref = createRef<refElement>(); const ref = createRef<refElement>();
useLayoutEffect(() => { useLayoutEffect(() => {
if (ref.current) { if (ref.current) {
const elements = ref.current.querySelectorAll('[data-loading]'); const elements = ref.current.querySelectorAll(selector);
elements.forEach(element => { elements.forEach(element => {
if (loading) { if (loading) {

View File

@ -789,25 +789,28 @@ export default class ProjectService {
archived: boolean = false, archived: boolean = false,
userId?: number, userId?: number,
): Promise<IProjectOverview> { ): Promise<IProjectOverview> {
const project = await this.store.get(projectId); const [
const environments = await this.store.getEnvironmentsForProject( project,
projectId, environments,
); features,
const features = await this.featureToggleService.getFeatureOverview({ members,
projectId, favorite,
archived, projectStats,
userId, ] = await Promise.all([
}); this.store.get(projectId),
const members = await this.store.getMembersCountByProject(projectId); this.store.getEnvironmentsForProject(projectId),
this.featureToggleService.getFeatureOverview({
const favorite = await this.favoritesService.isFavoriteProject({ projectId,
project: projectId, archived,
userId, userId,
}); }),
this.store.getMembersCountByProject(projectId),
const projectStats = await this.projectStatsStore.getProjectStats( this.favoritesService.isFavoriteProject({
projectId, project: projectId,
); userId,
}),
this.projectStatsStore.getProjectStats(projectId),
]);
return { return {
stats: projectStats, stats: projectStats,