-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dw-virtual-data-warehouse-table-breakdowns
- Loading branch information
Showing
30 changed files
with
958 additions
and
153 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -182,4 +182,4 @@ services: | |
- clickhouse | ||
- kafka | ||
- object_storage | ||
- temporal | ||
- temporal |
Binary file modified
BIN
-25 Bytes
(100%)
frontend/__snapshots__/lemon-ui-colors--color-palette--dark.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
BIN
-12 Bytes
(100%)
frontend/__snapshots__/lemon-ui-colors--color-palette--light.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
BIN
+112 Bytes
(110%)
frontend/__snapshots__/lemon-ui-lemon-slider--basic--dark.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
BIN
+73 Bytes
(110%)
frontend/__snapshots__/lemon-ui-lemon-slider--basic--light.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
BIN
+24 Bytes
(100%)
frontend/__snapshots__/lemon-ui-lemon-tag--breakdown-tag--dark.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
BIN
+26 Bytes
(100%)
frontend/__snapshots__/lemon-ui-lemon-tag--breakdown-tag--light.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
BIN
+268 Bytes
(110%)
frontend/__snapshots__/lemon-ui-scrollable-shadows--horizontal--dark.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
BIN
+207 Bytes
(110%)
frontend/__snapshots__/lemon-ui-scrollable-shadows--horizontal--light.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
BIN
+354 Bytes
(110%)
frontend/__snapshots__/lemon-ui-scrollable-shadows--vertical--dark.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
BIN
+346 Bytes
(110%)
frontend/__snapshots__/lemon-ui-scrollable-shadows--vertical--light.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
BIN
+968 Bytes
(100%)
frontend/__snapshots__/posthog-3000-navigation--navigation-base--dark.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
BIN
-426 Bytes
(100%)
frontend/__snapshots__/posthog-3000-navigation--navigation-base--light.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
BIN
+242 Bytes
(100%)
frontend/__snapshots__/scenes-app-batchexports--view-export--dark.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 added
BIN
+98.9 KB
...tend/__snapshots__/scenes-app-sidepanels--side-panel-support-no-email--dark.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 added
BIN
+99.7 KB
...end/__snapshots__/scenes-app-sidepanels--side-panel-support-no-email--light.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 added
BIN
+187 KB
...nd/__snapshots__/scenes-app-sidepanels--side-panel-support-with-email--dark.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 added
BIN
+180 KB
...d/__snapshots__/scenes-app-sidepanels--side-panel-support-with-email--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
268 changes: 268 additions & 0 deletions
268
frontend/src/layout/navigation-3000/components/AlgoliaSearch.tsx
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,268 @@ | ||
import { IconCheckCircle } from '@posthog/icons' | ||
import { LemonButton, LemonInput, LemonTag } from '@posthog/lemon-ui' | ||
import algoliasearch from 'algoliasearch/lite' | ||
import { useActions } from 'kea' | ||
import { useEffect, useRef, useState } from 'react' | ||
import { InstantSearch, useHits, useRefinementList, useSearchBox } from 'react-instantsearch' | ||
import { AutoSizer } from 'react-virtualized/dist/es/AutoSizer' | ||
import { List } from 'react-virtualized/dist/es/List' | ||
|
||
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic' | ||
import { SidePanelTab } from '~/types' | ||
|
||
const searchClient = algoliasearch('7VNQB5W0TX', '37f41fd37095bc85af76ed4edc85eb5a') | ||
|
||
const rowRenderer = ({ key, index, style, hits, activeOption }: any): JSX.Element => { | ||
const { slug, title, type, resolved } = hits[index] | ||
return ( | ||
// eslint-disable-next-line react/forbid-dom-props | ||
<li key={key} style={style} role="listitem" tabIndex={-1} className="p-1 border-b last:border-b-0"> | ||
<LemonButton | ||
active={activeOption === index} | ||
to={`https://posthog.com/${slug}`} | ||
className="[&_>span>span]:flex-col [&_>span>span]:items-start [&_>span>span]:space-y-1" | ||
> | ||
<span> | ||
<span className="flex space-x-2 items-center"> | ||
<p className="m-0 font-bold font-sans line-clamp-1">{title}</p> | ||
{type === 'question' && resolved && ( | ||
<IconCheckCircle className="text-success size-4 flex-shrink-0" /> | ||
)} | ||
</span> | ||
<p className="text-xs m-0 opacity-80 font-normal font-sans line-clamp-1">/{slug}</p> | ||
</span> | ||
</LemonButton> | ||
</li> | ||
) | ||
} | ||
|
||
const Hits = ({ activeOption }: { activeOption?: number }): JSX.Element => { | ||
const { hits } = useHits() | ||
return ( | ||
<ol role="listbox" className="list-none m-0 p-0 h-[80vh]"> | ||
<AutoSizer> | ||
{({ height, width }: { height: number; width: number }) => ( | ||
<List | ||
scrollToIndex={activeOption} | ||
width={width} | ||
height={height} | ||
rowCount={hits.length} | ||
rowHeight={50} | ||
rowRenderer={(options: any) => rowRenderer({ ...options, hits, activeOption })} | ||
/> | ||
)} | ||
</AutoSizer> | ||
</ol> | ||
) | ||
} | ||
|
||
const SearchInput = ({ | ||
value, | ||
setValue, | ||
}: { | ||
value: string | ||
setValue: React.Dispatch<React.SetStateAction<string>> | ||
}): JSX.Element => { | ||
const { refine } = useSearchBox() | ||
|
||
const handleChange = (value: string): void => { | ||
setValue(value) | ||
refine(value) | ||
} | ||
|
||
return <LemonInput onChange={handleChange} value={value} type="search" fullWidth placeholder="Search..." /> | ||
} | ||
|
||
type Tag = { | ||
type: string | ||
label: string | ||
} | ||
|
||
const tags: Tag[] = [ | ||
{ | ||
type: 'all', | ||
label: 'All', | ||
}, | ||
{ | ||
type: 'docs', | ||
label: 'Docs', | ||
}, | ||
{ | ||
type: 'question', | ||
label: 'Questions', | ||
}, | ||
{ | ||
type: 'tutorial', | ||
label: 'Tutorials', | ||
}, | ||
] | ||
|
||
type SearchTagProps = Tag & { | ||
active?: boolean | ||
onClick: (type: string) => void | ||
} | ||
|
||
const SearchTag = ({ type, label, active, onClick }: SearchTagProps): JSX.Element => { | ||
const { refine, items } = useRefinementList({ attribute: 'type' }) | ||
const itemCount = type !== 'all' && items.find(({ value }) => value === type)?.count | ||
|
||
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => { | ||
e.stopPropagation() | ||
onClick(type) | ||
} | ||
|
||
useEffect(() => { | ||
refine(type) | ||
}, []) | ||
|
||
return ( | ||
<button className="p-0 cursor-pointer bg-bg-light" onClick={handleClick}> | ||
<LemonTag size="medium" type={active ? 'primary' : 'option'}> | ||
<span>{label}</span> | ||
{type !== 'all' && <span>({itemCount ?? 0})</span>} | ||
</LemonTag> | ||
</button> | ||
) | ||
} | ||
|
||
const Tags = ({ | ||
activeTag, | ||
setActiveTag, | ||
}: { | ||
activeTag: string | ||
setActiveTag: React.Dispatch<React.SetStateAction<string>> | ||
}): JSX.Element => { | ||
const handleClick = (type: string): void => { | ||
setActiveTag(type) | ||
} | ||
|
||
return ( | ||
<ul className="list-none m-0 p-0 flex space-x-1 mt-1 mb-0.5 pb-1.5 border-b px-2"> | ||
{tags.map((tag) => { | ||
const { type } = tag | ||
return ( | ||
<li key={type}> | ||
<SearchTag {...tag} active={activeTag === type} onClick={handleClick} /> | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
) | ||
} | ||
|
||
const Search = (): JSX.Element => { | ||
const { openSidePanel } = useActions(sidePanelStateLogic) | ||
const { hits } = useHits() | ||
const { items, refine } = useRefinementList({ attribute: 'type' }) | ||
|
||
const ref = useRef<HTMLDivElement>(null) | ||
const [searchValue, setSearchValue] = useState<string>('') | ||
const [activeOption, setActiveOption] = useState<undefined | number>() | ||
const [activeTag, setActiveTag] = useState('all') | ||
const [searchOpen, setSearchOpen] = useState(false) | ||
|
||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>): void => { | ||
switch (e.key) { | ||
case 'Enter': { | ||
if (activeOption !== undefined) { | ||
openSidePanel(SidePanelTab.Docs, `https://posthog.com/${hits[activeOption].slug}`) | ||
} | ||
break | ||
} | ||
|
||
case 'Escape': { | ||
setSearchOpen(false) | ||
break | ||
} | ||
case 'ArrowDown': { | ||
e.preventDefault() | ||
setActiveOption((currOption) => { | ||
if (currOption === undefined || currOption >= hits.length - 1) { | ||
return 0 | ||
} | ||
return currOption + 1 | ||
}) | ||
break | ||
} | ||
case 'ArrowUp': { | ||
e.preventDefault() | ||
setActiveOption((currOption) => { | ||
if (currOption !== undefined) { | ||
return currOption <= 0 ? hits.length - 1 : currOption - 1 | ||
} | ||
}) | ||
break | ||
} | ||
case 'Tab': | ||
case 'ArrowRight': { | ||
e.preventDefault() | ||
const currTagIndex = tags.findIndex(({ type }) => type === activeTag) | ||
setActiveTag(tags[currTagIndex >= tags.length - 1 ? 0 : currTagIndex + 1].type) | ||
break | ||
} | ||
case 'ArrowLeft': { | ||
e.preventDefault() | ||
const currTagIndex = tags.findIndex(({ type }) => type === activeTag) | ||
setActiveTag(tags[currTagIndex <= 0 ? tags.length - 1 : currTagIndex - 1].type) | ||
} | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
setSearchOpen(!!searchValue) | ||
setActiveOption(0) | ||
}, [searchValue]) | ||
|
||
useEffect(() => { | ||
setActiveOption(0) | ||
if (activeTag === 'all') { | ||
const filteredItems = items.filter(({ value }) => tags.some(({ type }) => type === value)) | ||
filteredItems.forEach(({ value, isRefined }) => { | ||
if (!isRefined) { | ||
refine(value) | ||
} | ||
}) | ||
} else { | ||
items.forEach(({ value, isRefined }) => { | ||
if (isRefined) { | ||
refine(value) | ||
} | ||
}) | ||
refine(activeTag) | ||
} | ||
}, [activeTag]) | ||
|
||
useEffect(() => { | ||
const handleClick = (e: any): void => { | ||
if (!ref?.current?.contains(e.target)) { | ||
setSearchOpen(false) | ||
} | ||
} | ||
|
||
window.addEventListener('click', handleClick) | ||
|
||
return () => { | ||
window.removeEventListener('click', handleClick) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div className="relative" ref={ref} onKeyDown={handleKeyDown}> | ||
<SearchInput value={searchValue} setValue={setSearchValue} /> | ||
{searchOpen && ( | ||
<div className="absolute w-full bg-bg-light z-50 border rounded-lg shadow-xl mt-0.5"> | ||
<Tags activeTag={activeTag} setActiveTag={setActiveTag} /> | ||
<Hits activeOption={activeOption} /> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default function AlgoliaSearch(): JSX.Element { | ||
return ( | ||
<InstantSearch searchClient={searchClient} indexName="prod_posthog_com"> | ||
<Search /> | ||
</InstantSearch> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { Meta, StoryFn } from '@storybook/react' | ||
import { useActions } from 'kea' | ||
import { router } from 'kea-router' | ||
import { supportLogic } from 'lib/components/Support/supportLogic' | ||
import { useEffect } from 'react' | ||
import { App } from 'scenes/App' | ||
import { urls } from 'scenes/urls' | ||
|
||
import { mswDecorator } from '~/mocks/browser' | ||
import { mswDecorator, useStorybookMocks } from '~/mocks/browser' | ||
import organizationCurrent from '~/mocks/fixtures/api/organizations/@current/@current.json' | ||
import { SidePanelTab } from '~/types' | ||
|
||
import { sidePanelStateLogic } from './sidePanelStateLogic' | ||
|
@@ -59,3 +61,36 @@ export const SidePanelActivation: StoryFn = () => { | |
export const SidePanelNotebooks: StoryFn = () => { | ||
return <BaseTemplate panel={SidePanelTab.Notebooks} /> | ||
} | ||
|
||
export const SidePanelSupportNoEmail: StoryFn = () => { | ||
return <BaseTemplate panel={SidePanelTab.Support} /> | ||
} | ||
|
||
export const SidePanelSupportWithEmail: StoryFn = () => { | ||
const { openEmailForm } = useActions(supportLogic) | ||
useStorybookMocks({ | ||
get: { | ||
// TODO: setting available featues should be a decorator to make this easy | ||
'/api/users/@me': () => [ | ||
200, | ||
{ | ||
email: '[email protected]', | ||
first_name: 'Test Hedgehog', | ||
organization: { | ||
...organizationCurrent, | ||
available_product_features: [ | ||
{ | ||
key: 'email_support', | ||
name: 'Email support', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
useEffect(() => { | ||
openEmailForm() | ||
}, []) | ||
return <BaseTemplate panel={SidePanelTab.Support} /> | ||
} |
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
Oops, something went wrong.