-
Notifications
You must be signed in to change notification settings - Fork 406
Move JS filters to Session storage #2016
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
Changes from all commits
7be60ca
63aaa84
921926e
9201b1a
2e56058
d2ec352
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we validate the session storage works in secure environments, I assume it does. But I would like to double check
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you mean by secure env?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant https, I think the browser might require and extra config. it's possible that the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * Copyright 2025 Redpanda Data, Inc. | ||
| * | ||
| * Use of this software is governed by the Business Source License | ||
| * included in the file https://github.com/redpanda-data/redpanda/blob/dev/licenses/bsl.md | ||
| * | ||
| * As of the Change Date specified in that file, in accordance with | ||
| * the Business Source License, use of this software will be governed | ||
| * by the Apache License, Version 2.0 | ||
| */ | ||
|
|
||
| import type { FilterEntry } from '../state/ui'; | ||
|
|
||
| const SESSION_STORAGE_KEY = 'topic-filters'; | ||
|
|
||
| interface TopicFiltersMap { | ||
| [topicName: string]: FilterEntry[]; | ||
| } | ||
|
|
||
| /** | ||
| * Get all filters from sessionStorage | ||
| */ | ||
| function getAllFilters(): TopicFiltersMap { | ||
| try { | ||
| const stored = sessionStorage.getItem(SESSION_STORAGE_KEY); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is sessionStorage a global variable ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a globally accessible object we can rely on |
||
| if (!stored) { | ||
| return {}; | ||
| } | ||
| return JSON.parse(stored) as TopicFiltersMap; | ||
| } catch (error) { | ||
| // biome-ignore lint/suspicious/noConsole: intentional console usage for debugging | ||
| console.warn('Failed to parse filters from sessionStorage:', error); | ||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Save all filters to sessionStorage | ||
| */ | ||
| function saveAllFilters(filters: TopicFiltersMap): void { | ||
| try { | ||
| sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(filters)); | ||
| } catch (error) { | ||
| // biome-ignore lint/suspicious/noConsole: intentional console usage for debugging | ||
| console.warn('Failed to save filters to sessionStorage:', error); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get filters for a specific topic | ||
| */ | ||
| export function getTopicFilters(topicName: string): FilterEntry[] { | ||
| const allFilters = getAllFilters(); | ||
| return allFilters[topicName] ?? []; | ||
| } | ||
|
|
||
| /** | ||
| * Set filters for a specific topic | ||
| */ | ||
| export function setTopicFilters(topicName: string, filters: FilterEntry[]): void { | ||
| const allFilters = getAllFilters(); | ||
| allFilters[topicName] = filters; | ||
| saveAllFilters(allFilters); | ||
| } | ||
|
|
||
| /** | ||
| * Clear filters for a specific topic | ||
| */ | ||
| export function clearTopicFilters(topicName: string): void { | ||
| const allFilters = getAllFilters(); | ||
| delete allFilters[topicName]; | ||
| saveAllFilters(allFilters); | ||
| } | ||
|
|
||
| /** | ||
| * Clear all filters from sessionStorage | ||
| */ | ||
| export function clearAllTopicFilters(): void { | ||
| sessionStorage.removeItem(SESSION_STORAGE_KEY); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the change was to replace the global state by sessions storage, could we use zustand to manage this global state and use the persistence layer https://redpandadata.slack.com/archives/C063X3UEWCA/p1762753166216419
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow, what is the advantage of this? Session storage is persisted per reloads and only gets erased once user close the tab. Having zustand in between does't really make sense. UX doesn't want to have any kind of persistance here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes my point is if I want to use a global state that happens to be stored in Session Storage, so maybe if there is a known pattern of handling this global state it will be easier to maintain as opposed to a solution only for this page.