-
Notifications
You must be signed in to change notification settings - Fork 928
feat: resources card #1627
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
feat: resources card #1627
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
448070b
Set up table
presleyp 99e63e5
Format
presleyp 7b318ee
Hook up api and test - bug assigning resources
presleyp 8cfb56a
Remove debugging code
presleyp 2a3897c
Merge branch 'main' into resources/presleyp/1031
presleyp c5b60dd
Format
presleyp c4257a2
Remove unnecessary cards
presleyp be67df8
Fix test
presleyp 85a869d
Fix assignment
presleyp 1289ad2
Fix tests
presleyp abc7703
Lint
presleyp 416be20
Merge branch 'main' into resources/presleyp/1031
presleyp c300c07
Merge branch 'main' into resources/presleyp/1031
presleyp 13ba13c
Merge branch 'main' of github.com:coder/coder into resources/presleyp…
BrunoQuaresma 85c2ac8
Refactor design
BrunoQuaresma e7b1110
Refactor resources table
BrunoQuaresma f645de3
Fix tests
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,66 @@ | ||
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 React from "react" | ||
import { WorkspaceResource } from "../../api/typesGenerated" | ||
import { TableHeaderRow } from "../TableHeaders/TableHeaders" | ||
import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection" | ||
|
||
const Language = { | ||
resources: "Resources", | ||
resourceLabel: "Resource", | ||
agentsLabel: "Agents", | ||
agentLabel: "Agent", | ||
statusLabel: "Status", | ||
} | ||
|
||
interface ResourcesProps { | ||
resources?: WorkspaceResource[] | ||
getResourcesError?: Error | ||
} | ||
|
||
export const Resources: React.FC<ResourcesProps> = ({ resources, getResourcesError }) => { | ||
return ( | ||
<WorkspaceSection title={Language.resources}> | ||
{getResourcesError ? ( | ||
{ getResourcesError } | ||
) : ( | ||
<Table> | ||
<TableHead> | ||
<TableHeaderRow> | ||
<TableCell size="small">{Language.resourceLabel}</TableCell> | ||
<TableCell size="small">{Language.agentsLabel}</TableCell> | ||
</TableHeaderRow> | ||
</TableHead> | ||
<TableBody> | ||
{resources?.map((resource) => ( | ||
<TableRow key={resource.id}> | ||
<TableCell size="small">{resource.name}</TableCell> | ||
<TableCell> | ||
<Table> | ||
<TableHead> | ||
<TableHeaderRow> | ||
<TableCell size="small">{Language.agentLabel}</TableCell> | ||
<TableCell size="small">{Language.statusLabel}</TableCell> | ||
</TableHeaderRow> | ||
</TableHead> | ||
<TableBody> | ||
{resource.agents?.map((agent) => ( | ||
<TableRow key={`${resource.id}-${agent.id}`}> | ||
<TableCell size="small">{agent.name}</TableCell> | ||
<TableCell size="small">{agent.status}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
)} | ||
</WorkspaceSection> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,8 @@ import { | |
MockStoppingWorkspace, | ||
MockTemplate, | ||
MockWorkspace, | ||
MockWorkspaceAgent, | ||
MockWorkspaceAgentDisconnected, | ||
MockWorkspaceBuild, | ||
renderWithAuth, | ||
} from "../../testHelpers/renderHelpers" | ||
|
@@ -63,103 +65,122 @@ describe("Workspace Page", () => { | |
const workspaceName = screen.getByText(MockWorkspace.name) | ||
expect(workspaceName).toBeDefined() | ||
}) | ||
it("shows the status of the workspace", async () => { | ||
await renderWorkspacePage() | ||
const status = screen.getByRole("status") | ||
expect(status).toHaveTextContent("Running") | ||
}) | ||
it("requests a stop job when the user presses Stop", async () => { | ||
const stopWorkspaceMock = jest.spyOn(api, "stopWorkspace").mockResolvedValueOnce(MockWorkspaceBuild) | ||
await testButton(Language.stop, stopWorkspaceMock) | ||
}) | ||
it("requests a start job when the user presses Start", async () => { | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.json(MockStoppedWorkspace)) | ||
}), | ||
) | ||
const startWorkspaceMock = jest | ||
.spyOn(api, "startWorkspace") | ||
.mockImplementation(() => Promise.resolve(MockWorkspaceBuild)) | ||
await testButton(Language.start, startWorkspaceMock) | ||
}) | ||
it("requests a start job when the user presses Retry after trying to start", async () => { | ||
// Use a workspace that failed during start | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
...MockFailedWorkspace, | ||
latest_build: { | ||
...MockFailedWorkspace.latest_build, | ||
transition: "start", | ||
}, | ||
}), | ||
) | ||
}), | ||
) | ||
const startWorkSpaceMock = jest.spyOn(api, "startWorkspace").mockResolvedValueOnce(MockWorkspaceBuild) | ||
await testButton(Language.retry, startWorkSpaceMock) | ||
}) | ||
it("requests a stop job when the user presses Retry after trying to stop", async () => { | ||
// Use a workspace that failed during stop | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
...MockFailedWorkspace, | ||
latest_build: { | ||
...MockFailedWorkspace.latest_build, | ||
transition: "stop", | ||
}, | ||
}), | ||
) | ||
}), | ||
) | ||
const stopWorkspaceMock = jest | ||
.spyOn(api, "stopWorkspace") | ||
.mockImplementation(() => Promise.resolve(MockWorkspaceBuild)) | ||
await testButton(Language.retry, stopWorkspaceMock) | ||
}) | ||
it("requests a template when the user presses Update", async () => { | ||
const getTemplateMock = jest.spyOn(api, "getTemplate").mockResolvedValueOnce(MockTemplate) | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.json(MockOutdatedWorkspace)) | ||
}), | ||
) | ||
await testButton(Language.update, getTemplateMock) | ||
}) | ||
it("shows the Stopping status when the workspace is stopping", async () => { | ||
await testStatus(MockStoppingWorkspace, Language.stopping) | ||
}) | ||
it("shows the Stopped status when the workspace is stopped", async () => { | ||
await testStatus(MockStoppedWorkspace, Language.stopped) | ||
describe("Status", () => { | ||
it("shows the status of the workspace", async () => { | ||
await renderWorkspacePage() | ||
const status = screen.getByRole("status") | ||
expect(status).toHaveTextContent("Running") | ||
}) | ||
it("requests a stop job when the user presses Stop", async () => { | ||
const stopWorkspaceMock = jest.spyOn(api, "stopWorkspace").mockResolvedValueOnce(MockWorkspaceBuild) | ||
await testButton(Language.stop, stopWorkspaceMock) | ||
}) | ||
it("requests a start job when the user presses Start", async () => { | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.json(MockStoppedWorkspace)) | ||
}), | ||
) | ||
const startWorkspaceMock = jest | ||
.spyOn(api, "startWorkspace") | ||
.mockImplementation(() => Promise.resolve(MockWorkspaceBuild)) | ||
await testButton(Language.start, startWorkspaceMock) | ||
}) | ||
it("requests a start job when the user presses Retry after trying to start", async () => { | ||
// Use a workspace that failed during start | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
...MockFailedWorkspace, | ||
latest_build: { | ||
...MockFailedWorkspace.latest_build, | ||
transition: "start", | ||
}, | ||
}), | ||
) | ||
}), | ||
) | ||
const startWorkSpaceMock = jest.spyOn(api, "startWorkspace").mockResolvedValueOnce(MockWorkspaceBuild) | ||
await testButton(Language.retry, startWorkSpaceMock) | ||
}) | ||
it("requests a stop job when the user presses Retry after trying to stop", async () => { | ||
// Use a workspace that failed during stop | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
...MockFailedWorkspace, | ||
latest_build: { | ||
...MockFailedWorkspace.latest_build, | ||
transition: "stop", | ||
}, | ||
}), | ||
) | ||
}), | ||
) | ||
const stopWorkspaceMock = jest | ||
.spyOn(api, "stopWorkspace") | ||
.mockImplementation(() => Promise.resolve(MockWorkspaceBuild)) | ||
await testButton(Language.retry, stopWorkspaceMock) | ||
}) | ||
it("requests a template when the user presses Update", async () => { | ||
const getTemplateMock = jest.spyOn(api, "getTemplate").mockResolvedValueOnce(MockTemplate) | ||
server.use( | ||
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.json(MockOutdatedWorkspace)) | ||
}), | ||
) | ||
await testButton(Language.update, getTemplateMock) | ||
}) | ||
it("shows the Stopping status when the workspace is stopping", async () => { | ||
await testStatus(MockStoppingWorkspace, Language.stopping) | ||
}) | ||
it("shows the Stopped status when the workspace is stopped", async () => { | ||
await testStatus(MockStoppedWorkspace, Language.stopped) | ||
}) | ||
it("shows the Building status when the workspace is starting", async () => { | ||
await testStatus(MockStartingWorkspace, Language.starting) | ||
}) | ||
it("shows the Running status when the workspace is started", async () => { | ||
await testStatus(MockWorkspace, Language.started) | ||
}) | ||
it("shows the Error status when the workspace is failed or canceled", async () => { | ||
await testStatus(MockFailedWorkspace, Language.error) | ||
}) | ||
it("shows the Loading status when the workspace is canceling", async () => { | ||
await testStatus(MockCancelingWorkspace, Language.canceling) | ||
}) | ||
it("shows the Deleting status when the workspace is deleting", async () => { | ||
await testStatus(MockDeletingWorkspace, Language.deleting) | ||
}) | ||
it("shows the Deleted status when the workspace is deleted", async () => { | ||
await testStatus(MockDeletedWorkspace, Language.deleted) | ||
}) | ||
}) | ||
it("shows the Building status when the workspace is starting", async () => { | ||
await testStatus(MockStartingWorkspace, Language.starting) | ||
}) | ||
it("shows the Running status when the workspace is started", async () => { | ||
await testStatus(MockWorkspace, Language.started) | ||
}) | ||
it("shows the Error status when the workspace is failed or canceled", async () => { | ||
await testStatus(MockFailedWorkspace, Language.error) | ||
}) | ||
it("shows the Loading status when the workspace is canceling", async () => { | ||
await testStatus(MockCancelingWorkspace, Language.canceling) | ||
}) | ||
it("shows the Deleting status when the workspace is deleting", async () => { | ||
await testStatus(MockDeletingWorkspace, Language.deleting) | ||
}) | ||
it("shows the Deleted status when the workspace is deleted", async () => { | ||
await testStatus(MockDeletedWorkspace, Language.deleted) | ||
|
||
describe("Resources", () => { | ||
it("shows the status of each agent in each resource", async () => { | ||
renderWithAuth(<WorkspacePage />, { route: `/workspaces/${MockWorkspace.id}`, path: "/workspaces/:workspace" }) | ||
const agent1Names = await screen.findAllByText(MockWorkspaceAgent.name) | ||
expect(agent1Names.length).toEqual(2) | ||
const agent2Names = await screen.findAllByText(MockWorkspaceAgentDisconnected.name) | ||
expect(agent2Names.length).toEqual(2) | ||
const agent1Status = await screen.findAllByText(MockWorkspaceAgent.status) | ||
expect(agent1Status.length).toEqual(2) | ||
const agent2Status = await screen.findAllByText(MockWorkspaceAgentDisconnected.status) | ||
expect(agent2Status.length).toEqual(2) | ||
}) | ||
}) | ||
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. 🎉 |
||
it("shows the timeline build", async () => { | ||
await renderWorkspacePage() | ||
const table = await screen.findByRole("table") | ||
const rows = table.querySelectorAll("tbody > tr") | ||
expect(rows).toHaveLength(MockBuilds.length) | ||
|
||
describe("Timeline", () => { | ||
it("shows the timeline build", async () => { | ||
await renderWorkspacePage() | ||
const table = await screen.findByTestId("builds-table") | ||
const rows = table.querySelectorAll("tbody > tr") | ||
expect(rows).toHaveLength(MockBuilds.length) | ||
}) | ||
}) | ||
}) |
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.
🎉