Skip to content
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

fix: Filter throwing an error on Embedded Dashboard #21157

Merged
Merged
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
19 changes: 14 additions & 5 deletions superset-frontend/src/hooks/useTabId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,28 @@ const channel = new BroadcastChannel<TabIdChannelMessage>('tab_id_channel');

export function useTabId() {
const [tabId, setTabId] = useState<string>();
let sessionStorage: any;
let localStorage: any;

try {
localStorage = window.localStorage || {};
sessionStorage = window.sessionStorage || {};
} catch (e) {
localStorage = null;
sessionStorage = null;
}
useEffect(() => {
const updateTabId = () => {
const lastTabId = window.localStorage.getItem('last_tab_id');
const lastTabId = localStorage?.getItem('last_tab_id');
const newTabId = String(
lastTabId ? Number.parseInt(lastTabId, 10) + 1 : 1,
);
window.sessionStorage.setItem('tab_id', newTabId);
window.localStorage.setItem('last_tab_id', newTabId);
sessionStorage?.setItem('tab_id', newTabId);
localStorage?.setItem('last_tab_id', newTabId);
setTabId(newTabId);
};

const storedTabId = window.sessionStorage.getItem('tab_id');
const storedTabId = sessionStorage && sessionStorage.getItem('tab_id');
if (storedTabId) {
channel.postMessage({
type: 'REQUESTING_TAB_ID',
Expand All @@ -67,7 +76,7 @@ export function useTabId() {
}
}
};
}, [tabId]);
}, [localStorage, tabId, sessionStorage]);

return tabId;
}