Skip to content

chore(site): remove update check service #10355

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 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use isVisible
  • Loading branch information
BrunoQuaresma committed Oct 20, 2023
commit e7b47ac7cbb6c7087c9c01c62f4df3822027aeca
20 changes: 14 additions & 6 deletions site/src/components/Dashboard/DashboardLayout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { renderWithAuth } from "testHelpers/renderHelpers";
import { DashboardLayout } from "./DashboardLayout";
import * as API from "api/api";
import { screen } from "@testing-library/react";
import { rest } from "msw";
import { server } from "testHelpers/server";

test("Show the new Coder version notification", async () => {
jest.spyOn(API, "getUpdateCheck").mockResolvedValue({
current: false,
version: "v0.12.9",
url: "https://github.com/coder/coder/releases/tag/v0.12.9",
});
server.use(
rest.get("/api/v2/updatecheck", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
current: false,
version: "v0.12.9",
url: "https://github.com/coder/coder/releases/tag/v0.12.9",
}),
);
}),
);
renderWithAuth(<DashboardLayout />, {
children: [{ element: <h1>Test page</h1> }],
});
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/Dashboard/DashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const DashboardLayout: FC = () => {

<Snackbar
data-testid="update-check-snackbar"
open={updateCheck.state === "show"}
open={updateCheck.isVisible}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
Expand Down
12 changes: 6 additions & 6 deletions site/src/components/Dashboard/useUpdateCheck.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ it("is dismissed when does not have permission to see it", () => {
const { result } = renderHook(() => useUpdateCheck(false), {
wrapper: createWrapper(),
});
expect(result.current.state).toBe("hide");
expect(result.current.isVisible).toBeFalsy();
});

it("is dismissed when it is already using current version", async () => {
Expand All @@ -41,7 +41,7 @@ it("is dismissed when it is already using current version", async () => {
});

await waitFor(() => {
expect(result.current.state).toBe("hide");
expect(result.current.isVisible).toBeFalsy();
});
});

Expand All @@ -63,7 +63,7 @@ it("is dismissed when it was dismissed previously", async () => {
});

await waitFor(() => {
expect(result.current.state).toBe("hide");
expect(result.current.isVisible).toBeFalsy();
});
});

Expand All @@ -84,7 +84,7 @@ it("shows when has permission and is outdated", async () => {
});

await waitFor(() => {
expect(result.current.state).toBe("show");
expect(result.current.isVisible).toBeTruthy();
});
});

Expand All @@ -105,15 +105,15 @@ it("shows when has permission and is outdated", async () => {
});

await waitFor(() => {
expect(result.current.state).toBe("show");
expect(result.current.isVisible).toBeTruthy();
});

act(() => {
result.current.dismiss();
});

await waitFor(() => {
expect(result.current.state).toBe("hide");
expect(result.current.isVisible).toBeFalsy();
});
expect(localStorage.getItem("dismissedVersion")).toEqual(
MockUpdateCheck.version,
Expand Down
10 changes: 4 additions & 6 deletions site/src/components/Dashboard/useUpdateCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { updateCheck } from "api/queries/updateCheck";
import { useMemo, useState } from "react";
import { useQuery } from "react-query";

type UpdateCheckState = "show" | "hide";

export const useUpdateCheck = (enabled: boolean) => {
const [dismissedVersion, setDismissedVersion] = useState(() =>
getDismissedVersionOnLocal(),
Expand All @@ -13,14 +11,14 @@ export const useUpdateCheck = (enabled: boolean) => {
enabled,
});

const state: UpdateCheckState = useMemo(() => {
const isVisible: boolean = useMemo(() => {
if (!updateCheckQuery.data) {
return "hide";
return false;
}

const isNotDismissed = dismissedVersion !== updateCheckQuery.data.version;
const isOutdated = !updateCheckQuery.data.current;
return isNotDismissed && isOutdated ? "show" : "hide";
return isNotDismissed && isOutdated ? true : false;
}, [dismissedVersion, updateCheckQuery.data]);

const dismiss = () => {
Expand All @@ -34,7 +32,7 @@ export const useUpdateCheck = (enabled: boolean) => {
};

return {
state,
isVisible,
dismiss,
data: updateCheckQuery.data,
};
Expand Down