mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-15 01:16:22 +02:00
feat: hook up project resources API to resources widget (#8657)
This PR wires up the connectedenvironments data from the API to the
resources widget.
Additionally, it adjusts the orval schema to add the new
connectedEnvironments property, and adds a loading state indicator for
the resource values based on the project status endpoint response.
As was discussed in a previous PR, I think this is a good time to update
the API to include all the information required for this view. This
would get rid of three hooks, lots of loading state indicators (because
we **can** do them individually; check out
0a334f9892
)
and generally simplify this component a bit.
Here's the loading state:

This commit is contained in:
parent
1cf8755929
commit
2b13aff4f1
@ -14,6 +14,8 @@ import { Link } from 'react-router-dom';
|
|||||||
import ApiKeyIcon from '@mui/icons-material/Key';
|
import ApiKeyIcon from '@mui/icons-material/Key';
|
||||||
import SegmentsIcon from '@mui/icons-material/DonutLarge';
|
import SegmentsIcon from '@mui/icons-material/DonutLarge';
|
||||||
import ConnectedIcon from '@mui/icons-material/Cable';
|
import ConnectedIcon from '@mui/icons-material/Cable';
|
||||||
|
import { useProjectStatus } from 'hooks/api/getters/useProjectStatus/useProjectStatus';
|
||||||
|
import useLoading from 'hooks/useLoading';
|
||||||
|
|
||||||
const Wrapper = styled('article')(({ theme }) => ({
|
const Wrapper = styled('article')(({ theme }) => ({
|
||||||
backgroundColor: theme.palette.envAccordion.expanded,
|
backgroundColor: theme.palette.envAccordion.expanded,
|
||||||
@ -89,7 +91,7 @@ const ListItem: FC<
|
|||||||
<ListItemRow>
|
<ListItemRow>
|
||||||
<ItemContent>
|
<ItemContent>
|
||||||
{icon}
|
{icon}
|
||||||
<span>{children}</span>
|
<span data-loading-resources>{children}</span>
|
||||||
</ItemContent>
|
</ItemContent>
|
||||||
<Link to={linkUrl}>{linkText}</Link>
|
<Link to={linkUrl}>{linkText}</Link>
|
||||||
</ListItemRow>
|
</ListItemRow>
|
||||||
@ -97,10 +99,11 @@ const ListItem: FC<
|
|||||||
|
|
||||||
export const ProjectResources = () => {
|
export const ProjectResources = () => {
|
||||||
const projectId = useRequiredPathParam('projectId');
|
const projectId = useRequiredPathParam('projectId');
|
||||||
const { project, loading: loadingProject } = useProjectOverview(projectId);
|
const { project } = useProjectOverview(projectId);
|
||||||
const { tokens, loading: loadingTokens } = useProjectApiTokens(projectId);
|
const { tokens } = useProjectApiTokens(projectId);
|
||||||
const { segments, loading: loadingSegments } = useSegments();
|
const { segments } = useSegments();
|
||||||
// todo: add sdk connections
|
const { data: projectStatus, loading: loadingResources } =
|
||||||
|
useProjectStatus(projectId);
|
||||||
|
|
||||||
const segmentCount = useMemo(
|
const segmentCount = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@ -109,8 +112,10 @@ export const ProjectResources = () => {
|
|||||||
[segments, projectId],
|
[segments, projectId],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const loadingStatusRef = useLoading(true, '[data-loading-resources=true]');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper ref={loadingStatusRef}>
|
||||||
<ProjectResourcesInner>
|
<ProjectResourcesInner>
|
||||||
<Typography variant='h3' sx={{ margin: 0 }}>
|
<Typography variant='h3' sx={{ margin: 0 }}>
|
||||||
Project Resources
|
Project Resources
|
||||||
@ -137,7 +142,8 @@ export const ProjectResources = () => {
|
|||||||
linkText='View connections'
|
linkText='View connections'
|
||||||
icon={<ConnectedIcon />}
|
icon={<ConnectedIcon />}
|
||||||
>
|
>
|
||||||
1 connected environment(s)
|
{projectStatus?.resources?.connectedEnvironments}{' '}
|
||||||
|
connected environment(s)
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
||||||
<ListItem
|
<ListItem
|
||||||
|
@ -6,6 +6,7 @@ const path = (projectId: string) => `api/admin/projects/${projectId}/status`;
|
|||||||
|
|
||||||
const placeholderData: ProjectStatusSchema = {
|
const placeholderData: ProjectStatusSchema = {
|
||||||
activityCountByDate: [],
|
activityCountByDate: [],
|
||||||
|
resources: { connectedEnvironments: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useProjectStatus = (projectId: string) => {
|
export const useProjectStatus = (projectId: string) => {
|
||||||
|
@ -11,4 +11,10 @@ import type { ProjectActivitySchema } from './projectActivitySchema';
|
|||||||
export interface ProjectStatusSchema {
|
export interface ProjectStatusSchema {
|
||||||
/** Array of activity records with date and count, representing the project’s daily activity statistics. */
|
/** Array of activity records with date and count, representing the project’s daily activity statistics. */
|
||||||
activityCountByDate: ProjectActivitySchema;
|
activityCountByDate: ProjectActivitySchema;
|
||||||
|
|
||||||
|
/** Key resources within the project */
|
||||||
|
resources: {
|
||||||
|
/** Handwritten placeholder */
|
||||||
|
connectedEnvironments: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ export const projectStatusSchema = {
|
|||||||
properties: {
|
properties: {
|
||||||
connectedEnvironments: {
|
connectedEnvironments: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
minimum: 0,
|
||||||
description:
|
description:
|
||||||
'The number of environments that have received SDK traffic in this project.',
|
'The number of environments that have received SDK traffic in this project.',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user