Skip to content
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
8 changes: 8 additions & 0 deletions frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,13 @@
onEnterEditModeFromEdge?: (event: React.MouseEvent<HTMLDivElement>, edge: EditModeEdge) => void
/** Called when the user mousedowns on the card (drag handle) in view mode to enter edit mode. */
onDragHandleMouseDown?: React.MouseEventHandler<HTMLDivElement>
/** Project the insight belongs to, when that is not the current project. The card's links then open it there. */
projectId?: number
/** Shown above the title, for a card that has to name where its insight comes from. */
contextHeading?: JSX.Element | null
}

function InsightCardInternal(

Check warning on line 232 in frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx

View workflow job for this annotation

GitHub Actions / Frontend formatting

lint:complexity

`InsightCardInternal` has cyclomatic complexity 19 (warn >10)
{
tile,
insight,
Expand Down Expand Up @@ -262,6 +266,8 @@
filtersOverride,
variablesOverride,
children,
projectId,
contextHeading,
breakdownColorOverride: _breakdownColorOverride,
dataColorThemeId: _dataColorThemeId,
surveyOpportunity,
Expand Down Expand Up @@ -347,7 +353,7 @@
const sharedView = isSharedView()

// Empty states that completely replace the Query component.
const BlockingEmptyState = (() => {

Check warning on line 356 in frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx

View workflow job for this annotation

GitHub Actions / Frontend formatting

lint:complexity

`<anonymous>` has cyclomatic complexity 12 (warn >10)
// Check for access denied - use the same logic as other components
const canViewInsight = insight?.user_access_level
? accessLevelSatisfied(
Expand Down Expand Up @@ -465,6 +471,8 @@
<InsightMeta
tile={tile}
insight={insight}
projectId={projectId}
contextHeading={contextHeading}
ribbonColor={ribbonColor}
dashboardId={dashboardId}
canEditDashboard={canEditDashboard}
Expand Down
66 changes: 42 additions & 24 deletions frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
| 'placement'
| 'surveyOpportunity'
| 'showCreateAnomalyAlertButton'
| 'projectId'
| 'contextHeading'
> {
/** Called when the user mousedowns on the card meta (drag handle) in view mode to enter edit mode. */
onDragHandleMouseDown?: React.MouseEventHandler<HTMLDivElement>
Expand All @@ -133,7 +135,7 @@
onCreateAnomalyAlert?: () => void
}

export function InsightMeta({

Check warning on line 138 in frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx

View workflow job for this annotation

GitHub Actions / Frontend formatting

lint:complexity

`InsightMeta` has cyclomatic complexity 118 (warn >10)
tile,
insight,
ribbonColor,
Expand Down Expand Up @@ -167,6 +169,8 @@
onCreateAlert,
onEditAlert,
onCreateAnomalyAlert,
projectId,
contextHeading,
}: InsightMetaProps): JSX.Element {
const { short_id, name, next_allowed_client_refresh: nextAllowedClientRefresh } = insight
const tileFiltersOverride = tile?.filters_overrides
Expand Down Expand Up @@ -450,15 +454,16 @@
: undefined

// Carries the dashboard's filters and variables, so the link opens exactly what the tile shows
const insightViewUrl = urls.insightView(
short_id,
dashboardId,
variablesOverride,
filtersOverride,
tileFiltersOverride
// A card showing another project's insight must link into that project, not the current one.
const inInsightProject = (path: string): string => (projectId ? urls.project(projectId, path) : path)
const insightViewUrl = inInsightProject(
urls.insightView(short_id, dashboardId, variablesOverride, filtersOverride, tileFiltersOverride)
)
const copyInsightLink = (): void => {
void copyToClipboard(urls.absolute(urls.currentProject(insightViewUrl)), 'insight link')
void copyToClipboard(
urls.absolute(projectId ? insightViewUrl : urls.currentProject(insightViewUrl)),
'insight link'
)
}

return (
Expand All @@ -472,7 +477,16 @@
areDetailsShown={areDetailsShown}
detailsTooltip="Show insight details, such as creator, last edit, and applied filters."
onMouseDown={onDragHandleMouseDown}
topHeading={topHeadingEl}
topHeading={
contextHeading ? (
<span className="flex items-center gap-2 min-w-0">
{contextHeading}
{topHeadingEl}
</span>
) : (
topHeadingEl
)
}
popoverTopHeading={popoverTopHeadingEl}
content={
<InsightMetaContent
Expand Down Expand Up @@ -531,40 +545,44 @@
{canEditInsight && (
<>
<LemonButton
to={
to={inInsightProject(
isDataVisualizationNode(insight.query)
? urls.sqlEditor({
insightShortId: short_id,
dashboard: dashboardId ?? undefined,
})
: urls.insightEdit(short_id, dashboardId)
}
)}
fullWidth
{...getOverrideWarningPropsForButton(filtersOverride, variablesOverride)}
>
Edit
</LemonButton>
<LemonButton onClick={rename} fullWidth>
Rename
</LemonButton>
{rename && (
<LemonButton onClick={rename} fullWidth>
Rename
</LemonButton>
)}
{tile && (
<LemonButton onClick={setOverride} fullWidth>
Set override
</LemonButton>
)}
</>
)}
<LemonButton
onClick={duplicate}
fullWidth
data-attr={
dashboardId
? 'duplicate-insight-from-dashboard'
: 'duplicate-insight-from-card-list-view'
}
>
Duplicate
</LemonButton>
{duplicate && (
<LemonButton
onClick={duplicate}
fullWidth
data-attr={
dashboardId
? 'duplicate-insight-from-dashboard'
: 'duplicate-insight-from-card-list-view'
}
>
Duplicate
</LemonButton>
)}
{showDashboardAlertsMenuItem && insight.id ? (
<LemonButton
onClick={() => {
Expand Down Expand Up @@ -836,7 +854,7 @@
)
}

export function InsightMetaContent({

Check warning on line 857 in frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx

View workflow job for this annotation

GitHub Actions / Frontend formatting

lint:complexity

`InsightMetaContent` has cyclomatic complexity 23 (warn >10)
title,
fallbackTitle,
description,
Expand Down
Loading