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(command-bar): add search to command bar #17864

Merged
merged 59 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2e07cfc
add feature flag and scaffold
thmsobrmlr Oct 9, 2023
71442c7
style container
thmsobrmlr Oct 9, 2023
d9281af
add search input
thmsobrmlr Oct 9, 2023
5445cf9
move search bar to separate component
thmsobrmlr Oct 9, 2023
8e6ed8b
hide command bar on escape
thmsobrmlr Oct 9, 2023
6bc8b84
Merge branch 'master' into command-bar
thmsobrmlr Oct 10, 2023
6c5d264
add search bar logic
thmsobrmlr Oct 10, 2023
2ea24fd
scaffold search endpoint
thmsobrmlr Oct 10, 2023
7bf7d67
return ranked dashboards
thmsobrmlr Oct 10, 2023
43248ec
basic multi-model search
thmsobrmlr Oct 10, 2023
daf0779
move rank order out
thmsobrmlr Oct 10, 2023
95671e3
filter by rank and take q input
thmsobrmlr Oct 10, 2023
27bc138
dummy search
thmsobrmlr Oct 10, 2023
616920a
implement tabs and adjust styles
thmsobrmlr Oct 10, 2023
e6229e1
styling changes
thmsobrmlr Oct 10, 2023
65a68d8
naive prefix search
thmsobrmlr Oct 10, 2023
7935f16
handle empty query
thmsobrmlr Oct 10, 2023
e24f114
refactor search endpoint
thmsobrmlr Oct 11, 2023
93c6f21
re-add counts
thmsobrmlr Oct 11, 2023
fc42e47
add other postgres based entities
thmsobrmlr Oct 11, 2023
51dd9a1
handle other entities frontend side
thmsobrmlr Oct 11, 2023
0adaf51
fix typo
thmsobrmlr Oct 11, 2023
f6ca7ec
refactor frontend
thmsobrmlr Oct 11, 2023
c568f54
more refactoring
thmsobrmlr Oct 11, 2023
1a5dd7a
use plural for tabs
thmsobrmlr Oct 11, 2023
e43c55a
fix kea issue by re-ordering
thmsobrmlr Oct 11, 2023
9e89e51
keyboard select
thmsobrmlr Oct 11, 2023
d30485a
implement navigation
thmsobrmlr Oct 11, 2023
8fe359b
add tests
thmsobrmlr Oct 12, 2023
1a6a1e0
work on keyboard navigation
thmsobrmlr Oct 12, 2023
9e37dbf
more reliable opening of results
thmsobrmlr Oct 12, 2023
cd9a302
Merge branch 'master' into command-bar
thmsobrmlr Oct 31, 2023
c46bdd8
search on mount
thmsobrmlr Oct 31, 2023
dcffc23
make tabs work
thmsobrmlr Oct 31, 2023
e7ae614
add empty state
thmsobrmlr Oct 31, 2023
9e9edf8
add loading state
thmsobrmlr Oct 31, 2023
44bec6a
replace with lemon modal
thmsobrmlr Oct 31, 2023
bcd7718
shadow
thmsobrmlr Oct 31, 2023
8c25873
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 31, 2023
c26d8c8
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 31, 2023
a356130
improve scroll behaviour
thmsobrmlr Oct 31, 2023
364435b
keyboard select fixes
thmsobrmlr Oct 31, 2023
8c38182
fix lint issues
thmsobrmlr Oct 31, 2023
23b9434
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 31, 2023
d154332
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 31, 2023
6bfae8e
fix search with all invalid charaters
thmsobrmlr Nov 2, 2023
64d78d8
fix types
thmsobrmlr Nov 2, 2023
56f2d97
fix mypy
thmsobrmlr Nov 2, 2023
71be2cc
Update frontend/src/lib/lemon-ui/LemonSkeleton/LemonSkeleton.tsx
thmsobrmlr Nov 8, 2023
565bd8e
bem class names
thmsobrmlr Nov 8, 2023
45e763e
add debounce
thmsobrmlr Nov 8, 2023
7c3b88c
Update frontend/src/lib/components/CommandBar/CommandBar.tsx
thmsobrmlr Nov 8, 2023
5537b38
remove leftover shadow style
thmsobrmlr Nov 8, 2023
ed0d69b
use css for conditional styling
thmsobrmlr Nov 8, 2023
31066e5
rename to isAutoScrolling
thmsobrmlr Nov 8, 2023
46ccdbf
format
thmsobrmlr Nov 8, 2023
eb443aa
Merge branch 'master' into command-bar
thmsobrmlr Nov 8, 2023
7657de5
feat(command-bar): add commands from existing palette (#18355)
thmsobrmlr Nov 14, 2023
a006476
Merge branch 'master' into command-bar
thmsobrmlr Nov 15, 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
70 changes: 70 additions & 0 deletions frontend/src/lib/components/CommandBar/CommandBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useRef, forwardRef } from 'react'
import { useActions, useValues } from 'kea'

import { useEventListener } from 'lib/hooks/useEventListener'
import { useOutsideClickHandler } from 'lib/hooks/useOutsideClickHandler'

