Skip to content

Commit

Permalink
WIP - move status to react memo
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Schmidt committed Apr 8, 2019
1 parent d287775 commit 93a0d18
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 17 additions & 1 deletion plugins/services/src/js/columns/ServicesTableStatusColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Trans } from "@lingui/macro";
import { TextCell } from "@dcos/ui-kit";

import StringUtil from "#SRC/js/utils/StringUtil";
import DateUtil from "#SRC/js/utils/DateUtil";
import DeclinedOffersUtil from "../utils/DeclinedOffersUtil";
import ServiceStatusIcon from "../components/ServiceStatusIcon";
import * as ServiceStatus from "../constants/ServiceStatus";
import ServiceStatusProgressBar from "../components/ServiceStatusProgressBar";
Expand All @@ -16,13 +18,19 @@ const StatusMapping: any = {
Running: "running-state"
};

interface ServiceQueue {
since: unknown;
}

export function statusRenderer(
service: Service | Pod | ServiceTree
): React.ReactNode {
const serviceStatusText: string = service.getStatus();
const serviceStatusClassSet: string = StatusMapping[serviceStatusText] || "";
const instancesCount = service.getInstancesCount() as number;
const runningInstances = service.getRunningInstancesCount() as number;
const queue = (service.getQueue() as unknown) as ServiceQueue;

const serviceStatusClassSet: string = StatusMapping[serviceStatusText] || "";
// L10NTODO: Pluralize
const tooltipContent = (
<Trans render="span">
Expand All @@ -38,6 +46,14 @@ export function statusRenderer(
<div className="flex">
<div className={`${serviceStatusClassSet} service-status-icon-wrapper`}>
<ServiceStatusIcon
serviceId={service.getId()}
isService={service instanceof Service}
waitingSince={
service.getQueue()
? DeclinedOffersUtil.getTimeWaiting(service.getQueue())
: null
}
queuedSince={queue ? DateUtil.strToMs(queue.since) : null}
service={service}
showTooltip={true}
tooltipContent={tooltipContent}
Expand Down
18 changes: 18 additions & 0 deletions plugins/services/src/js/utils/DeclinedOffersUtil.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
interface Queue {
app?: unknown;
pod?: unknown;
processedOffersSummary?: unknown;
lastUnusedOffers?: unknown;
since?: unknown;
}

interface ItemWithQueue {
getQueue(): Queue;
}

export default class DeclinedOffersUtil {
getSummaryFromQueue(queue: Queue): unknown;
getOffersFromQueue(queue: Queue): unknown;
getTimeWaiting(queue: Queue): number | null;
displayDeclinedOffersWarning(item: ItemWithQueue): boolean | null;
}

0 comments on commit 93a0d18

Please sign in to comment.