mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
feat: connect application envs to backend (#6324)
This commit is contained in:
parent
ef021a9464
commit
0de0313563
@ -14,6 +14,7 @@ import Check from '@mui/icons-material/CheckCircle';
|
|||||||
import Warning from '@mui/icons-material/Warning';
|
import Warning from '@mui/icons-material/Warning';
|
||||||
import { ArcherContainer, ArcherElement } from 'react-archer';
|
import { ArcherContainer, ArcherElement } from 'react-archer';
|
||||||
import { FC, useLayoutEffect, useRef, useState } from 'react';
|
import { FC, useLayoutEffect, useRef, useState } from 'react';
|
||||||
|
import { useApplicationOverview } from 'hooks/api/getters/useApplicationOverview/useApplicationOverview';
|
||||||
|
|
||||||
const StyledTable = styled('table')(({ theme }) => ({
|
const StyledTable = styled('table')(({ theme }) => ({
|
||||||
fontSize: theme.fontSizes.smallerBody,
|
fontSize: theme.fontSizes.smallerBody,
|
||||||
@ -64,7 +65,7 @@ const StyledEnvironmentBox = styled(Box)<{ mode: 'success' | 'warning' }>(
|
|||||||
backgroundColor:
|
backgroundColor:
|
||||||
theme.palette[mode === 'success' ? 'secondary' : 'warning'].light,
|
theme.palette[mode === 'success' ? 'secondary' : 'warning'].light,
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
padding: theme.spacing(1.5, 0, 1.5, 1.5),
|
padding: theme.spacing(1.5, 1.5, 1.5, 1.5),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -123,28 +124,7 @@ export const ApplicationOverview = () => {
|
|||||||
const applicationName = useRequiredPathParam('name');
|
const applicationName = useRequiredPathParam('name');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { data, loading } = useApplicationOverview(applicationName);
|
||||||
const app = {
|
|
||||||
projects: ['default', 'dx'],
|
|
||||||
featureCount: 12,
|
|
||||||
environments: [
|
|
||||||
{
|
|
||||||
name: 'production',
|
|
||||||
instanceCount: 34,
|
|
||||||
sdks: [
|
|
||||||
'unleash-client-node:5.4.0',
|
|
||||||
'unleash-client-node:5.4.1',
|
|
||||||
],
|
|
||||||
lastSeen: '2021-10-01T12:00:00Z',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'development',
|
|
||||||
instanceCount: 16,
|
|
||||||
sdks: ['unleash-client-java:5.4.0'],
|
|
||||||
lastSeen: '2021-10-01T12:00:00Z',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.navigateToInstances = (environment: string) => {
|
window.navigateToInstances = (environment: string) => {
|
||||||
@ -159,7 +139,7 @@ export const ApplicationOverview = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={1 === 2 + 1}
|
condition={!loading && data.environments.length === 0}
|
||||||
show={<Alert severity='warning'>No data available.</Alert>}
|
show={<Alert severity='warning'>No data available.</Alert>}
|
||||||
elseShow={
|
elseShow={
|
||||||
<Box sx={{ width }}>
|
<Box sx={{ width }}>
|
||||||
@ -170,7 +150,7 @@ export const ApplicationOverview = () => {
|
|||||||
<StyleApplicationContainer>
|
<StyleApplicationContainer>
|
||||||
<ArcherElement
|
<ArcherElement
|
||||||
id='application'
|
id='application'
|
||||||
relations={app.environments.map(
|
relations={data.environments.map(
|
||||||
(environment) => ({
|
(environment) => ({
|
||||||
targetId: environment.name,
|
targetId: environment.name,
|
||||||
targetAnchor: 'top',
|
targetAnchor: 'top',
|
||||||
@ -221,7 +201,7 @@ export const ApplicationOverview = () => {
|
|||||||
</StyleApplicationContainer>
|
</StyleApplicationContainer>
|
||||||
|
|
||||||
<StyledEnvironmentsContainer ref={elementRef}>
|
<StyledEnvironmentsContainer ref={elementRef}>
|
||||||
{app.environments.map((environment) => (
|
{data.environments.map((environment) => (
|
||||||
<ArcherElement id={environment.name}>
|
<ArcherElement id={environment.name}>
|
||||||
<StyledEnvironmentBox
|
<StyledEnvironmentBox
|
||||||
mode={mode}
|
mode={mode}
|
||||||
|
@ -35,8 +35,8 @@ export const StringArrayCell: VFC<IArrayFieldCellProps<any>> = ({
|
|||||||
<TooltipLink
|
<TooltipLink
|
||||||
highlighted={
|
highlighted={
|
||||||
searchQuery.length > 0 &&
|
searchQuery.length > 0 &&
|
||||||
fieldValue.some((item: string) =>
|
fieldValue.some((item: string | null) =>
|
||||||
item.toLowerCase().includes(searchQuery.toLowerCase()),
|
item?.toLowerCase().includes(searchQuery.toLowerCase()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
tooltip={
|
tooltip={
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
import useSWR, { SWRConfiguration } from 'swr';
|
||||||
|
import { formatApiPath } from 'utils/formatPath';
|
||||||
|
import handleErrorResponses from '../httpErrorResponseHandler';
|
||||||
|
import { ApplicationOverviewSchema } from 'openapi';
|
||||||
|
|
||||||
|
export const useApplicationOverview = (
|
||||||
|
application: string,
|
||||||
|
options: SWRConfiguration = {},
|
||||||
|
) => {
|
||||||
|
const path = formatApiPath(
|
||||||
|
`api/admin/metrics/applications/${application}/overview`,
|
||||||
|
);
|
||||||
|
const { data, error } = useSWR<ApplicationOverviewSchema>(
|
||||||
|
path,
|
||||||
|
fetcher,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: data || { environments: [], featureCount: 0, projects: [] },
|
||||||
|
error,
|
||||||
|
loading: !error && !data,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetcher = async (path: string): Promise<ApplicationOverviewSchema> => {
|
||||||
|
const res = await fetch(path).then(
|
||||||
|
handleErrorResponses('Application overview'),
|
||||||
|
);
|
||||||
|
const data = await res.json();
|
||||||
|
return data;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user