-
Notifications
You must be signed in to change notification settings - Fork 953
feat(desktop): add local v1/v2 version toggle in top bar #3347
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { FEATURE_FLAGS } from "@superset/shared/constants"; | ||
| import { useFeatureFlagEnabled } from "posthog-js/react"; | ||
| import { useV2LocalOverrideStore } from "renderer/stores/v2-local-override"; | ||
|
|
||
| /** | ||
| * Returns effective v2 state: remote PostHog flag AND local override. | ||
| * Also returns the raw remote flag so the toggle can be shown conditionally. | ||
| */ | ||
| export function useIsV2CloudEnabled() { | ||
| const remoteV2Enabled = | ||
| useFeatureFlagEnabled(FEATURE_FLAGS.V2_CLOUD) ?? false; | ||
| const forceV1 = useV2LocalOverrideStore((s) => s.forceV1); | ||
|
|
||
| return { | ||
| /** The effective value — use this wherever you previously checked the flag directly. */ | ||
| isV2CloudEnabled: remoteV2Enabled && !forceV1, | ||
| /** Whether the remote PostHog flag is on (for showing the toggle). */ | ||
| isRemoteV2Enabled: remoteV2Enabled, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...es/_authenticated/_dashboard/components/TopBar/components/VersionToggle/VersionToggle.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; | ||
| import { cn } from "@superset/ui/utils"; | ||
| import { useV2LocalOverrideStore } from "renderer/stores/v2-local-override"; | ||
|
|
||
| export function VersionToggle() { | ||
| const { forceV1, toggle } = useV2LocalOverrideStore(); | ||
| const activeVersion = forceV1 ? "v1" : "v2"; | ||
|
|
||
| return ( | ||
| <Tooltip delayDuration={300}> | ||
| <TooltipTrigger asChild> | ||
| <button | ||
| type="button" | ||
| onClick={toggle} | ||
| className="no-drag flex items-center h-6 rounded-full bg-muted border border-border text-[11px] font-medium overflow-hidden transition-colors" | ||
|
Kitenite marked this conversation as resolved.
|
||
| > | ||
| <span | ||
| className={cn( | ||
| "px-2 py-0.5 rounded-full transition-colors", | ||
| activeVersion === "v1" | ||
| ? "bg-foreground text-background" | ||
| : "text-muted-foreground hover:text-foreground", | ||
| )} | ||
| > | ||
| v1 | ||
| </span> | ||
| <span | ||
| className={cn( | ||
| "px-2 py-0.5 rounded-full transition-colors", | ||
| activeVersion === "v2" | ||
| ? "bg-foreground text-background" | ||
| : "text-muted-foreground hover:text-foreground", | ||
| )} | ||
| > | ||
| v2 | ||
| </span> | ||
| </button> | ||
| </TooltipTrigger> | ||
| <TooltipContent> | ||
| {forceV1 | ||
| ? "Early Access: Switch to Superset V2" | ||
| : "Switch to Superset V1"} | ||
| </TooltipContent> | ||
|
Kitenite marked this conversation as resolved.
|
||
| </Tooltip> | ||
| ); | ||
| } | ||
1 change: 1 addition & 0 deletions
1
...erer/routes/_authenticated/_dashboard/components/TopBar/components/VersionToggle/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { VersionToggle } from "./VersionToggle"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { create } from "zustand"; | ||
| import { devtools, persist } from "zustand/middleware"; | ||
|
|
||
| interface V2LocalOverrideState { | ||
| /** When true, forces v1 mode locally even though v2 is enabled remotely. */ | ||
| forceV1: boolean; | ||
| toggle: () => void; | ||
| } | ||
|
|
||
| export const useV2LocalOverrideStore = create<V2LocalOverrideState>()( | ||
| devtools( | ||
| persist( | ||
| (set, get) => ({ | ||
| forceV1: false, | ||
| toggle: () => set({ forceV1: !get().forceV1 }), | ||
| }), | ||
| { name: "v2-local-override" }, | ||
| ), | ||
| { name: "V2LocalOverrideStore" }, | ||
| ), | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The entire
<button>has a singleonClick={toggle}. This means clicking the already-active segment also flips to the other version, which is unexpected UX for a segmented control — users expect clicking the active segment to be a no-op.Consider splitting into two independent
<button>elements that each set an explicit target state instead of toggling:This would require adding a
setForceV1(value: boolean)action alongsidetogglein the store.