You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/edge/edge-stacks/utils/uniqueStatus.ts

17 lines
558 B

import { DeploymentStatus } from '../types';
/**
* returns the latest status object of each type
*/
export function uniqueStatus(statusArray: Array<DeploymentStatus> = []) {
// keep only the last status object of each type, assume that the last status is the most recent
return statusArray.reduce((acc, status) => {
const index = acc.findIndex((s) => s.Type === status.Type);
if (index === -1) {
return [...acc, status];
}
return [...acc.slice(0, index), ...acc.slice(index + 1), status];
}, [] as Array<DeploymentStatus>);
}