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

chore(editor-3000): extract datavizlogic #26266

Merged
merged 65 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
276296d
working with consolidated logic
EDsCODE Oct 10, 2024
260cece
UI mvp
EDsCODE Oct 11, 2024
15004bb
Merge branch 'master' into dw-editor-layout
EDsCODE Oct 17, 2024
2fed1ec
move behind flag
EDsCODE Oct 18, 2024
b2b2953
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
67014b7
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
f9082d8
fix prettier
EDsCODE Oct 18, 2024
32588f4
Merge branch 'dw-editor-layout' of github.com:PostHog/posthog into dw…
EDsCODE Oct 18, 2024
985c750
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
ba316e8
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
5e47389
fix prettier
EDsCODE Oct 18, 2024
cd55bac
Merge branch 'dw-editor-layout' of github.com:PostHog/posthog into dw…
EDsCODE Oct 18, 2024
7aa0d80
editor sizing logic import
EDsCODE Oct 18, 2024
d86da7e
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
0009be7
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
2b74633
Merge branch 'master' into dw-editor-layout
EDsCODE Nov 5, 2024
59d533d
merge
EDsCODE Nov 5, 2024
faeece1
Merge branch 'master' into dw-editor-layout
EDsCODE Nov 5, 2024
9072267
ported over tab logic
EDsCODE Nov 6, 2024
37fdc29
working query results
EDsCODE Nov 7, 2024
bae8cbe
merge master
EDsCODE Nov 7, 2024
2a25955
Update UI snapshots for `chromium` (2)
github-actions[bot] Nov 7, 2024
5294ee1
fix styling
EDsCODE Nov 7, 2024
b8c982e
Merge branch 'dw-editor-layout' of github.com:PostHog/posthog into dw…
EDsCODE Nov 7, 2024
9343d24
merge main
EDsCODE Nov 7, 2024
eb016dc
restore some styles for now
EDsCODE Nov 7, 2024
a008e95
refactor logic
EDsCODE Nov 8, 2024
b19619c
add state updaet
EDsCODE Nov 8, 2024
8f82a65
saving view
EDsCODE Nov 8, 2024
a465cdc
remove flag from alt logic
EDsCODE Nov 11, 2024
8756f45
merge main
EDsCODE Nov 11, 2024
673bd16
add export
EDsCODE Nov 11, 2024
2bc978b
types
EDsCODE Nov 11, 2024
14a443b
types
EDsCODE Nov 12, 2024
352e838
fix logics
EDsCODE Nov 12, 2024
3c868b5
restore errors
EDsCODE Nov 13, 2024
c589212
use existing sidebar
EDsCODE Nov 13, 2024
5d9ccf5
type
EDsCODE Nov 14, 2024
306c41b
Merge branch 'master' into dw-editor-logic-refactor
EDsCODE Nov 14, 2024
086ad9a
Merge branch 'dw-editor-logic-refactor' into dw-sidebar-integration
EDsCODE Nov 14, 2024
2c345f2
search, sources, sidebar overlay
EDsCODE Nov 14, 2024
1728a86
Merge branch 'master' into dw-editor-logic-refactor
EDsCODE Nov 14, 2024
ab92a89
Merge branch 'dw-editor-logic-refactor' into dw-sidebar-integration
EDsCODE Nov 14, 2024
853f0c5
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 14, 2024
426d5ef
typing
EDsCODE Nov 14, 2024
fab29e8
Merge branch 'dw-sidebar-integration' of github.com:PostHog/posthog i…
EDsCODE Nov 14, 2024
fa1cc97
edit view
EDsCODE Nov 14, 2024
b6e8c91
loading and style
EDsCODE Nov 14, 2024
ab914bb
create/edit view logic
EDsCODE Nov 15, 2024
b2de0ee
update toasts
EDsCODE Nov 15, 2024
ddfc325
merge main
EDsCODE Nov 15, 2024
7f261dc
remove navbar button handling
EDsCODE Nov 15, 2024
a2f759a
restore logic
EDsCODE Nov 18, 2024
b02a159
refactor logic: remove insightlogic dependencies from datavizlogic
EDsCODE Nov 18, 2024
3caf611
fix type
EDsCODE Nov 19, 2024
03c8c07
Merge branch 'master' into dw-sidebar-integration
EDsCODE Nov 19, 2024
e03969b
Merge branch 'dw-sidebar-integration' into dw-editor-visualization
EDsCODE Nov 19, 2024
5e4dbbf
address comments
EDsCODE Nov 19, 2024
14e38d0
Merge branch 'dw-editor-visualization' of github.com:PostHog/posthog …
EDsCODE Nov 19, 2024
a397150
merge main
EDsCODE Nov 19, 2024
a36651f
edit test
EDsCODE Nov 19, 2024
661eb29
Merge branch 'master' into dw-editor-visualization
EDsCODE Nov 19, 2024
4f48573
Merge branch 'master' into dw-editor-visualization
EDsCODE Nov 22, 2024
2570268
Merge branch 'master' into dw-editor-visualization
EDsCODE Nov 26, 2024
02f4268
Merge branch 'master' into dw-editor-visualization
EDsCODE Nov 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const variablesLogic = kea<variablesLogicType>([
actions: [dataVisualizationLogic, ['setQuery', 'loadData'], variableDataLogic, ['getVariables']],
values: [
dataVisualizationLogic,
['query', 'insightLogicProps'],
['query', 'dashboardId'],
variableDataLogic,
['variables', 'variablesLoading'],
featureFlagLogic,
Expand Down Expand Up @@ -124,9 +124,9 @@ export const variablesLogic = kea<variablesLogicType>([
},
],
showVariablesBar: [
(state) => [state.insightLogicProps],
(insightLogicProps) => {
return !insightLogicProps.dashboardId
(state) => [state.dashboardId],
(dashboardId) => {
return !dashboardId
},
],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'

import { DataVisualizationNode, NodeKind } from '~/queries/schema'
import { initKeaTests } from '~/test/init'
import { ChartDisplayType } from '~/types'
import { ChartDisplayType, ItemMode } from '~/types'

import { dataNodeLogic } from '../../DataNode/dataNodeLogic'
import { dataVisualizationLogic, DataVisualizationLogicProps } from '../dataVisualizationLogic'
Expand Down Expand Up @@ -63,10 +63,8 @@ const dummyDataVisualizationLogicProps: DataVisualizationLogicProps = {
setQuery: (query) => {
globalQuery = query
},
insightLogicProps: {
cachedInsight: null,
dashboardItemId: 'new-test-SQL',
},
insightMode: ItemMode.View,
dataNodeCollectionId: 'new-test-SQL',
}

describe('seriesBreakdownLogic', () => {
Expand Down
25 changes: 17 additions & 8 deletions frontend/src/queries/nodes/DataVisualization/DataVisualization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DatabaseTableTreeWithItems } from 'scenes/data-warehouse/external/DataW
import { InsightErrorState } from 'scenes/insights/EmptyStates'
import { insightDataLogic } from 'scenes/insights/insightDataLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightSceneLogic } from 'scenes/insights/insightSceneLogic'
import { HogQLBoldNumber } from 'scenes/insights/views/BoldNumber/BoldNumber'
import { urls } from 'scenes/urls'

Expand All @@ -26,7 +27,7 @@ import {
NodeKind,
} from '~/queries/schema'
import { QueryContext } from '~/queries/types'
import { ChartDisplayType, ExporterFormat, InsightLogicProps } from '~/types'
import { ChartDisplayType, ExportContext, ExporterFormat, InsightLogicProps } from '~/types'

import { dataNodeLogic, DataNodeLogicProps } from '../DataNode/dataNodeLogic'
import { DateRange } from '../DataNode/DateRange'
Expand Down Expand Up @@ -54,6 +55,7 @@ interface DataTableVisualizationProps {
the data node logic becomes read only implicitly */
cachedResults?: AnyResponseType
readOnly?: boolean
exportContext?: ExportContext
/** Dashboard variables to override the ones in the query */
variablesOverride?: Record<string, HogQLVariable> | null
}
Expand All @@ -78,10 +80,15 @@ export function DataTableVisualization({
}

const vizKey = insightVizDataNodeKey(insightProps)
const dataNodeCollectionId = insightVizDataCollectionId(insightProps, key)
const { insightMode } = useValues(insightSceneLogic)
const dataVisualizationLogicProps: DataVisualizationLogicProps = {
key: vizKey,
query,
insightLogicProps: insightProps,
dashboardId: insightProps.dashboardId,
dataNodeCollectionId,
loadPriority: insightProps.loadPriority,
insightMode,
setQuery,
cachedResults,
variablesOverride,
Expand All @@ -92,10 +99,13 @@ export function DataTableVisualization({
key: vizKey,
cachedResults,
loadPriority: insightProps.loadPriority,
dataNodeCollectionId: insightVizDataCollectionId(insightProps, key),
dataNodeCollectionId,
variablesOverride,
}

const { insightProps: insightLogicProps } = useValues(insightLogic)
const { exportContext } = useValues(insightDataLogic(insightLogicProps))

return (
<BindLogic logic={dataNodeLogic} props={dataNodeLogicProps}>
<BindLogic logic={dataVisualizationLogic} props={dataVisualizationLogicProps}>
Expand All @@ -112,6 +122,7 @@ export function DataTableVisualization({
context={context}
cachedResults={cachedResults}
readOnly={readOnly}
exportContext={exportContext}
/>
</BindLogic>
</BindLogic>
Expand All @@ -123,8 +134,6 @@ export function DataTableVisualization({

function InternalDataTableVisualization(props: DataTableVisualizationProps): JSX.Element {
const { readOnly } = props
const { insightProps } = useValues(insightLogic)
const { exportContext } = useValues(insightDataLogic(insightProps))

const {
query,
Expand Down Expand Up @@ -228,7 +237,7 @@ function InternalDataTableVisualization(props: DataTableVisualizationProps): JSX
tooltip="Visualization settings"
/>

{exportContext && (
{props.exportContext && (
<ExportButton
disabledReason={
visualizationType != ChartDisplayType.ActionsTable &&
Expand All @@ -238,11 +247,11 @@ function InternalDataTableVisualization(props: DataTableVisualizationProps): JSX
items={[
{
export_format: ExporterFormat.CSV,
export_context: exportContext,
export_context: props.exportContext,
},
{
export_format: ExporterFormat.XLSX,
export_context: exportContext,
export_context: props.exportContext,
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { subscriptions } from 'kea-subscriptions'
import { dayjs } from 'lib/dayjs'
import { lightenDarkenColor, RGBToHex, uuid } from 'lib/utils'
import mergeObject from 'lodash.merge'
import { insightSceneLogic } from 'scenes/insights/insightSceneLogic'
import { teamLogic } from 'scenes/teamLogic'

import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { insightVizDataCollectionId } from '~/queries/nodes/InsightViz/InsightViz'
import {
AnyResponseType,
ChartAxis,
Expand All @@ -19,7 +17,7 @@ import {
HogQLVariable,
} from '~/queries/schema'
import { QueryContext } from '~/queries/types'
import { ChartDisplayType, InsightLogicProps, ItemMode } from '~/types'
import { ChartDisplayType, DashboardType, ItemMode } from '~/types'

import { dataNodeLogic } from '../DataNode/dataNodeLogic'
import { getQueryFeatures, QueryFeature } from '../DataTable/queryFeatures'
Expand Down Expand Up @@ -64,11 +62,14 @@ export interface AxisSeries<T> {
export interface DataVisualizationLogicProps {
key: string
query: DataVisualizationNode
insightMode: ItemMode
dataNodeCollectionId: string
setQuery?: (node: DataVisualizationNode) => void
insightLogicProps: InsightLogicProps<DataVisualizationNode>
context?: QueryContext<DataVisualizationNode>
cachedResults?: AnyResponseType
insightLoading?: boolean
dashboardId?: DashboardType['id']
loadPriority?: number
/** Dashboard variables to override the ones in the query */
variablesOverride?: Record<string, HogQLVariable> | null
}
Expand Down Expand Up @@ -217,14 +218,12 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
values: [
teamLogic,
['currentTeamId'],
insightSceneLogic,
['insightMode'],
dataNodeLogic({
cachedResults: props.cachedResults,
key: props.key,
query: props.query.source,
dataNodeCollectionId: insightVizDataCollectionId(props.insightLogicProps, props.key),
loadPriority: props.insightLogicProps.loadPriority,
dataNodeCollectionId: props.dataNodeCollectionId,
loadPriority: props.loadPriority,
variablesOverride: props.variablesOverride,
}),
['response', 'responseLoading', 'responseError', 'queryCancelled'],
Expand All @@ -236,8 +235,8 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
cachedResults: props.cachedResults,
key: props.key,
query: props.query.source,
dataNodeCollectionId: insightVizDataCollectionId(props.insightLogicProps, props.key),
loadPriority: props.insightLogicProps.loadPriority,
dataNodeCollectionId: props.dataNodeCollectionId,
loadPriority: props.loadPriority,
variablesOverride: props.variablesOverride,
}),
['loadData'],
Expand Down Expand Up @@ -559,31 +558,31 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
return columns.filter((n) => n.type.isNumerical)
},
],
dashboardId: [() => [(_, props) => props.dashboardId], (dashboardId) => dashboardId ?? null],
showEditingUI: [
(state, props) => [state.insightMode, props.insightLogicProps],
(insightMode, insightLogicProps) => {
if (insightLogicProps.dashboardId) {
(state, props) => [props.insightMode, state.dashboardId],
(insightMode, dashboardId) => {
if (dashboardId) {
return false
}

return insightMode == ItemMode.Edit
},
],
insightLogicProps: [(_state, props) => [props.insightLogicProps], (insightLogicProps) => insightLogicProps],
showResultControls: [
(state, props) => [state.insightMode, props.insightLogicProps],
(insightMode, insightLogicProps) => {
(state, props) => [props.insightMode, state.dashboardId],
(insightMode, dashboardId) => {
if (insightMode === ItemMode.Edit) {
return true
}

return !insightLogicProps.dashboardId
return !dashboardId
},
],
presetChartHeight: [
(_state, props) => [props.insightLogicProps],
(insightLogicProps) => {
return !insightLogicProps.dashboardId
(state) => [state.dashboardId],
(dashboardId) => {
return !dashboardId
},
],
sourceFeatures: [(_, props) => [props.query], (query): Set<QueryFeature> => getQueryFeatures(query.source)],
Expand Down
Loading