-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/url-history-issues
- Loading branch information
Showing
2 changed files
with
50 additions
and
64 deletions.
There are no files selected for viewing
107 changes: 46 additions & 61 deletions
107
web-common/src/features/dashboards/tab-bar/TabBar.svelte
This file contains 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 |
---|---|---|
@@ -1,90 +1,75 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import Chart from "@rilldata/web-common/components/icons/Chart.svelte"; | ||
import Pivot from "@rilldata/web-common/components/icons/Pivot.svelte"; | ||
import Tag from "@rilldata/web-common/components/tag/Tag.svelte"; | ||
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers"; | ||
import { getUrlForWebView } from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store"; | ||
import { behaviourEvent } from "@rilldata/web-common/metrics/initMetrics"; | ||
import { BehaviourEventMedium } from "@rilldata/web-common/metrics/service/BehaviourEventTypes"; | ||
import { | ||
MetricsEventScreenName, | ||
MetricsEventSpace, | ||
} from "@rilldata/web-common/metrics/service/MetricsTypes"; | ||
import { V1ExploreWebView } from "@rilldata/web-common/runtime-client"; | ||
import Tab from "./Tab.svelte"; | ||
import type { ComponentType } from "svelte"; | ||
export let hidePivot: boolean = false; | ||
const StateManagers = getStateManagers(); | ||
type TabName = MetricsEventScreenName.Pivot | MetricsEventScreenName.Explore; | ||
type TabData = { label: string; Icon: ComponentType; beta?: true }; | ||
const { | ||
exploreName, | ||
selectors: { | ||
pivot: { showPivot }, | ||
}, | ||
defaultExploreState, | ||
} = StateManagers; | ||
const tabs = new Map<TabName, TabData>([ | ||
[ | ||
MetricsEventScreenName.Explore, | ||
{ | ||
label: "Explore", | ||
Icon: Chart, | ||
}, | ||
], | ||
[ | ||
MetricsEventScreenName.Pivot, | ||
{ | ||
label: "Pivot", | ||
Icon: Pivot, | ||
}, | ||
], | ||
]); | ||
$: tabs = [ | ||
{ | ||
label: "Explore", | ||
Icon: Chart, | ||
beta: false, | ||
href: getUrlForWebView( | ||
$page.url, | ||
V1ExploreWebView.EXPLORE_WEB_VIEW_EXPLORE, | ||
$defaultExploreState, | ||
), | ||
}, | ||
...(hidePivot | ||
? [] | ||
: [ | ||
{ | ||
label: "Pivot", | ||
Icon: Pivot, | ||
beta: false, | ||
href: getUrlForWebView( | ||
$page.url, | ||
V1ExploreWebView.EXPLORE_WEB_VIEW_PIVOT, | ||
$defaultExploreState, | ||
), | ||
}, | ||
]), | ||
]; | ||
$: currentTabIndex = $showPivot ? 1 : 0; | ||
export let hidePivot: boolean = false; | ||
export let exploreName: string; | ||
export let onPivot = false; | ||
function handleTabChange(index: number) { | ||
if (currentTabIndex === index) return; | ||
const selectedTab = tabs[index]; | ||
$: currentTab = onPivot | ||
? MetricsEventScreenName.Pivot | ||
: MetricsEventScreenName.Explore; | ||
async function handleTabChange(tab: MetricsEventScreenName) { | ||
// We do not have behaviour events in cloud | ||
behaviourEvent?.fireNavigationEvent( | ||
$exploreName, | ||
await behaviourEvent?.fireNavigationEvent( | ||
exploreName, | ||
BehaviourEventMedium.Tab, | ||
MetricsEventSpace.Workspace, | ||
MetricsEventScreenName.Dashboard, | ||
selectedTab.label === "Pivot" | ||
? MetricsEventScreenName.Pivot | ||
: MetricsEventScreenName.Explore, | ||
tab, | ||
); | ||
} | ||
</script> | ||
|
||
<div class="mr-4"> | ||
<div class="flex gap-x-2"> | ||
{#each tabs as { label, Icon, beta, href }, i (label)} | ||
{@const selected = currentTabIndex === i} | ||
<Tab {selected} {href} on:click={() => handleTabChange(i)}> | ||
<Icon /> | ||
<div class="flex gap-x-1 items-center group"> | ||
{label} | ||
{#if beta} | ||
<Tag height={18} color={selected ? "blue" : "gray"}>BETA</Tag> | ||
{/if} | ||
</div> | ||
</Tab> | ||
{#each tabs as [tab, { label, Icon, beta }] (tab)} | ||
{#if !hidePivot || tab === MetricsEventScreenName.Explore} | ||
{@const selected = tab === currentTab} | ||
<Tab | ||
{selected} | ||
href="?view={tab}" | ||
on:click={() => handleTabChange(tab)} | ||
> | ||
<Icon /> | ||
<div class="flex gap-x-1 items-center group"> | ||
{label} | ||
{#if beta} | ||
<Tag height={18} color={selected ? "blue" : "gray"}>BETA</Tag> | ||
{/if} | ||
</div> | ||
</Tab> | ||
{/if} | ||
{/each} | ||
</div> | ||
</div> |
This file contains 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