Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ocm): add sorting to the ocm ClusterStatusPage table #1052

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/ocm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"@material-ui/lab": "^4.0.0-alpha.45",
"@patternfly/patternfly": "^5.1.0",
"@patternfly/react-icons": "^5.1.1",
"react-use": "^17.4.0"
"react-use": "^17.4.0",
"semver": "^7.5.4"
Zaperex marked this conversation as resolved.
Show resolved Hide resolved
},
"peerDependencies": {
"react": "^16.13.1 || ^17.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
} from '@janus-idp/backstage-plugin-ocm-common';

import { OcmApiRef } from '../../api';
import { ClusterStatusRowData } from '../../types';
import { Status, Update } from '../common';
import { columns } from './tableHeading';

const useStylesTwo = makeStyles({
container: {
Expand All @@ -53,17 +55,15 @@ const NodeChip = ({
}) => (
<>
{count > 0 ? (
<>
<Chip
label={
<>
{indicator}
{count}
</>
}
variant="outlined"
/>
</>
<Chip
label={
<>
{indicator}
{count}
</>
}
variant="outlined"
/>
) : (
<></>
)}
Expand Down Expand Up @@ -140,7 +140,7 @@ const CatalogClusters = () => {
return <CircularProgress />;
}

const data = clusterEntities
const data: ClusterStatusRowData[] = clusterEntities
? clusterEntities.map(ce => {
return {
name: (
Expand Down Expand Up @@ -168,29 +168,7 @@ const CatalogClusters = () => {
<Table
options={{ paging: false }}
data={data}
columns={[
{
title: 'Name',
field: 'name',
highlight: true,
},
{
title: 'Status',
field: 'status',
},
{
title: 'Infrastructure',
field: 'infrastructure',
},
{
title: 'Version',
field: 'version',
},
{
title: 'Nodes',
field: 'nodes',
},
]}
columns={columns}
title="All"
/>
</div>
Expand Down
53 changes: 53 additions & 0 deletions plugins/ocm/src/components/ClusterStatusPage/tableHeading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { TableColumn } from '@backstage/core-components';

import semver from 'semver';

import { ClusterStatusRowData } from '../../types';

export const columns: TableColumn<ClusterStatusRowData>[] = [
{
title: 'Name',
field: 'name',
highlight: true,
customSort: (a, b) => {
// The children type here is actually a ReactNode, but we know it's a string
return (a.name.props.children as string).localeCompare(
b.name.props.children as string,
'en',
);
},
},
{
title: 'Status',
field: 'status',
customSort: (a, b) => {
const availabilityA = a.status.props.status.available;
const availabilityB = b.status.props.status.available;
if (availabilityA === availabilityB) return 0;
return availabilityA ? -1 : 1;
},
},
{
title: 'Infrastructure',
field: 'infrastructure',
},
{
title: 'Version',
field: 'version',
customSort: (a, b) => {
return semver.gt(
a.version.props.data.version,
b.version.props.data.version,
)
? 1
: -1;
},
},
{
title: 'Nodes',
field: 'nodes',
customSort: (a, b) => {
return a.nodes.props.nodes.length - b.nodes.props.nodes.length;
},
},
];
13 changes: 4 additions & 9 deletions plugins/ocm/src/components/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import {
import { Button, Grid, makeStyles, Tooltip } from '@material-ui/core';
import { ArrowCircleUpIcon } from '@patternfly/react-icons';

import {
ClusterStatus,
ClusterUpdate,
} from '@janus-idp/backstage-plugin-ocm-common';
import { ClusterStatus } from '@janus-idp/backstage-plugin-ocm-common';

import { versionDetails } from '../types';

const useStyles = makeStyles({
button: {
Expand Down Expand Up @@ -48,11 +47,7 @@ export const Status = ({ status }: { status: ClusterStatus }) => {
);
};

export const Update = ({
data,
}: {
data: { version: string; update: ClusterUpdate };
}) => {
export const Update = ({ data }: { data: versionDetails }) => {
const classes = useStyles();
return (
<>
Expand Down
22 changes: 22 additions & 0 deletions plugins/ocm/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

import { EntityRefLinkProps } from '@backstage/plugin-catalog-react';

import {
ClusterNodesStatus,
ClusterStatus,
ClusterUpdate,
} from '@janus-idp/backstage-plugin-ocm-common';

export type versionDetails = {
version: string;
update: ClusterUpdate;
};

export type ClusterStatusRowData = {
name: React.ReactElement<EntityRefLinkProps>;
status: React.ReactElement<{ status: ClusterStatus }>;
infrastructure: string;
version: React.ReactElement<{ data: versionDetails }>;
nodes: React.ReactElement<{ nodes: Array<ClusterNodesStatus> }>;
};