Skip to content

Commit

Permalink
fuzzy finder: log user events (#45358)
Browse files Browse the repository at this point in the history
  • Loading branch information
taras-yemets committed Dec 8, 2022
1 parent b69b159 commit 3a774ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
26 changes: 23 additions & 3 deletions client/web/src/components/fuzzyFinder/FuzzyFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const FuzzyFinderContainer: React.FunctionComponent<FuzzyFinderContainerP
const { isVisible, setIsVisible } = props
const isVisibleRef = useRef(isVisible)
isVisibleRef.current = isVisible
const state = useFuzzyState(props, () => setIsVisible(false))
const { tabs, activeTab, setActiveTab, repoRevision, isScopeToggleDisabled, toggleScope } = state
const state = useFuzzyState(props)
const { tabs, activeTab, setActiveTab, repoRevision, scope, isScopeToggleDisabled, toggleScope } = state
const isScopeToggleDisabledRef = useRef(isScopeToggleDisabled)
isScopeToggleDisabledRef.current = isScopeToggleDisabled

Expand Down Expand Up @@ -79,6 +79,14 @@ export const FuzzyFinderContainer: React.FunctionComponent<FuzzyFinderContainerP
}
}, [props.telemetryService, isVisible])

const handleItemClick = useCallback(
(eventName: 'FuzzyFinderResultClicked' | 'FuzzyFinderGoToResultsPageClicked') => {
props.telemetryService.log(eventName, { activeTab, scope }, { activeTab, scope })
setIsVisible(false)
},
[props.telemetryService, setIsVisible, activeTab, scope]
)

if (tabs.isAllDisabled()) {
return null
}
Expand All @@ -103,14 +111,26 @@ export const FuzzyFinderContainer: React.FunctionComponent<FuzzyFinderContainerP
/>
))
)}
{isVisible && <FuzzyFinder {...state} setIsVisible={setIsVisible} location={props.location} />}
{isVisible && (
<FuzzyFinder
{...state}
setIsVisible={setIsVisible}
location={props.location}
onClickItem={handleItemClick}
/>
)}
</>
)
}

interface FuzzyFinderProps extends FuzzyState {
setIsVisible: Dispatch<SetStateAction<boolean>>

/**
* Search result click handler.
*/
onClickItem: (eventName: 'FuzzyFinderResultClicked' | 'FuzzyFinderGoToResultsPageClicked') => void

location: H.Location

/**
Expand Down
14 changes: 10 additions & 4 deletions client/web/src/components/fuzzyFinder/FuzzyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface FuzzyModalProps extends FuzzyState {
initialMaxResults: number
initialQuery: string
onClose: () => void
onClickItem: (eventName: 'FuzzyFinderResultClicked' | 'FuzzyFinderGoToResultsPageClicked') => void
tabs: FuzzyTabs
location: H.Location
}
Expand Down Expand Up @@ -236,6 +237,7 @@ export const FuzzyModal: React.FunctionComponent<React.PropsWithChildren<FuzzyMo
)

// Stage 2: render results from the fuzzy matcher.
const handleResultClick = useCallback(() => onClickItem('FuzzyFinderResultClicked'), [onClickItem])
const queryResult = useMemo<QueryResult>(() => {
const fsmErrors = fuzzyErrors(tabs, activeTab, scope)
if (fsmErrors.length > 0) {
Expand All @@ -247,7 +249,7 @@ export const FuzzyModal: React.FunctionComponent<React.PropsWithChildren<FuzzyMo
maxResults,
initialMaxResults,
setMaxResults,
onClickItem
handleResultClick
)
}, [
activeTab,
Expand All @@ -257,7 +259,7 @@ export const FuzzyModal: React.FunctionComponent<React.PropsWithChildren<FuzzyMo
maxResults,
initialMaxResults,
setMaxResults,
onClickItem,
handleResultClick,
tabs,
])

Expand Down Expand Up @@ -336,6 +338,10 @@ export const FuzzyModal: React.FunctionComponent<React.PropsWithChildren<FuzzyMo
}
: {}

const handleGoToResultsPageClick = useCallback(() => onClickItem('FuzzyFinderGoToResultsPageClicked'), [
onClickItem,
])

return (
<Modal
position="center"
Expand Down Expand Up @@ -427,7 +433,7 @@ export const FuzzyModal: React.FunctionComponent<React.PropsWithChildren<FuzzyMo
)}
<hr className="my-0 w-100" />
<div className="d-flex align-items-center w-100 p-3">
<SearchQueryLink {...props} />
<SearchQueryLink {...props} onClickItem={handleGoToResultsPageClick} />
<span className="ml-auto mr-2">
<ArrowKeyExplanation />
</span>
Expand Down Expand Up @@ -502,7 +508,7 @@ const ScopeSelect: React.FunctionComponent<ScopeSelectProps> = ({
</Select>
)

const SearchQueryLink: React.FunctionComponent<FuzzyState> = props => {
const SearchQueryLink: React.FunctionComponent<FuzzyState & { onClickItem: () => void }> = props => {
const { onClickItem, scope } = props
const searchQueryLink = useCallback(
(query: string): JSX.Element => {
Expand Down
5 changes: 1 addition & 4 deletions client/web/src/components/fuzzyFinder/FuzzyTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export interface FuzzyState {
isScopeToggleDisabled: boolean
scope: FuzzyScope
toggleScope: () => void
onClickItem: () => void
}

export function fuzzyIsActive(activeTab: FuzzyTabKey, tab: FuzzyTabKey): boolean {
Expand Down Expand Up @@ -177,7 +176,6 @@ export function defaultFuzzyState(): FuzzyState {
let activeTab: FuzzyTabKey = 'all'
return {
query,
onClickItem: () => {},
setQuery: newQuery => {
if (typeof newQuery === 'function') {
query = newQuery(query)
Expand Down Expand Up @@ -219,7 +217,7 @@ export interface FuzzyTabsProps extends FuzzyActionProps {
isVisible: boolean
}

export function useFuzzyState(props: FuzzyTabsProps, onClickItem: () => void): FuzzyState {
export function useFuzzyState(props: FuzzyTabsProps): FuzzyState {
const {
themeState,
isVisible,
Expand Down Expand Up @@ -383,7 +381,6 @@ export function useFuzzyState(props: FuzzyTabsProps, onClickItem: () => void): F
])

return {
onClickItem,
query,
setQuery,
activeTab,
Expand Down

0 comments on commit 3a774ed

Please sign in to comment.