Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe3aecc

Browse files
committed
Merge branch 'main' into apps
2 parents b056400 + 2b12bee commit fe3aecc

31 files changed

+337
-180
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"workspaceagent",
8383
"workspaceapp",
8484
"workspaceapps",
85+
"workspacebuilds",
8586
"wsconncache",
8687
"xerrors",
8788
"xstate",

site/can-ndjson-stream.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "can-ndjson-stream" {
2+
function ndjsonStream<TValueType>(body: ReadableStream<Uint8Array> | null): Promise<ReadableStream<TValueType>>
3+
export default ndjsonStream
4+
}

site/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"@xstate/inspect": "0.6.5",
3636
"@xstate/react": "3.0.0",
3737
"axios": "0.26.1",
38+
"can-ndjson-stream": "1.0.2",
39+
"cron-parser": "4.4.0",
3840
"cronstrue": "2.5.0",
3941
"dayjs": "1.11.2",
4042
"formik": "2.2.9",

site/src/api/api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axios, { AxiosRequestHeaders } from "axios"
2+
import ndjsonStream from "can-ndjson-stream"
23
import * as Types from "./types"
34
import { WorkspaceBuildTransition } from "./types"
45
import * as TypesGen from "./typesGenerated"
@@ -271,6 +272,20 @@ export const getWorkspaceBuildLogs = async (buildname: string): Promise<TypesGen
271272
return response.data
272273
}
273274

275+
export const streamWorkspaceBuildLogs = async (
276+
buildname: string,
277+
): Promise<ReadableStreamDefaultReader<TypesGen.ProvisionerJobLog>> => {
278+
// Axios does not support HTTP stream in the browser
279+
// https://github.com/axios/axios/issues/1474
280+
// So we are going to use window.fetch and return a "stream" reader
281+
const reader = await window
282+
.fetch(`/api/v2/workspacebuilds/${buildname}/logs?follow=true`)
283+
.then((res) => ndjsonStream<TypesGen.ProvisionerJobLog>(res.body))
284+
.then((stream) => stream.getReader())
285+
286+
return reader
287+
}
288+
274289
export const putWorkspaceExtension = async (
275290
workspaceId: string,
276291
extendWorkspaceRequest: TypesGen.PutExtendWorkspaceRequest,

site/src/components/BorderedMenu/BorderedMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const useStyles = makeStyles((theme) => ({
3131
},
3232
paperRoot: {
3333
width: "292px",
34-
border: `2px solid ${theme.palette.primary.main}`,
34+
border: `2px solid ${theme.palette.secondary.dark}`,
3535
borderRadius: 7,
36-
boxShadow: `4px 4px 0px ${fade(theme.palette.primary.main, 0.2)}`,
36+
boxShadow: `4px 4px 0px ${fade(theme.palette.secondary.dark, 0.2)}`,
3737
},
3838
}))

site/src/components/BorderedMenuRow/BorderedMenuRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ const useStyles = makeStyles((theme) => ({
7878
},
7979

8080
"&[data-status='active']": {
81-
color: theme.palette.primary.main,
81+
color: theme.palette.secondary.dark,
8282
"& .BorderedMenuRow-description": {
8383
color: theme.palette.text.primary,
8484
},
8585
"& .BorderedMenuRow-icon": {
86-
color: theme.palette.primary.main,
86+
color: theme.palette.secondary.dark,
8787
},
8888
},
8989
},

site/src/components/BuildsTable/BuildsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const useStyles = makeStyles((theme) => ({
106106
},
107107

108108
"&:focus": {
109-
outline: `1px solid ${theme.palette.primary.dark}`,
109+
outline: `1px solid ${theme.palette.secondary.dark}`,
110110
},
111111
},
112112
}))

