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

[release-4.4] Bug 1812258: Create custom sort for operand status colunn #4769

Merged
merged 1 commit into from
Mar 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const OperandTableHeader = () => {
},
{
title: 'Status',
sortField: 'status.phase',
sortFunc: 'operandStatus',
transforms: [sortable],
props: { className: tableColumnClasses[2] },
},
Expand Down Expand Up @@ -244,6 +244,25 @@ export const OperandStatusIconAndText: React.FunctionComponent<OperandStatusIcon
return iconAndText;
};

const getSortableOperandStatus = (statusObject: K8sResourceKind['status']) => {
let statusText = 'Unknown';
if (_.isEmpty(statusObject)) {
return statusText;
}
_.find(Object.keys(OperatorStatusType), (key) => {
if (_.has(statusObject, key)) {
const status = statusObject[key];
const statusSubText = key === OperatorStatusType.conditions ? status[0]?.type : status;
if (statusSubText) {
return (statusText = `${OperatorStatusTypeText[key]}${statusSubText}`);
}
}
return false;
});

return statusText;
};

export const OperandTableRow: React.FC<OperandTableRowProps> = ({ obj, index, key, style }) => {
return (
<TableRow id={obj.metadata.uid} index={index} trKey={key} style={style}>
Expand Down Expand Up @@ -298,6 +317,10 @@ export const OperandList: React.SFC<OperandListProps> = (props) => {
return (
<Table
{...props}
customSorts={{
operandStatus: (operand: K8sResourceKind): string =>
getSortableOperandStatus(operand.status),
}}
data={ensureKind(props.data)}
EmptyMsg={EmptyMsg}
aria-label="Operands"
Expand Down
5 changes: 5 additions & 0 deletions frontend/public/components/factory/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const sorts = {
const stateToProps = (
{ UI },
{
customSorts = {},
data = [],
defaultSortField = 'metadata.name',
defaultSortFunc = undefined,
Expand Down Expand Up @@ -164,6 +165,9 @@ const stateToProps = (
} else {
sortBy = (resource) => sorts.string(_.get(resource, currentSortField, ''));
}
} else if (currentSortFunc && customSorts[currentSortFunc]) {
// Sort resources by a function in the 'customSorts' prop
sortBy = customSorts[currentSortFunc];
} else if (currentSortFunc && sorts[currentSortFunc]) {
// Sort resources by a function in the 'sorts' object
sortBy = sorts[currentSortFunc];
Expand Down Expand Up @@ -339,6 +343,7 @@ export type VirtualBodyProps = {

export type TableProps = {
customData?: any;
customSorts?: { [key: string]: any };
data?: any[];
defaultSortFunc?: string;
defaultSortField?: string;
Expand Down