Skip to content

Commit

Permalink
feat(OCPADVISOR-135): workload detail page header (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsToNlele authored Nov 6, 2023
1 parent ab135d2 commit f44d697
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 75 deletions.
42 changes: 40 additions & 2 deletions src/Components/Workload/Workload.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
import React from 'react';
import PageHeader from '@redhat-cloud-services/frontend-components/PageHeader';
import { Flex, FlexItem, PageSection } from '@patternfly/react-core';
import Breadcrumbs from '../Breadcrumbs';
import WorkloadsHeader from '../WorkloadHeader';
import PropTypes from 'prop-types';

export const Workload = () => {
export const Workload = ({ workload, namespaceId, clusterId }) => {
return (
<React.Fragment>
<PageHeader className="pf-m-light ins-inventory-detail" />
<PageHeader className="pf-m-light ins-inventory-detail">
<Flex direction={{ default: 'column' }}>
<FlexItem>
<Breadcrumbs
current={
workload?.data?.status === 'ok'
? `${workload.data.cluster.display_name} | ${workload.data.namespace.name}`
: `${clusterId} | ${namespaceId}`
}
/>
<WorkloadsHeader />
</FlexItem>
</Flex>
</PageHeader>
<PageSection>{/* <WorkloadRules workload={workload} /> */}</PageSection>
</React.Fragment>
);
};

Workload.propTypes = {
clusterId: PropTypes.string.isRequired,
namespaceId: PropTypes.string.isRequired,
workload: PropTypes.shape({
isUninitialized: PropTypes.bool.isRequired,
isFetching: PropTypes.bool.isRequired,
data: PropTypes.shape({
namespace: PropTypes.shape({
uuid: PropTypes.string,
name: PropTypes.string,
}),
cluster: PropTypes.shape({
uuid: PropTypes.string,
display_name: PropTypes.string,
}),
status: PropTypes.string,
}),
}),
};
34 changes: 31 additions & 3 deletions src/Components/Workload/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
//Wrapper for API connection
import React from 'react';
import React, { useEffect } from 'react';
import { Workload } from './Workload';
import { useParams } from 'react-router-dom';
import { useGetWorkloadByIdQuery } from '../../Services/SmartProxy';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';

const WorkloadWrapper = () => {
return <Workload />;
const chrome = useChrome();
const { namespaceId, clusterId } = useParams();
const workload = useGetWorkloadByIdQuery({
namespaceId,
clusterId,
});

useEffect(() => {
workload.refetch();
}, [namespaceId, clusterId]);

useEffect(() => {
const subnav = `${
workload?.data?.status === 'ok'
? `${workload?.data?.cluster.display_name} | ${workload?.data?.namespace.name} - Workloads`
: `${clusterId} | ${namespaceId} - Workloads`
}`;
chrome.updateDocumentTitle(`${subnav} - OCP Advisor | Red Hat Insights`);
}, [workload, namespaceId, clusterId]);

return (
<Workload
workload={workload}
namespaceId={namespaceId}
clusterId={clusterId}
/>
);
};

export default WorkloadWrapper;
84 changes: 84 additions & 0 deletions src/Components/WorkloadHeader/WorkloadHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';

import {
Grid,
GridItem,
Stack,
StackItem,
Title,
} from '@patternfly/react-core';
import Skeleton from '@redhat-cloud-services/frontend-components/Skeleton';
import { OneLineLoader } from '../../Utilities/Loaders';
import DateFormat from '@redhat-cloud-services/frontend-components/DateFormat';
import PropTypes from 'prop-types';

export const WorkloadHeader = ({ workloadData, namespaceId, clusterId }) => {
const { isUninitialized, isFetching, data: workload } = workloadData;
return (
<Grid id="workload-header" md={12} hasGutter>
<GridItem span={8}>
<Title
size="2xl"
headingLevel="h1"
id="cluster-header-title"
ouiaId="cluster-name"
>
{isUninitialized || isFetching ? (
<>
<Skeleton size="sm" />
<Skeleton size="sm" />
</>
) : (
<>
<p>{workload.cluster.display_name}</p>
<p>{workload.namespace.name}</p>
</>
)}
</Title>
</GridItem>
<GridItem>
<Stack>
<StackItem id="workload-header-uuid">
<span>Cluster UUID:</span> <span>{clusterId}</span>{' '}
<span>Namespace UUID:</span> <span>{namespaceId}</span>
</StackItem>
<StackItem id="workload-header-last-seen">
<span>Last seen: </span>
<span>
{isUninitialized || isFetching ? (
<OneLineLoader />
) : workload?.metadata?.last_checked_at ? (
<DateFormat
date={workload.metadata.last_checked_at}
type="exact"
/>
) : (
<>Unknown</>
)}
</span>
</StackItem>
</Stack>
</GridItem>
</Grid>
);
};

WorkloadHeader.propTypes = {
clusterId: PropTypes.string.isRequired,
namespaceId: PropTypes.string.isRequired,
workloadData: PropTypes.shape({
isUninitialized: PropTypes.bool.isRequired,
isFetching: PropTypes.bool.isRequired,
data: PropTypes.shape({
namespace: PropTypes.shape({
uuid: PropTypes.string,
name: PropTypes.string,
}),
cluster: PropTypes.shape({
uuid: PropTypes.string,
display_name: PropTypes.string,
}),
status: PropTypes.string,
}),
}),
};
22 changes: 22 additions & 0 deletions src/Components/WorkloadHeader/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { WorkloadHeader } from './WorkloadHeader';
import { useParams } from 'react-router-dom';
import { useGetWorkloadByIdQuery } from '../../Services/SmartProxy';

const WorkloadsHeaderWrapper = () => {
const { namespaceId, clusterId } = useParams();
const workloadData = useGetWorkloadByIdQuery({
namespaceId,
clusterId,
});

return (
<WorkloadHeader
workloadData={workloadData}
namespaceId={namespaceId}
clusterId={clusterId}
/>
);
};

export default WorkloadsHeaderWrapper;
44 changes: 0 additions & 44 deletions src/Components/WorkloadsHeader/WorkloadsHeader.js

This file was deleted.

22 changes: 0 additions & 22 deletions src/Components/WorkloadsHeader/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const AppRoutes = () => {
}
/>
<Route
path="/workloads/:workloadId"
path="/workloads/:clusterId/:namespaceId"
element={
workloadsEnabled ? (
<Workload
Expand Down
6 changes: 3 additions & 3 deletions src/Services/SmartProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const SmartProxyApi = createApi({
query: () => `v2/namespaces/dvo`,
}),
getWorkloadById: builder.query({
query: ({ namespace_uuid, cluster_uuid }) =>
`v2/namespaces/dvo/${namespace_uuid}/cluster/${cluster_uuid}`,
query: ({ namespaceId, clusterId }) =>
`v2/namespaces/dvo/${namespaceId}/cluster/${clusterId}`,
}),
}),
});
Expand All @@ -66,5 +66,5 @@ export const {
useGetClusterInfoQuery,
useGetUpdateRisksQuery,
useGetWorkloadsQuery,
useLazyGetWorkloadByIdQuery,
useGetWorkloadByIdQuery,
} = SmartProxyApi;

0 comments on commit f44d697

Please sign in to comment.