import { commandBarLogic } from './commandBarLogic'
import { BarStatus } from './types'
import '../CommandPalette/index.scss'

const CommandBarOverlay = ({ children }: { children?: React.ReactNode }): JSX.Element => (
<div
className="fixed top-0 left-0 w-full h-full flex flex-col items-center"
// eslint-disable-next-line react/forbid-dom-props
style={{ zIndex: 'var(--z-command-palette)' }}
>
{children}
</div>
)

const CommandBarContainer = forwardRef<HTMLDivElement, { children?: React.ReactNode }>(function CommandBarContainer(
{ children },
ref
): JSX.Element {
return (
<div className="bg-white p-4" ref={ref}>
{children}
</div>
)
})

function CommandBar(): JSX.Element | null {
const containerRef = useRef<HTMLDivElement | null>(null)
const { barStatus } = useValues(commandBarLogic)
const { toggleSearchBar, toggleActionsBar, hideCommandBar } = useActions(commandBarLogic)

useEventListener('keydown', (event) => {
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
event.preventDefault()
if (event.shiftKey) {
toggleActionsBar()
} else {
toggleSearchBar()
}
}
})

useOutsideClickHandler(
containerRef,
() => {
hideCommandBar()
},
thmsobrmlr marked this conversation as resolved.
Show resolved Hide resolved
[]
)

if (barStatus === BarStatus.HIDDEN) {
return null
}

return (
<CommandBarOverlay>
<CommandBarContainer ref={containerRef}>
{barStatus === BarStatus.SHOW_ACTIONS && <div>Actions</div>}
{barStatus === BarStatus.SHOW_SEARCH && <div>Search</div>}
</CommandBarContainer>
</CommandBarOverlay>
)
}

export default CommandBar
25 changes: 25 additions & 0 deletions frontend/src/lib/components/CommandBar/commandBarLogic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { kea, path, actions, reducers } from 'kea'
import { BarStatus } from './types'

import type { commandBarLogicType } from './commandBarLogicType'

export const commandBarLogic = kea<commandBarLogicType>([
path(['lib', 'components', 'CommandBar', 'commandBarLogic']),
actions({
hideCommandBar: true,
toggleSearchBar: true,
toggleActionsBar: true,
}),
reducers({
barStatus: [
BarStatus.HIDDEN as BarStatus,
{
hideCommandBar: () => BarStatus.HIDDEN,
toggleSearchBar: (previousState) =>
previousState === BarStatus.HIDDEN ? BarStatus.SHOW_SEARCH : BarStatus.HIDDEN,
toggleActionsBar: (previousState) =>
previousState === BarStatus.HIDDEN ? BarStatus.SHOW_ACTIONS : BarStatus.HIDDEN,
},
],
}),
])
5 changes: 5 additions & 0 deletions frontend/src/lib/components/CommandBar/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum BarStatus {
HIDDEN = 'hidden',
SHOW_SEARCH = 'show_search',
SHOW_ACTIONS = 'show_actions',
}
18 changes: 17 additions & 1 deletion frontend/src/lib/components/CommandPalette/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,24 @@ import { CommandResults } from './CommandResults'
import { useEventListener } from 'lib/hooks/useEventListener'
import squeakFile from 'public/squeak.mp3'
import './index.scss'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { FEATURE_FLAGS } from 'lib/constants'
import CommandBar from '../CommandBar/CommandBar'

export function CommandPalette(): JSX.Element | null {
/** Use the new Cmd+K search when the respective feature flag is enabled. */
export function CommandPalette(): JSX.Element {
const { featureFlags } = useValues(featureFlagLogic)

const isUsingCmdKSearch = featureFlags[FEATURE_FLAGS.CMD_K_SEARCH]

if (isUsingCmdKSearch) {
return <CommandBar />
} else {
return <_CommandPalette />
}
}

function _CommandPalette(): JSX.Element | null {
useMountedLogic(commandPaletteLogic)

const { setInput, hidePalette, togglePalette, backFlow } = useActions(commandPaletteLogic)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const FEATURE_FLAGS = {
SURVEYS_RESULTS_VISUALIZATIONS: 'surveys-results-visualizations', // owner: @jurajmajerik
CONSOLE_RECORDING_SEARCH: 'console-recording-search', // owner: #team-monitoring
PERSONS_HOGQL_QUERY: 'persons-hogql-query', // owner: @mariusandra
CMD_K_SEARCH: 'cmd-k-search', // owner: @thmsobrmlr
} as const
export type FeatureFlagKey = (typeof FEATURE_FLAGS)[keyof typeof FEATURE_FLAGS]

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/styles/vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ $_lifecycle_dormant: $_danger;
--recording-highlight-event: var(--mark);
--recording-highlight-event-dark: #946508;

// Z-indexes, synced with vars.ts
thmsobrmlr marked this conversation as resolved.
Show resolved Hide resolved
// Z-indexes
--z-bottom-notice: 5100;
--z-command-palette: 1875;
--z-force-modal-above-popovers: 1850;
Expand Down
Loading