Skip to content

Commit

Permalink
ui/nodes:
Browse files Browse the repository at this point in the history
Add missing constant for Node status

User constants instead of strings in NodeUtils table data generator to be consistent with Sorting

Implement Status Sorting

Refs: #2919
  • Loading branch information
Alex Le Dinh committed Nov 12, 2020
1 parent e70489e commit 6283bd2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
20 changes: 19 additions & 1 deletion ui/src/components/NodeListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import {
TableHeader,
} from './CommonLayoutStyle';
import { compareHealth } from '../services/utils';
import {
API_STATUS_READY,
API_STATUS_NOT_READY,
API_STATUS_UNKNOWN,
API_STATUS_DEPLOYING,
} from '../constants';

const NodeListContainer = styled.div`
color: ${(props) => props.theme.brand.textPrimary};
Expand Down Expand Up @@ -219,6 +225,18 @@ function Table({ columns, data, rowClicked, theme, selectedNodeName }) {
row1?.values?.health?.health,
);
},
status: (row1, row2) => {
const weights = {};
weights[API_STATUS_READY] = 3;
weights[API_STATUS_NOT_READY] = 2;
weights[API_STATUS_DEPLOYING] = 1;
weights[API_STATUS_UNKNOWN] = 0;

return (
weights[row1?.values?.status?.status] -
weights[row2?.values?.status?.status]
);
},
};
}, []);

Expand Down Expand Up @@ -422,7 +440,6 @@ const NodeListTable = (props) => {
cellStyle: { textAlign: 'center', width: '80px' },
Cell: (cellProps) => {
const { statusTextColor, computedStatus } = cellProps.value;
console.log(computedStatus);
return computedStatus.map((status) => {
return (
<StatusText key={status} textColor={statusTextColor}>
Expand All @@ -431,6 +448,7 @@ const NodeListTable = (props) => {
);
});
},
sortType: 'status',
},
],
[],
Expand Down
1 change: 1 addition & 0 deletions ui/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const STATUS_HEALTH = 'health';
export const API_STATUS_READY = 'ready';
export const API_STATUS_NOT_READY = 'not_ready';
export const API_STATUS_UNKNOWN = 'unknown';
export const API_STATUS_DEPLOYING = 'deploying';

export const STATUS_BOUND = 'Bound';
export const STATUS_PENDING = 'Pending';
Expand Down
17 changes: 10 additions & 7 deletions ui/src/services/NodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
STATUS_WARNING,
STATUS_HEALTH,
STATUS_NONE,
API_STATUS_READY,
API_STATUS_NOT_READY,
API_STATUS_UNKNOWN,
API_STATUS_DEPLOYING,
} from '../constants';

const METALK8S_CONTROL_PLANE_IP = 'metalk8s:control_plane_ip';
Expand Down Expand Up @@ -64,25 +67,25 @@ export const getNodeListData = createSelector(
// "yellow" when status.conditions['Ready'] == True and some other conditions are true
// "red" when status.conditions['Ready'] == False
// "grey" when there is no status.conditions
if (node?.status === 'ready' && node?.conditions.length === 0) {
if (node?.status === API_STATUS_READY && node?.conditions.length === 0) {
statusTextColor = brand?.healthy;
computedStatus.push('ready');
} else if (node?.status === 'ready' && node?.conditions.length !== 0) {
computedStatus.push(API_STATUS_READY);
} else if (node?.status === API_STATUS_READY && node?.conditions.length !== 0) {
statusTextColor = brand?.warning;
nodes.conditions.map((cond) => {
return computedStatus.push(cond);
});
} else if (node.deploying && node.status === API_STATUS_UNKNOWN) {
statusTextColor = brand?.textSecondary;
computedStatus.push('deploying');
computedStatus.push(API_STATUS_DEPLOYING);
health = STATUS_NONE;
} else if (node?.status !== 'ready') {
} else if (node?.status !== API_STATUS_READY) {
statusTextColor = brand?.critical;
computedStatus.push('not_ready');
computedStatus.push(API_STATUS_NOT_READY);
health = STATUS_NONE;
} else {
statusTextColor = brand?.textSecondary;
computedStatus.push('unknown');
computedStatus.push(API_STATUS_UNKNOWN);
health = STATUS_NONE;
}

Expand Down

0 comments on commit 6283bd2

Please sign in to comment.