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

feat(3000): more search improvements #18759

Merged
merged 24 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5547f28
shortcuts
thmsobrmlr Nov 20, 2023
fb4a01c
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 20, 2023
fb25258
Merge branch 'master' into search-improvements-3
thmsobrmlr Nov 20, 2023
f95512b
fix shortcut side icon
thmsobrmlr Nov 20, 2023
de62351
Merge branch 'master' into search-improvements-3
thmsobrmlr Nov 21, 2023
5a74ebb
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 21, 2023
5f1970e
fix merge conflicts
thmsobrmlr Nov 21, 2023
5c9b2ba
styling
thmsobrmlr Nov 21, 2023
f260731
more styling
thmsobrmlr Nov 21, 2023
65ba5ec
implement tabable tabs
thmsobrmlr Nov 21, 2023
9280f2d
Merge branch 'master' into search-improvements-3
thmsobrmlr Nov 21, 2023
33a45ac
tab styling
thmsobrmlr Nov 21, 2023
900f2cf
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 21, 2023
6b30c39
changes dark mode background, border, added a few borders
corywatilo Nov 21, 2023
724c364
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 21, 2023
dd5442a
Update UI snapshots for `chromium` (2)
github-actions[bot] Nov 21, 2023
936b7f3
Merge branch 'dark-mode-color-adjustments' into search-improvements-3
corywatilo Nov 21, 2023
9be4065
list view bg colors
corywatilo Nov 21, 2023
09a4b25
show multiple keys together in one box, darken border
corywatilo Nov 21, 2023
bd9adf8
Update UI snapshots for `chromium` (2)
github-actions[bot] Nov 21, 2023
37d5558
Merge branch 'master' into search-improvements-3
thmsobrmlr Nov 22, 2023
707355b
Merge branch 'master' into search-improvements-3
thmsobrmlr Nov 22, 2023
ba80622
prevent switching to search mode on key repeat
thmsobrmlr Nov 22, 2023
bb6ef15
same for escape key press
thmsobrmlr Nov 22, 2023
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
Binary file modified frontend/__snapshots__/components-command-bar--actions.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__/components-command-bar--search.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.
Binary file modified frontend/__snapshots__/posthog-3000-keyboard-shortcut--muted.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.
Binary file modified frontend/__snapshots__/scenes-app-notebooks--notebooks-list.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-other-settings--settings-project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@
}

.KeyboardShortcut__key {
display: inline-flex;
align-items: center;
justify-content: center;
height: 1.25rem;
min-width: 1.25rem;
padding: 0 0.1875rem;
background: var(--accent-3000);
border-radius: 0.125rem;
border-width: 1px;
background: var(--accent-3000);
color: var(--default);
display: inline-flex;
height: 1.25rem;
justify-content: center;
min-width: 1.25rem;
padding: 0 0.1875rem;
text-transform: capitalize;

.posthog-3000 & {
text-transform: uppercase;
border-radius: 0.25rem;
border-bottom-width: 2px;
border-color: var(--secondary-3000-button-border-hover);
border-radius: 0.25rem;
font-size: 0.625rem;
padding: 0.125rem 0.25rem;
}

.posthog-3000[theme='dark'] & {
border-color: var(--muted-3000);
text-transform: uppercase;
}

.KeyboardShortcut--muted > & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export function KeyboardShortcut({ muted, ...keys }: KeyboardShortcutProps): JSX
) as HotKeyOrModifier[]

return (
<span className={clsx('KeyboardShortcut', muted && 'KeyboardShortcut--muted')}>
<span
className={clsx('KeyboardShortcut KeyboardShortcut__key space-x-0.5', muted && 'KeyboardShortcut--muted')}
>
{sortedKeys.map((key) => (
<span key={key} className="KeyboardShortcut__key">
{KEY_TO_SYMBOL[key] || key}
</span>
<span key={key}>{KEY_TO_SYMBOL[key] || key}</span>
))}
</span>
)
Expand Down
22 changes: 21 additions & 1 deletion frontend/src/layout/navigation-3000/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LemonBadge } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { IconGear, IconDay, IconNight, IconAsterisk } from '@posthog/icons'
import { IconGear, IconDay, IconNight, IconAsterisk, IconSearch } from '@posthog/icons'
import { Popover } from 'lib/lemon-ui/Popover'
import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture'
import { Scene } from 'scenes/sceneTypes'
Expand All @@ -14,6 +14,9 @@ import { urls } from 'scenes/urls'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { Resizer } from 'lib/components/Resizer/Resizer'
import { useRef } from 'react'
import { commandBarLogic } from 'lib/components/CommandBar/commandBarLogic'
import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardShortcut'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'

