Skip to content

Commit

Permalink
chore(editor-3000): move over materialization (#26619)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
EDsCODE and github-actions[bot] authored Dec 4, 2024
1 parent fd23e4f commit f2a09b9
Showing 1 changed file with 164 additions and 3 deletions.
167 changes: 164 additions & 3 deletions frontend/src/scenes/data-warehouse/editor/editorSidebarLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Fuse from 'fuse.js'
import { connect, kea, path, selectors } from 'kea'
import { router } from 'kea-router'
import { subscriptions } from 'kea-subscriptions'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import { sceneLogic } from 'scenes/sceneLogic'
import { Scene } from 'scenes/sceneTypes'
Expand All @@ -14,6 +16,7 @@ import { DatabaseSchemaDataWarehouseTable, DatabaseSchemaTable } from '~/queries
import { DataWarehouseSavedQuery, PipelineTab } from '~/types'

import { dataWarehouseViewsLogic } from '../saved_queries/dataWarehouseViewsLogic'
import { viewLinkLogic } from '../viewLinkLogic'
import { editorSceneLogic } from './editorSceneLogic'
import type { editorSidebarLogicType } from './editorSidebarLogicType'
import { multitabEditorLogic } from './multitabEditorLogic'
Expand All @@ -39,6 +42,20 @@ const savedQueriesfuse = new Fuse<DataWarehouseSavedQuery>([], {
includeMatches: true,
})

const nonMaterializedViewsfuse = new Fuse<DataWarehouseSavedQuery>([], {
keys: [{ name: 'name', weight: 2 }],
threshold: 0.3,
ignoreLocation: true,
includeMatches: true,
})

const materializedViewsfuse = new Fuse<DataWarehouseSavedQuery>([], {
keys: [{ name: 'name', weight: 2 }],
threshold: 0.3,
ignoreLocation: true,
includeMatches: true,
})

export const editorSidebarLogic = kea<editorSidebarLogicType>([
path(['data-warehouse', 'editor', 'editorSidebarLogic']),
connect({
Expand All @@ -49,8 +66,17 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
['dataWarehouseSavedQueries', 'dataWarehouseSavedQueryMapById', 'dataWarehouseSavedQueriesLoading'],
databaseTableListLogic,
['posthogTables', 'dataWarehouseTables', 'databaseLoading', 'views', 'viewsMapById'],
featureFlagLogic,
['featureFlags'],
],
actions: [
editorSceneLogic,
['selectSchema'],
dataWarehouseViewsLogic,
['deleteDataWarehouseSavedQuery', 'runDataWarehouseSavedQuery'],
viewLinkLogic,
['selectSourceTable', 'toggleJoinTableModal'],
],
actions: [editorSceneLogic, ['selectSchema'], dataWarehouseViewsLogic, ['deleteDataWarehouseSavedQuery']],
}),
selectors(({ actions }) => ({
contents: [
Expand All @@ -60,13 +86,19 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
s.relevantPosthogTables,
s.relevantDataWarehouseTables,
s.databaseLoading,
s.relevantNonMaterializedViews,
s.relevantMaterializedViews,
s.featureFlags,
],
(
relevantSavedQueries,
dataWarehouseSavedQueriesLoading,
relevantPosthogTables,
relevantDataWarehouseTables,
databaseLoading
databaseLoading,
relevantNonMaterializedViews,
relevantMaterializedViews,
featureFlags
) => [
{
key: 'data-warehouse-sources',
Expand All @@ -85,6 +117,15 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
onClick: () => {
actions.selectSchema(table)
},
menuItems: [
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(table.name)
actions.toggleJoinTableModal()
},
},
],
})),
onAdd: () => {
router.actions.push(urls.pipeline(PipelineTab.Sources))
Expand All @@ -107,13 +148,25 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
onClick: () => {
actions.selectSchema(table)
},
menuItems: [
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(table.name)
actions.toggleJoinTableModal()
},
},
],
})),
} as SidebarCategory,
{
key: 'data-warehouse-views',
noun: ['view', 'views'],
loading: dataWarehouseSavedQueriesLoading,
items: relevantSavedQueries.map(([savedQuery, matches]) => ({
items: (featureFlags[FEATURE_FLAGS.DATA_MODELING]
? relevantNonMaterializedViews
: relevantSavedQueries
).map(([savedQuery, matches]) => ({
key: savedQuery.id,
name: savedQuery.name,
url: '',
Expand All @@ -135,6 +188,23 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
}).actions.createTab(savedQuery.query.query, savedQuery)
},
},
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(savedQuery.name)
actions.toggleJoinTableModal()
},
},
...(featureFlags[FEATURE_FLAGS.DATA_MODELING] && !savedQuery.status
? [
{
label: 'Materialize',
onClick: () => {
actions.runDataWarehouseSavedQuery(savedQuery.id)
},
},
]
: []),
{
label: 'Delete',
status: 'danger',
Expand All @@ -145,8 +215,77 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
],
})),
} as SidebarCategory,
...(featureFlags[FEATURE_FLAGS.DATA_MODELING]
? [
{
key: 'data-warehouse-materialized-views',
noun: ['materialized view', 'materialized views'],
loading: dataWarehouseSavedQueriesLoading,
items: relevantMaterializedViews.map(([materializedView, matches]) => ({
key: materializedView.id,
name: materializedView.name,
url: '',
searchMatch: matches
? {
matchingFields: matches.map((match) => match.key),
nameHighlightRanges: matches.find((match) => match.key === 'name')?.indices,
}
: null,
onClick: () => {
actions.selectSchema(materializedView)
},
menuItems: [
{
label: 'Edit view definition',
onClick: () => {
multitabEditorLogic({
key: `hogQLQueryEditor/${router.values.location.pathname}`,
}).actions.createTab(materializedView.query.query, materializedView)
},
},
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(materializedView.name)
actions.toggleJoinTableModal()
},
},
...(featureFlags[FEATURE_FLAGS.DATA_MODELING] && materializedView.status
? [
{
label: 'Run',
onClick: () => {
actions.runDataWarehouseSavedQuery(materializedView.id)
},
},
]
: []),
{
label: 'Delete',
status: 'danger',
onClick: () => {
actions.deleteDataWarehouseSavedQuery(materializedView.id)
},
},
],
})),
},
]
: []),
],
],
nonMaterializedViews: [
(s) => [s.dataWarehouseSavedQueries],
(views): DataWarehouseSavedQuery[] => {
return views.filter((view) => !view.status && !view.last_run_at)
},
],
materializedViews: [
(s) => [s.dataWarehouseSavedQueries],
(views): DataWarehouseSavedQuery[] => {
return views.filter((view) => view.status || view.last_run_at)
},
],
activeListItemKey: [
(s) => [s.activeScene, s.sceneParams],
(activeScene, sceneParams): [string, number] | null => {
Expand Down Expand Up @@ -188,6 +327,28 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
return dataWarehouseSavedQueries.map((savedQuery) => [savedQuery, null])
},
],
relevantNonMaterializedViews: [
(s) => [s.nonMaterializedViews, navigation3000Logic.selectors.searchTerm],
(nonMaterializedViews, searchTerm): [DataWarehouseSavedQuery, FuseSearchMatch[] | null][] => {
if (searchTerm) {
return nonMaterializedViewsfuse
.search(searchTerm)
.map((result) => [result.item, result.matches as FuseSearchMatch[]])
}
return nonMaterializedViews.map((view) => [view, null])
},
],
relevantMaterializedViews: [
(s) => [s.materializedViews, navigation3000Logic.selectors.searchTerm],
(materializedViews, searchTerm): [DataWarehouseSavedQuery, FuseSearchMatch[] | null][] => {
if (searchTerm) {
return materializedViewsfuse
.search(searchTerm)
.map((result) => [result.item, result.matches as FuseSearchMatch[]])
}
return materializedViews.map((view) => [view, null])
},
],
})),
subscriptions({
dataWarehouseTables: (dataWarehouseTables) => {
Expand Down

0 comments on commit f2a09b9

Please sign in to comment.