Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(dashboards): show sharing state in the share button (#105378)

Matt Pua19972e8fe4c5
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 0615fb31023d..38b4ce57b121 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -10421,9 +10421,9 @@ snapshots:
scenes-app-notebooks-widget-views--cohort-views--light:
hash: v1.k794b7964.4d0085a9e284643ac1b101e4c32e9a36cc6b4507411086f13a3ef3a113bb6d97.f2wK3yMByUBnhBKWyAMm_dq3wxZihAXUeJbbhjiLUC8
scenes-app-notebooks-widget-views--dashboard-views--dark:
- hash: v1.k794b7964.a7c878fe0c34aafe4fe8ee585b802bec19fc85694db7d6aea4ec0ebfaf1904d3.T9jGsQP2QkUF8Xq-SxEMZEzdEDYSBjJTaXCUH6oJ484
+ hash: v1.k794b7964.d79e53323467652beeebb729e08e0b0bdf1d7b3643a23bf22e50a9edcff829f4.UTL6_ZHwNMFRp5X_glYGn-zdKUnL3X5lB_SLwgdow6A
scenes-app-notebooks-widget-views--dashboard-views--light:
- hash: v1.k794b7964.462a6bfd5eb375f20448a5947e4cd4e8e69c287b0863c80c83ca96e6844fc06d.EC5X5MSr0Dz5BifRSO9NlmCn-fZ6M9mFHgAk0xMCbxs
+ hash: v1.k794b7964.0807a31123ca41857d9d1c3bce475468288d06119c3fc655ee529edc58a1ff64.QBabN7Z6NzZTZsBiMYESuRZ4WvliSh8NeHjKA7Wm9SM
scenes-app-notebooks-widget-views--early-access-feature-views--dark:
hash: v1.k794b7964.080e4eb18a5bc5975a3796cb50f3a58e020fb5a0bd9dd5fa37c034861a8361f4.R8ZqTVM9LKrvh-VlgvnQWWlCKV9MsNffT8ovqJh6xOs
scenes-app-notebooks-widget-views--early-access-feature-views--light:
diff --git a/frontend/src/scenes/dashboard/Dashboard.tsx b/frontend/src/scenes/dashboard/Dashboard.tsx
index 260c52224f16..1e461cac26cb 100644
--- a/frontend/src/scenes/dashboard/Dashboard.tsx
+++ b/frontend/src/scenes/dashboard/Dashboard.tsx
@@ -29,7 +29,7 @@ import { teamLogic } from '../teamLogic'
import { AddInsightToDashboardModal } from './addInsightToDashboardModal/AddInsightToDashboardModal'
import { addInsightToDashboardLogic } from './addInsightToDashboardModalLogic'
import { DashboardHeader } from './DashboardHeader'
-import { DashboardPublicAccessBanner } from './DashboardPublicAccessBanner'
+import { DashboardEmbeddedShareButton } from './DashboardHeaderActions'
import { DashboardQueryScanBanner } from './DashboardQueryScanBanner'
import { DashboardRetentionBanner } from './DashboardRetentionBanner'
import { dashboardSubscribeNudgeLogic } from './dashboardSubscribeNudgeLogic'
@@ -167,7 +167,7 @@ function DashboardScene({
{placement !== DashboardPlacement.Export && (
<ScreenShotEditor screenshotKey={dashboardTileScreenshotKey(dashboard?.id)} />
)}
- <DashboardPublicAccessBanner dashboard={dashboard} placement={placement} />
+ <DashboardEmbeddedShareButton dashboard={dashboard} placement={placement} />
{dashboardFailedToLoad ? (
<InsightErrorState
diff --git a/frontend/src/scenes/dashboard/DashboardHeader.test.tsx b/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
index 2473340b3b19..100a07e68f22 100644
--- a/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
@@ -7,12 +7,13 @@ import { DashboardEventSource } from 'lib/utils/eventUsageLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
-import { AccessControlLevel, DashboardMode, DashboardType, InsightModel } from '~/types'
+import { AccessControlLevel, DashboardMode, DashboardPlacement, DashboardType, InsightModel } from '~/types'
import { useMcpToolApplyBack } from 'products/posthog_ai/frontend/api/logics'
import type { ToolStreamEvent } from 'products/posthog_ai/frontend/types/streamTypes'
import { DashboardHeader, insightIsAddedToDashboard } from './DashboardHeader'
+import { DashboardEmbeddedShareButton } from './DashboardHeaderActions'
import { DashboardLoadAction, dashboardLogic } from './dashboardLogic'
jest.mock('lib/components/FullScreen', () => ({
@@ -182,6 +183,60 @@ describe('DashboardHeader', () => {
logic.unmount()
})
+ it.each([
+ { isShared: false, active: false, empty: false },
+ { isShared: true, active: true, empty: false },
+ { isShared: true, active: true, empty: true },
+ ])(
+ 'shows the share button as active when sharing is $isShared and empty is $empty',
+ ({ isShared, active, empty }) => {
+ const dashboard = makeDashboard({
+ is_shared: isShared,
+ tiles: empty ? [] : [{ id: 1, color: null, layouts: {}, text: { body: 'Dashboard note' } }],
+ })
+ const { logic } = renderHeader({ dashboard })
+
+ const shareButton = document.querySelector('[data-attr="dashboard-share-button"]')
+
+ if (active) {
+ expect(shareButton).toHaveClass('LemonButton--active')
+ expect(shareButton).toHaveTextContent('OnSharing')
+ expect(shareButton?.querySelector('.LemonBadge--primary')).toBeVisible()
+ expect(shareButton?.querySelector('.LemonButton__icon svg')).not.toBeInTheDocument()
+ } else {
+ expect(shareButton).not.toHaveClass('LemonButton--active')
+ expect(shareButton).toHaveTextContent('Share')
+ expect(shareButton?.querySelector('.LemonBadge')).not.toBeInTheDocument()
+ expect(shareButton?.querySelector('.LemonButton__icon svg')).toBeInTheDocument()
+ }
+
+ logic.unmount()
+ }
+ )
+
+ it.each([
+ { placement: DashboardPlacement.Builtin, isShared: true, visible: true },
+ { placement: DashboardPlacement.ProjectHomepage, isShared: true, visible: true },
+ { placement: DashboardPlacement.Builtin, isShared: false, visible: false },
+ { placement: DashboardPlacement.Public, isShared: true, visible: false },
+ { placement: DashboardPlacement.Export, isShared: true, visible: false },
+ ])(
+ 'shows the embedded sharing state for $placement when sharing is $isShared',
+ ({ placement, isShared, visible }) => {
+ const dashboard = makeDashboard({ is_shared: isShared })
+
+ render(<DashboardEmbeddedShareButton dashboard={dashboard} placement={placement} />)
+
+ const shareButton = document.querySelector('[data-attr="dashboard-share-button"]')
+ if (visible) {
+ expect(shareButton).toHaveTextContent('OnSharing')
+ expect(shareButton).toHaveClass('LemonButton--active')
+ } else {
+ expect(shareButton).not.toBeInTheDocument()
+ }
+ }
+ )
+
it.each([
{
scenario: 'View mode, can edit',
diff --git a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
index 44ad553173a2..ef4a285d7cff 100644
--- a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
@@ -7,6 +7,7 @@ import { AccessControlAction } from 'lib/components/AccessControlAction'
import { Shortcut } from 'lib/components/Shortcuts/Shortcut'
import { keyBinds } from 'lib/components/Shortcuts/shortcuts'
import { FEATURE_FLAGS } from 'lib/constants'
+import { LemonBadge } from 'lib/lemon-ui/LemonBadge'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonMenu, LemonMenuItem, LemonMenuItems } from 'lib/lemon-ui/LemonMenu'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
@@ -16,7 +17,7 @@ import { Scene } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'
-import { AccessControlLevel, AccessControlResourceType } from '~/types'
+import { AccessControlLevel, AccessControlResourceType, DashboardPlacement, DashboardType } from '~/types'
import { DashboardCustomizeMenu } from 'products/dashboards/frontend/components/DashboardCustomizeMenu/DashboardCustomizeMenu'
@@ -289,33 +290,59 @@ export function FullscreenModeActions(): JSX.Element {
)
}
-export function ViewModeActions(): JSX.Element {
- const { dashboard, canEditDashboard, tiles } = useValues(dashboardLogic)
+export function DashboardShareButton({ dashboard }: { dashboard: DashboardType }): JSX.Element {
const { push } = useActions(router)
- if (!dashboard) {
- return <></>
- }
-
const sharingDisabledReason = getAccessControlDisabledReason(
AccessControlResourceType.SharingConfiguration,
AccessControlLevel.Viewer
)
+ return (
+ <LemonButton
+ type="secondary"
+ data-attr="dashboard-share-button"
+ onClick={() => push(urls.dashboardSharing(dashboard.id))}
+ size="small"
+ icon={dashboard.is_shared ? <LemonBadge content="On" size="small" /> : <IconShare fontSize="16" />}
+ active={dashboard.is_shared}
+ disabledReason={sharingDisabledReason ?? undefined}
+ >
+ {dashboard.is_shared ? 'Sharing' : 'Share'}
+ </LemonButton>
+ )
+}
+
+export function DashboardEmbeddedShareButton({
+ dashboard,
+ placement,
+}: {
+ dashboard: DashboardType | null
+ placement: DashboardPlacement
+}): JSX.Element | null {
+ if (
+ !dashboard?.is_shared ||
+ ![DashboardPlacement.ProjectHomepage, DashboardPlacement.Builtin].includes(placement)
+ ) {
+ return null
+ }
+
+ return (
+ <div className="flex justify-end mb-2">
+ <DashboardShareButton dashboard={dashboard} />
+ </div>
+ )
+}
+
+export function ViewModeActions(): JSX.Element {
+ const { dashboard, canEditDashboard, tiles } = useValues(dashboardLogic)
+ if (!dashboard) {
+ return <></>
+ }
+
return (
<>
<DashboardSubscribeButton />
- {tiles.length > 0 && (
- <LemonButton
- type="secondary"
- data-attr="dashboard-share-button"
- onClick={() => push(urls.dashboardSharing(dashboard.id))}
- size="small"
- icon={<IconShare fontSize="16" />}
- disabledReason={sharingDisabledReason ?? undefined}
- >
- Share
- </LemonButton>
- )}
+ {(tiles.length > 0 || dashboard.is_shared) && <DashboardShareButton dashboard={dashboard} />}
{canEditDashboard && tiles.length > 0 && <DashboardCustomizeButton />}
<DashboardAddTileButton />
</>
diff --git a/frontend/src/scenes/dashboard/DashboardPublicAccessBanner.test.tsx b/frontend/src/scenes/dashboard/DashboardPublicAccessBanner.test.tsx
deleted file mode 100644
index d0d728273470..000000000000
--- a/frontend/src/scenes/dashboard/DashboardPublicAccessBanner.test.tsx
+++ /dev/null
@@ -1,89 +0,0 @@
-import '@testing-library/jest-dom'
-
-import { cleanup, render, screen } from '@testing-library/react'
-
-import { AccessControlLevel, DashboardPlacement, DashboardType } from '~/types'
-
-import { DashboardPublicAccessBanner } from './DashboardPublicAccessBanner'
-
-const MOCK_DASHBOARD: DashboardType = {
- id: 5,
- name: 'Test dashboard',
- description: 'A test dashboard',
- pinned: false,
- tiles: [],
- tags: [],
- created_at: '2020-01-01T00:00:00Z',
- created_by: {
- id: 1,
- first_name: 'Test',
- last_name: 'User',
- email: '[email protected]',
- uuid: 'abc',
- distinct_id: 'test-distinct-id',
- },
- last_accessed_at: '2020-01-01T00:00:00Z',
- is_shared: false,
- deleted: false,
- creation_mode: 'default',
- user_access_level: AccessControlLevel.Editor,
- filters: {},
- variables: {},
-}
-
-function makeDashboard(overrides: Partial<DashboardType> = {}): DashboardType {
- return { ...MOCK_DASHBOARD, ...overrides }
-}
-
-function renderBanner({
- dashboard = makeDashboard({ is_shared: true }),
- placement = DashboardPlacement.Dashboard,
-}: {
- dashboard?: DashboardType
- placement?: DashboardPlacement
-} = {}): void {
- render(<DashboardPublicAccessBanner dashboard={dashboard} placement={placement} />)
-}
-
-describe('DashboardPublicAccessBanner', () => {
- afterEach(() => {
- cleanup()
- })
-
- it('shows when a standard dashboard is shared publicly', async () => {
- renderBanner()
-
- expect(
- screen.getByText(
- 'This dashboard is shared publicly. Updates you make here may be visible to anyone with the public link. Avoid adding sensitive data.'
- )
- ).toBeInTheDocument()
- expect(screen.getAllByText('Manage sharing')).toHaveLength(2)
- })
-
- it('shows for read-only team users', async () => {
- renderBanner({
- dashboard: makeDashboard({
- is_shared: true,
- user_access_level: AccessControlLevel.Viewer,
- }),
- })
-
- expect(screen.getByText(/This dashboard is shared publicly/)).toBeInTheDocument()
- })
-
- it('does not show when the dashboard is not shared', async () => {
- renderBanner({ dashboard: makeDashboard({ is_shared: false }) })
-
- expect(screen.queryByText(/This dashboard is shared publicly/)).not.toBeInTheDocument()
- })
-
- it.each([DashboardPlacement.Public, DashboardPlacement.Export])(
- 'does not show for %s placement',
- async (placement) => {
- renderBanner({ placement })
-
- expect(screen.queryByText(/This dashboard is shared publicly/)).not.toBeInTheDocument()
- }
- )
-})
diff --git a/frontend/src/scenes/dashboard/DashboardPublicAccessBanner.tsx b/frontend/src/scenes/dashboard/DashboardPublicAccessBanner.tsx
deleted file mode 100644
index f51fc88294ad..000000000000
--- a/frontend/src/scenes/dashboard/DashboardPublicAccessBanner.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import { useActions } from 'kea'
-import { router } from 'kea-router'
-
-import { LemonBanner } from '@posthog/lemon-ui'
-
-import { urls } from 'scenes/urls'
-
-import { DashboardPlacement, DashboardType } from '~/types'
-
-const DASHBOARD_PUBLIC_ACCESS_BANNER_PLACEMENTS = [
- DashboardPlacement.Dashboard,
- DashboardPlacement.ProjectHomepage,
- DashboardPlacement.Builtin,
-]
-
-export function DashboardPublicAccessBanner({
- dashboard,
- placement,
-}: {
- dashboard: DashboardType | null
- placement: DashboardPlacement
-}): JSX.Element | null {
- const { push } = useActions(router)
-
- if (!dashboard?.is_shared || !DASHBOARD_PUBLIC_ACCESS_BANNER_PLACEMENTS.includes(placement)) {
- return null
- }
-
- return (
- <LemonBanner
- type="warning"
- className="mb-4"
- dismissKey={`dashboard-public-access-banner-${dashboard.id}`}
- action={{
- children: 'Manage sharing',
- onClick: () => push(urls.dashboardSharing(dashboard.id)),
- }}
- >
- This dashboard is shared publicly. Updates you make here may be visible to anyone with the public link.
- Avoid adding sensitive data.
- </LemonBanner>
- )
-}