Skip to content

Commit 51809d7

Browse files
committed
Address review comments
1 parent 8b8cf0a commit 51809d7

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

site/src/components/ServiceBanner/ServiceBannerView.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ const useStyles = makeStyles((theme) => ({
7777
}))
7878

7979
const readableForegroundColor = (backgroundColor: string): string => {
80-
const [_, __, lum] = hex.hsl(backgroundColor)
81-
if (lum > 50) {
82-
return "black"
83-
}
84-
return "white"
80+
const rgb = hex.rgb(backgroundColor)
81+
82+
// Logic taken from here:
83+
// https://github.com/casesandberg/react-color/blob/bc9a0e1dc5d11b06c511a8e02a95bd85c7129f4b/src/helpers/color.js#L56
84+
// to be consistent with the color-picker label.
85+
const yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000
86+
return yiq >= 128 ? "#000" : "#fff"
8587
}

site/src/pages/DeploySettingsPage/ServiceBannerSettingsPage.tsx

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ import { useTheme } from "@material-ui/core/styles"
2525
import FormHelperText from "@material-ui/core/FormHelperText"
2626
import Button from "@material-ui/core/Button"
2727

28-
export const Language = {
29-
messageLabel: "Message",
30-
backgroundColorLabel: "Background Color",
31-
updateBanner: "Update",
32-
previewBanner: "Preview",
33-
}
34-
3528
export interface ServiceBannerFormValues {
3629
message?: string
3730
backgroundColor?: string
@@ -109,7 +102,7 @@ const ServiceBannerSettingsPage: React.FC = () => {
109102
<Header
110103
title="Service Banner"
111104
description="Configure a banner that displays a message to all users"
112-
docsHref="https://coder.com/docs/coder-oss/latest/admin/high-availability#service-banners"
105+
docsHref="https://coder.com/docs/coder-oss/latest/admin/service-banners"
113106
/>
114107
<Badges>
115108
{isEntitled ? <EntitledBadge /> : <DisabledBadge />}
@@ -122,7 +115,6 @@ const ServiceBannerSettingsPage: React.FC = () => {
122115
<FormControlLabel
123116
control={
124117
<Switch
125-
{...getFieldHelpers("enabled")}
126118
color="primary"
127119
checked={form.values.enabled}
128120
onChange={() => {
@@ -142,7 +134,7 @@ const ServiceBannerSettingsPage: React.FC = () => {
142134
<TextField
143135
{...getFieldHelpers("message")}
144136
fullWidth
145-
label={Language.messageLabel}
137+
label="Message"
146138
variant="outlined"
147139
multiline
148140
onChange={(e) => {
@@ -162,7 +154,7 @@ const ServiceBannerSettingsPage: React.FC = () => {
162154
</Stack>
163155

164156
<Stack spacing={0}>
165-
<h3>Background Color</h3>
157+
<h3>{"Background Color"}</h3>
166158
<BlockPicker
167159
color={backgroundColor}
168160
onChange={(color) => {
@@ -197,14 +189,8 @@ const ServiceBannerSettingsPage: React.FC = () => {
197189
</Stack>
198190

199191
<Stack direction="row">
200-
<LoadingButton
201-
loading={false}
202-
// aria-disabled={!editable}
203-
// disabled={!editable}
204-
type="submit"
205-
variant="contained"
206-
>
207-
{Language.updateBanner}
192+
<LoadingButton loading={false} type="submit" variant="contained">
193+
{"Update"}
208194
</LoadingButton>
209195
</Stack>
210196
</Stack>

site/src/xServices/serviceBanner/serviceBannerXService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { displaySuccess } from "components/GlobalSnackbar/utils"
12
import { assign, createMachine } from "xstate"
23
import * as API from "../../api/api"
34
import { ServiceBanner } from "../../api/typesGenerated"
@@ -87,7 +88,7 @@ export const serviceBannerMachine = createMachine(
8788
src: "setBanner",
8889
onDone: {
8990
target: "idle",
90-
actions: ["assignBanner"],
91+
actions: ["assignBanner", "notifyUpdateBannerSuccess"],
9192
},
9293
onError: {
9394
target: "idle",
@@ -105,6 +106,9 @@ export const serviceBannerMachine = createMachine(
105106
// to find a way to do that that doesn't generate type errors.
106107
preview: (_, __) => true,
107108
}),
109+
notifyUpdateBannerSuccess: () => {
110+
displaySuccess("Successfully updated Service Banner!")
111+
},
108112
assignBanner: assign({
109113
serviceBanner: (_, event) => event.data as ServiceBanner,
110114
preview: (_, __) => false,

0 commit comments

Comments
 (0)