- Notifications
You must be signed in to change notification settings - Fork928
refactor: Move schedule info to the sidebar#1665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
29 changes: 23 additions & 6 deletionssite/src/components/Workspace/Workspace.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletionssite/src/components/WorkspaceSchedule/WorkspaceSchedule.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Story } from "@storybook/react" | ||
import React from "react" | ||
import { MockWorkspace } from "../../testHelpers/renderHelpers" | ||
import { WorkspaceSchedule, WorkspaceScheduleProps } from "./WorkspaceSchedule" | ||
export default { | ||
title: "components/WorkspaceSchedule", | ||
component: WorkspaceSchedule, | ||
argTypes: {}, | ||
} | ||
const Template: Story<WorkspaceScheduleProps> = (args) => <WorkspaceSchedule {...args} /> | ||
export const Example = Template.bind({}) | ||
Example.args = { | ||
workspace: MockWorkspace, | ||
} |
118 changes: 118 additions & 0 deletionssite/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import Link from "@material-ui/core/Link" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import Typography from "@material-ui/core/Typography" | ||
import ScheduleIcon from "@material-ui/icons/Schedule" | ||
import cronstrue from "cronstrue" | ||
import dayjs from "dayjs" | ||
import duration from "dayjs/plugin/duration" | ||
import relativeTime from "dayjs/plugin/relativeTime" | ||
import React from "react" | ||
import { Workspace } from "../../api/typesGenerated" | ||
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants" | ||
import { extractTimezone, stripTimezone } from "../../util/schedule" | ||
import { Stack } from "../Stack/Stack" | ||
dayjs.extend(duration) | ||
dayjs.extend(relativeTime) | ||
const autoStartLabel = (schedule: string): string => { | ||
const prefix = "Start" | ||
if (schedule) { | ||
return `${prefix} (${extractTimezone(schedule)})` | ||
} else { | ||
return prefix | ||
} | ||
} | ||
const autoStartDisplay = (schedule: string): string => { | ||
if (schedule) { | ||
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) | ||
} | ||
return "Manual" | ||
} | ||
const autoStopDisplay = (workspace: Workspace): string => { | ||
const latest = workspace.latest_build | ||
if (!workspace.ttl || workspace.ttl < 1) { | ||
return "Manual" | ||
} | ||
if (latest.transition === "start") { | ||
const now = dayjs() | ||
const updatedAt = dayjs(latest.updated_at) | ||
const deadline = updatedAt.add(workspace.ttl / 1_000_000, "ms") | ||
if (now.isAfter(deadline)) { | ||
return "Workspace is shutting down now" | ||
} | ||
return now.to(deadline) | ||
} | ||
const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds") | ||
return `${duration.humanize()} after start` | ||
} | ||
export interface WorkspaceScheduleProps { | ||
workspace: Workspace | ||
} | ||
export const WorkspaceSchedule: React.FC<WorkspaceScheduleProps> = ({ workspace }) => { | ||
const styles = useStyles() | ||
return ( | ||
<div className={styles.schedule}> | ||
<Stack spacing={2}> | ||
<Typography variant="body1" className={styles.title}> | ||
<ScheduleIcon className={styles.scheduleIcon} /> | ||
Schedule | ||
</Typography> | ||
<div> | ||
<span className={styles.scheduleLabel}>{autoStartLabel(workspace.autostart_schedule)}</span> | ||
<span className={styles.scheduleValue}>{autoStartDisplay(workspace.autostart_schedule)}</span> | ||
</div> | ||
<div> | ||
<span className={styles.scheduleLabel}>Shutdown</span> | ||
<span className={styles.scheduleValue}>{autoStopDisplay(workspace)}</span> | ||
</div> | ||
<div> | ||
<Link className={styles.scheduleAction}>Edit schedule</Link> | ||
</div> | ||
</Stack> | ||
</div> | ||
) | ||
} | ||
const useStyles = makeStyles((theme) => ({ | ||
schedule: { | ||
fontFamily: MONOSPACE_FONT_FAMILY, | ||
}, | ||
title: { | ||
fontWeight: 600, | ||
fontFamily: "inherit", | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
scheduleIcon: { | ||
width: 16, | ||
height: 16, | ||
marginRight: theme.spacing(1), | ||
}, | ||
scheduleLabel: { | ||
fontSize: 12, | ||
textTransform: "uppercase", | ||
display: "block", | ||
fontWeight: 600, | ||
color: theme.palette.text.secondary, | ||
}, | ||
scheduleValue: { | ||
fontSize: 16, | ||
marginTop: theme.spacing(0.25), | ||
display: "inline-block", | ||
color: theme.palette.text.secondary, | ||
}, | ||
scheduleAction: { | ||
cursor: "pointer", | ||
}, | ||
})) |
55 changes: 0 additions & 55 deletionssite/src/components/WorkspaceStats/WorkspaceStats.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.