Skip to content

Commit

Permalink
view/edit source even for new insights
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Oct 18, 2023
1 parent 3dc0655 commit 9aeda88
Showing 1 changed file with 80 additions and 82 deletions.
162 changes: 80 additions & 82 deletions frontend/src/scenes/insights/InsightPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
}
buttons={
<div className="flex justify-between items-center gap-2">
{hasDashboardItemId && (
<>
<More
overlay={
<More
overlay={
<>
{hasDashboardItemId && (
<>
<LemonButton
status="stealth"
Expand Down Expand Up @@ -181,80 +181,78 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
>
Share or embed
</LemonButton>
{insight.short_id && (
<>
<SubscribeButton insightShortId={insight.short_id} />
{exporterResourceParams ? (
<ExportButton
fullWidth
items={[
{
export_format: ExporterFormat.PNG,
insight: insight.id,
},
{
export_format: ExporterFormat.CSV,
export_context: exporterResourceParams,
},
]}
/>
) : null}
{isInsightVizNode(query) ? (
<LemonButton
data-attr={`${
showQueryEditor ? 'hide' : 'show'
}-insight-source`}
status="stealth"
onClick={() => {
// for an existing insight in view mode
if (
hasDashboardItemId &&
insightMode !== ItemMode.Edit
) {
// enter edit mode
setInsightMode(ItemMode.Edit, null)

// exit early if query editor doesn't need to be toggled
if (showQueryEditor !== false) {
return
}
}
toggleQueryEditorPanel()
}}
fullWidth
>
{showQueryEditor ? 'Hide source' : 'View source'}
</LemonButton>
) : null}
{hogQL && (
<LemonButton
data-attr={`edit-insight-sql`}
status="stealth"
onClick={() => {
router.actions.push(
urls.insightNew(
undefined,
undefined,
JSON.stringify({
kind: NodeKind.DataTableNode,
source: {
kind: NodeKind.HogQLQuery,
query: hogQL,
},
full: true,
} as DataTableNode)
)
)
}}
fullWidth
>
Edit SQL directly
</LemonButton>
)}
<LemonDivider />
</>
)}
</>
)}
{insight.short_id && (
<>
<SubscribeButton insightShortId={insight.short_id} />
{exporterResourceParams ? (
<ExportButton
fullWidth
items={[
{
export_format: ExporterFormat.PNG,
insight: insight.id,
},
{
export_format: ExporterFormat.CSV,
export_context: exporterResourceParams,
},
]}
/>
) : null}
</>
)}
{isInsightVizNode(query) ? (
<LemonButton
data-attr={`${showQueryEditor ? 'hide' : 'show'}-insight-source`}
status="stealth"
onClick={() => {
// for an existing insight in view mode
if (hasDashboardItemId && insightMode !== ItemMode.Edit) {
// enter edit mode
setInsightMode(ItemMode.Edit, null)

// exit early if query editor doesn't need to be toggled
if (showQueryEditor !== false) {
return
}
}
toggleQueryEditorPanel()
}}
fullWidth
>
{showQueryEditor ? 'Hide source' : 'View source'}
</LemonButton>
) : null}
{hogQL && (
<LemonButton
data-attr={`edit-insight-sql`}
status="stealth"
onClick={() => {
router.actions.push(
urls.insightNew(
undefined,
undefined,
JSON.stringify({
kind: NodeKind.DataTableNode,
source: {
kind: NodeKind.HogQLQuery,
query: hogQL,
},
full: true,
} as DataTableNode)
)
)
}}
fullWidth
>
Edit SQL directly
</LemonButton>
)}
{hasDashboardItemId && (
<>
<LemonDivider />
<LemonButton
status="danger"
onClick={() =>
Expand All @@ -272,11 +270,11 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
Delete insight
</LemonButton>
</>
}
/>
<LemonDivider vertical />
</>
)}
)}
</>
}
/>
<LemonDivider vertical />

{insightMode === ItemMode.Edit && hasDashboardItemId && (
<LemonButton type="secondary" onClick={() => setInsightMode(ItemMode.View, null)}>
Expand Down

0 comments on commit 9aeda88

Please sign in to comment.