Skip to content

Commit a071bfa

Browse files
authored
fix: Store dismissedBanner key in localStorage (#5388)
* fix: Store dismissedBanner key in localStorage * cleanup * removed comment * spelling * fixed eslint * wote test
1 parent 40a5c04 commit a071bfa

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

site/.eslintrc.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ plugins:
3030
- import
3131
- react-hooks
3232
- jest
33-
- no-storage
3433
- unicorn
3534
root: true
3635
rules:
@@ -98,7 +97,6 @@ rules:
9897
message:
9998
"Use path imports to avoid pulling in unused modules. See:
10099
https://material-ui.com/guides/minimizing-bundle-size/"
101-
no-storage/no-browser-storage: error
102100
no-unused-vars: "off"
103101
"object-curly-spacing": "off"
104102
react-hooks/exhaustive-deps: warn

site/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
"eslint-plugin-import": "2.26.0",
114114
"eslint-plugin-jest": "27.0.1",
115115
"eslint-plugin-jsx-a11y": "6.6.1",
116-
"eslint-plugin-no-storage": "1.0.2",
117116
"eslint-plugin-react": "7.31.1",
118117
"eslint-plugin-react-hooks": "4.6.0",
119118
"eslint-plugin-unicorn": "44.0.0",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { fireEvent, screen } from "@testing-library/react"
2+
import { renderWithAuth } from "testHelpers/renderHelpers"
3+
import { AccountPage } from "pages/UserSettingsPage/AccountPage/AccountPage"
4+
import i18next from "i18next"
5+
6+
const { t } = i18next
7+
8+
describe("AuthAndFrame", () => {
9+
it("sets localStorage key-value when dismissed", async () => {
10+
const localStorageMock = {
11+
...global.localStorage,
12+
getItem: jest.fn(),
13+
}
14+
global.localStorage = localStorageMock
15+
16+
// rendering a random page that is wrapped in AuthAndFrame
17+
return renderWithAuth(<AccountPage />)
18+
fireEvent.click(
19+
screen.getByRole("button", {
20+
name: t("ctas.dismissCta", { ns: "common" }),
21+
}),
22+
)
23+
expect(localStorageMock.getItem).toHaveBeenCalledWith("dismissedVersion")
24+
})
25+
})

site/src/xServices/updateCheck/updateCheckXService.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const updateCheckMachine = createMachine(
117117
dismissOrClear: {
118118
on: {
119119
DISMISS: {
120-
actions: ["assignHide"],
120+
actions: ["assignHide", "setDismissedVersion"],
121121
target: "dismissed",
122122
},
123123
CLEAR: {
@@ -141,9 +141,11 @@ export const updateCheckMachine = createMachine(
141141
assignPermissions: assign({
142142
permissions: (_, event) => event.data as Permissions,
143143
}),
144-
assignShow: assign({
145-
show: true,
146-
}),
144+
assignShow: assign((context) => ({
145+
show:
146+
localStorage.getItem("dismissedVersion") !==
147+
context.updateCheck?.version,
148+
})),
147149
assignHide: assign({
148150
show: false,
149151
}),
@@ -161,6 +163,12 @@ export const updateCheckMachine = createMachine(
161163
...context,
162164
error: undefined,
163165
})),
166+
setDismissedVersion: (context) => {
167+
if (context.updateCheck?.version) {
168+
// We use localStorage to ensure users who have dismissed the UpdateCheckBanner are not plagued by its reappearance on page reload
169+
localStorage.setItem("dismissedVersion", context.updateCheck.version)
170+
}
171+
},
164172
},
165173
guards: {
166174
canViewUpdateCheck: (context) =>

site/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6557,11 +6557,6 @@ eslint-plugin-jsx-a11y@6.6.1:
65576557
minimatch "^3.1.2"
65586558
semver "^6.3.0"
65596559

6560-
eslint-plugin-no-storage@1.0.2:
6561-
version "1.0.2"
6562-
resolved "https://registry.yarnpkg.com/eslint-plugin-no-storage/-/eslint-plugin-no-storage-1.0.2.tgz#b32b2f00c4084f8e70c6c4ea79704ffe28b6caad"
6563-
integrity sha512-INY2pA4ynTsPIb7wP6+j1QEzDx+zVZ1rZsQkC3up+TQLXsVGg3AnYSqDv/LlwR1QPfh4fDEgQ2Hg5Zxk2XxxEw==
6564-
65656560
eslint-plugin-react-hooks@4.6.0:
65666561
version "4.6.0"
65676562
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"

0 commit comments

Comments
 (0)