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

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
63 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
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.
17 changes: 15 additions & 2 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: 2rem;
--sidebar-row-height: 2.5rem;
--sidebar-background: var(--bg-3000);

position: relative;
Expand Down Expand Up @@ -451,7 +451,8 @@
}

// Accommodate menu button by moving stuff out of the way
&.SidebarListItem--has-menu:not(.SidebarListItem--extended) .SidebarListItem__link {
&.SidebarListItem--has-menu:not(.SidebarListItem--extended) .SidebarListItem__link,
&.SidebarListItem--has-menu:not(.SidebarListItem--extended) .SidebarListItem__button {
padding-right: calc(var(--sidebar-horizontal-padding) + 1.25rem);
}

Expand Down Expand Up @@ -523,6 +524,7 @@
}
}

.SidebarListItem__button,
.SidebarListItem__link,
.SidebarListItem__rename {
--sidebar-list-item-inset: calc(
Expand Down Expand Up @@ -555,6 +557,17 @@
}
}

.SidebarListItem__button {
row-gap: 1px;
padding: 0 var(--sidebar-horizontal-padding) 0 var(--sidebar-list-item-inset);
color: inherit !important; // Disable link color
cursor: pointer;

&:hover {
background: var(--border-3000);
}
}

.SidebarListItem__rename {
// Pseudo-elements don't work on inputs, so we use a wrapper div
background: var(--bg-light);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation-3000/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function Navbar(): JSX.Element {
const { isAccountPopoverOpen, systemStatusHealthy } = useValues(navigationLogic)
const { closeAccountPopover, toggleAccountPopover } = useActions(navigationLogic)
const { isNavShown, isSidebarShown, activeNavbarItemId, navbarItems, mobileLayout } = useValues(navigation3000Logic)
const { showSidebar, hideSidebar, toggleNavCollapsed, hideNavOnMobile } = useActions(navigation3000Logic)
const { toggleNavCollapsed, hideNavOnMobile, showSidebar, hideSidebar } = useActions(navigation3000Logic)
const { featureFlags } = useValues(featureFlagLogic)
const { toggleSearchBar } = useActions(commandBarLogic)

Expand Down
36 changes: 35 additions & 1 deletion frontend/src/layout/navigation-3000/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ const SEARCH_DEBOUNCE_MS = 300

interface SidebarProps {
navbarItem: SidebarNavbarItem // Sidebar can only be rendered if there's an active sidebar navbar item
sidebarOverlay?: React.ReactNode
sidebarOverlayProps?: SidebarOverlayProps
}
export function Sidebar({ navbarItem }: SidebarProps): JSX.Element {

interface SidebarOverlayProps {
className?: string
isOpen?: boolean
}

export function Sidebar({ navbarItem, sidebarOverlay, sidebarOverlayProps }: SidebarProps): JSX.Element {
const inputElementRef = useRef<HTMLInputElement>(null)

const {
Expand Down Expand Up @@ -81,6 +89,11 @@ export function Sidebar({ navbarItem }: SidebarProps): JSX.Element {
}
}}
/>
{sidebarOverlay && (
<SidebarOverlay {...sidebarOverlayProps} isOpen={isShown && sidebarOverlayProps?.isOpen} width={width}>
{sidebarOverlay}
</SidebarOverlay>
)}
</div>
)
}
Expand Down Expand Up @@ -199,3 +212,24 @@ function SidebarKeyboardShortcut(): JSX.Element {
</div>
)
}

function SidebarOverlay({
className,
isOpen = false,
children,
width,
}: SidebarOverlayProps & { children: React.ReactNode; width: number }): JSX.Element | null {
if (!isOpen) {
return null
}

return (
<div
className={clsx('absolute top-0 left-0 h-full bg-bg-3000', className)}
// eslint-disable-next-line react/forbid-dom-props
style={{ width: `${width}px` }}
>
{children}
</div>
)
}
23 changes: 20 additions & 3 deletions frontend/src/layout/navigation-3000/components/SidebarList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import { InfiniteLoader } from 'react-virtualized/dist/es/InfiniteLoader'
import { List, ListProps } from 'react-virtualized/dist/es/List'

import { ITEM_KEY_PART_SEPARATOR, navigation3000Logic } from '../navigationLogic'
import { BasicListItem, ExtendedListItem, ExtraListItemContext, SidebarCategory, TentativeListItem } from '../types'
import {
BasicListItem,
ButtonListItem,
ExtendedListItem,
ExtraListItemContext,
SidebarCategory,
TentativeListItem,
} from '../types'
import { KeyboardShortcut } from './KeyboardShortcut'

export function SidebarList({ category }: { category: SidebarCategory }): JSX.Element {
Expand Down Expand Up @@ -122,7 +129,7 @@ export function SidebarList({ category }: { category: SidebarCategory }): JSX.El
}

interface SidebarListItemProps {
item: BasicListItem | ExtendedListItem | TentativeListItem
item: BasicListItem | ExtendedListItem | TentativeListItem | ButtonListItem
validateName?: SidebarCategory['validateName']
active?: boolean
style: React.CSSProperties
Expand All @@ -132,6 +139,10 @@ function isItemTentative(item: SidebarListItemProps['item']): item is TentativeL
return 'onSave' in item
}

function isItemClickable(item: SidebarListItemProps['item']): item is ButtonListItem {
return 'onClick' in item
}

function SidebarListItem({ item, validateName, active, style }: SidebarListItemProps): JSX.Element {
const [isMenuOpen, setIsMenuOpen] = useState(false)
const [newName, setNewName] = useState<null | string>(null)
Expand Down Expand Up @@ -218,7 +229,13 @@ function SidebarListItem({ item, validateName, active, style }: SidebarListItemP
}) // Intentionally run on every render so that ref value changes are picked up

