Skip to content

Commit 83bbea5

Browse files
committed
refactor: switch StateIndicator to BEM
1 parent f31b9df commit 83bbea5

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

src/frontend/src/pad/controls/StateIndicator.scss

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
.state-indicator {
2+
// Block properties
23
width: 100%;
34
height: 100%;
4-
55
display: inline-flex;
66
align-items: center;
77
justify-content: center;
8-
98
transition: background-color 0.3s ease;
109
color: white;
1110
font-weight: bold;
12-
1311
position: relative;
1412
box-sizing: border-box;
1513

14+
// Element
1615
&__text {
1716
text-align: center;
1817
}
1918

19+
// Modifiers for different states
2020
&--running {
2121
background-color: #2a7d2e; // Green for running
2222
}
@@ -33,6 +33,14 @@
3333
background-color: #e74c3c; // Red for stopped
3434
}
3535

36+
&--loading {
37+
background-color: #9b59b6; // Purple for loading
38+
}
39+
40+
&--unauthenticated {
41+
background-color: #34495e; // Dark blue for unauthenticated
42+
}
43+
3644
&--error {
3745
background-color: #aaaaaa; // Light gray for error
3846
}

src/frontend/src/pad/controls/StateIndicator.tsx

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,40 @@ export const StateIndicator: React.FC = () => {
1313
refetchInterval: isAuthenticated === true ? undefined : false,
1414
});
1515

16-
const getStateClassName = () => {
17-
if (isAuthLoading || isWorkspaceLoading) return 'state-indicator state-indicator--loading';
18-
if (isAuthenticated === false) return 'state-indicator state-indicator--unauthenticated';
19-
if (!workspaceState) return 'state-indicator state-indicator--unknown';
20-
21-
switch (workspaceState.status) {
22-
case 'running':
23-
return 'state-indicator state-indicator--running';
24-
case 'starting':
25-
return 'state-indicator state-indicator--starting';
26-
case 'stopping':
27-
return 'state-indicator state-indicator--stopping';
28-
case 'stopped':
29-
return 'state-indicator state-indicator--stopped';
30-
case 'error':
31-
return 'state-indicator state-indicator--error';
32-
default:
33-
return 'state-indicator state-indicator--unknown';
16+
const getState = () => {
17+
if (isAuthLoading || isWorkspaceLoading) {
18+
return { modifier: 'loading', text: 'Loading...' };
19+
}
20+
21+
if (isAuthenticated === false) {
22+
return { modifier: 'unauthenticated', text: 'Not Authenticated' };
23+
}
24+
25+
if (!workspaceState) {
26+
return { modifier: 'unknown', text: 'Unknown' };
3427
}
35-
};
36-
37-
const getStateText = () => {
38-
if (isAuthLoading || isWorkspaceLoading) return 'Loading...';
39-
if (isAuthenticated === false) return 'Not Authenticated';
40-
if (!workspaceState) return 'Unknown';
4128

4229
switch (workspaceState.status) {
4330
case 'running':
44-
return 'Running';
31+
return { modifier: 'running', text: 'Running' };
4532
case 'starting':
46-
return 'Starting';
33+
return { modifier: 'starting', text: 'Starting' };
4734
case 'stopping':
48-
return 'Stopping';
35+
return { modifier: 'stopping', text: 'Stopping' };
4936
case 'stopped':
50-
return 'Stopped';
37+
return { modifier: 'stopped', text: 'Stopped' };
5138
case 'error':
52-
return 'Error';
39+
return { modifier: 'error', text: 'Error' };
5340
default:
54-
return 'Unknown';
41+
return { modifier: 'unknown', text: 'Unknown' };
5542
}
5643
};
5744

45+
const { modifier, text } = getState();
46+
5847
return (
59-
<div className={getStateClassName()}>
60-
<div className="state-indicator__text">{getStateText()}</div>
48+
<div className={`state-indicator state-indicator--${modifier}`}>
49+
<div className="state-indicator__text">{text}</div>
6150
</div>
6251
);
6352
};

0 commit comments

Comments
 (0)