-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refactor(site): replace MUI update-check snackbar with <UpdateCheckNotice/>
#27728
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6f0fac6
refactor(site): replace MUI update-check snackbar with `<UpdateCheckN…
jakehwll 591803e
🤖 fix(site): address Codex review comments on update-check notice
jakehwll 341f11e
chore: remove `as const`
jakehwll 2cc07ed
Merge branch 'main' into jakehwll/updatechecknotice-demui
jakehwll 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
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,8 +1,10 @@ | ||
| import { API } from "#/api/api"; | ||
|
|
||
| export const updateCheckQueryKey = ["updateCheck"]; | ||
|
|
||
| export const updateCheck = () => { | ||
| return { | ||
| queryKey: ["updateCheck"], | ||
| queryKey: updateCheckQueryKey, | ||
| queryFn: () => API.getUpdateCheck(), | ||
| }; | ||
| }; |
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,125 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { expect, screen, userEvent, within } from "storybook/test"; | ||
| import { | ||
| reactRouterOutlet, | ||
| reactRouterParameters, | ||
| } from "storybook-addon-remix-react-router"; | ||
| import { buildInfoKey } from "#/api/queries/buildInfo"; | ||
| import { deploymentStatsQueryKey } from "#/api/queries/deployment"; | ||
| import { updateCheckQueryKey } from "#/api/queries/updateCheck"; | ||
| import type { UpdateCheckResponse } from "#/api/typesGenerated"; | ||
| import { | ||
| MockBuildInfo, | ||
| MockDeploymentStats, | ||
| MockNoPermissions, | ||
| MockPermissions, | ||
| MockUpdateCheck, | ||
| MockUserMember, | ||
| MockUserOwner, | ||
| } from "#/testHelpers/entities"; | ||
| import { pixelWithTablet } from "#/testHelpers/pixel"; | ||
| import { | ||
| withAuthProvider, | ||
| withDashboardProvider, | ||
| withProxyProvider, | ||
| } from "#/testHelpers/storybook"; | ||
| import { DashboardFullPage, DashboardLayout } from "./DashboardLayout"; | ||
|
|
||
| const outdatedUpdateCheck: UpdateCheckResponse = { | ||
| ...MockUpdateCheck, | ||
| current: false, | ||
| version: "v0.12.9", | ||
| url: "https://github.com/coder/coder/releases/tag/v0.12.9", | ||
| }; | ||
|
|
||
| const pageContent = ( | ||
| <DashboardFullPage className="p-6"> | ||
| <h1>Workspaces</h1> | ||
| <p>Page content rendered in the dashboard outlet.</p> | ||
| </DashboardFullPage> | ||
| ); | ||
|
|
||
| const meta: Meta<typeof DashboardLayout> = { | ||
| title: "modules/dashboard/DashboardLayout", | ||
| component: DashboardLayout, | ||
| decorators: [withAuthProvider, withDashboardProvider, withProxyProvider()], | ||
| parameters: { | ||
| layout: "fullscreen", | ||
| pixel: { matrix: pixelWithTablet }, | ||
| user: MockUserOwner, | ||
| permissions: MockPermissions, | ||
| reactRouter: reactRouterParameters({ | ||
| location: { path: "/" }, | ||
| routing: reactRouterOutlet({ path: "/" }, pageContent), | ||
| }), | ||
| queries: [ | ||
| { key: buildInfoKey, data: MockBuildInfo }, | ||
| { key: updateCheckQueryKey, data: MockUpdateCheck }, | ||
| { key: deploymentStatsQueryKey, data: MockDeploymentStats }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof DashboardLayout>; | ||
|
|
||
| export const Default: Story = { | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = within(canvasElement); | ||
| await expect( | ||
| canvas.getByRole("heading", { name: "Workspaces" }), | ||
| ).toBeVisible(); | ||
| await expect( | ||
| canvas.getByRole("link", { name: "Skip to main content" }), | ||
| ).toBeInTheDocument(); | ||
| }, | ||
| }; | ||
|
|
||
| export const ForMember: Story = { | ||
| parameters: { | ||
| user: MockUserMember, | ||
| permissions: MockNoPermissions, | ||
| }, | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = within(canvasElement); | ||
| await expect( | ||
| canvas.getByRole("heading", { name: "Workspaces" }), | ||
| ).toBeVisible(); | ||
| await expect( | ||
| screen.queryByTestId("update-check-notice"), | ||
| ).not.toBeInTheDocument(); | ||
| }, | ||
| }; | ||
|
|
||
| export const UpdateAvailable: Story = { | ||
| parameters: { | ||
| queries: [ | ||
| { key: buildInfoKey, data: MockBuildInfo }, | ||
| { key: updateCheckQueryKey, data: outdatedUpdateCheck }, | ||
| { key: deploymentStatsQueryKey, data: MockDeploymentStats }, | ||
| ], | ||
| }, | ||
| beforeEach: () => { | ||
| localStorage.removeItem("dismissedVersion"); | ||
| }, | ||
| play: async () => { | ||
| const notice = await screen.findByTestId("update-check-notice"); | ||
| await expect(notice).toBeVisible(); | ||
| await expect( | ||
| screen.getByText(/Coder v0\.12\.9 is now available/), | ||
| ).toBeVisible(); | ||
| }, | ||
| }; | ||
|
|
||
| export const SkipToMainContent: Story = { | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = within(canvasElement); | ||
| const skipLink = canvas.getByRole("link", { | ||
| name: "Skip to main content", | ||
| }); | ||
| const main = canvas.getByRole("main"); | ||
|
|
||
| await userEvent.click(skipLink); | ||
| await expect(main).toHaveFocus(); | ||
| }, | ||
| }; | ||
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
47 changes: 47 additions & 0 deletions
47
site/src/modules/dashboard/UpdateCheckNotice/UpdateCheckNotice.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,47 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { expect, fn, userEvent, within } from "storybook/test"; | ||
| import { UpdateCheckNotice } from "./UpdateCheckNotice"; | ||
|
|
||
| const meta: Meta<typeof UpdateCheckNotice> = { | ||
| title: "modules/dashboard/UpdateCheckNotice", | ||
| component: UpdateCheckNotice, | ||
| args: { | ||
| version: "v0.12.9", | ||
| releaseNotesUrl: "https://github.com/coder/coder/releases/tag/v0.12.9", | ||
| onDismiss: fn(), | ||
| aboveDeploymentBanner: true, | ||
| }, | ||
| parameters: { | ||
| layout: "fullscreen", | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof UpdateCheckNotice>; | ||
|
|
||
| export const AboveDeploymentBanner: Story = { | ||
| play: async ({ canvasElement, args }) => { | ||
| const canvas = within(canvasElement); | ||
| await expect( | ||
| canvas.getByText(/Coder v0\.12\.9 is now available/), | ||
| ).toBeVisible(); | ||
| await expect( | ||
| canvas.getByRole("link", { name: "release notes" }), | ||
| ).toHaveAttribute( | ||
| "href", | ||
| "https://github.com/coder/coder/releases/tag/v0.12.9", | ||
| ); | ||
| await expect( | ||
| canvas.getByRole("link", { name: "upgrade instructions" }), | ||
| ).toBeVisible(); | ||
|
|
||
| await userEvent.click(canvas.getByRole("button", { name: "Dismiss" })); | ||
| await expect(args.onDismiss).toHaveBeenCalled(); | ||
| }, | ||
| }; | ||
|
|
||
| export const WithoutDeploymentBanner: Story = { | ||
| args: { | ||
| aboveDeploymentBanner: false, | ||
| }, | ||
| }; |
66 changes: 66 additions & 0 deletions
66
site/src/modules/dashboard/UpdateCheckNotice/UpdateCheckNotice.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,66 @@ | ||
| import { InfoIcon, XIcon } from "lucide-react"; | ||
| import type { FC } from "react"; | ||
| import { Button } from "#/components/Button/Button"; | ||
| import { cn } from "#/utils/cn"; | ||
| import { docs } from "#/utils/docs"; | ||
|
|
||
| type UpdateCheckNoticeProps = { | ||
| version: string; | ||
| releaseNotesUrl: string; | ||
| onDismiss: () => void; | ||
| aboveDeploymentBanner?: boolean; | ||
| }; | ||
|
|
||
| export const UpdateCheckNotice: FC<UpdateCheckNoticeProps> = ({ | ||
| version, | ||
| releaseNotesUrl, | ||
| onDismiss, | ||
| aboveDeploymentBanner = false, | ||
| }) => { | ||
| return ( | ||
| <div | ||
| data-testid="update-check-notice" | ||
| role="status" | ||
| className={cn( | ||
| "fixed right-6 z-50 flex max-w-[420px] items-start gap-4 rounded border border-solid border-highlight-sky bg-surface-primary p-4 text-sm text-content-primary shadow", | ||
| // 60px keeps a 24px gap above the 36px deployment banner. | ||
| aboveDeploymentBanner ? "bottom-[60px]" : "bottom-6", | ||
| )} | ||
| > | ||
| <InfoIcon className="mt-0.5 size-icon-sm shrink-0 text-highlight-sky" /> | ||
| <div className="flex flex-col gap-1"> | ||
| <p className="m-0 font-semibold">Coder {version} is now available. </p> | ||
| <p className="m-0 flex-1 leading-5"> | ||
| View the{" "} | ||
| <a | ||
| href={releaseNotesUrl} | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| className="text-content-link underline hover:no-underline" | ||
| > | ||
| release notes | ||
| </a>{" "} | ||
| and{" "} | ||
| <a | ||
| href={docs("/install/upgrade")} | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| className="text-content-link underline hover:no-underline" | ||
| > | ||
| upgrade instructions | ||
| </a>{" "} | ||
| for more information. | ||
| </p> | ||
| </div> | ||
| <Button | ||
| aria-label="Dismiss" | ||
| size="icon" | ||
| variant="subtle" | ||
| onClick={onDismiss} | ||
| className="-m-2" | ||
| > | ||
| <XIcon /> | ||
| </Button> | ||
| </div> | ||
| ); | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.