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(editor-3001): info tab #26844

Merged
merged 24 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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.
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.
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.
13 changes: 10 additions & 3 deletions frontend/src/layout/navigation-3000/Navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
.Sidebar3000 {
--sidebar-slider-padding: 0.125rem;
--sidebar-horizontal-padding: 0.5rem;
--sidebar-row-height: 2.5rem;
--sidebar-row-height: 3rem;
--sidebar-background: var(--bg-3000);

position: relative;
Expand Down Expand Up @@ -533,8 +533,6 @@

position: relative;
display: flex;
flex-direction: column;
justify-content: center;
width: 100%;
height: 100%;
color: inherit;
Expand All @@ -549,7 +547,9 @@
}

.SidebarListItem__link {
flex-direction: column;
row-gap: 1px;
justify-content: center;
padding: 0 var(--sidebar-horizontal-padding) 0 var(--sidebar-list-item-inset);
color: inherit !important; // Disable link color
.SidebarListItem[aria-disabled='true'] & {
Expand All @@ -558,8 +558,12 @@
}

.SidebarListItem__button {
flex-direction: row;
gap: 0.25rem;
row-gap: 1px;
align-items: center;
padding: 0 var(--sidebar-horizontal-padding) 0 var(--sidebar-list-item-inset);
font-size: 1.125rem; // Make icons bigger
color: inherit !important; // Disable link color
cursor: pointer;

Expand All @@ -569,6 +573,9 @@
}

.SidebarListItem__rename {
flex-direction: column;
justify-content: center;

// Pseudo-elements don't work on inputs, so we use a wrapper div
background: var(--bg-light);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ function SidebarListItem({ item, validateName, active, style }: SidebarListItemP
if (isItemClickable(item)) {
content = (
<li className="SidebarListItem__button" onClick={item.onClick}>
{item.icon}
<h5>{item.name}</h5>
</li>
)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/layout/navigation-3000/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ export interface TentativeListItem {
export interface ButtonListItem extends BasicListItem {
key: '__button__'
onClick: () => void
icon?: JSX.Element
}
6 changes: 4 additions & 2 deletions frontend/src/lib/monaco/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as monaco from 'monaco-editor'
import { useEffect, useMemo, useRef, useState } from 'react'

import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { AnyDataNode, HogLanguage } from '~/queries/schema'
import { AnyDataNode, HogLanguage, HogQLMetadataResponse } from '~/queries/schema'

if (loader) {
loader.config({ monaco })
Expand All @@ -32,7 +32,7 @@ export interface CodeEditorProps extends Omit<EditorProps, 'loading' | 'theme'>
sourceQuery?: AnyDataNode
globals?: Record<string, any>
schema?: Record<string, any> | null

onMetadata?: (metadata: HogQLMetadataResponse) => void
onError?: (error: string | null, isValidView: boolean) => void
}
let codeEditorIndex = 0
Expand Down Expand Up @@ -121,6 +121,7 @@ export function CodeEditor({
sourceQuery,
schema,
onError,
onMetadata,
...editorProps
}: CodeEditorProps): JSX.Element {
const { isDarkModeOn } = useValues(themeLogic)
Expand All @@ -140,6 +141,7 @@ export function CodeEditor({
monaco: monaco,
editor: editor,
onError,
onMetadata,
})
useMountedLogic(builtCodeEditorLogic)

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/monaco/codeEditorLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface CodeEditorLogicProps {
globals?: Record<string, any>
multitab?: boolean
onError?: (error: string | null, isValidView: boolean) => void
onMetadata?: (metadata: HogQLMetadataResponse) => void
}

export const codeEditorLogic = kea<codeEditorLogicType>([
Expand Down Expand Up @@ -100,6 +101,7 @@ export const codeEditorLogic = kea<codeEditorLogicType>([
variables,
})
breakpoint()
props.onMetadata?.(response)
return [query, response]
},
},
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7265,6 +7265,12 @@
"query": {
"type": "string"
},
"table_names": {
"items": {
"type": "string"
},
"type": "array"
},
"warnings": {
"items": {
"$ref": "#/definitions/HogQLNotice"
Expand Down Expand Up @@ -9426,6 +9432,12 @@
"query": {
"type": "string"
},
"table_names": {
"items": {
"type": "string"
},
"type": "array"
},
"warnings": {
"items": {
"$ref": "#/definitions/HogQLNotice"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export interface HogQLMetadataResponse {
warnings: HogQLNotice[]
notices: HogQLNotice[]
query_status?: never
table_names?: string[]
}

export type AutocompleteCompletionItemKind =
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/scenes/data-warehouse/editor/OutputPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ import { ChartDisplayType, ExporterFormat } from '~/types'
import { dataWarehouseViewsLogic } from '../saved_queries/dataWarehouseViewsLogic'
import { multitabEditorLogic } from './multitabEditorLogic'
import { outputPaneLogic, OutputTab } from './outputPaneLogic'
import { InfoTab } from './OutputPaneTabs/InfoTab'

export function OutputPane(): JSX.Element {
const { activeTab } = useValues(outputPaneLogic)
const { setActiveTab } = useActions(outputPaneLogic)
const { variablesForInsight } = useValues(variablesLogic)

const { editingView, sourceQuery, exportContext, isValidView, error } = useValues(multitabEditorLogic)
const { editingView, sourceQuery, exportContext, isValidView, error, editorKey } = useValues(multitabEditorLogic)
const { saveAsInsight, saveAsView, setSourceQuery, runQuery } = useActions(multitabEditorLogic)
const { isDarkModeOn } = useValues(themeLogic)
const { response, responseLoading, responseError } = useValues(dataNodeLogic)
Expand Down Expand Up @@ -130,6 +131,10 @@ export function OutputPane(): JSX.Element {
)
}

if (activeTab === OutputTab.Info) {
return <InfoTab codeEditorKey={editorKey} />
}

return null
}

Expand All @@ -153,6 +158,10 @@ export function OutputPane(): JSX.Element {
key: OutputTab.Visualization,
label: 'Visualization',
},
{
key: OutputTab.Info,
label: 'Info',
},
]}
/>
<div className="flex gap-4">
Expand Down Expand Up @@ -214,7 +223,7 @@ export function OutputPane(): JSX.Element {
</LemonButton>
</div>
</div>
<div className="flex flex-1 relative bg-dark justify-center items-center">
<div className="flex flex-1 relative bg-dark">
<Content />
</div>
</div>
Expand Down
101 changes: 101 additions & 0 deletions frontend/src/scenes/data-warehouse/editor/OutputPaneTabs/InfoTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { LemonButton, Tooltip } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { LemonTable } from 'lib/lemon-ui/LemonTable'

import { multitabEditorLogic } from '../multitabEditorLogic'
import { infoTabLogic } from './infoTabLogic'

interface InfoTabProps {
codeEditorKey: string
}

export function InfoTab({ codeEditorKey }: InfoTabProps): JSX.Element {
const { sourceTableItems } = useValues(infoTabLogic({ codeEditorKey: codeEditorKey }))
const { editingView, isEditingMaterializedView } = useValues(multitabEditorLogic)
const { runDataWarehouseSavedQuery } = useActions(multitabEditorLogic)

return (
<div className="flex flex-col flex-1 m-4 gap-4">
<div>
<h3>Materialization</h3>
<div>
{isEditingMaterializedView ? (
<div>
{editingView?.last_run_at ? (
`Last run at ${editingView?.last_run_at}`
) : (
<div>
<span>Materialization scheduled</span>
</div>
)}
<LemonButton
onClick={() => editingView && runDataWarehouseSavedQuery(editingView.id)}
className="mt-2"
type="secondary"
>
Run now
</LemonButton>
</div>
) : (
<LemonButton
onClick={() => editingView && runDataWarehouseSavedQuery(editingView.id)}
type="primary"
disabledReason={editingView ? undefined : 'You must save the view first'}
>
Materialize
</LemonButton>
)}
</div>
</div>
<div>
<h3>Dependencies</h3>
<p className="text-muted">
Dependencies are tables that this query uses. See when a source or materialized table was last run.
</p>
</div>
<LemonTable
columns={[
{
key: 'Name',
title: 'Name',
render: (_, { name }) => name,
},
{
key: 'Type',
title: 'Type',
render: (_, { type }) => type,
},
{
key: 'Status',
title: 'Status',
render: (_, { type, status }) => {
if (type === 'source') {
return (
<Tooltip title="This is a source table, so it doesn't have a status">
<span className="text-muted">N/A</span>
</Tooltip>
)
}
return status
},
},
{
key: 'Last run at',
title: 'Last run at',
render: (_, { type, last_run_at }) => {
if (type === 'source') {
return (
<Tooltip title="This is a source table, so it is never run">
<span className="text-muted">N/A</span>
</Tooltip>
)
}
return last_run_at
},
},
]}
dataSource={sourceTableItems}
/>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { connect, kea, path, props, selectors } from 'kea'
import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import { dataWarehouseViewsLogic } from 'scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic'

import { multitabEditorLogic } from '../multitabEditorLogic'
import type { infoTabLogicType } from './infoTabLogicType'

export interface InfoTableRow {
name: string
type: 'source' | 'table'
status?: string
last_run_at?: string
}

interface InfoTabLogicProps {
codeEditorKey: string
}

export const infoTabLogic = kea<infoTabLogicType>([
path(['data-warehouse', 'editor', 'outputPaneTabs', 'infoTabLogic']),
props({} as InfoTabLogicProps),
EDsCODE marked this conversation as resolved.
Show resolved Hide resolved
connect((props: InfoTabLogicProps) => ({
values: [
multitabEditorLogic({ key: props.codeEditorKey }),
['metadata'],
databaseTableListLogic,
['posthogTablesMap', 'dataWarehouseTablesMap'],
dataWarehouseViewsLogic,
['dataWarehouseSavedQueryMap'],
],
})),
selectors({
sourceTableItems: [
(s) => [s.metadata, s.dataWarehouseTablesMap, s.posthogTablesMap, s.dataWarehouseSavedQueryMap],
(metadata, dataWarehouseTablesMap, posthogTablesMap, dataWarehouseSavedQueryMap) => {
if (!metadata) {
return []
}
return metadata.table_names.map((table_name) => {

Check failure on line 39 in frontend/src/scenes/data-warehouse/editor/OutputPaneTabs/infoTabLogic.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

'metadata.table_names' is possibly 'undefined'.
let table = dataWarehouseSavedQueryMap[table_name]
if (table) {
return {
name: table_name,
type: 'table',
status: table.status,
last_run_at: table.last_run_at || 'never',
}
}

table = dataWarehouseTablesMap[table_name] || posthogTablesMap[table_name]

Check failure on line 50 in frontend/src/scenes/data-warehouse/editor/OutputPaneTabs/infoTabLogic.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Type 'DatabaseSchemaDataWarehouseTable' is missing the following properties from type 'DataWarehouseSavedQuery': query, columns
return {
name: table_name,
type: 'source',
status: undefined,
last_run_at: undefined,
}
})
},
],
}),
])
10 changes: 8 additions & 2 deletions frontend/src/scenes/data-warehouse/editor/QueryWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function QueryWindow(): JSX.Element {
})

const { allTabs, activeModelUri, queryInput, editingView, sourceQuery } = useValues(logic)
const { selectTab, deleteTab, createTab, setQueryInput, runQuery, setError, setIsValidView } = useActions(logic)
const { selectTab, deleteTab, createTab, setQueryInput, runQuery, setError, setIsValidView, setMetadata } =
useActions(logic)

return (
<div className="flex flex-1 flex-col h-full">
Expand All @@ -50,7 +51,9 @@ export function QueryWindow(): JSX.Element {
/>
{editingView && (
<div className="h-7 bg-warning-highlight p-1">
<span> Editing view "{editingView.name}"</span>
<span>
Editing {editingView.status ? 'materialized view' : 'view'} "{editingView.name}"
</span>
</div>
)}
<QueryPane
Expand All @@ -76,6 +79,9 @@ export function QueryWindow(): JSX.Element {
setError(error)
setIsValidView(isValidView)
},
onMetadata: (metadata) => {
setMetadata(metadata)
},
}}
/>
<BindLogic logic={multitabEditorLogic} props={{ key: codeEditorKey, monaco, editor }}>
Expand Down
Loading
Loading