-
Notifications
You must be signed in to change notification settings - Fork 929
feat: Add timeline in the workspace page #1533
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
339e8fe
Add base structure
BrunoQuaresma 1355674
Merge branch 'main' of github.com:coder/coder into bq/add-build-logs
BrunoQuaresma 89c042e
Refactor table to properly show the status and times
BrunoQuaresma f9c27e0
Refresh timeline when the build is updated
BrunoQuaresma db88444
Update started at format
BrunoQuaresma c766228
Make columns fixed
BrunoQuaresma 92a7b01
Refactor duration logic
BrunoQuaresma 5876cf9
Fix tests
BrunoQuaresma 9291730
Fix tests
BrunoQuaresma 281228a
Add basic test to see if the timeline is rendered
BrunoQuaresma 2cf0e97
Add storybook
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,103 @@ | ||
import Box from "@material-ui/core/Box" | ||
import { Theme } from "@material-ui/core/styles" | ||
import Table from "@material-ui/core/Table" | ||
import TableBody from "@material-ui/core/TableBody" | ||
import TableCell from "@material-ui/core/TableCell" | ||
import TableHead from "@material-ui/core/TableHead" | ||
import TableRow from "@material-ui/core/TableRow" | ||
import useTheme from "@material-ui/styles/useTheme" | ||
import dayjs from "dayjs" | ||
import duration from "dayjs/plugin/duration" | ||
import relativeTime from "dayjs/plugin/relativeTime" | ||
import React from "react" | ||
import * as TypesGen from "../../api/typesGenerated" | ||
import { getDisplayStatus } from "../../util/workspace" | ||
import { EmptyState } from "../EmptyState/EmptyState" | ||
import { TableLoader } from "../TableLoader/TableLoader" | ||
|
||
dayjs.extend(relativeTime) | ||
dayjs.extend(duration) | ||
|
||
export const Language = { | ||
pageTitle: "Builds", | ||
usersTitle: "All users", | ||
emptyMessage: "No users found", | ||
usernameLabel: "User", | ||
suspendMenuItem: "Suspend", | ||
resetPasswordMenuItem: "Reset password", | ||
rolesLabel: "Roles", | ||
inProgressLabel: "In progress", | ||
actionLabel: "Action", | ||
durationLabel: "Duration", | ||
startedAtLabel: "Started at", | ||
statusLabel: "Status", | ||
} | ||
|
||
const getDurationInSeconds = (build: TypesGen.WorkspaceBuild) => { | ||
let display = Language.inProgressLabel | ||
|
||
if (build.job.started_at && build.job.completed_at) { | ||
const startedAt = dayjs(build.job.started_at) | ||
const completedAt = dayjs(build.job.completed_at) | ||
const diff = completedAt.diff(startedAt, "seconds") | ||
display = `${diff} seconds` | ||
} | ||
|
||
return display | ||
} | ||
|
||
export interface BuildsTableProps { | ||
builds?: TypesGen.WorkspaceBuild[] | ||
className?: string | ||
} | ||
|
||
export const BuildsTable: React.FC<BuildsTableProps> = ({ builds, className }) => { | ||
const isLoading = !builds | ||
const theme: Theme = useTheme() | ||
|
||
return ( | ||
<Table className={className}> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell width="20%">{Language.actionLabel}</TableCell> | ||
<TableCell width="20%">{Language.durationLabel}</TableCell> | ||
<TableCell width="40%">{Language.startedAtLabel}</TableCell> | ||
<TableCell width="20%">{Language.statusLabel}</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{isLoading && <TableLoader />} | ||
{builds && | ||
builds.map((b) => { | ||
const status = getDisplayStatus(theme, b) | ||
const duration = getDurationInSeconds(b) | ||
|
||
return ( | ||
<TableRow key={b.id}> | ||
<TableCell>{b.transition}</TableCell> | ||
<TableCell> | ||
<span style={{ color: theme.palette.text.secondary }}>{duration}</span> | ||
</TableCell> | ||
<TableCell> | ||
<span style={{ color: theme.palette.text.secondary }}>{new Date(b.created_at).toLocaleString()}</span> | ||
</TableCell> | ||
<TableCell> | ||
<span style={{ color: status.color }}>{status.status}</span> | ||
</TableCell> | ||
</TableRow> | ||
) | ||
})} | ||
|
||
{builds && builds.length === 0 && ( | ||
<TableRow> | ||
<TableCell colSpan={999}> | ||
<Box p={4}> | ||
<EmptyState message="No builds for this workspace" /> | ||
</Box> | ||
</TableCell> | ||
</TableRow> | ||
)} | ||
</TableBody> | ||
</Table> | ||
) | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { Theme } from "@material-ui/core/styles" | ||
import { WorkspaceBuildTransition } from "../api/types" | ||
import { WorkspaceBuild } from "../api/typesGenerated" | ||
|
||
|
@@ -47,3 +48,71 @@ export const getWorkspaceStatus = (workspaceBuild?: WorkspaceBuild): WorkspaceSt | |
return "error" | ||
} | ||
} | ||
|
||
export const getDisplayStatus = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
theme: Theme, | ||
build: WorkspaceBuild, | ||
): { | ||
color: string | ||
status: string | ||
} => { | ||
const status = getWorkspaceStatus(build) | ||
switch (status) { | ||
case undefined: | ||
return { | ||
color: theme.palette.text.secondary, | ||
status: "Loading...", | ||
} | ||
case "started": | ||
return { | ||
color: theme.palette.success.main, | ||
status: "⦿ Running", | ||
} | ||
case "starting": | ||
return { | ||
color: theme.palette.success.main, | ||
status: "⦿ Starting", | ||
} | ||
case "stopping": | ||
return { | ||
color: theme.palette.text.secondary, | ||
status: "◍ Stopping", | ||
} | ||
case "stopped": | ||
return { | ||
color: theme.palette.text.secondary, | ||
status: "◍ Stopped", | ||
} | ||
case "deleting": | ||
return { | ||
color: theme.palette.text.secondary, | ||
status: "⦸ Deleting", | ||
} | ||
case "deleted": | ||
return { | ||
color: theme.palette.text.secondary, | ||
status: "⦸ Deleted", | ||
} | ||
case "canceling": | ||
return { | ||
color: theme.palette.warning.light, | ||
status: "◍ Canceling", | ||
} | ||
case "canceled": | ||
return { | ||
color: theme.palette.text.secondary, | ||
status: "◍ Canceled", | ||
} | ||
case "error": | ||
return { | ||
color: theme.palette.error.main, | ||
status: "ⓧ Failed", | ||
} | ||
case "queued": | ||
return { | ||
color: theme.palette.text.secondary, | ||
status: "◍ Queued", | ||
} | ||
} | ||
throw new Error("unknown status " + status) | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
toLocaleString()
because it is better to have, for logs at least, the format5/17/2022, 2:06:25 PM
instead of50 seconds ago
.