Skip to content

Commit

Permalink
Merge pull request #73 from SamoKopecky/upgrade-indicator-frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
tumido authored Jan 18, 2023
2 parents dc4d503 + a9c0b73 commit 1829123
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
40 changes: 39 additions & 1 deletion plugins/ocm/src/components/ClusterInfoCard/ClusterInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
import React from 'react';

import { Button, Grid, makeStyles, Tooltip } from '@material-ui/core';
import ArrowUpwardRoundedIcon from '@material-ui/icons/ArrowUpwardRounded';
import { useCluster } from '../ClusterContext';
import { TableCardFromData } from '../TableCardFromData';

const useStyles = makeStyles({
button: {
textTransform: 'none',
borderRadius: 16,
margin: '0px',
paddingLeft: '4px',
paddingRight: '4px',
},
});

export const ClusterInfoCard = () => {
const { data } = useCluster();
const classes = useStyles();

if (!data) {
return null;
}

data.openshiftVersion = (
<>
{data.update?.available ? (
<Grid container direction="column" spacing={0}>
<Grid item>{data.openshiftVersion}</Grid>
<Grid item>
<Tooltip title={`Version ${data.update?.version!} available`}>
<Button
variant="text"
color="primary"
startIcon={<ArrowUpwardRoundedIcon style={{ fontSize: 22 }} />}
className={classes.button}
href={data.update?.url}
size="small"
>
Upgrade available
</Button>
</Tooltip>
</Grid>
</Grid>
) : (
data.openshiftVersion
)}
</>
) as any;

const nameMap = new Map<string, string>([
['name', 'Name'],
['kubernetesVersion', 'Kubernetes version'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const valueFormatter = (value: any): any => {
return <Link to={value}>{value}</Link>;
}
}
return value.toString();
return value;
};

export const TableCardFromData = ({
Expand All @@ -30,12 +30,12 @@ export const TableCardFromData = ({
title: string;
nameMap: Map<string, string>;
}) => {
const parsedData: { name: string; value: string }[] = [];
const parsedData: { name: string; value: any }[] = [];
const entries = Object.entries(data);

nameMap.forEach((_, key) => {
const entry = entries.find(e => e[0] === key)!;
// If key of the map doesnt have an prop in the cluster object, continue
// If key of the map doesn't have an prop in the cluster object, continue
if (entry === undefined) {
return;
}
Expand Down

0 comments on commit 1829123

Please sign in to comment.