Skip to content

Commit e7c6c3a

Browse files
authored
chore: Update bgAdmin to inline derived values, compatible with recent API changes (#1927)
1 parent f9ded59 commit e7c6c3a

File tree

1 file changed

+27
-41
lines changed

1 file changed

+27
-41
lines changed

packages/background-charm-service/bgAdmin.tsx

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,6 @@ function fromNow(then: Date): string {
8585
return `${Math.floor(then.getFullYear() - now.getFullYear())} `;
8686
}
8787

88-
function StatusIcon(
89-
{ status, disabledAt }: { status?: string; disabledAt?: number },
90-
) {
91-
let color;
92-
let title = status;
93-
const SUCCESS = `#4CAF50`;
94-
const UNKNOWN = `#FFC107`;
95-
const DISABLED = `#9E9E9E`;
96-
const FAILURE = `#F44336`;
97-
if (!disabledAt) {
98-
if (status === "Success") {
99-
color = SUCCESS;
100-
title = "Running";
101-
} else {
102-
color = UNKNOWN;
103-
}
104-
} else {
105-
if (status === DISABLED_VIA_UI) {
106-
color = DISABLED;
107-
} else {
108-
color = FAILURE;
109-
}
110-
}
111-
return (
112-
<div
113-
title={title}
114-
style={{
115-
backgroundColor: color,
116-
width: "20px",
117-
borderRadius: "20px",
118-
}}
119-
>
120-
</div>
121-
);
122-
}
123-
12488
const getRenderData = lift((
12589
charm: BGCharmEntry,
12690
) => {
@@ -152,7 +116,6 @@ Last run ${lastRunDate ? fromNow(lastRunDate) : "never"} ${
152116
}`;
153117

154118
return {
155-
status,
156119
statusDisplay,
157120
disabledAt,
158121
details,
@@ -217,8 +180,6 @@ export default recipe<InputSchema, ResultSchema>(
217180
<div className="bg-charm-container">
218181
{charms.map((charm) => {
219182
const {
220-
status,
221-
disabledAt,
222183
details,
223184
name,
224185
integration,
@@ -231,8 +192,33 @@ export default recipe<InputSchema, ResultSchema>(
231192
onClick={toggleCharm({ charm })}
232193
type="button"
233194
>
234-
<StatusIcon status={status} disabledAt={disabledAt}>
235-
</StatusIcon>
195+
{derive(charm, ({ status, disabledAt }) => {
196+
const SUCCESS = `#4CAF50`;
197+
const UNKNOWN = `#FFC107`;
198+
const DISABLED = `#9E9E9E`;
199+
const FAILURE = `#F44336`;
200+
const statusColor = disabledAt === 0
201+
? status === "Success" ? SUCCESS : UNKNOWN
202+
: status === DISABLED_VIA_UI
203+
? DISABLED
204+
: FAILURE;
205+
const statusTitle =
206+
disabledAt === 0 && status === "Success"
207+
? "Running"
208+
: status;
209+
return (
210+
<div
211+
title={statusTitle}
212+
style={{
213+
backgroundColor: statusColor,
214+
width: "20px",
215+
height: "20px",
216+
borderRadius: "20px",
217+
}}
218+
>
219+
</div>
220+
);
221+
})}
236222
</button>
237223
</div>
238224
<div className="name ellipsis" title={details}>

0 commit comments

Comments
 (0)