site/src/components/ConfirmDialog/ConfirmDialog.stories.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,24 @@ InfoDialog.args = {
3636
hideCancel: true,
3737
type: "info",
3838
}
39+
40+
export const InfoDialogWithCancel = Template.bind({})
41+
InfoDialogWithCancel.args = {
42+
description: "Information can be cool!",
43+
hideCancel: false,
44+
type: "info",
45+
}
46+
47+
export const SuccessDialog = Template.bind({})
48+
SuccessDialog.args = {
49+
description: "I am successful.",
50+
hideCancel: true,
51+
type: "success",
52+
}
53+
54+
export const SuccessDialogWithCancel = Template.bind({})
55+
SuccessDialogWithCancel.args = {
56+
description: "I may be successful.",
57+
hideCancel: false,
58+
type: "success",
59+
}

site/src/components/ConfirmDialog/ConfirmDialog.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const CONFIRM_DIALOG_DEFAULTS: Record<ConfirmDialogType, ConfirmDialogTypeConfig
1919
confirmText: "OK",
2020
hideCancel: true,
2121
},
22+
success: {
23+
confirmText: "OK",
24+
hideCancel: true,
25+
},
2226
}
2327

2428
export interface ConfirmDialogProps extends Omit<DialogActionButtonsProps, "color" | "confirmDialog" | "onCancel"> {
@@ -41,40 +45,32 @@ export interface ConfirmDialogProps extends Omit<DialogActionButtonsProps, "colo
4145
readonly title: string
4246
}
4347

44-
interface StyleProps {
45-
type: ConfirmDialogType
46-
}
47-
4848
const useStyles = makeStyles((theme) => ({
49-
dialogWrapper: (props: StyleProps) => ({
49+
dialogWrapper: {
5050
"& .MuiPaper-root": {
51-
background: props.type === "info" ? theme.palette.primary.main : theme.palette.background.paper,
51+
background: theme.palette.background.paper,
5252
border: `1px solid ${theme.palette.divider}`,
5353
},
5454
"& .MuiDialogActions-spacing": {
5555
padding: `0 ${theme.spacing(3.75)}px ${theme.spacing(3.75)}px`,
5656
},
57-
}),
58-
dialogContent: (props: StyleProps) => ({
59-
color: props.type === "info" ? theme.palette.primary.contrastText : theme.palette.text.secondary,
57+
},
58+
dialogContent: {
59+
color: theme.palette.text.secondary,
6060
padding: theme.spacing(6),
6161
textAlign: "center",
62-
}),
62+
},
6363
titleText: {
6464
marginBottom: theme.spacing(3),
6565
},
66-
description: (props: StyleProps) => ({
67-
color:
68-
props.type === "info" ? fade(theme.palette.primary.contrastText, 0.75) : fade(theme.palette.text.secondary, 0.75),
66+
description: {
67+
color: fade(theme.palette.text.secondary, 0.75),
6968
lineHeight: "160%",
7069

7170
"& strong": {
72-
color:
73-
props.type === "info"
74-
? fade(theme.palette.primary.contrastText, 0.95)
75-
: fade(theme.palette.text.secondary, 0.95),
71+
color: fade(theme.palette.text.secondary, 0.95),
7672
},
77-
}),
73+
},
7874
}))
7975

