Skip to content

Commit

Permalink
feat: Toolbar 3000 (#17276)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Nov 23, 2023
1 parent 8fb7e19 commit 3cb9ed4
Show file tree
Hide file tree
Showing 83 changed files with 1,974 additions and 2,646 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/toolbar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Toolbar', () => {
.then((href) => {
cy.visit(href)
})
cy.get('#__POSTHOG_TOOLBAR__').shadow().find('.floating-toolbar-button').should('exist')
cy.get('#__POSTHOG_TOOLBAR__').shadow().find('.Toolbar').should('exist')
})
})

Expand Down
Binary file modified frontend/__snapshots__/exporter-exporter--dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-input--small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-surveys--survey-not-found.png
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.
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.
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.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion frontend/src/layout/GlobalModals.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LemonModal } from '@posthog/lemon-ui'
import { actions, kea, path, reducers, useActions, useValues } from 'kea'
import { FlaggedFeature } from 'lib/components/FlaggedFeature'
import { HedgehogBuddyWithLogic } from 'lib/components/HedgehogBuddy/HedgehogBuddy'
import { HedgehogBuddyWithLogic } from 'lib/components/HedgehogBuddy/HedgehogBuddyWithLogic'
import { Prompt } from 'lib/logic/newPrompt/Prompt'
import { Setup2FA } from 'scenes/authentication/Setup2FA'
import { CreateOrganizationModal } from 'scenes/organization/CreateOrganizationModal'
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/layout/navigation-3000/themeLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { actions, events, kea, path, reducers, selectors } from 'kea'
import { actions, connect, events, kea, path, reducers, selectors } from 'kea'
import { subscriptions } from 'kea-subscriptions'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
Expand All @@ -8,6 +8,9 @@ import type { themeLogicType } from './themeLogicType'

