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

fix: Toolbar better auth issue #21096

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 0 additions & 4 deletions frontend/src/toolbar/bar/Toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,4 @@
transform: var(--toolbar-translate) scale(0);
}
}

&--unauthenticated {
width: calc(5rem + 1px); // Account for border
}
}
39 changes: 29 additions & 10 deletions frontend/src/toolbar/bar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@ function MoreMenu(): JSX.Element {
}
maxContentWidth={true}
>
<ToolbarButton icon={<IconMenu />} title="More options" />
<ToolbarButton title="More options">
<IconMenu />
</ToolbarButton>
</LemonMenu>
)
}

export function ToolbarInfoMenu(): JSX.Element {
export function ToolbarInfoMenu(): JSX.Element | null {
const ref = useRef<HTMLDivElement | null>(null)
const { visibleMenu, isDragging, menuProperties, minimized, isBlurred } = useValues(toolbarLogic)
const { setMenu } = useActions(toolbarLogic)
const { isAuthenticated } = useValues(toolbarConfigLogic)

const content = minimized ? null : visibleMenu === 'flags' ? (
<FlagsToolbarMenu />
Expand All @@ -102,6 +105,10 @@ export function ToolbarInfoMenu(): JSX.Element {
return () => setMenu(null)
}, [ref.current])

if (!isAuthenticated) {
return null
}

return (
<div
className={clsx(
Expand Down Expand Up @@ -163,7 +170,6 @@ export function Toolbar(): JSX.Element {
className={clsx(
'Toolbar',
minimized && 'Toolbar--minimized',
!isAuthenticated && 'Toolbar--unauthenticated',
hedgehogMode && 'Toolbar--hedgehog-mode',
isDragging && 'Toolbar--dragging'
)}
Expand All @@ -178,19 +184,32 @@ export function Toolbar(): JSX.Element {
}
>
<ToolbarButton
icon={<IconLogomark />}
onClick={isAuthenticated ? toggleMinimized : authenticate}
title={isAuthenticated ? 'Minimize' : 'Authenticate the PostHog Toolbar'}
titleMinimized={isAuthenticated ? 'Expand the toolbar' : 'Authenticate the PostHog Toolbar'}
/>
>
<IconLogomark />
</ToolbarButton>
{isAuthenticated ? (
<>
<ToolbarButton icon={<IconSearch />} menuId="inspect" />
<ToolbarButton icon={<IconCursorClick />} menuId="heatmap" />
<ToolbarButton icon={<IconBolt />} menuId="actions" />
<ToolbarButton icon={<IconToggle />} menuId="flags" title="Feature flags" />
<ToolbarButton menuId="inspect">
<IconSearch />
</ToolbarButton>
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
<ToolbarButton menuId="heatmap">
<IconCursorClick />
</ToolbarButton>
<ToolbarButton menuId="actions">
<IconBolt />
</ToolbarButton>
<ToolbarButton menuId="flags" title="Feature flags">
<IconToggle />
</ToolbarButton>
</>
) : null}
) : (
<ToolbarButton flex onClick={authenticate}>
Authenticate
</ToolbarButton>
)}

<MoreMenu />
</div>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/toolbar/bar/ToolbarButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
justify-content: center;
width: 2rem;
height: 2rem;
margin: 0.25rem;
min-height: var(--lemon-button-height);
color: var(--muted-alt);
appearance: none !important; // Important as this gets overridden by Ant styles...
Expand All @@ -23,6 +24,7 @@
border: none;
border-radius: var(--radius);
transition: transform 100ms ease;
font-weight: 600;

> svg {
font-size: 1.5rem;
Expand All @@ -43,4 +45,12 @@
}
}
}

&--flex {
flex-grow: 1;
width: auto;
button {
width: 100%;
}
}
}
13 changes: 9 additions & 4 deletions frontend/src/toolbar/bar/ToolbarButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import React from 'react'
import { MenuState, toolbarLogic } from './toolbarLogic'

export type ToolbarButtonProps = {
icon: React.ReactElement | null
children: React.ReactNode
onClick?: () => void
title?: string
titleMinimized?: JSX.Element | string
menuId?: MenuState
flex?: boolean
}

export const ToolbarButton: FunctionComponent<ToolbarButtonProps> = React.forwardRef<
HTMLDivElement,
ToolbarButtonProps
>(({ icon, title, onClick, titleMinimized, menuId, ...props }, ref): JSX.Element => {
>(({ children, title, onClick, titleMinimized, menuId, flex, ...props }, ref): JSX.Element => {
const { visibleMenu, minimized, isDragging } = useValues(toolbarLogic)
const { setVisibleMenu } = useActions(toolbarLogic)

Expand Down Expand Up @@ -54,9 +55,13 @@ export const ToolbarButton: FunctionComponent<ToolbarButtonProps> = React.forwar
}

const theButton = (
<div className={clsx('ToolbarButton', active && 'ToolbarButton--active')} aria-label={theTitle} ref={ref}>
<div
className={clsx('ToolbarButton', active && 'ToolbarButton--active', flex && 'ToolbarButton--flex')}
aria-label={theTitle}
ref={ref}
>
<button className="ToolbarButton__button" {...props} onClick={_onClick}>
{icon}
{children}
</button>
</div>
)
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/toolbar/flags/flagsToolbarLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ export const flagsToolbarLogic = kea<flagsToolbarLogicType>([
`/api/projects/@current/feature_flags/my_flags${encodeParams(params, '?')}`
)

if (response.status >= 400) {
toolbarConfigLogic.actions.tokenExpired()
return []
}

breakpoint()
if (!response.ok) {
return []
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/toolbar/toolbarConfigLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ export async function toolbarFetch(
if (response.status === 403) {
const responseData = await response.json()
// Do not try to authenticate if the user has no project access altogether
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
if (responseData.detail !== "You don't have access to the project.") {
if (responseData.detail === "You don't have access to the project.") {
toolbarConfigLogic.actions.authenticate()
}
}
if (response.status == 401) {
toolbarConfigLogic.actions.tokenExpired()
}
return response
}
87 changes: 0 additions & 87 deletions frontend/src/toolbar/toolbarLogic.ts

This file was deleted.

Loading