Skip to content

Commit 6e14633

Browse files
committed
Add sorting on status column
1 parent fb4df24 commit 6e14633

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

plugin/src/components/camel-list-page/CamelIntegrationRow.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
} from '@openshift-console/dynamic-plugin-sdk';
1010
import { useTranslation } from 'react-i18next';
1111
import { Link } from 'react-router-dom';
12-
import CamelIntegrationStatus from './CamelIntegrationStatus';
12+
import Status from '@openshift-console/dynamic-plugin-sdk/lib/app/components/status/Status';
13+
import { CamelIntegrationStatusTitle, CamelIntegrationStatusValue } from './CamelIntegrationStatus';
1314

1415
const getKind = (obj) => obj.kind;
1516
const getNamespace = (obj) => obj.metadata?.namespace;
@@ -38,9 +39,7 @@ const ResourcesRow: React.FC<RowProps<K8sResourceKind>> = ({ obj: camelInt, acti
3839
<>
3940
<TableData id="name" activeColumnIDs={activeColumnIDs}>
4041
<span className="co-resource-item co-resource-item--truncate">
41-
<span className="co-m-resource-icon co-m-resource-secret">
42-
C
43-
</span>
42+
<span className="co-m-resource-icon co-m-resource-secret">C</span>
4443
<Link
4544
to={`/camel/integration/ns/${camelInt.metadata.namespace}/kind/${camelInt.kind}/name/${camelInt.metadata.name}`}
4645
className="co-resource-item__resource-name"
@@ -67,7 +66,10 @@ const ResourcesRow: React.FC<RowProps<K8sResourceKind>> = ({ obj: camelInt, acti
6766
</span>
6867
</TableData>
6968
<TableData id="status" activeColumnIDs={activeColumnIDs}>
70-
<CamelIntegrationStatus camelInt={camelInt} />
69+
<Status
70+
title={CamelIntegrationStatusTitle(camelInt)}
71+
status={CamelIntegrationStatusValue(camelInt)}
72+
/>
7173
</TableData>
7274
<TableData id="camel" activeColumnIDs={activeColumnIDs}>
7375
{camelVersion || <span className="text-muted">{t('No camel version')}</span>}
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
import * as React from 'react';
21
import { K8sResourceKind } from '@openshift-console/dynamic-plugin-sdk';
32

4-
import Status from '@openshift-console/dynamic-plugin-sdk/lib/app/components/status/Status';
5-
//import { useTranslation } from "react-i18next";
3+
export const CamelIntegrationStatuses = ['Succeeded', 'Failed', 'Unknown'] as const;
64

7-
const CamelIntegrationStatus = ({ camelInt }: { camelInt: K8sResourceKind }) => {
8-
// Use translated values for Succeded and Failed
9-
//const { t } = useTranslation('plugin__camel-openshift-console-plugin');
5+
export type CamelIntegrationStatuses = typeof CamelIntegrationStatuses[number];
106

7+
export const CamelIntegrationStatusValue = (
8+
camelInt: K8sResourceKind,
9+
): CamelIntegrationStatuses => {
1110
if (camelInt.kind == 'Deployment' || camelInt.kind == 'DeploymentConfig') {
12-
return (
13-
<Status
14-
title={`${camelInt.status.availableReplicas} of ${camelInt.status.replicas} pods`}
15-
status={
16-
camelInt.status.availableReplicas === camelInt.status.replicas ? 'Succeeded' : 'Failed'
17-
}
18-
/>
19-
);
20-
} else if (camelInt.kind == 'CronJob') {
21-
return (
22-
<Status
23-
title={`${camelInt.status.lastSuccessfulTime}`}
24-
status={camelInt.status.lastSuccessfulTime ? 'Succeeded' : 'Failed'}
25-
/>
26-
);
11+
return camelInt.status.availableReplicas === camelInt.status.replicas ? 'Succeeded' : 'Failed';
2712
}
13+
14+
if (camelInt.kind == 'CronJob') {
15+
return camelInt.status.lastSuccessfulTime ? 'Succeeded' : 'Failed';
16+
}
17+
18+
return 'Unknown';
2819
};
2920

30-
export default CamelIntegrationStatus;
21+
export const CamelIntegrationStatusTitle = (camelInt: K8sResourceKind): string => {
22+
if (camelInt.kind == 'Deployment' || camelInt.kind == 'DeploymentConfig') {
23+
return camelInt.status.availableReplicas + ' of ' + camelInt.status.replicas + ' pods';
24+
}
25+
26+
if (camelInt.kind == 'CronJob') {
27+
return camelInt.status.lastSuccessfulTime;
28+
}
29+
30+
return 'Unknown';
31+
};

plugin/src/components/camel-list-page/useCamelIntegrationColumns.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { K8sResourceKind, TableColumn } from '@openshift-console/dynamic-plugin-sdk';
22
import { sortable } from '@patternfly/react-table';
33
import { useTranslation } from 'react-i18next';
4+
import { CamelIntegrationStatusValue } from './CamelIntegrationStatus';
5+
6+
export const sortResourceByStatus =
7+
(direction: string) => (a: K8sResourceKind, b: K8sResourceKind) => {
8+
const { first, second } =
9+
direction === 'asc' ? { first: a, second: b } : { first: b, second: a };
10+
11+
const firstValue = CamelIntegrationStatusValue(first);
12+
const secondValue = CamelIntegrationStatusValue(second);
13+
14+
return firstValue?.localeCompare(secondValue);
15+
};
416

517
const useCamelIntegrationColumns = (namespace): TableColumn<K8sResourceKind>[] => {
618
const { t } = useTranslation('plugin__camel-openshift-console-plugin');
@@ -30,8 +42,8 @@ const useCamelIntegrationColumns = (namespace): TableColumn<K8sResourceKind>[] =
3042
{
3143
title: t('Status'),
3244
id: 'status',
33-
sort: 'status.phase',
34-
transforms: [],
45+
sort: (data, direction) => data?.sort(sortResourceByStatus(direction)),
46+
transforms: [sortable],
3547
},
3648
{
3749
title: t('Camel'),

0 commit comments

Comments
 (0)