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