Skip to content

Commit

Permalink
refactor logic: remove insightlogic dependencies from datavizlogic
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE committed Nov 18, 2024
1 parent a2f759a commit b02a159
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
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
27 changes: 18 additions & 9 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 All @@ -45,7 +46,7 @@ import { variablesLogic } from './Components/Variables/variablesLogic'
import { dataVisualizationLogic, DataVisualizationLogicProps } from './dataVisualizationLogic'
import { displayLogic } from './displayLogic'

interface DataTableVisualizationProps {
export interface DataTableVisualizationProps {
uniqueKey?: string | number
query: DataVisualizationNode
setQuery: (query: DataVisualizationNode) => void
Expand All @@ -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: [(_state, props) => [props.dashboardId], (dashboardId) => dashboardId],

Check failure on line 561 in frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Type '[(() => number | undefined) | undefined]' is not assignable to type 'SelectorTuple'.
showEditingUI: [
(state, props) => [state.insightMode, props.insightLogicProps],
(insightMode, insightLogicProps) => {
if (insightLogicProps.dashboardId) {
(_state, props) => [props.insightMode, props.dashboardId],

Check failure on line 563 in frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Type '[() => ItemMode, (() => number | undefined) | undefined]' is not assignable to type 'SelectorTuple'.
(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, props.dashboardId],

Check failure on line 573 in frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Type '[() => ItemMode, (() => number | undefined) | undefined]' is not assignable to type 'SelectorTuple'.
(insightMode, dashboardId) => {
if (insightMode === ItemMode.Edit) {
return true
}

return !insightLogicProps.dashboardId
return !dashboardId
},
],
presetChartHeight: [
(_state, props) => [props.insightLogicProps],
(insightLogicProps) => {
return !insightLogicProps.dashboardId
(_state, props) => [props.dashboardId],

Check failure on line 583 in frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Type '[(() => number | undefined) | undefined]' is not assignable to type 'SelectorTuple'.
(dashboardId) => {
return !dashboardId
},
],
sourceFeatures: [(_, props) => [props.query], (query): Set<QueryFeature> => getQueryFeatures(query.source)],
Expand Down

0 comments on commit b02a159

Please sign in to comment.