export const themeLogic = kea<themeLogicType>([
path(['layout', 'navigation-3000', 'themeLogic']),
connect({
values: [featureFlagLogic, ['featureFlags']],
}),
actions({
toggleTheme: true,
overrideTheme: (darkModePreference: boolean | null) => ({ darkModePreference }),
Expand Down Expand Up @@ -36,7 +39,7 @@ export const themeLogic = kea<themeLogicType>([
(s) => [
s.darkModeSavedPreference,
s.darkModeSystemPreference,
featureFlagLogic.selectors.featureFlags,
s.featureFlags,
sceneLogic.selectors.sceneConfig,
],
(darkModeSavedPreference, darkModeSystemPreference, featureFlags, sceneConfig) => {
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/lib/components/HedgehogBuddy/HedgehogAccessories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { capitalizeFirstLetter } from 'lib/utils'

import { HedgehogBuddyAccessory } from './components/AccessoryButton'
import { accessoryGroups, standardAccessories } from './sprites/sprites'

export function HedgehogAccessories({ isDarkModeOn }: { isDarkModeOn: boolean }): JSX.Element {
return (
<>
<h3>Hi, I'm Max!</h3>
<p>
Don't mind me. I'm just here to keep you company.
<br />
You can move me around by clicking and dragging or control me with WASD / arrow keys.
</p>

{accessoryGroups.map((group) => (
<div key={group}>
<h4>{capitalizeFirstLetter(group)}</h4>

<div className="flex gap-2 my-2 overflow-y-auto">
{Object.keys(standardAccessories)
.filter((acc) => standardAccessories[acc].group === group)
.map((acc) => (
<HedgehogBuddyAccessory
key={acc}
accessoryKey={acc}
accessory={standardAccessories[acc]}
isDarkModeOn={isDarkModeOn}
/>
))}
</div>
</div>
))}
</>
)
}
75 changes: 11 additions & 64 deletions frontend/src/lib/components/HedgehogBuddy/HedgehogBuddy.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import './HedgehogBuddy.scss'
import './HedgehogBuddy.scss'

import { useActions, useValues } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { useValues } from 'kea'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { Popover } from 'lib/lemon-ui/Popover/Popover'
import { capitalizeFirstLetter, range, sampleOne } from 'lib/utils'
import { range, sampleOne } from 'lib/utils'
import { MutableRefObject, useEffect, useRef, useState } from 'react'

import { themeLogic } from '~/layout/navigation-3000/themeLogic'

import { FlaggedFeature } from '../FlaggedFeature'
import { HedgehogBuddyAccessory } from './components/AccessoryButton'
import { HedgehogAccessories } from './HedgehogAccessories'
import { hedgehogbuddyLogic } from './hedgehogbuddyLogic'
import {
accessoryGroups,
AccessoryInfo,
baseSpriteAccessoriesPath,
baseSpritePath,
Expand Down Expand Up @@ -318,7 +314,10 @@ export class HedgehogActor {
<div
className="HedgehogBuddy"
data-content={preloadContent}
onMouseDown={() => {
onMouseDown={(e) => {
if (e.button !== 0) {
return
}
let moved = false
const onMouseMove = (e: any): void => {
moved = true
Expand Down Expand Up @@ -399,7 +398,7 @@ export function HedgehogBuddy({
onClick?: () => void
onPositionChange?: (actor: HedgehogActor) => void
popoverOverlay?: React.ReactNode
// passed in because toolbar needs to check this differently than the app
// passed in as this might need to be the app's global dark mode setting or the toolbar's local one
isDarkModeOn: boolean
}): JSX.Element {
const actorRef = useRef<HedgehogActor>()
Expand Down Expand Up @@ -478,48 +477,8 @@ export function HedgehogBuddy({
overlay={
popoverOverlay || (
<div className="HedgehogBuddyPopover p-2 max-w-140">
<h3>Hi, I'm Max!</h3>
<p>
Don't mind me. I'm just here to keep you company.
<br />
You can move me around by clicking and dragging or control me with WASD / arrow keys.
</p>

{accessoryGroups.map((group) => (
<div key={group}>
<h4>{capitalizeFirstLetter(group)}</h4>

<div className="flex gap-2 my-2 overflow-y-auto">
{Object.keys(standardAccessories)
.filter((acc) => standardAccessories[acc].group === group)
.map((acc) => (
<HedgehogBuddyAccessory
key={acc}
accessoryKey={acc}
accessory={standardAccessories[acc]}
/>
))}
</div>
</div>
))}

<FlaggedFeature flag={FEATURE_FLAGS.HEDGEHOG_MODE_DEBUG}>
<>
<LemonDivider />
<div className="flex gap-2 my-2 overflow-y-auto">
{Object.keys(standardAnimations).map((x) => (
<LemonButton
key={x}
type="secondary"
size="small"
onClick={() => actor.setAnimation(x)}
>
{capitalizeFirstLetter(x)}
</LemonButton>
))}
</div>
</>
</FlaggedFeature>
<HedgehogAccessories isDarkModeOn={isDarkModeOn} />

<LemonDivider />
<div className="flex justify-end gap-2">
<LemonButton type="secondary" status="danger" onClick={() => disappear()}>
Expand All @@ -537,15 +496,3 @@ export function HedgehogBuddy({
</Popover>
)
}

export function HedgehogBuddyWithLogic(): JSX.Element {
const { hedgehogModeEnabled } = useValues(hedgehogbuddyLogic)
const { setHedgehogModeEnabled } = useActions(hedgehogbuddyLogic)
const { isDarkModeOn } = useValues(themeLogic)

return hedgehogModeEnabled ? (
<HedgehogBuddy onClose={() => setHedgehogModeEnabled(false)} isDarkModeOn={isDarkModeOn} />
) : (
<></>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import './HedgehogBuddy.scss'

import { useActions, useValues } from 'kea'

import { themeLogic } from '~/layout/navigation-3000/themeLogic'

import { HedgehogBuddy } from './HedgehogBuddy'
import { hedgehogbuddyLogic } from './hedgehogbuddyLogic'

export function HedgehogBuddyWithLogic(): JSX.Element {
const { hedgehogModeEnabled } = useValues(hedgehogbuddyLogic)
const { setHedgehogModeEnabled } = useActions(hedgehogbuddyLogic)
const { isDarkModeOn } = useValues(themeLogic)

return hedgehogModeEnabled ? (
<HedgehogBuddy onClose={() => setHedgehogModeEnabled(false)} isDarkModeOn={isDarkModeOn} />
) : (
<></>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ import { IconLock } from 'lib/lemon-ui/icons'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { capitalizeFirstLetter } from 'lib/utils'

import { themeLogic } from '~/layout/navigation-3000/themeLogic'

import { hedgehogbuddyLogic } from '../hedgehogbuddyLogic'
import { AccessoryInfo, baseSpriteAccessoriesPath } from '../sprites/sprites'

export type HedgehogBuddyAccessoryProps = {
accessory: AccessoryInfo
accessoryKey: string
isDarkModeOn: boolean
}

export function HedgehogBuddyAccessory({ accessoryKey, accessory }: HedgehogBuddyAccessoryProps): JSX.Element {
export function HedgehogBuddyAccessory({
accessoryKey,
accessory,
isDarkModeOn,
}: HedgehogBuddyAccessoryProps): JSX.Element {
const { accessories, availableAccessories } = useValues(hedgehogbuddyLogic)
const { addAccessory, removeAccessory } = useActions(hedgehogbuddyLogic)
const { isDarkModeOn } = useValues(themeLogic)

const isUnlocked = availableAccessories.includes(accessoryKey)

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/lemon-ui/LemonMenu/LemonMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface LemonMenuProps
| 'closeParentPopoverOnClickInside'
| 'className'
| 'onClickOutside'
| 'getPopupContainer'
>,
LemonMenuOverlayProps {
/** Must support `ref` and `onKeyDown` for keyboard navigation. */
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
}

.LemonSwitch--checked & {
background-color: var(--primary);
border-color: var(--primary);
background-color: var(--primary-3000);
border-color: var(--primary-3000);
transform: translateX(1rem);

.posthog-3000 & {
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/lib/lemon-ui/Link/Link.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@
> .LemonIcon {
margin-left: 0.15em;
}

&--subtle {
.posthog-3000 & {
color: var(--default);

&:not(:disabled):hover {
color: var(--primary-3000-hover);
}
}
}
}
7 changes: 5 additions & 2 deletions frontend/src/lib/lemon-ui/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type LinkProps = Pick<React.HTMLProps<HTMLAnchorElement>, 'target' | 'cla
* This is true by default if `children` is a string.
*/
targetBlankIcon?: boolean
/** If true, the default color will be as normal text with only a link color on hover */
subtle?: boolean
}

// Some URLs we want to enforce a full reload such as billing which is redirected by Django
Expand Down Expand Up @@ -68,6 +70,7 @@ export const Link: React.FC<LinkProps & React.RefAttributes<HTMLElement>> = Reac
{
to,
target,
subtle,
disableClientSideRouting,
preventClick = false,
onClick: onClickRaw,
Expand Down Expand Up @@ -124,7 +127,7 @@ export const Link: React.FC<LinkProps & React.RefAttributes<HTMLElement>> = Reac
// eslint-disable-next-line react/forbid-elements
<a
ref={ref as any}
className={clsx('Link', className)}
className={clsx('Link', subtle && 'Link--subtle', className)}
onClick={onClick}
href={typeof to === 'string' ? to : '#'}
target={target}
Expand All @@ -140,7 +143,7 @@ export const Link: React.FC<LinkProps & React.RefAttributes<HTMLElement>> = Reac
<span>
<button
ref={ref as any}
className={clsx('Link', className)}
className={clsx('Link', subtle && 'Link--subtle', className)}
onClick={onClick}
type="button"
disabled={disabled || !!disabledReason}
Expand Down
Loading

0 comments on commit 3cb9ed4

Please sign in to comment.