Skip to content

Commit

Permalink
web: add analytics information for filter term input (#4672)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizzthabet committed Jun 22, 2021
1 parent 66e60f9 commit 59dd5b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion web/src/OverviewActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ function FilterTermFieldError({ error }: { error: string }) {
}

const debounceFilterLogs = debounce((history: History, search: string) => {
// Record the action for analytics
incr("ui.web.filterTerm", { action: "edit" })
// Navigate to filtered logs with search query
history.push({ search })
}, FILTER_INPUT_DEBOUNCE)

Expand Down Expand Up @@ -530,7 +533,7 @@ export function FilterTermField({ termFromUrl }: { termFromUrl: FilterTerm }) {
const endAdornment = (
<InputAdornment position="end">
<ClearFilterTermTextButton
analyticsName="TODO"
analyticsName="ui.web.clearFilterTerm"
onClick={() => setTerm(EMPTY_TERM, false)}
>
<SrOnly>Clear filter term</SrOnly>
Expand Down
12 changes: 11 additions & 1 deletion web/src/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { FilterLevel, filterSetFromLocation, FilterSource } from "./logfilters"
import {
FilterLevel,
filterSetFromLocation,
FilterSource,
isRegexp,
TermState,
} from "./logfilters"

export type Tags = { [key: string]: string }

Expand Down Expand Up @@ -46,5 +52,9 @@ export let navigationToTags = (location: any, action: string): Tags => {
if (filterSet.source != FilterSource.all) {
tags.source = filterSet.source
}
if (filterSet.term.state !== TermState.Empty) {
const termType = isRegexp(filterSet.term.input) ? "regexp" : "text"
tags.term = termType
}
return tags
}
6 changes: 5 additions & 1 deletion web/src/logfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ export const EMPTY_FILTER_TERM: FilterTerm = {
}
const TERM_REGEXP_FLAGS = "gi" // Terms are case-insensitive and can match multiple instances

export function isRegexp(input: string): boolean {
return input.length > 2 && input[0] === "/" && input[input.length - 1] === "/"
}

export function parseTermInput(input: string): RegExp {
// Input strings that are surrounded by `/` can be parsed as regular expressions
if (input.length > 2 && input[0] === "/" && input[input.length - 1] === "/") {
if (isRegexp(input)) {
const regexpInput = input.slice(1, input.length - 1)

return new RegExp(regexpInput, TERM_REGEXP_FLAGS)
Expand Down

0 comments on commit 59dd5b1

Please sign in to comment.