Path: blob/main/components/dashboard/src/workspaces/WorkspaceStatusIndicator.tsx
2500 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { WorkspaceInstanceConditions } from "@gitpod/gitpod-protocol";7import Tooltip from "../components/Tooltip";8import { WorkspacePhase_Phase, WorkspaceStatus } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";910export function WorkspaceStatusIndicator({ status }: { status?: WorkspaceStatus }) {11const state: WorkspacePhase_Phase = status?.phase?.name ?? WorkspacePhase_Phase.STOPPED;12const conditions = status?.conditions;13let stateClassName = "rounded-full w-3 h-3 text-sm align-middle";14switch (state) {15case WorkspacePhase_Phase.RUNNING: {16stateClassName += " bg-green-500";17break;18}19case WorkspacePhase_Phase.STOPPED: {20if (conditions?.failed) {21stateClassName += " bg-red-400";22} else {23stateClassName += " bg-gray-400";24}25break;26}27case WorkspacePhase_Phase.INTERRUPTED: {28stateClassName += " bg-red-400";29break;30}31case WorkspacePhase_Phase.UNSPECIFIED: {32stateClassName += " bg-red-400";33break;34}35default: {36stateClassName += " bg-kumquat-ripe animate-pulse";37break;38}39}40return (41<div className="m-auto">42<Tooltip content={getLabel(state, conditions)}>43<div className={stateClassName} />44</Tooltip>45</div>46);47}4849export function getLabel(state: WorkspacePhase_Phase, conditions?: WorkspaceInstanceConditions) {50if (conditions?.failed) {51return "Failed";52}53const phaseStr = WorkspacePhase_Phase[state];54return phaseStr.substring(0, 1) + phaseStr.substring(1).toLocaleLowerCase();55}565758