diff --git a/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx b/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
index 0304a7db954b1..d472f19bd107b 100644
--- a/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
+++ b/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
@@ -1,7 +1,7 @@
import { ChartDisplayType, InsightLogicProps, InsightModel } from '~/types'
import { BindLogic } from 'kea'
import { insightLogic } from 'scenes/insights/insightLogic'
-import { InsightViz } from 'lib/components/Cards/InsightCard/InsightCard'
+import { FilterBasedCardContent } from 'lib/components/Cards/InsightCard/InsightCard'
import './ExportedInsight.scss'
import { FriendlyLogo } from '~/toolbar/assets/FriendlyLogo'
import { InsightLegend } from 'lib/components/InsightLegend/InsightLegend'
@@ -91,7 +91,11 @@ export function ExportedInsight({
)
) : (
-
+
)}
{showLegend ? (
diff --git a/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx b/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx
index c686e30e77b09..3a0161c9d3844 100644
--- a/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx
+++ b/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx
@@ -1,6 +1,5 @@
import clsx from 'clsx'
-import { BindLogic, useActions, useValues } from 'kea'
-import { capitalizeFirstLetter } from 'lib/utils'
+import { BindLogic, useValues } from 'kea'
import React, { useEffect, useState } from 'react'
import { Layout } from 'react-grid-layout'
import {
@@ -11,8 +10,6 @@ import {
InsightTimeoutState,
} from 'scenes/insights/EmptyStates'
import { insightLogic } from 'scenes/insights/insightLogic'
-import { urls } from 'scenes/urls'
-import { dashboardsModel } from '~/models/dashboardsModel'
import {
ChartDisplayType,
ChartParams,
@@ -20,36 +17,23 @@ import {
DashboardPlacement,
DashboardTile,
DashboardType,
- ExporterFormat,
FilterType,
InsightColor,
InsightLogicProps,
InsightModel,
InsightType,
} from '~/types'
-import { Splotch, SplotchColor } from 'lib/lemon-ui/Splotch'
-import { LemonButton, LemonButtonWithDropdown } from 'lib/lemon-ui/LemonButton'
-import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
-import { Link } from 'lib/lemon-ui/Link'
-import { ObjectTags } from 'lib/components/ObjectTags/ObjectTags'
import { ResizeHandle1D, ResizeHandle2D } from '../handles'
import './InsightCard.scss'
-import { InsightDetails } from './InsightDetails'
import { funnelLogic } from 'scenes/funnels/funnelLogic'
import { ActionsHorizontalBar, ActionsLineGraph, ActionsPie } from 'scenes/trends/viz'
import { DashboardInsightsTable } from 'scenes/insights/views/InsightsTable/DashboardInsightsTable'
import { Funnel } from 'scenes/funnels/Funnel'
import { RetentionContainer } from 'scenes/retention/RetentionContainer'
import { Paths } from 'scenes/paths/Paths'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { groupsModel } from '~/models/groupsModel'
-import { cohortsModel } from '~/models/cohortsModel'
-import { mathsLogic } from 'scenes/trends/mathsLogic'
import { WorldMap } from 'scenes/insights/views/WorldMap'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
-import { UserActivityIndicator } from '../../UserActivityIndicator/UserActivityIndicator'
-import { ExportButton } from 'lib/components/ExportButton/ExportButton'
import { BoldNumber } from 'scenes/insights/views/BoldNumber'
import { SpinnerOverlay } from 'lib/lemon-ui/Spinner/Spinner'
import {
@@ -59,16 +43,15 @@ import {
isRetentionFilter,
isTrendsFilter,
} from 'scenes/insights/sharedUtils'
-import { CardMeta, Resizeable } from 'lib/components/Cards/CardMeta'
-import { DashboardPrivilegeLevel, FEATURE_FLAGS } from 'lib/constants'
+import { Resizeable } from 'lib/components/Cards/CardMeta'
import { Query } from '~/queries/Query/Query'
-import { PieChartFilled } from '@ant-design/icons'
-import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { QueriesUnsupportedHere } from 'lib/components/Cards/InsightCard/QueriesUnsupportedHere'
-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { TopHeading } from 'lib/components/Cards/InsightCard/TopHeading'
-import { summarizeInsight } from 'scenes/insights/summarizeInsight'
import { QueryContext } from '~/queries/schema'
+import { InsightMeta } from './InsightMeta'
+import { dataNodeLogic, DataNodeLogicProps } from '~/queries/nodes/DataNode/dataNodeLogic'
+import { filtersToQueryNode } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
+import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/InsightViz'
+import { getCachedResults } from '~/queries/nodes/InsightViz/utils'
type DisplayedType = ChartDisplayType | 'RetentionContainer' | 'FunnelContainer' | 'PathsContainer'
@@ -173,252 +156,13 @@ export interface InsightCardProps extends Resizeable, React.HTMLAttributes
{
- /**
- * Optional callback to update height of the primary InsightMeta div. Allow for coordinating InsightViz height
- * with InsightMeta in a way that makes it possible for meta to overlay viz in expanded (InsightDetails) state.
- */
- setPrimaryHeight?: (primaryHeight: number | undefined) => void
- areDetailsShown?: boolean
- setAreDetailsShown?: React.Dispatch>
-}
-
-function InsightMeta({
- insight,
- ribbonColor,
- dashboardId,
- updateColor,
- removeFromDashboard,
- deleteWithUndo,
- refresh,
- rename,
- duplicate,
- moveToDashboard,
- setPrimaryHeight,
- areDetailsShown,
- setAreDetailsShown,
- showEditingControls = true,
- showDetailsControls = true,
- moreButtons,
-}: InsightMetaProps): JSX.Element {
- const { short_id, name, dashboards } = insight
- const { exporterResourceParams, insightProps } = useValues(insightLogic)
- const { reportDashboardItemRefreshed } = useActions(eventUsageLogic)
- const { aggregationLabel } = useValues(groupsModel)
- const { cohortsById } = useValues(cohortsModel)
- const { nameSortedDashboards } = useValues(dashboardsModel)
- const { mathDefinitions } = useValues(mathsLogic)
- const { featureFlags } = useValues(featureFlagLogic)
-
- const otherDashboards = nameSortedDashboards.filter((d) => !dashboards?.includes(d.id))
- const editable = insight.effective_privilege_level >= DashboardPrivilegeLevel.CanEdit
-
- // not all interactions are currently implemented for queries
- const allInteractionsAllowed = !insight.query
-
- const summary = summarizeInsight(insight.query, insight.filters, {
- aggregationLabel,
- cohortsById,
- mathDefinitions,
- isUsingDashboardQueries: !!featureFlags[FEATURE_FLAGS.HOGQL],
- })
-
- return (
- }
- meta={
- <>
-
-
- {name || {summary}}
-
-
-
- {!!insight.description && {insight.description}
}
- {insight.tags && insight.tags.length > 0 && }
-
- >
- }
- metaDetails={}
- samplingNotice={
- insight.filters.sampling_factor && insight.filters.sampling_factor < 1 ? (
-
-
-
- ) : null
- }
- moreButtons={
- <>
- {allInteractionsAllowed && (
- <>
-
- View
-
- {refresh && (
- {
- refresh()
- reportDashboardItemRefreshed(insight)
- }}
- fullWidth
- >
- Refresh
-
- )}
- >
- )}
- {editable && updateColor && (
- (
- updateColor(availableColor)}
- icon={
- availableColor !== InsightColor.White ? (
-
- ) : null
- }
- fullWidth
- >
- {availableColor !== InsightColor.White
- ? capitalizeFirstLetter(availableColor)
- : 'No color'}
-
- )),
- placement: 'right-start',
- fallbackPlacements: ['left-start'],
- actionable: true,
- closeParentPopoverOnClickInside: true,
- }}
- fullWidth
- >
- Set color
-
- )}
- {editable && moveToDashboard && otherDashboards.length > 0 && (
- (
- {
- moveToDashboard(otherDashboard)
- }}
- fullWidth
- >
- {otherDashboard.name || Untitled}
-
- )),
- placement: 'right-start',
- fallbackPlacements: ['left-start'],
- actionable: true,
- closeParentPopoverOnClickInside: true,
- }}
- fullWidth
- >
- Move to
-
- )}
-
- {editable && allInteractionsAllowed && (
-
- Edit
-
- )}
- {editable && (
-
- Rename
-
- )}
-
- Duplicate
-
-
- {exporterResourceParams ? (
-
- ) : null}
- {moreButtons && (
- <>
-
- {moreButtons}
- >
- )}
- {editable && (
- <>
-
- {removeFromDashboard ? (
-
- Remove from dashboard
-
- ) : allInteractionsAllowed ? (
-
- Delete insight
-
- ) : null}
- >
- )}
- >
- }
- />
- )
-}
-
function VizComponentFallback(): JSX.Element {
return Unknown insight display type
}
-export interface InsightVizProps
+export interface FilterBasedCardContentProps
extends Pick {
+ insightProps: InsightLogicProps
tooFewFunnelSteps?: boolean
invalidFunnelExclusion?: boolean
empty?: boolean
@@ -427,8 +171,9 @@ export interface InsightVizProps
context?: QueryContext
}
-export function InsightViz({
+export function FilterBasedCardContent({
insight,
+ insightProps,
loading,
setAreDetailsShown,
style,
@@ -438,10 +183,15 @@ export function InsightViz({
tooFewFunnelSteps,
invalidFunnelExclusion,
context,
-}: InsightVizProps): JSX.Element {
+}: FilterBasedCardContentProps): JSX.Element {
const displayedType = getDisplayedType(insight.filters)
const VizComponent = displayMap[displayedType]?.element || VizComponentFallback
-
+ const query = filtersToQueryNode(insight.filters)
+ const dataNodeLogicProps: DataNodeLogicProps = {
+ query,
+ key: insightVizDataNodeKey(insightProps),
+ cachedResults: getCachedResults(insightProps.cachedInsight, query),
+ }
useEffect(() => {
// If displaying a BoldNumber Trends insight, we need to fire the window resize event
// Without this, the value is only autosized before `metaPrimaryHeight` is determined, so it's wrong
@@ -456,37 +206,39 @@ export function InsightViz({
}, [style?.height])
return (
- {
- setAreDetailsShown?.(false)
- }
- : undefined
- }
- >
- {loading && }
- {tooFewFunnelSteps ? (
-
- ) : invalidFunnelExclusion ? (
-
- ) : empty ? (
-
- ) : !loading && timedOut ? (
-
- ) : apiErrored && !loading ? (
-
- ) : (
- !apiErrored &&
- )}
-
+
+ {
+ setAreDetailsShown?.(false)
+ }
+ : undefined
+ }
+ >
+ {loading && }
+ {tooFewFunnelSteps ? (
+
+ ) : invalidFunnelExclusion ? (
+
+ ) : empty ? (
+
+ ) : !loading && timedOut ? (
+
+ ) : apiErrored && !loading ? (
+
+ ) : (
+ !apiErrored &&
+ )}
+
+
)
}
@@ -613,8 +365,9 @@ function InsightCardInternal(
)}
) : (
-