: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(insights): add stickiness bar storybook story (#60137)
Sam Penningtond739b5c11922
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex f8bf8410407d..57584890a358 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -1871,7 +1871,7 @@ snapshots:filters-taxonomic-filter-headless--properties--dark:hash: v1.k794b7964.4ee695e5751c6f73e9742ab0cfeecf61b5adfe829cf3a0d49ab2877cae8b212f.jPN9l5TDgLRy9NzHenXHCU903UDg8-GdeGpf4PXt7aAfilters-taxonomic-filter-headless--properties--light:- hash: v1.k794b7964.bd715b36b456df8730e934366a35faed4556dffa881456db1272e2804047a036.IH74-bf3miZ6nC3E0bqbzIb0km4fBh97_2XubTpcmns+ hash: v1.k794b7964.7af6b884e5d826df422db99e4a99d2172f3316561a499dbe386ea098b1fc54a9.rti2DMpqC0WEtd_AtG838vQlgQMHfwjBAR4uLN_HnUkfilters-taxonomic-filter-headless--suggested-filters-with-recents--dark:hash: v1.k794b7964.c3a6cd419610bc486261efa753816547f080f00c838bde0b8720cf12067b3b22.nxBtExiDfJ3USkhV9RY1VPU_U2dGyEYCMFbhvtOcuVsfilters-taxonomic-filter-headless--suggested-filters-with-recents--light:@@ -1976,6 +1976,14 @@ snapshots:hash: v1.k794b7964.d669cc7bd939e7cd9bae4003a228e194a6c383d827feb04baf491a89dfc0b698.eD11DZ4cr8p1GMBdBaTW1doXInEVj9CIhnyMP8RNpFoinsights-insightstable--is-legend--light:hash: v1.k794b7964.d9eec920b0b2f3c9ea87c9e0d2b298bc37339217e4211d0cf1a147630f09b75d.xGcJlQO8pvoNnHyoMNZ4F58uqKh5PDg_UiGlO5bAMn8+ insights-stickinessbarchart--stacked--dark:+ hash: v1.k794b7964.bb556b544383908fa7f4f693bf22996fb380b889125d48274a1e509953448dd6.ymAf-B1_w1RKqqqbS-k4R2OpywscDSL_ZNZ0LteJNvk+ insights-stickinessbarchart--stacked--light:+ hash: v1.k794b7964.de0a45d686781ea8b3faec3faa59caa6f1b3fa212bf47cc75cd98dcc4b3c100f.6VDcPquIXsTylHH-PyGYrsPKyh8X9s884s9r2dQdkPM+ insights-stickinessbarchart--unstacked--dark:+ hash: v1.k794b7964.926b87de4cc263ef7f0de71af6a9794ac4a5d7e7241b5f6f4a22149d1d2b806d.kH54rhusBn5aNFTWpqXGVc5Q7H3OBUWZRa9Pdse_XrY+ insights-stickinessbarchart--unstacked--light:+ hash: v1.k794b7964.3a26bab454664c963aa40e43119b2cd15648e7b685f1deb5c4ac832fb09bb779.lH5oTsXozu3VrPnI8Nin3u-jerIhsSkQcQ9Yb8mtHfsinsights-stickinesslinechart--area--dark:hash: v1.k794b7964.2d8f13bdaaffd8ffd4cad37112cae92022ace61ad5761f630a70d4c9fcecc2ae.-oVvCJIPaQGhJ4H0h-HhUv5F2FhogTXDhOTz53oJ6AQinsights-stickinesslinechart--area--light:@@ -4755,7 +4763,7 @@ snapshots:scenes-app-insights-funnels--funnel-historical-trends-edit--light:hash: v1.k794b7964.fa67675b6f95f0ae9c46eb0e803f9db69702419bb4ccc2d21ea973f9fe49d9cc.Zz4siV83g7nIXf96Nfvy6eN5rRtzwO3CEmv24KSztlAscenes-app-insights-funnels--funnel-left-to-right-breakdown-edit--dark:- hash: v1.k794b7964.1df97c88a1076b096c08deccb8c4c291c13b6a4a59fb615e2d77254547381c48.gTsDByOCU_bfzNraCRF_0neMgtIfTq796QitehbRNVQ+ hash: v1.k794b7964.2a18d8ba3f9634f9d7c9ece2ad8ee2f6716706ecbb30595102d003ca8ad27184.y6n_yOa8fbdhe6yHOtjclzfTFAJ9hj0Da0VbQIhaj2Mscenes-app-insights-funnels--funnel-left-to-right-breakdown-edit--light:hash: v1.k794b7964.414326f685dca45885b93d728ae8a75c7d8b600af35d76c9512a74a27e453006.IyZ8qHUwOv6qsBYvdUR1ZsK1Md_GNFCftDGvNZj78BQscenes-app-insights-funnels--funnel-left-to-right-edit--dark:diff --git a/products/product_analytics/frontend/insights/trends/StickinessBarChart/StickinessBarChart.stories.tsx b/products/product_analytics/frontend/insights/trends/StickinessBarChart/StickinessBarChart.stories.tsxnew file mode 100644index 000000000000..19eda9e9d6a2--- /dev/null+++ b/products/product_analytics/frontend/insights/trends/StickinessBarChart/StickinessBarChart.stories.tsx@@ -0,0 +1,177 @@+import { Meta, StoryObj } from '@storybook/react'+import { BindLogic } from 'kea'+import { useState } from 'react'++import { insightLogic } from 'scenes/insights/insightLogic'++import { mswDecorator } from '~/mocks/browser'+import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'+import type { DataNodeLogicProps } from '~/queries/nodes/DataNode/dataNodeLogic'+import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/InsightViz'+import { getCachedResults } from '~/queries/nodes/InsightViz/utils'+import { type InsightLogicProps, type InsightShortId } from '~/types'++import { StickinessBarChart } from './StickinessBarChart'++type Story = StoryObj<{}>++const meta: Meta = {+ title: 'Insights/StickinessBarChart',+ component: StickinessBarChart,+ parameters: {+ layout: 'centered',+ mockDate: '2022-03-15',+ testOptions: { snapshotBrowsers: ['chromium'] },+ },+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:team_id/annotations/': {+ count: 0,+ next: null,+ previous: null,+ results: [],+ },+ },+ }),+ ],+}+export default meta++let uniqueNode = 0++function Stage({ children }: { children: React.ReactNode }): JSX.Element {+ return (+ // eslint-disable-next-line react/forbid-dom-props+ <div style={{ height: 360, width: 720, display: 'flex', flexDirection: 'column' }}>{children}</div>+ )+}++function StickinessBarChartStory({ insightFixture }: { insightFixture: any }): JSX.Element {+ const [dashboardItemId] = useState(() => `StickinessBarChartStory.${uniqueNode++}` as InsightShortId)+ const cachedInsight = { ...insightFixture, short_id: dashboardItemId }++ const insightProps: InsightLogicProps = { dashboardItemId, doNotLoad: true, cachedInsight }+ const dataNodeLogicProps: DataNodeLogicProps = {+ query: cachedInsight.query.source,+ key: insightVizDataNodeKey(insightProps),+ cachedResults: getCachedResults(cachedInsight, cachedInsight.query.source),+ doNotLoad: true,+ }++ return (+ <BindLogic logic={insightLogic} props={insightProps}>+ <BindLogic logic={dataNodeLogic} props={dataNodeLogicProps}>+ <Stage>+ <StickinessBarChart />+ </Stage>+ </BindLogic>+ </BindLogic>+ )+}++const STICKINESS_DAYS = [1, 2, 3, 4, 5, 6, 7, 8]+const STICKINESS_LABELS = STICKINESS_DAYS.map((d) => (d === 1 ? '1 day' : `${d} days`))++const ACTION = {+ id: '$pageview',+ type: 'events',+ order: 0,+ name: '$pageview',+ custom_name: null,+ math: null,+ math_property: null,+ math_group_type_index: null,+ properties: {},+}++function buildStickinessInsight({+ display,+ id,+ short_id,+ results,+}: {+ display: 'ActionsBar' | 'ActionsUnstackedBar'+ id: number+ short_id: string+ results: Array<{+ label: string+ count: number+ data: number[]+ breakdown_value?: string+ }>+}): Record<string, unknown> {+ return {+ id,+ short_id,+ name: 'Pageview stickiness',+ derived_name: 'User stickiness based on Pageview',+ filters: {},+ last_refresh: '2022-03-15T21:50:39Z',+ refreshing: false,+ saved: true,+ is_sample: false,+ description: '',+ tags: [],+ favorited: false,+ created_at: '2022-03-15T21:31:00Z',+ updated_at: '2022-03-15T21:50:39Z',+ last_modified_at: '2022-03-15T21:50:39Z',+ dashboards: [],+ dashboard_tiles: [],+ result: results.map((r) => ({+ action: ACTION,+ label: r.label,+ count: r.count,+ data: r.data,+ labels: STICKINESS_LABELS,+ days: STICKINESS_DAYS,+ breakdown_value: r.breakdown_value,+ filter: {+ date_from: '2022-03-08T00:00:00Z',+ insight: 'STICKINESS',+ interval: 'day',+ shown_as: 'Stickiness',+ },+ })),+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'StickinessQuery',+ interval: 'day',+ series: [{ event: '$pageview', kind: 'EventsNode', name: '$pageview' }],+ stickinessFilter: { display },+ version: 2,+ },+ full: true,+ },+ }+}++const BROWSER_BREAKDOWN_RESULTS = [+ { label: 'Chrome', count: 12000, data: [9500, 1800, 400, 200, 80, 10, 8, 2], breakdown_value: 'Chrome' },+ { label: 'Safari', count: 6000, data: [4800, 900, 200, 60, 30, 5, 3, 2], breakdown_value: 'Safari' },+ { label: 'Firefox', count: 2400, data: [1900, 350, 100, 30, 12, 5, 2, 1], breakdown_value: 'Firefox' },+]++const STACKED_INSIGHT = buildStickinessInsight({+ display: 'ActionsBar',+ id: 301,+ short_id: 'stickyBarStacked',+ results: BROWSER_BREAKDOWN_RESULTS,+})++export const Stacked: Story = {+ render: () => <StickinessBarChartStory insightFixture={STACKED_INSIGHT} />,+}++const UNSTACKED_INSIGHT = buildStickinessInsight({+ display: 'ActionsUnstackedBar',+ id: 302,+ short_id: 'stickyBarGrouped',+ results: BROWSER_BREAKDOWN_RESULTS,+})++export const Unstacked: Story = {+ render: () => <StickinessBarChartStory insightFixture={UNSTACKED_INSIGHT} />,+}