generated from RedHatInsights/frontend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(OCPADVISOR-126): workloads list table (#625)
- Loading branch information
Showing
5 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,7 @@ | |
|
||
#cluster-header-dropdown { | ||
justify-self: end; | ||
} | ||
.grey-icon { | ||
color: var(--pf-global--Color--200); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Components/HighestSeverityBadge/HighestSeverityBadge.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { Tooltip } from '@patternfly/react-core'; | ||
import { TooltipPosition } from '@patternfly/react-core/dist/js/components/Tooltip'; | ||
import InsightsLabel from '@redhat-cloud-services/frontend-components/InsightsLabel'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const HighestSeverityBadge = ({ severities }) => { | ||
let highestSeverity = 0; | ||
|
||
Object.keys(severities).forEach((severityType) => | ||
severities[severityType] > 0 ? (highestSeverity = severityType) : null | ||
); | ||
|
||
const severityTypeToText = (value) => { | ||
value = parseInt(value); | ||
if (value === 1) { | ||
return 'Low'; | ||
} else if (value === 2) { | ||
return 'Moderate'; | ||
} else if (value === 3) { | ||
return 'Important'; | ||
} else { | ||
return 'Critical'; | ||
} | ||
}; | ||
|
||
const severitiesToDisplay = Object.keys(severities) | ||
.map((severityType) => { | ||
return severities[severityType] > 0 ? ( | ||
<p key={severityType}> | ||
{severities[severityType]} {severityTypeToText(severityType)} | ||
</p> | ||
) : null; | ||
}) | ||
.reverse(); | ||
|
||
return ( | ||
<div> | ||
<Tooltip position={TooltipPosition.top} content={severitiesToDisplay}> | ||
<InsightsLabel value={highestSeverity} isCompact /> | ||
</Tooltip> | ||
</div> | ||
); | ||
}; | ||
|
||
HighestSeverityBadge.propTypes = { | ||
severities: PropTypes.arrayOf(PropTypes.number), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 116 additions & 3 deletions
119
src/Components/WorkloadsListTable/WorkloadsListTable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,126 @@ | ||
/* eslint-disable no-unused-vars */ | ||
//^ this will be removed later | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import useFeatureFlag, { | ||
WORKLOADS_ENABLE_FLAG, | ||
} from '../../Utilities/useFeatureFlag'; | ||
import PrimaryToolbar from '@redhat-cloud-services/frontend-components/PrimaryToolbar'; | ||
import { | ||
Table, | ||
TableBody, | ||
TableHeader, | ||
TableVariant, | ||
} from '@patternfly/react-table'; | ||
import { PaginationVariant } from '@patternfly/react-core/dist/js/components/Pagination/Pagination'; | ||
import { WORKLOADS_LIST_COLUMNS } from '../../AppConstants'; | ||
import DateFormat from '@redhat-cloud-services/frontend-components/DateFormat'; | ||
import { Link } from 'react-router-dom'; | ||
import { BASE_PATH } from '../../Routes'; | ||
import { HighestSeverityBadge } from '../HighestSeverityBadge/HighestSeverityBadge'; | ||
import { Pagination } from '@patternfly/react-core'; | ||
|
||
const workloadsData = [ | ||
{ | ||
workload_id: 'asd4134asd-1234241', | ||
workload_name: 'Workload 1', | ||
risks: { | ||
1: 2, | ||
2: 0, | ||
3: 3, | ||
4: 1, | ||
}, | ||
recommendations: 4, | ||
objects: 14, | ||
lastSeen: '2023-10-30T09:55:52Z', | ||
}, | ||
{ | ||
workload_id: 'worklooaaaasd-2', | ||
workload_name: 'Workload 2', | ||
risks: { | ||
1: 1, | ||
2: 3, | ||
3: 2, | ||
4: 0, | ||
}, | ||
recommendations: 5, | ||
objects: 3, | ||
lastSeen: '2023-10-30T05:55:52Z', | ||
}, | ||
]; | ||
|
||
const WorkloadsListTable = () => { | ||
const workloadsEnabled = useFeatureFlag(WORKLOADS_ENABLE_FLAG); | ||
console.log(workloadsEnabled, 'FLAG'); | ||
|
||
const workloads = workloadsData; | ||
|
||
const [rows, setRows] = React.useState([]); | ||
|
||
useEffect(() => { | ||
setRows(buildRows(workloads)); | ||
}, [workloads]); | ||
|
||
const buildRows = (items) => { | ||
return items.map((item, index) => { | ||
return { | ||
entity: item, | ||
cells: [ | ||
<span key={index}> | ||
<Link to={`${BASE_PATH}/workloads/${item.workload_id}`}> | ||
{item.workload_name || item.workload_id} | ||
</Link> | ||
</span>, | ||
item.recommendations, | ||
<span key={index}> | ||
<HighestSeverityBadge severities={item.risks} /> | ||
</span>, | ||
item.objects, | ||
<span key={Math.random()}> | ||
<DateFormat | ||
extraTitle="Last seen: " | ||
date={item.lastSeen} | ||
variant="relative" | ||
/> | ||
</span>, | ||
], | ||
}; | ||
}); | ||
}; | ||
|
||
return ( | ||
<div id="workloads-list-table"> | ||
<PrimaryToolbar | ||
pagination={{ | ||
itemCount: 2, | ||
page: 1, | ||
perPage: 20, | ||
onSetPage: () => {}, | ||
onPerPageSelect: () => {}, | ||
isCompact: true, | ||
ouiaId: 'pager', | ||
}} | ||
/> | ||
<Table | ||
aria-label="Table of workloads" | ||
ouiaId="workloads" | ||
variant={TableVariant.compact} | ||
cells={WORKLOADS_LIST_COLUMNS} | ||
rows={rows} | ||
isStickyHeader | ||
> | ||
<TableHeader /> | ||
<TableBody /> | ||
</Table> | ||
<Pagination | ||
ouiaId="pager" | ||
itemCount={2} | ||
page={1} | ||
perPage={20} | ||
onSetPage={() => {}} | ||
onPerPageSelect={() => {}} | ||
widgetId={`pagination-options-menu-bottom`} | ||
variant={PaginationVariant.bottom} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export { WorkloadsListTable }; |