-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 commands from existing palette #18355
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ef46acc
scaffold
thmsobrmlr f9a5ee7
separate out action result
thmsobrmlr 2db8426
cleanup
thmsobrmlr 20f3b26
allow executing result
thmsobrmlr efcc85f
Update UI snapshots for `chromium` (2)
github-actions[bot] 645d072
Update UI snapshots for `chromium` (2)
github-actions[bot] 2469fb9
remove isFirst
thmsobrmlr cd0c8c4
move event listener to logic
thmsobrmlr 49fbad7
add scope to name util
thmsobrmlr 04d35c0
wip
thmsobrmlr e083cba
rename index to CommandPalette
thmsobrmlr ab9b9fd
minor changes
thmsobrmlr 5570519
wip
thmsobrmlr 5ac9203
wip
thmsobrmlr 8e2f3db
keyboard commands
thmsobrmlr de0dc9f
cleanup
thmsobrmlr dc47a89
Update UI snapshots for `webkit` (2)
github-actions[bot] e506066
move useEventListener into commandBarLogic
thmsobrmlr 44688a9
Update UI snapshots for `webkit` (2)
github-actions[bot] 6299368
hide dashboard search from commands
thmsobrmlr fe27ef0
add comments
thmsobrmlr 099fb53
add mouse hover interaction
thmsobrmlr 0655da4
Update UI snapshots for `chromium` (2)
github-actions[bot] c443637
Update UI snapshots for `webkit` (2)
github-actions[bot] 9678f07
Update UI snapshots for `webkit` (2)
github-actions[bot] 76b07e9
Update UI snapshots for `chromium` (2)
github-actions[bot] df66174
Update UI snapshots for `chromium` (2)
github-actions[bot] 202834b
Update UI snapshots for `chromium` (1)
github-actions[bot] fc94c51
Update UI snapshots for `chromium` (1)
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+15.5 KB
(120%)
frontend/__snapshots__/scenes-app-insights--retention--webkit.png
thmsobrmlr marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
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
BIN
+813 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--recordings-playlist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useValues } from 'kea' | ||
|
||
import { actionBarLogic } from './actionBarLogic' | ||
|
||
import ActionInput from './ActionInput' | ||
import ActionResults from './ActionResults' | ||
|
||
const ActionBar = (): JSX.Element => { | ||
const { activeFlow } = useValues(actionBarLogic) | ||
|
||
return ( | ||
<div className="flex flex-col h-full"> | ||
{(!activeFlow || activeFlow.instruction) && <ActionInput />} | ||
{<ActionResults />} | ||
</div> | ||
) | ||
} | ||
|
||
export default ActionBar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import { useActions, useValues } from 'kea' | ||
|
||
import { LemonInput } from '@posthog/lemon-ui' | ||
import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardShortcut' | ||
|
||
import { actionBarLogic } from './actionBarLogic' | ||
import { IconChevronRight, IconEdit } from 'lib/lemon-ui/icons' | ||
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" /> | ||
} else { | ||
return <IconChevronRight className="palette__icon" /> | ||
} | ||
} | ||
|
||
const ActionInput = (): JSX.Element => { | ||
const { input, activeFlow } = useValues(actionBarLogic) | ||
const { setInput } = useActions(actionBarLogic) | ||
|
||
return ( | ||
<div className="border-b"> | ||
<LemonInput | ||
size="small" | ||
className="CommandBar__input" | ||
fullWidth | ||
prefix={<PrefixIcon activeFlow={activeFlow} />} | ||
suffix={<KeyboardShortcut escape muted />} | ||
placeholder={activeFlow?.instruction ?? 'What would you like to do? Try some suggestions…'} | ||
autoFocus | ||
value={input} | ||
onChange={setInput} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default ActionInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useEffect, useRef } from 'react' | ||
import { useActions } from 'kea' | ||
|
||
import { actionBarLogic } from './actionBarLogic' | ||
import { getNameFromActionScope } from './utils' | ||
import { CommandResultDisplayable } from '../CommandPalette/commandPaletteLogic' | ||
|
||
type SearchResultProps = { | ||
result: CommandResultDisplayable | ||
focused: boolean | ||
} | ||
|
||
const ActionResult = ({ result, focused }: SearchResultProps): JSX.Element => { | ||
const { executeResult, onMouseEnterResult, onMouseLeaveResult } = useActions(actionBarLogic) | ||
|
||
const ref = useRef<HTMLDivElement | null>(null) | ||
const isExecutable = !!result.executor | ||
|
||
useEffect(() => { | ||
if (focused) { | ||
ref.current?.scrollIntoView() | ||
} | ||
}, [focused]) | ||
|
||
return ( | ||
<div className={`border-l-4 ${isExecutable ? 'border-primary' : ''}`}> | ||
<div | ||
className={`w-full pl-3 pr-2 ${ | ||
focused ? 'bg-secondary-3000-hover' : 'bg-secondary-3000' | ||
} border-b cursor-pointer`} | ||
onMouseEnter={() => { | ||
onMouseEnterResult(result.index) | ||
}} | ||
onMouseLeave={() => { | ||
onMouseLeaveResult() | ||
}} | ||
onClick={() => { | ||
if (isExecutable) { | ||
executeResult(result) | ||
} | ||
}} | ||
ref={ref} | ||
> | ||
<div className="px-2 py-3 w-full space-y-0.5 flex flex-col items-start"> | ||
{result.source.scope && ( | ||
<span className="text-muted-3000 text-xs">{getNameFromActionScope(result.source.scope)}</span> | ||
)} | ||
<span className="text-text-3000">{result.display}</span> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default ActionResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useValues } from 'kea' | ||
|
||
import { CommandResultDisplayable } from '../CommandPalette/commandPaletteLogic' | ||
|
||
import { actionBarLogic } from './actionBarLogic' | ||
import ActionResult from './ActionResult' | ||
import { getNameFromActionScope } from 'lib/components/CommandBar/utils' | ||
|
||
type ResultsGroupProps = { | ||
scope: string | ||
results: CommandResultDisplayable[] | ||
activeResultIndex: number | ||
} | ||
|
||
const ResultsGroup = ({ scope, results, activeResultIndex }: ResultsGroupProps): JSX.Element => { | ||
return ( | ||
<> | ||
<div className="border-b pl-3 pr-2 pt-1 pb-1 bg-bg-3000-light">{getNameFromActionScope(scope)}</div> | ||
{results.map((result) => ( | ||
<ActionResult | ||
key={`command_result_${result.index}`} | ||
result={result} | ||
focused={result.index === activeResultIndex} | ||
/> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
const ActionResults = (): JSX.Element => { | ||
const { commandSearchResultsGrouped, activeResultIndex } = useValues(actionBarLogic) | ||
|
||
return ( | ||
<div className="grow overscroll-none overflow-y-auto"> | ||
{commandSearchResultsGrouped.map(([scope, results]) => ( | ||
<ResultsGroup key={scope} scope={scope} results={results} activeResultIndex={activeResultIndex} /> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
export default ActionResults | ||
thmsobrmlr marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { kea, path, listeners, connect, afterMount, beforeUnmount } from 'kea' | ||
|
||
import { commandPaletteLogic } from '../CommandPalette/commandPaletteLogic' | ||
import { commandBarLogic } from './commandBarLogic' | ||
|
||
import { BarStatus } from './types' | ||
|
||
import type { actionBarLogicType } from './actionBarLogicType' | ||
|
||
export const actionBarLogic = kea<actionBarLogicType>([ | ||
path(['lib', 'components', 'CommandBar', 'actionBarLogic']), | ||
connect({ | ||
actions: [ | ||
commandBarLogic, | ||
['hideCommandBar', 'setCommandBar'], | ||
commandPaletteLogic, | ||
[ | ||
'showPalette', | ||
'hidePalette', | ||
'setInput', | ||
'executeResult', | ||
'backFlow', | ||
'onArrowUp', | ||
'onArrowDown', | ||
'onMouseEnterResult', | ||
'onMouseLeaveResult', | ||
], | ||
], | ||
values: [ | ||
commandPaletteLogic, | ||
[ | ||
'input', | ||
'activeResultIndex', | ||
'commandRegistrations', | ||
'commandSearchResults', | ||
'commandSearchResultsGrouped', | ||
'activeFlow', | ||
], | ||
], | ||
}), | ||
listeners(({ actions }) => ({ | ||
hidePalette: () => { | ||
// listen on hide action from legacy palette, and hide command bar | ||
actions.hideCommandBar() | ||
}, | ||
})), | ||
afterMount(({ actions, values, cache }) => { | ||
// trigger show action from legacy palette | ||
actions.showPalette() | ||
|
||
// register keyboard shortcuts | ||
cache.onKeyDown = (event: KeyboardEvent) => { | ||
if (event.key === 'Enter' && values.commandSearchResults.length) { | ||
// execute result | ||
const result = values.commandSearchResults[values.activeResultIndex] | ||
const isExecutable = !!result.executor | ||
if (isExecutable) { | ||
actions.executeResult(result) | ||
} | ||
} else if (event.key === 'ArrowDown') { | ||
// navigate to next result | ||
event.preventDefault() | ||
actions.onArrowDown(values.commandSearchResults.length - 1) | ||
} else if (event.key === 'ArrowUp') { | ||
// navigate to previous result | ||
event.preventDefault() | ||
actions.onArrowUp() | ||
} else if (event.key === 'Escape') { | ||
event.preventDefault() | ||
|
||
if (values.activeFlow) { | ||
// return to previous flow | ||
actions.backFlow() | ||
} else if (values.input) { | ||
// or erase input | ||
actions.setInput('') | ||
} else { | ||
// or hide palette | ||
actions.hidePalette() | ||
} | ||
} else if (event.key === 'Backspace') { | ||
if (values.input.length === 0) { | ||
// transition to search when pressing backspace with empty input | ||
actions.setCommandBar(BarStatus.SHOW_SEARCH) | ||
} | ||
} | ||
} | ||
window.addEventListener('keydown', cache.onKeyDown) | ||
}), | ||
beforeUnmount(({ actions, cache }) => { | ||
// trigger hide action from legacy palette | ||
actions.hidePalette() | ||
|
||
// unregister keyboard shortcuts | ||
window.removeEventListener('keydown', cache.onKeyDown) | ||
}), | ||
]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placeholder didn't render when doing CMD+K (it did with CMD+SHIFT+K)