Skip to content
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

feat(max): Show query summary #25696

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-max-ai--thread--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-max-ai--thread--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@
}
}

.InsightDetails__breakdown {
margin-bottom: 0.5rem;
}

.InsightDetails__footer {
display: flex;
flex-wrap: wrap;
Expand Down
51 changes: 13 additions & 38 deletions frontend/src/lib/components/Cards/InsightCard/InsightDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ import {
isTrendsQuery,
isValidBreakdown,
} from '~/queries/utils'
import {
AnyPropertyFilter,
FilterLogicalOperator,
FilterType,
PropertyGroupFilter,
QueryBasedInsightModel,
} from '~/types'
import { AnyPropertyFilter, FilterLogicalOperator, PropertyGroupFilter, QueryBasedInsightModel } from '~/types'

import { PropertyKeyInfo } from '../../PropertyKeyInfo'
import { TZLabel } from '../../TZLabel'
Expand Down Expand Up @@ -253,9 +247,9 @@ function PathsSummary({ query }: { query: PathsQuery }): JSX.Element {

export function SeriesSummary({ query }: { query: InsightQueryNode }): JSX.Element {
return (
<>
<section>
<h5>Query summary</h5>
<section className="InsightDetails__query">
<div className="InsightDetails__query">
{isTrendsQuery(query) && query.trendsFilter?.formula && (
<>
<LemonRow className="InsightDetails__formula" icon={<IconCalculate />} fullWidth>
Expand Down Expand Up @@ -283,8 +277,8 @@ export function SeriesSummary({ query }: { query: InsightQueryNode }): JSX.Eleme
<i>Unavailable for this insight type.</i>
)}
</div>
</section>
</>
</div>
</section>
)
}

Expand All @@ -306,31 +300,12 @@ export function PropertiesSummary({
: properties || null

return (
<>
<section>
<h5>Filters</h5>
<section>
<div>
<CompactPropertyFiltersDisplay groupFilter={groupFilter} />
</section>
</>
)
}

export function LEGACY_FilterBasedBreakdownSummary({ filters }: { filters: Partial<FilterType> }): JSX.Element | null {
if (filters.breakdown_type == null || filters.breakdown == null) {
return null
}

const breakdownArray = Array.isArray(filters.breakdown) ? filters.breakdown : [filters.breakdown]

return (
<>
<h5>Breakdown by</h5>
<section className="InsightDetails__breakdown">
{breakdownArray.map((breakdown) => (
<BreakdownTag key={breakdown} breakdown={breakdown} breakdownType={filters.breakdown_type} />
))}
</section>
</>
</div>
</section>
)
}

Expand All @@ -342,9 +317,9 @@ export function BreakdownSummary({ query }: { query: InsightQueryNode }): JSX.El
const { breakdown_type, breakdown, breakdowns } = query.breakdownFilter

return (
<>
<section>
<h5>Breakdown by</h5>
<section className="InsightDetails__breakdown">
<div>
{Array.isArray(breakdowns)
? breakdowns.map((b) => (
<BreakdownTag key={`${b.type}-${b.property}`} breakdown={b.property} breakdownType={b.type} />
Expand All @@ -355,8 +330,8 @@ export function BreakdownSummary({ query }: { query: InsightQueryNode }): JSX.El
: [breakdown].map((b) => (
<BreakdownTag key={b} breakdown={b} breakdownType={breakdown_type} />
)))}
</section>
</>
</div>
</section>
)
}

Expand Down
32 changes: 20 additions & 12 deletions frontend/src/scenes/max/Thread.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LemonButton, Spinner } from '@posthog/lemon-ui'
import clsx from 'clsx'
import { useValues } from 'kea'
import { BreakdownSummary, PropertiesSummary, SeriesSummary } from 'lib/components/Cards/InsightCard/InsightDetails'
import { IconOpenInNew } from 'lib/lemon-ui/icons'
import React from 'react'
import { urls } from 'scenes/urls'
Expand Down Expand Up @@ -49,18 +50,25 @@ export function Thread(): JSX.Element | null {
<div className="h-96 flex">
<Query query={query} readOnly embedded />
</div>
<LemonButton
className="mt-4 w-fit"
type="primary"
to={urls.insightNew(undefined, undefined, {
kind: NodeKind.InsightVizNode,
source: message.content.answer as InsightQueryNode,
} as InsightVizNode)}
sideIcon={<IconOpenInNew />}
targetBlank
>
Open as new insight
</LemonButton>
<div className="relative mb-1">
<LemonButton
to={urls.insightNew(undefined, undefined, {
kind: NodeKind.InsightVizNode,
source: message.content.answer as InsightQueryNode,
} as InsightVizNode)}
sideIcon={<IconOpenInNew />}
size="xsmall"
targetBlank
className="absolute right-0 -top-px"
>
Open as new insight
</LemonButton>
<SeriesSummary query={query.source!} />
<div className="flex flex-wrap gap-4 mt-1 *:grow">
<PropertiesSummary properties={query.source!.properties} />
<BreakdownSummary query={query.source!} />
</div>
</div>
</Message>
)}
</React.Fragment>
Expand Down
Loading