8076
/**

site/src/components/Dialog/Dialog.tsx

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ export const DialogActionButtons: React.FC<DialogActionButtonsProps> = ({
126126
color={typeToColor(type)}
127127
loading={confirmLoading}
128128
type="submit"
129-
className={combineClasses([
130-
styles.dialogButton,
131-
styles.submitButton,
132-
type === "delete" ? styles.errorButton : "",
133-
])}
129+
className={combineClasses({
130+
[styles.dialogButton]: true,
131+
[styles.submitButton]: true,
132+
[styles.errorButton]: type === "delete",
133+
[styles.successButton]: type === "success",
134+
})}
134135
>
135136
{confirmText}
136137
</LoadingButton>
@@ -246,6 +247,56 @@ const useButtonStyles = makeStyles((theme) => ({
246247
},
247248
},
248249
},
250+
successButton: {
251+
"&.MuiButton-contained": {
252+
backgroundColor: theme.palette.success.main,
253+
color: theme.palette.primary.contrastText,
254+
"&:hover": {
255+
backgroundColor: darken(theme.palette.success.main, 0.3),
256+
"@media (hover: none)": {
257+
backgroundColor: "transparent",
258+
},
259+
"&.Mui-disabled": {
260+
backgroundColor: "transparent",
261+
},
262+
},
263+
"&.Mui-disabled": {
264+
backgroundColor: theme.palette.action.disabledBackground,
265+
color: fade(theme.palette.text.disabled, 0.5),
266+
},
267+
},
268+
269+
"&.MuiButton-outlined": {
270+
color: theme.palette.success.main,
271+
borderColor: theme.palette.success.main,
272+
"&:hover": {
273+
backgroundColor: fade(theme.palette.success.main, theme.palette.action.hoverOpacity),
274+
"@media (hover: none)": {
275+
backgroundColor: "transparent",
276+
},
277+
"&.Mui-disabled": {
278+
backgroundColor: "transparent",
279+
},
280+
},
281+
"&.Mui-disabled": {
282+
color: fade(theme.palette.text.disabled, 0.5),
283+
borderColor: theme.palette.action.disabled,
284+
},
285+
},
286+
287+
"&.MuiButton-text": {
288+
color: theme.palette.success.main,
289+
"&:hover": {
290+
backgroundColor: fade(theme.palette.success.main, theme.palette.action.hoverOpacity),
291+
"@media (hover: none)": {
292+
backgroundColor: "transparent",
293+
},
294+
},
295+
"&.Mui-disabled": {
296+
color: fade(theme.palette.text.disabled, 0.5),
297+
},
298+
},
299+
},
249300
}))
250301

251302
export type DialogSearchProps = Omit<OutlinedInputProps, "className" | "fullWidth" | "labelWidth" | "startAdornment">

site/src/components/Dialog/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type ConfirmDialogType = "delete" | "info"
1+
export type ConfirmDialogType = "delete" | "info" | "success"

site/src/components/EnterpriseSnackbar/EnterpriseSnackbar.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ Info.args = {
2121
open: true,
2222
message: "Hey, something happened.",
2323
}
24+
25+
export const Success = Template.bind({})
26+
Success.args = {
27+
variant: "success",
28+
open: true,
29+
message: "Hey, something good happened.",
30+
}

site/src/components/EnterpriseSnackbar/EnterpriseSnackbar.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CloseIcon from "@material-ui/icons/Close"
55
import { FC } from "react"
66
import { combineClasses } from "../../util/combineClasses"
77

8-
type EnterpriseSnackbarVariant = "error" | "info"
8+
type EnterpriseSnackbarVariant = "error" | "info" | "success"
99

1010
export interface EnterpriseSnackbarProps extends MuiSnackbarProps {
1111
/** Called when the snackbar should close, either from timeout or clicking close */
@@ -45,7 +45,7 @@ export const EnterpriseSnackbar: FC<EnterpriseSnackbarProps> = ({
4545
<div className={styles.actionWrapper}>
4646
{action}
4747
<IconButton onClick={onClose} className={styles.iconButton}>
48-
<CloseIcon className={variant === "info" ? styles.closeIcon : styles.closeIconError} />
48+
<CloseIcon className={styles.closeIcon} />
4949
</IconButton>
5050
</div>
5151
}
@@ -55,6 +55,7 @@ export const EnterpriseSnackbar: FC<EnterpriseSnackbarProps> = ({
5555
[styles.snackbarContent]: true,
5656
[styles.snackbarContentInfo]: variant === "info",
5757
[styles.snackbarContentError]: variant === "error",
58+
[styles.snackbarContentSuccess]: variant === "success",
5859
}),
5960
}}
6061
onClose={onClose}
@@ -73,12 +74,7 @@ const useStyles = makeStyles((theme) => ({
7374
closeIcon: {
7475
width: 25,
7576
height: 25,
76-
color: theme.palette.info.contrastText,
77-
},
78-
closeIconError: {
79-
width: 25,
80-
height: 25,
81-
color: theme.palette.error.contrastText,
77+
color: theme.palette.primary.contrastText,
8278
},
8379
snackbarContent: {
8480
border: `1px solid ${theme.palette.divider}`,
@@ -87,16 +83,17 @@ const useStyles = makeStyles((theme) => ({
8783
padding: `${theme.spacing(1)}px ${theme.spacing(3)}px ${theme.spacing(1)}px ${theme.spacing(2)}px`,
8884
boxShadow: theme.shadows[6],
8985
alignItems: "inherit",
86+
backgroundColor: theme.palette.background.paper,
87+
color: theme.palette.text.secondary,
9088
},
9189
snackbarContentInfo: {
92-
backgroundColor: theme.palette.info.main,
93-
// Use primary color as a highlight
90+
// Use success color as a highlight
9491
borderLeftColor: theme.palette.primary.main,
95-
color: theme.palette.info.contrastText,
9692
},
9793
snackbarContentError: {
98-
backgroundColor: theme.palette.background.paper,
9994
borderLeftColor: theme.palette.error.main,
100-
color: theme.palette.text.secondary,
95+
},
96+
snackbarContentSuccess: {
97+
borderLeftColor: theme.palette.success.main,
10198
},
10299
}))

site/src/components/GlobalSnackbar/GlobalSnackbar.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import {
1515
SnackbarEventType,
1616
} from "./utils"
1717

18+
const variantFromMsgType = (type: MsgType) => {
19+
if (type === MsgType.Error) {
20+
return "error"
21+
} else if (type === MsgType.Success) {
22+
return "success"
23+
} else {
24+
return "info"
25+
}
26+
}
27+
1828
export const GlobalSnackbar: React.FC = () => {
1929
const styles = useStyles()
2030
const [open, setOpen] = useState<boolean>(false)
@@ -63,7 +73,7 @@ export const GlobalSnackbar: React.FC = () => {
6373
return (
6474
<EnterpriseSnackbar
6575
open={open}
66-
variant={notification.msgType === MsgType.Error ? "error" : "info"}
76+
variant={variantFromMsgType(notification.msgType)}
6777
message={
6878
<div className={styles.messageWrapper}>
6979
{notification.msgType === MsgType.Error && <ErrorIcon className={styles.errorIcon} />}

site/src/components/NavbarView/NavbarView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const useStyles = makeStyles((theme) => ({
116116
content: `" "`,
117117
bottom: 0,
118118
left: theme.spacing(3),
119-
background: "#C16800",
119+
background: theme.palette.secondary.dark,
120120
right: theme.spacing(3),
121121
height: 2,
122122
position: "absolute",

site/src/components/TabSidebar/TabSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const useStyles = makeStyles((theme) => ({
6868
color: theme.palette.text.primary,
6969
},
7070
"&.active": {
71-
color: theme.palette.primary.dark,
71+
color: theme.palette.secondary.dark,
7272
},
7373

7474
"&.active, &:hover": {

site/src/components/TerminalLink/TerminalLink.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { combineClasses } from "../../util/combineClasses"
77

88
export const Language = {
99
linkText: "Open terminal",
10+
terminalTitle: "Terminal",
1011
}
1112

1213
export interface TerminalLinkProps {
@@ -25,12 +26,17 @@ export interface TerminalLinkProps {
2526
*/
2627
export const TerminalLink: FC<TerminalLinkProps> = ({ agentName, userName = "me", workspaceName, className }) => {
2728
const styles = useStyles()
29+
const href = `/${userName}/${workspaceName}${agentName ? `.${agentName}` : ""}/terminal`
2830

2931
return (
3032
<Link
31-
href={`/${userName}/${workspaceName}${agentName ? `.${agentName}` : ""}/terminal`}
33+
href={href}
3234
className={combineClasses([styles.link, className])}
3335
target="_blank"
36+
onClick={(event) => {
37+
event.preventDefault()
38+
window.open(href, Language.terminalTitle, "width=900,height=600")
39+
}}
3440
>
3541
<ComputerIcon className={styles.icon} />
3642
{Language.linkText}

0 commit comments

Comments
 (0)