Skip to content

Commit

Permalink
fix(data-warehouse): data warehouse scene ui updates (#21189)
Browse files Browse the repository at this point in the history
* add loading indicator for data warehouse tables

* typing

* add refresh time on external table info

* typing

* add height limit
  • Loading branch information
EDsCODE authored Mar 27, 2024
1 parent ed58302 commit ccee1fb
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export type TreeItem = TreeItemFolder | TreeItemLeaf

export interface TreeItemFolder {
name: string
items: TreeItemLeaf[]
items: TreeItem[]
emptyLabel?: JSX.Element
isLoading?: boolean
}

export interface TreeItemLeaf {
Expand All @@ -33,7 +34,10 @@ export function DatabaseTableTree({
...props
}: TreeProps): JSX.Element {
return (
<ul className={`bg-bg-light p-4 rounded-lg ${className}`} {...props}>
<ul
className={`bg-bg-light ${depth == 1 ? 'p-4 overflow-y-scroll h-full' : ''} rounded-lg ${className}`}
{...props}
>
{items.map((item, index) => {
if ('items' in item) {
return (
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/lib/components/DatabaseTableTree/TreeRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './TreeRow.scss'

import { IconChevronDown } from '@posthog/icons'
import { Spinner } from '@posthog/lemon-ui'
import clsx from 'clsx'
import { IconChevronRight } from 'lib/lemon-ui/icons'
import { useCallback, useState } from 'react'
Expand Down Expand Up @@ -58,7 +59,7 @@ export function TreeFolderRow({ item, depth, onClick, selectedRow }: TreeFolderR
depth={depth + 1}
onSelectRow={onClick}
selectedRow={selectedRow}
style={{ marginLeft: `${2 * depth}rem`, padding: 0 }}
style={{ marginLeft: `2rem`, padding: 0 }}
/>
) : (
<div
Expand All @@ -67,7 +68,13 @@ export function TreeFolderRow({ item, depth, onClick, selectedRow }: TreeFolderR
marginLeft: `${2 * depth}rem`,
}}
>
{emptyLabel ? emptyLabel : <span className="text-muted">No tables found</span>}
{item.isLoading ? (
<Spinner className="mt-2" />
) : emptyLabel ? (
emptyLabel
) : (
<span className="text-muted">No tables found</span>
)}
</div>
))}
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DatabaseTableTree, TreeItem } from 'lib/components/DatabaseTableTree/Da
import { EmptyMessage } from 'lib/components/EmptyMessage/EmptyMessage'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { humanFriendlyDetailedTime } from 'lib/utils'
import { DatabaseTable } from 'scenes/data-management/database/DatabaseTable'
import { urls } from 'scenes/urls'

Expand All @@ -17,8 +18,16 @@ import { dataWarehouseSceneLogic } from './dataWarehouseSceneLogic'
import SourceModal from './SourceModal'

export const DataWarehouseTables = (): JSX.Element => {
const { isSourceModalOpen, externalTables, posthogTables, savedQueriesFormatted, allTables, selectedRow } =
useValues(dataWarehouseSceneLogic)
const {
isSourceModalOpen,
externalTablesBySourceType,
dataWarehouseLoading,
posthogTables,
savedQueriesFormatted,
allTables,
selectedRow,
dataWarehouseSavedQueriesLoading,
} = useValues(dataWarehouseSceneLogic)
const { toggleSourceModal, selectRow, deleteDataWarehouseSavedQuery, deleteDataWarehouseTable } =
useActions(dataWarehouseSceneLogic)
const { featureFlags } = useValues(featureFlagLogic)
Expand Down Expand Up @@ -63,12 +72,15 @@ export const DataWarehouseTables = (): JSX.Element => {
}

const treeItems = (): TreeItem[] => {
const items = [
const items: TreeItem[] = [
{
name: 'External',
items: externalTables.map((table) => ({
table: table,
icon: <IconDatabase />,
items: Object.keys(externalTablesBySourceType).map((source_type) => ({
name: source_type,
items: externalTablesBySourceType[source_type].map((table) => ({
table: table,
icon: <IconDatabase />,
})),
})),
emptyLabel: (
<span className="text-muted">
Expand All @@ -82,6 +94,7 @@ export const DataWarehouseTables = (): JSX.Element => {
</Link>
</span>
),
isLoading: dataWarehouseLoading,
},
{
name: 'PostHog',
Expand All @@ -99,6 +112,8 @@ export const DataWarehouseTables = (): JSX.Element => {
table: table,
icon: <IconBrackets />,
})),
emptyLabel: <span className="text-muted">No views found</span>,
isLoading: dataWarehouseSavedQueriesLoading,
})
}

Expand All @@ -108,7 +123,7 @@ export const DataWarehouseTables = (): JSX.Element => {
return (
<>
<div className="grid md:grid-cols-3">
<div className="sm:col-span-3 md:col-span-1">
<div className="sm:col-span-3 md:col-span-1 max-h-160">
<DatabaseTableTree onSelectRow={selectRow} items={treeItems()} selectedRow={selectedRow} />
</div>
{selectedRow ? (
Expand Down Expand Up @@ -149,6 +164,19 @@ export const DataWarehouseTables = (): JSX.Element => {
</div>
{selectedRow.type == DataWarehouseRowType.ExternalTable && (
<div className="flex flex-col">
<>
<span className="card-secondary mt-2">Last Synced At</span>
<span>
{selectedRow.payload.external_schema?.last_synced_at
? humanFriendlyDetailedTime(
selectedRow.payload.external_schema?.last_synced_at,
'MMMM DD, YYYY',
'h:mm A'
)
: 'Not yet synced'}
</span>
</>

<>
<span className="card-secondary mt-2">Files URL pattern</span>
<span>{selectedRow.payload.url_pattern}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { userLogic } from 'scenes/userLogic'
import { DataWarehouseTable } from '~/types'

import { dataWarehouseSavedQueriesLogic } from '../saved_queries/dataWarehouseSavedQueriesLogic'
import { DatabaseTableListRow, DataWarehouseRowType, DataWarehouseSceneTab, DataWarehouseTableType } from '../types'
import {
DatabaseTableListRow,
DataWarehouseExternalTableType,
DataWarehouseRowType,
DataWarehouseSceneTab,
DataWarehouseTableType,
} from '../types'
import type { dataWarehouseSceneLogicType } from './dataWarehouseSceneLogicType'

export const dataWarehouseSceneLogic = kea<dataWarehouseSceneLogicType>([
Expand All @@ -18,9 +24,9 @@ export const dataWarehouseSceneLogic = kea<dataWarehouseSceneLogicType>([
userLogic,
['user'],
databaseTableListLogic,
['filteredTables', 'dataWarehouse'],
['filteredTables', 'dataWarehouse', 'dataWarehouseLoading'],
dataWarehouseSavedQueriesLogic,
['savedQueries'],
['savedQueries', 'dataWarehouseSavedQueriesLoading'],
featureFlagLogic,
['featureFlags'],
],
Expand Down Expand Up @@ -132,6 +138,21 @@ export const dataWarehouseSceneLogic = kea<dataWarehouseSceneLogicType>([
return [...externalTables, ...posthogTables, ...savedQueriesFormatted]
},
],
externalTablesBySourceType: [
(s) => [s.externalTables],
(externalTables): Record<string, DataWarehouseTableType[]> => {
return externalTables.reduce((acc: Record<string, DataWarehouseTableType[]>, table) => {
table = table as DataWarehouseExternalTableType
if (table.payload.external_data_source) {
if (!acc[table.payload.external_data_source.source_type]) {
acc[table.payload.external_data_source.source_type] = []
}
acc[table.payload.external_data_source.source_type].push(table)
}
return acc
}, {})
},
],
}),
listeners(({ actions }) => ({
deleteDataWarehouseSavedQuery: async (view) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/data-warehouse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface DataWarehousePostHogTableType extends DataWarehouseTableBaseTyp
payload: DatabaseTableListRow
}

export interface DataWarehouseExternalTablType extends DataWarehouseTableBaseType {
export interface DataWarehouseExternalTableType extends DataWarehouseTableBaseType {
type: DataWarehouseRowType.ExternalTable
payload: DataWarehouseTable
}
Expand All @@ -54,7 +54,7 @@ export interface DataWarehouseViewType extends DataWarehouseTableBaseType {

export type DataWarehouseTableType =
| DataWarehousePostHogTableType
| DataWarehouseExternalTablType
| DataWarehouseExternalTableType
| DataWarehouseViewType

export enum DataWarehouseSceneTab {
Expand Down

0 comments on commit ccee1fb

Please sign in to comment.