Skip to content

Commit

Permalink
Merge branch 'master' into search-insight-name
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/__snapshots__/components-command-bar--search.png
  • Loading branch information
thmsobrmlr committed Nov 22, 2023
2 parents c3900cc + d78450e commit fb567f7
Show file tree
Hide file tree
Showing 56 changed files with 5,555 additions and 1,188 deletions.
13 changes: 11 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
},
ecmaVersion: 2018,
sourceType: 'module',
project: 'tsconfig.json'
project: 'tsconfig.json',
},
plugins: ['prettier', 'react', 'cypress', '@typescript-eslint', 'no-only-tests', 'jest', 'compat', 'posthog'],
rules: {
Expand Down Expand Up @@ -112,6 +112,11 @@ module.exports = {
importNames: ['Tooltip'],
message: 'Please use Tooltip from @posthog/lemon-ui instead.',
},
{
name: 'antd',
importNames: ['Alert'],
message: 'Please use LemonBanner from @posthog/lemon-ui instead.',
},
],
},
],
Expand Down Expand Up @@ -231,6 +236,10 @@ module.exports = {
element: 'a',
message: 'use <Link> instead',
},
{
element: 'Alert',
message: 'use <LemonBanner> instead',
},
],
},
],
Expand All @@ -254,7 +263,7 @@ module.exports = {
rules: {
// The below complains needlessly about expect(api.createInvite).toHaveBeenCalledWith(...)
'@typescript-eslint/unbound-method': 'off',
}
},
},
{
// disable these rules for files generated by kea-typegen
Expand Down
1 change: 1 addition & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
// CSS Color Module Level 3 says currentColor, Level 4 candidate says currentcolor
// Sticking to Level 3 for now
camelCaseSvgKeywords: true,
ignoreKeywords: ['BlinkMacSystemFont'], // BlinkMacSystemFont MUST have this particular casing
},
],
// Sadly Safari only started supporting the range syntax of media queries in 2023, so let's switch to that
Expand Down
3 changes: 3 additions & 0 deletions cypress/e2e/featureFlags.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('Feature Flags', () => {
cy.get('[data-attr=save-feature-flag]').first().click()

// after save there should be a delete button
cy.get('[data-attr="more-button"]').click()
cy.get('button[data-attr="delete-feature-flag"]').should('have.text', 'Delete feature flag')

// make sure the data is there as expected after a page reload!
Expand Down Expand Up @@ -83,11 +84,13 @@ describe('Feature Flags', () => {
cy.get('[data-attr=save-feature-flag]').first().click()

// after save there should be a delete button
cy.get('[data-attr="more-button"]').click()
cy.get('button[data-attr="delete-feature-flag"]').should('have.text', 'Delete feature flag')

cy.clickNavMenu('featureflags')
cy.get('[data-attr=feature-flag-table]').should('contain', name)
cy.get(`[data-row-key=${name}]`).contains(name).click()
cy.get('[data-attr="more-button"]').click()
cy.get('[data-attr=delete-feature-flag]').click()
cy.get('.Toastify').contains('Undo').should('be.visible')
})
Expand Down
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.
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.
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
10 changes: 10 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ class ApiRequest {
return this.featureFlags(teamId).addPathComponent(id)
}

public featureFlagCreateStaticCohort(id: FeatureFlagType['id'], teamId?: TeamType['id']): ApiRequest {
if (!id) {
throw new Error('Must provide an ID for the feature flag to construct the URL')
}
return this.featureFlag(id, teamId).addPathComponent('create_static_cohort_for_flag')
}

public featureFlagsActivity(id: FeatureFlagType['id'], teamId: TeamType['id']): ApiRequest {
if (id) {
return this.featureFlag(id, teamId).addPathComponent('activity')
Expand Down Expand Up @@ -728,6 +735,9 @@ const api = {
async get(id: FeatureFlagType['id']): Promise<FeatureFlagType> {
return await new ApiRequest().featureFlag(id).get()
},
async createStaticCohort(id: FeatureFlagType['id']): Promise<{ cohort: CohortType }> {
return await new ApiRequest().featureFlagCreateStaticCohort(id).create()
},
},

organizationFeatureFlags: {
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 @@ -47,9 +47,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

0 comments on commit fb567f7

Please sign in to comment.