forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ocm): add sorting to the ocm ClusterStatusPage table (janus-idp#…
- Loading branch information
Showing
5 changed files
with
94 additions
and
45 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
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
53 changes: 53 additions & 0 deletions
53
plugins/ocm/src/components/ClusterStatusPage/tableHeading.tsx
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,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; | ||
}, | ||
}, | ||
]; |
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
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,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> }>; | ||
}; |