export function Navbar(): JSX.Element {
const { user } = useValues(userLogic)
Expand All @@ -25,10 +28,12 @@ export function Navbar(): JSX.Element {
useValues(themeLogic)
const { toggleTheme } = useActions(themeLogic)
const { featureFlags } = useValues(featureFlagLogic)
const { toggleSearchBar } = useActions(commandBarLogic)

const activeThemeIcon = isDarkModeOn ? <IconNight /> : <IconDay />

const containerRef = useRef<HTMLDivElement | null>(null)
const isUsingNewNav = useFeatureFlag('POSTHOG_3000_NAV')

return (
<nav className="Navbar3000" ref={containerRef}>
Expand Down Expand Up @@ -65,6 +70,21 @@ export function Navbar(): JSX.Element {
</div>
<div className="Navbar3000__bottom">
<ul>
<NavbarButton
identifier="search-button"
icon={<IconSearch />}
title="Search"
onClick={toggleSearchBar}
sideIcon={
!isUsingNewNav ? (
<span className="text-xs">
<KeyboardShortcut shift k />
</span>
) : (
<></>
)
}
/>
<NavbarButton
icon={
isThemeSyncedWithSystem ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
export interface NavbarButtonProps {
identifier: string
icon: ReactElement
sideIcon?: ReactElement
title?: string
shortTitle?: string
tag?: 'alpha' | 'beta'
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/CommandBar/ActionInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CommandFlow } from 'lib/components/CommandPalette/commandPaletteLogic'
type PrefixIconProps = {
activeFlow: CommandFlow | null
}

const PrefixIcon = ({ activeFlow }: PrefixIconProps): React.ReactElement | null => {
if (activeFlow) {
return <activeFlow.icon className="palette__icon" /> ?? <IconEdit className="palette__icon" />
Expand All @@ -26,12 +27,11 @@ export const ActionInput = (): JSX.Element => {
return (
<div className="border-b">
<LemonInput
size="small"
className="CommandBar__input"
fullWidth
prefix={<PrefixIcon activeFlow={activeFlow} />}
suffix={<KeyboardShortcut escape />}
placeholder={activeFlow?.instruction ?? 'What would you like to do? Try some suggestions…'}
placeholder={activeFlow?.instruction ?? 'Run a command…'}
autoFocus
value={input}
onChange={setInput}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/lib/components/CommandBar/ActionResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export const ActionResult = ({ result, focused }: SearchResultProps): JSX.Elemen
}, [focused])

return (
<div className={`border-l-4 ${isExecutable ? 'border-primary' : ''}`}>
<div className={`border-l-4 ${isExecutable ? 'border-primary-3000' : ''}`}>
<div
className={`w-full pl-3 pr-2 ${focused ? 'bg-accent-3000' : 'bg-bg-light'} border-b cursor-pointer`}
className={`flex items-center w-full pl-3 pr-2 ${
focused ? 'bg-bg-3000' : 'bg-bg-light'
} border-b cursor-pointer`}
onMouseEnter={() => {
onMouseEnterResult(result.index)
}}
Expand All @@ -42,6 +44,7 @@ export const ActionResult = ({ result, focused }: SearchResultProps): JSX.Elemen
<result.icon className="text-muted-3000" />
<span className="ml-2 text-text-3000 font-bold">{result.display}</span>
</div>
{focused && <div className="shrink-0 text-primary-3000">Run command</div>}
</div>
</div>
)
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/components/CommandBar/SearchBarTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const SearchBarTab = ({ type, active, count, inputRef }: SearchBarTabProp
const { setActiveTab } = useActions(searchBarLogic)
return (
<div
className={`px-3 py-2 cursor-pointer text-xs whitespace-nowrap ${active && 'font-bold'}`}
className={`SearchBarTab flex items-center px-4 py-2 cursor-pointer text-xs whitespace-nowrap border-t-2 ${
active ? 'SearchBarTab__active font-bold border-primary-3000' : 'border-transparent'
}`}
onClick={() => {
setActiveTab(type)
inputRef.current?.focus()
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/lib/components/CommandBar/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@ import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardSh

import { searchBarLogic } from './searchBarLogic'
import { forwardRef, Ref } from 'react'

import { teamLogic } from 'scenes/teamLogic'
import { isMac } from 'lib/utils'

export const SearchInput = forwardRef(function _SearchInput(_, ref: Ref<HTMLInputElement>): JSX.Element {
const { currentTeam } = useValues(teamLogic)
const { searchQuery } = useValues(searchBarLogic)
const { setSearchQuery } = useActions(searchBarLogic)

const modifierKey = isMac() ? '⌘' : '^'
const placeholder = currentTeam
? `Search the ${currentTeam.name} project or press ${modifierKey}⇧K to go to commands…`
: `Search or press ${modifierKey}⇧K to go to commands…`

return (
<div className="border-b">
<LemonInput
ref={ref}
type="search"
size="small"
className="CommandBar__input"
fullWidth
suffix={<KeyboardShortcut escape />}
placeholder={placeholder}
autoFocus
value={searchQuery}
onChange={setSearchQuery}
placeholder={currentTeam ? `Search the ${currentTeam.name} project…` : 'Search…'}
/>
</div>
)
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/lib/components/CommandBar/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export const SearchResult = ({ result, resultIndex, focused, keyboardFocused }:

return (
<div
className={`w-full pl-3 pr-2 ${
focused ? 'bg-accent-3000' : 'bg-bg-light'
} border-r border-b cursor-pointer`}
className={`w-full pl-3 pr-2 ${focused ? 'bg-bg-light' : 'bg-bg-3000'} border-r border-b cursor-pointer`}
onMouseEnter={() => {
if (isAutoScrolling) {
return
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/CommandBar/SearchTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SearchTabs = ({ inputRef }: SearchTabsProps): JSX.Element | null =>
}

return (
<div className="flex items-center border-t space-x-3 px-2 shrink-0 overflow-x-auto">
<div className="flex items-center border-t shrink-0 overflow-x-auto bg-bg-light">
<SearchBarTab type="all" active={activeTab === 'all'} inputRef={inputRef} />
{Object.entries(searchResponse.counts).map(([type, count]) => (
<SearchBarTab
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/CommandBar/actionBarLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const actionBarLogic = kea<actionBarLogicType>([
// navigate to previous result
event.preventDefault()
actions.onArrowUp()
} else if (event.key === 'Escape') {
} else if (event.key === 'Escape' && event.repeat === false) {
event.preventDefault()

if (values.activeFlow) {
Expand All @@ -79,7 +79,7 @@ export const actionBarLogic = kea<actionBarLogicType>([
actions.hidePalette()
}
} else if (event.key === 'Backspace') {
if (values.input.length === 0) {
if (values.input.length === 0 && event.repeat === false) {
// transition to search when pressing backspace with empty input
actions.setCommandBar(BarStatus.SHOW_SEARCH)
}
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/lib/components/CommandBar/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
.CommandBar__input {
border-color: transparent !important;
border-radius: 0;
height: 2.75rem;
padding-left: 0.75rem;
padding-right: 0.375rem;
}

.SearchBarTab {
&:hover {
border-top: 2px solid var(--border-3000);
}

&.SearchBarTab__active {
border-color: var(--primary-3000);
}
}
16 changes: 15 additions & 1 deletion frontend/src/lib/components/CommandBar/searchBarLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export const searchBarLogic = kea<searchBarLogicType>([
(s) => [s.keyboardResultIndex, s.hoverResultIndex],
(keyboardResultIndex: number, hoverResultIndex: number | null) => hoverResultIndex || keyboardResultIndex,
],
tabs: [
(s) => [s.searchCounts],
(counts): ResultTypeWithAll[] => ['all', ...(Object.keys(counts || {}) as ResultTypeWithAll[])],
],
}),
listeners(({ values, actions }) => ({
openResult: ({ index }) => {
Expand Down Expand Up @@ -118,7 +122,7 @@ export const searchBarLogic = kea<searchBarLogicType>([
// navigate to previous result
event.preventDefault()
actions.onArrowUp(values.activeResultIndex, values.maxIndex)
} else if (event.key === 'Escape') {
} else if (event.key === 'Escape' && event.repeat === false) {
// hide command bar
actions.hideCommandBar()
} else if (event.key === '>') {
Expand All @@ -133,6 +137,16 @@ export const searchBarLogic = kea<searchBarLogicType>([
event.preventDefault()
actions.setCommandBar(BarStatus.SHOW_ACTIONS)
}
} else if (event.key === 'Tab') {
event.preventDefault()
const currentIndex = values.tabs.findIndex((tab) => tab === values.activeTab)
if (event.shiftKey) {
const prevIndex = currentIndex === 0 ? values.tabs.length - 1 : currentIndex - 1
actions.setActiveTab(values.tabs[prevIndex])
} else {
const nextIndex = currentIndex === values.tabs.length - 1 ? 0 : currentIndex + 1
actions.setActiveTab(values.tabs[nextIndex])
}
}
}
window.addEventListener('keydown', cache.onKeyDown)
Expand Down
Loading