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

chore(metrics): add metrics to track search query in AL #9235

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import graphql from 'babel-plugin-relay/macro'
import clsx from 'clsx'
import React, {useState} from 'react'
import React, {useEffect, useState} from 'react'
import {PreloadedQuery, usePreloadedQuery} from 'react-relay'
import {Redirect, useHistory} from 'react-router'
import {Link} from 'react-router-dom'
Expand All @@ -11,6 +11,8 @@ import {ActivityCard, ActivityCardImage} from '../ActivityCard'
import ActivityDetailsSidebar from '../ActivityDetailsSidebar'
import {CategoryID, CATEGORY_THEMES, QUICK_START_CATEGORY_ID} from '../Categories'
import {TemplateDetails} from './TemplateDetails'
import SendClientSideEvent from '../../../utils/SendClientSideEvent'
import useAtmosphere from '../../../hooks/useAtmosphere'

graphql`
fragment ActivityDetails_template on MeetingTemplate {
Expand All @@ -37,6 +39,7 @@ export const query = graphql`
query ActivityDetailsQuery($activityId: ID!) {
viewer {
...ActivityDetailsSidebar_viewer
activityLibrarySearch
preferredTeamId
tier
activity(activityId: $activityId) {
Expand All @@ -61,16 +64,27 @@ interface Props {
}

const ActivityDetails = (props: Props) => {
const atmosphere = useAtmosphere()
const {queryRef} = props
const data = usePreloadedQuery<ActivityDetailsQuery>(query, queryRef)
const {viewer} = data
const {activity, preferredTeamId, teams} = viewer
const {activity, activityLibrarySearch, preferredTeamId, teams} = viewer
const history = useHistory<{prevCategory?: string}>()
const [isEditing, setIsEditing] = useState(false)

if (!activity) {
return <Redirect to='/activity-library' />
}
useEffect(() => {
SendClientSideEvent(atmosphere, 'Viewed Template', {
meetingType: activity.type,
scope: activity.scope,
templateName: activity.name,
isFree: activity.isFree,
queryString: activityLibrarySearch
})
}, [])

const {category, illustrationUrl, viewerLowestScope} = activity
const prevCategory = history.location.state?.prevCategory
const categoryLink = `/activity-library/category/${
Expand Down
34 changes: 31 additions & 3 deletions packages/client/components/ActivityLibrary/ActivityLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ScrollArea from '@radix-ui/react-scroll-area'
import graphql from 'babel-plugin-relay/macro'
import clsx from 'clsx'
import React, {useMemo} from 'react'
import {PreloadedQuery, usePreloadedQuery} from 'react-relay'
import {PreloadedQuery, commitLocalUpdate, usePreloadedQuery} from 'react-relay'
import {Redirect} from 'react-router'
import {Link} from 'react-router-dom'
import {ActivityLibraryQuery} from '~/__generated__/ActivityLibraryQuery.graphql'
Expand All @@ -25,6 +25,8 @@ import {
} from './Categories'
import CreateActivityCard from './CreateActivityCard'
import SearchBar from './SearchBar'
import useAtmosphere from '../../hooks/useAtmosphere'
import SendClientSideEvent from '../../utils/SendClientSideEvent'

graphql`
fragment ActivityLibrary_templateSearchDocument on MeetingTemplate {
Expand Down Expand Up @@ -189,12 +191,26 @@ const ActivityGrid = ({templates, selectedCategory}: ActivityGridProps) => {
const MAX_PER_SUBCATEGORY = 6

export const ActivityLibrary = (props: Props) => {
const atmosphere = useAtmosphere()
const {queryRef} = props
const data = usePreloadedQuery<ActivityLibraryQuery>(query, queryRef)
const {viewer} = data
const {featureFlags, availableTemplates, organizations} = viewer
const hasOneOnOneFeatureFlag = !!organizations.find((org) => org.featureFlags.oneOnOne)

const setSearch = (value: string) => {
commitLocalUpdate(atmosphere, (store) => {
const viewer = store.getRoot().getLinkedRecord('viewer')
if (!viewer) return
viewer.setValue(value, 'activityLibrarySearch')
})
if (value.length > 2) {
SendClientSideEvent(atmosphere, 'Activity Library Searched', {
queryString: value
})
}
}

const templates = useMemo(() => {
const templatesMap = availableTemplates.edges.map((edge) => edge.node)
if (!hasOneOnOneFeatureFlag) {
Expand Down Expand Up @@ -279,7 +295,13 @@ export const ActivityLibrary = (props: Props) => {
</div>
</div>
<div className='hidden grow md:block'>
<SearchBar searchQuery={searchQuery} onChange={onQueryChange} />
<SearchBar
searchQuery={searchQuery}
onChange={(e) => {
onQueryChange(e)
setSearch(e.target.value)
}}
/>
</div>
<Link
className='rounded-full bg-sky-500 px-4 py-2 text-sm font-medium text-white hover:bg-sky-600'
Expand All @@ -289,7 +311,13 @@ export const ActivityLibrary = (props: Props) => {
</Link>
</div>
<div className='mt-4 flex w-full md:hidden'>
<SearchBar searchQuery={searchQuery} onChange={onQueryChange} />
<SearchBar
searchQuery={searchQuery}
onChange={(e) => {
onQueryChange(e)
setSearch(e.target.value)
}}
/>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/client/schemaExtensions/clientSchema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extend type User {
# If positive, client clock is ahead of server clock by this many ms
clientClockOffset: Int
dashSearch: String
activityLibrarySearch: String
pageName: String
# The team we should default to in team pickers, etc.
preferredTeamId: ID
Expand Down
Loading