You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2024/07/16 14:22:45 UTC
(superset) 01/01: Clear redux localStorage on logout
This is an automated email from the ASF dual-hosted git repository.
diegopucci pushed a commit to branch geido/chore/clear-sql-sqlab
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 087ac712c2fe241b3caf70f196cb16fcee17df10
Author: Diego Pucci <di...@gmail.com>
AuthorDate: Tue Jul 16 17:22:31 2024 +0300
Clear redux localStorage on logout
---
.../src/features/home/RightMenu.test.tsx | 27 ++++++++++++++++++++++
superset-frontend/src/features/home/RightMenu.tsx | 6 ++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/features/home/RightMenu.test.tsx b/superset-frontend/src/features/home/RightMenu.test.tsx
index bb4a40a534..50c0ca3259 100644
--- a/superset-frontend/src/features/home/RightMenu.test.tsx
+++ b/superset-frontend/src/features/home/RightMenu.test.tsx
@@ -346,3 +346,30 @@ test('If there is NOT a DB with allow_file_upload set as True the option should
(await screen.findByText('Upload CSV to database')).closest('a'),
).not.toBeInTheDocument();
});
+
+test('Logs out and clears local storage item redux', async () => {
+ const mockedProps = createProps();
+ resetUseSelectorMock();
+ render(<RightMenu {...mockedProps} />, {
+ useRedux: true,
+ useQueryParams: true,
+ useRouter: true,
+ });
+
+ // Set an item in local storage to test if it gets cleared
+ localStorage.setItem('redux', JSON.stringify({ test: 'test' }));
+ expect(localStorage.getItem('redux')).not.toBeNull();
+
+ userEvent.hover(await screen.findByText(/Settings/i));
+
+ // Simulate user clicking the logout button
+ await waitFor(() => {
+ const logoutButton = screen.getByText('Logout');
+ userEvent.click(logoutButton);
+ });
+
+ // Wait for local storage to be cleared
+ await waitFor(() => {
+ expect(localStorage.getItem('redux')).toBeNull();
+ });
+});
diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx
index 93e03f5ed5..99a1398366 100644
--- a/superset-frontend/src/features/home/RightMenu.tsx
+++ b/superset-frontend/src/features/home/RightMenu.tsx
@@ -348,6 +348,10 @@ const RightMenu = ({
const handleDatabaseAdd = () => setQuery({ databaseAdded: true });
+ const handleLogout = () => {
+ localStorage.removeItem('redux');
+ };
+
const theme = useTheme();
return (
@@ -512,7 +516,7 @@ const RightMenu = ({
<a href={navbarRight.user_info_url}>{t('Info')}</a>
</Menu.Item>
)}
- <Menu.Item key="logout">
+ <Menu.Item key="logout" onClick={handleLogout}>
<a href={navbarRight.user_logout_url}>{t('Logout')}</a>
</Menu.Item>
</Menu.ItemGroup>,