Skip to content

Commit 7286939

Browse files
committed
Update dashboard
Signed-off-by: João Vilaça <[email protected]>
1 parent 9e0e357 commit 7286939

File tree

1 file changed

+67
-32
lines changed

1 file changed

+67
-32
lines changed

frontend/src/app/Dashboard/Dashboard.tsx

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import {
2323
PageSection,
2424
Title,
2525
CodeBlock,
26-
CodeBlockCode, SimpleList, SimpleListGroup, SimpleListItem,
26+
CodeBlockCode, SimpleList, SimpleListGroup, SimpleListItem, Alert, ExpandableSection,
2727
} from "@patternfly/react-core";
2828
import {apiBaseUrl} from "@app/config";
2929
import {CheckCircleIcon, ExclamationCircleIcon, ExclamationTriangleIcon} from "@patternfly/react-icons";
30-
import {Table, TableHeader, TableBody, TableProps, TableVariant} from '@patternfly/react-table';
30+
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
3131

3232
type data = {
3333
meta: {
@@ -419,26 +419,28 @@ const Dashboard: React.FunctionComponent = () => {
419419
name: 'File name',
420420
importTime: 'Import date',
421421
gatherTime: 'Gather date',
422+
insightsData: 'Insights data',
422423
};
423424

424-
const columns: TableProps['cells'] = ['File name', 'Gather date', 'Import date'];
425+
const insightsIcons = (data) => {
426+
const nReports = JSON.parse(data)["reports"].length
425427

426-
let rows: TableProps['rows'] = [
427-
['Loading...', 'Loading...', 'Loading...'],
428-
];
429-
430-
if (importedMustGathers !== undefined) {
431-
if (importedMustGathers.data.length === 0) {
432-
rows = [
433-
['No must-gathers imported', '', ''],
434-
];
428+
if (nReports === 0) {
429+
return (
430+
<Icon status="success" className="pf-u-ml-xs">
431+
<CheckCircleIcon />
432+
</Icon>
433+
)
435434
}
436435

437-
rows = importedMustGathers.data.map((mustGather) => [
438-
<span onClick={() => setMustGatherInsightData(mustGather.insightsData)}>{mustGather.name}</span>,
439-
<span onClick={() => setMustGatherInsightData(mustGather.insightsData)}>{new Date(mustGather.gatherTime).toLocaleString()}</span>,
440-
<span onClick={() => setMustGatherInsightData(mustGather.insightsData)}>{new Date(mustGather.importTime).toLocaleString()}</span>,
441-
]);
436+
return (
437+
<>
438+
{nReports}
439+
<Icon status="danger" className="pf-u-ml-xs">
440+
<ExclamationCircleIcon />
441+
</Icon>
442+
</>
443+
)
442444
}
443445

444446
return (
@@ -451,13 +453,35 @@ const Dashboard: React.FunctionComponent = () => {
451453
<Spinner aria-label="Loading data" />
452454
</Bullseye>
453455
) : (
454-
<Table
455-
variant={TableVariant.compact}
456-
cells={columns}
457-
rows={rows}
458-
>
459-
<TableHeader />
460-
<TableBody />
456+
<Table aria-label="imported-must-gathers">
457+
<Thead>
458+
<Tr>
459+
<Th>{columnNames.name}</Th>
460+
<Th>{columnNames.gatherTime}</Th>
461+
<Th>{columnNames.importTime}</Th>
462+
<Th>{columnNames.insightsData}</Th>
463+
</Tr>
464+
</Thead>
465+
<Tbody>
466+
{importedMustGathers.data.map((mustGather) => (
467+
<Tr
468+
key={mustGather.name}
469+
onRowClick={() => setMustGatherInsightData(mustGather.insightsData)}
470+
isSelectable
471+
isHoverable={mustGather.insightsData !== undefined && mustGather.insightsData !== null}
472+
>
473+
<Td dataLabel={columnNames.name}>{mustGather.name}</Td>
474+
<Td dataLabel={columnNames.gatherTime}>{new Date(mustGather.gatherTime).toLocaleString()}</Td>
475+
<Td dataLabel={columnNames.importTime}>{new Date(mustGather.importTime).toLocaleString()}</Td>
476+
<Td dataLabel={columnNames.insightsData}>{
477+
mustGather.insightsData === undefined || mustGather.insightsData === null ?
478+
<span>-</span>
479+
:
480+
insightsIcons(mustGather.insightsData)
481+
}</Td>
482+
</Tr>
483+
))}
484+
</Tbody>
461485
</Table>
462486
)
463487
}
@@ -468,19 +492,24 @@ const Dashboard: React.FunctionComponent = () => {
468492

469493
const reportTable = (report) => {
470494
return (
471-
<div className="pf-u-mt-xl">
472-
<Title headingLevel="h2" size="md">{report["key"]} ({report["type"]} - {report["component"]})</Title>
473-
495+
<ExpandableSection
496+
key={report["key"]}
497+
className="pf-u-mt-xl"
498+
toggleContent={
499+
<Alert isInline isPlain variant="danger" title={`[FAIL] ${report["key"]} (${report["type"]} - ${report["component"]})`} ouiaId="DangerAlert" />
500+
}
501+
>
474502
<CodeBlock className="pf-u-mt-sm">
475-
<CodeBlockCode id="code-content">{JSON.stringify(report, null, 2)}</CodeBlockCode>
503+
<CodeBlockCode id="code-content">{JSON.stringify(report["details"], null, 2)}</CodeBlockCode>
476504
</CodeBlock>
477-
</div>
505+
</ExpandableSection>
478506
)
479507
}
480508

481509
const mustGatherInsightsDataModalContent = (data) => {
482510
const metadata = data["analysis_metadata"]
483511
const plugins = metadata["plugin_sets"]
512+
const reports = data["reports"]
484513

485514
return (
486515
<>
@@ -497,7 +526,11 @@ const Dashboard: React.FunctionComponent = () => {
497526
</SimpleListGroup>
498527
</SimpleList>
499528

500-
{data["reports"].map((report) => reportTable(report))}
529+
{reports.length === 0 ?
530+
<Alert variant="success" title="All rules passed" ouiaId="SuccessAlert" />
531+
:
532+
reports.map((report) => reportTable(report))
533+
}
501534
</>
502535
)
503536
}
@@ -540,17 +573,19 @@ const Dashboard: React.FunctionComponent = () => {
540573
{mustGatherInsightsDataModal()}
541574

542575
<Grid hasGutter>
576+
{/* line 0 */}
577+
<GridItem span={12}>{importedMustGathersCard()}</GridItem>
578+
543579
{/* line 1 */}
544580
<GridItem span={6}>{clusterInventoryCard()}</GridItem>
545-
<GridItem span={6}>{importedMustGathersCard()}</GridItem>
581+
<GridItem span={6}>{nodesStatusCard()}</GridItem>
546582

547583
{/* line 2 */}
548584
<GridItem span={6}>{subscriptionsCard()}</GridItem>
549585
<GridItem span={6}>{virtualMachineInstancesCard()}</GridItem>
550586

551587
{/* line 3 */}
552588
<GridItem span={6}>{podsCard()}</GridItem>
553-
<GridItem span={6}>{nodesStatusCard()}</GridItem>
554589
</Grid>
555590
</PageSection>
556591
</Page>

0 commit comments

Comments
 (0)