Skip to content

Commit

Permalink
feat(ui): Make view source a switch (#20070)
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie authored Feb 1, 2024
1 parent 3180726 commit 3e3a2f4
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions frontend/src/scenes/insights/InsightPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { UserActivityIndicator } from 'lib/components/UserActivityIndicator/User
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { More } from 'lib/lemon-ui/LemonButton/More'
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { LemonSwitch } from 'lib/lemon-ui/LemonSwitch'
import { deleteWithUndo } from 'lib/utils/deleteWithUndo'
import { useState } from 'react'
import { NewDashboardModal } from 'scenes/dashboard/NewDashboardModal'
Expand Down Expand Up @@ -164,48 +165,53 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
) : null}
</>
)}
<LemonButton
<LemonDivider />
<LemonSwitch
data-attr={`${showQueryEditor ? 'hide' : 'show'}-insight-source`}
onClick={() => {
className="px-2 py-1"
checked={showQueryEditor}
onChange={() => {
// 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) {
if (showQueryEditor) {
return
}
}
toggleQueryEditorPanel()
}}
fullWidth
>
{showQueryEditor ? 'Hide source' : 'View source'}
</LemonButton>
label="View Source"
/>
{hogQL && (
<LemonButton
data-attr="edit-insight-sql"
onClick={() => {
router.actions.push(
urls.insightNew(
undefined,
undefined,
JSON.stringify({
kind: NodeKind.DataTableNode,
source: {
kind: NodeKind.HogQLQuery,
query: hogQL,
},
full: true,
} as DataTableNode)
<>
<LemonDivider />
<LemonButton
data-attr="edit-insight-sql"
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>
}}
fullWidth
>
Edit SQL directly
</LemonButton>
</>
)}
{hasDashboardItemId && (
<>
Expand Down

0 comments on commit 3e3a2f4

Please sign in to comment.