let content: JSX.Element
if (!save || (!isItemTentative(item) && newName === null)) {
if (isItemClickable(item)) {
content = (
<li className="SidebarListItem__button" onClick={item.onClick}>
<h5>{item.name}</h5>
</li>
)
} else if (!save || (!isItemTentative(item) && newName === null)) {
if (isItemTentative(item)) {
throw new Error('Tentative items should not be rendered in read mode')
}
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/layout/navigation-3000/navigationLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { LemonMenuOverlay } from 'lib/lemon-ui/LemonMenu/LemonMenu'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { isNotNil } from 'lib/utils'
import React from 'react'
import { editorSidebarLogic } from 'scenes/data-warehouse/editor/editorSidebarLogic'
import { sceneLogic } from 'scenes/sceneLogic'
import { Scene } from 'scenes/sceneTypes'
import { teamLogic } from 'scenes/teamLogic'
Expand Down Expand Up @@ -103,9 +104,6 @@ export const navigation3000Logic = kea<navigation3000LogicType>([
reducers({
isSidebarShown: [
true,
{
persist: true,
},
{
hideSidebar: () => false,
showSidebar: () => true,
Expand Down Expand Up @@ -514,9 +512,10 @@ export const navigation3000Logic = kea<navigation3000LogicType>([
featureFlags[FEATURE_FLAGS.SQL_EDITOR]
? {
identifier: Scene.SQLEditor,
label: 'SQL editor',
label: 'Data warehouse',
icon: <IconServer />,
to: isUsingSidebar ? undefined : urls.sqlEditor(),
to: urls.sqlEditor(),
logic: editorSidebarLogic,
}
: null,
featureFlags[FEATURE_FLAGS.DATA_MODELING] && hasOnboardedAnyProduct
Expand Down Expand Up @@ -598,6 +597,9 @@ export const navigation3000Logic = kea<navigation3000LogicType>([
activeNavbarItemId: [
(s) => [s.activeNavbarItemIdRaw, featureFlagLogic.selectors.featureFlags],
(activeNavbarItemIdRaw, featureFlags): string | null => {
if (featureFlags[FEATURE_FLAGS.SQL_EDITOR] && activeNavbarItemIdRaw === Scene.SQLEditor) {
return Scene.SQLEditor
}
if (!featureFlags[FEATURE_FLAGS.POSTHOG_3000_NAV]) {
return null
}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/layout/navigation-3000/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface BasicListItem {
* URL within the app. In specific cases this can be null - such items are italicized.
*/
url: string | null
onClick?: () => void
/** An optional marker to highlight item state. */
marker?: {
/** A marker of type `fold` is a small triangle in the top left, `ribbon` is a narrow ribbon to the left. */
Expand Down Expand Up @@ -146,3 +147,8 @@ export interface TentativeListItem {
adding: boolean
ref?: BasicListItem['ref']
}

export interface ButtonListItem extends BasicListItem {
key: '__button__'
onClick: () => void
}
2 changes: 1 addition & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ const api = {
},
async update(
viewId: DataWarehouseSavedQuery['id'],
data: Pick<DataWarehouseSavedQuery, 'name' | 'query'>
data: Partial<DataWarehouseSavedQuery>
): Promise<DataWarehouseSavedQuery> {
return await new ApiRequest().dataWarehouseSavedQuery(viewId).update({ data })
},
Expand Down
23 changes: 20 additions & 3 deletions frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type LemonFormDialogProps = LemonDialogFormPropsType &
Omit<LemonDialogProps, 'primaryButton' | 'secondaryButton' | 'tertiaryButton'> & {
initialValues: Record<string, any>
onSubmit: (values: Record<string, any>) => void | Promise<void>
shouldAwaitSubmit?: boolean
}

export type LemonDialogProps = Pick<
Expand All @@ -26,6 +27,7 @@ export type LemonDialogProps = Pick<
onClose?: () => void
onAfterClose?: () => void
closeOnNavigate?: boolean
shouldAwaitSubmit?: boolean
}

export function LemonDialog({
Expand All @@ -37,12 +39,14 @@ export function LemonDialog({
content,
initialFormValues,
closeOnNavigate = true,
shouldAwaitSubmit = false,
footer,
...props
}: LemonDialogProps): JSX.Element {
const [isOpen, setIsOpen] = useState(true)
const { currentLocation } = useValues(router)
const lastLocation = useRef(currentLocation.pathname)
const [isLoading, setIsLoading] = useState(false)

primaryButton =
primaryButton ||
Expand All @@ -63,8 +67,20 @@ export function LemonDialog({
<LemonButton
type="secondary"
{...button}
onClick={(e) => {
button.onClick?.(e)
loading={button === primaryButton && shouldAwaitSubmit ? isLoading : undefined}
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onClick={async (e) => {
if (button === primaryButton && shouldAwaitSubmit) {
setIsLoading(true)
try {
// eslint-disable-next-line @typescript-eslint/await-thenable
await button.onClick?.(e)
} finally {
setIsLoading(false)
}
} else {
button.onClick?.(e)
}
setIsOpen(false)
}}
/>
Expand Down Expand Up @@ -117,7 +133,8 @@ export const LemonFormDialog = ({
type: 'primary',
children: 'Submit',
htmlType: 'submit',
onClick: () => void onSubmit(form),
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onClick: props.shouldAwaitSubmit ? async () => await onSubmit(form) : undefined,
disabledReason: !isFormValid ? firstError : undefined,
}

Expand Down
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
Loading
Loading