Skip to content
Open
Changes from all commits
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
18 changes: 17 additions & 1 deletion web/oss/src/components/SidebarBanners/state/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const PRIORITY_ORDER: Record<BannerType, number> = {
trial: 3, // Lowest priority - show after other banners are dismissed
}

/**
* Maximum number of dismissible sidebar banners a user should have to clear.
* Apply this before dismissal filtering so older changelog entries do not
* backfill the sidebar after each close.
*/
export const MAX_DISMISSIBLE_SIDEBAR_BANNERS = 2

/**
* Persisted atom for dismissed banner IDs.
* Uses localStorage to remember which banners the user has dismissed.
Expand Down Expand Up @@ -107,8 +114,17 @@ export const activeBannersAtom = atom((get) => {
export const visibleBannersAtom = atom((get) => {
const allBanners = get(activeBannersAtom)
const dismissedIds = get(dismissedBannerIdsAtom)
const sortedBanners = [...allBanners].sort(
(a, b) => PRIORITY_ORDER[a.type] - PRIORITY_ORDER[b.type],
)

const cappedDismissibleBanners = sortedBanners
.filter((banner) => banner.dismissible)
.slice(0, MAX_DISMISSIBLE_SIDEBAR_BANNERS)

const nonDismissibleBanners = sortedBanners.filter((banner) => !banner.dismissible)

return allBanners
return [...cappedDismissibleBanners, ...nonDismissibleBanners]
.filter((banner) => !dismissedIds.includes(banner.id))
.sort((a, b) => PRIORITY_ORDER[a.type] - PRIORITY_ORDER[b.type])
})
Expand Down
Loading