-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add AI Regex Helper to path cleaning (#28512)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7990817
commit 039d09b
Showing
8 changed files
with
260 additions
and
196 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
103 changes: 103 additions & 0 deletions
103
frontend/src/lib/components/PathCleanFilters/PathRegexModal.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,103 @@ | ||
import { LemonButton, LemonInput, LemonModal, Link } from '@posthog/lemon-ui' | ||
import { FEATURE_FLAGS } from 'lib/constants' | ||
import { isValidRegexp } from 'lib/utils/regexp' | ||
import { useState } from 'react' | ||
import { AiRegexHelperButton } from 'scenes/session-recordings/components/AiRegexHelper/AiRegexHelper' | ||
import { AiRegexHelper } from 'scenes/session-recordings/components/AiRegexHelper/AiRegexHelper' | ||
|
||
import { PathCleaningFilter } from '~/types' | ||
|
||
import { FlaggedFeature } from '../FlaggedFeature' | ||
|
||
export interface PathRegexModalProps { | ||
isOpen: boolean | ||
onSave: (filter: PathCleaningFilter) => void | ||
onClose: () => void | ||
filter?: PathCleaningFilter | ||
} | ||
|
||
export function PathRegexModal({ filter, isOpen, onSave, onClose }: PathRegexModalProps): JSX.Element { | ||
const [alias, setAlias] = useState(filter?.alias ?? '') | ||
const [regex, setRegex] = useState(filter?.regex ?? '') | ||
|
||
const isNew = !filter | ||
const disabledReason = !alias | ||
? 'Alias is required' | ||
: !regex | ||
? 'Regex is required' | ||
: !isValidRegexp(regex) | ||
? 'Malformed regex' | ||
: null | ||
|
||
return ( | ||
<LemonModal isOpen={isOpen} onClose={onClose}> | ||
<LemonModal.Header> | ||
{isNew ? <b>Add Path Cleaning Rule</b> : <b>Edit Path Cleaning Rule</b>} | ||
</LemonModal.Header> | ||
|
||
<LemonModal.Content> | ||
<div className="px-2 py-1" data-attr="path-regex-modal-content"> | ||
<div className="space-y-2"> | ||
<div> | ||
<span>Alias</span> | ||
<LemonInput | ||
value={alias} | ||
onChange={(alias) => setAlias(alias)} | ||
onPressEnter={() => false} | ||
/> | ||
<div className="text-muted"> | ||
We suggest you use <code><id></code> or <code><slug></code> to indicate a | ||
dynamic part of the path. | ||
</div> | ||
</div> | ||
<div> | ||
<span>Regex</span> | ||
<LemonInput | ||
value={regex} | ||
onChange={(regex) => setRegex(regex)} | ||
onPressEnter={() => false} | ||
/> | ||
<p className="text-secondary"> | ||
<span> | ||
Example:{' '} | ||
<span className="font-mono text-accent-primary text-xs"> | ||
/merchant/\d+/dashboard$ | ||
</span>{' '} | ||
(no need to escape slashes) | ||
</span>{' '} | ||
<br /> | ||
<span> | ||
We use the{' '} | ||
<Link to="https://github.com/google/re2/wiki/Syntax" target="_blank"> | ||
re2 | ||
</Link>{' '} | ||
syntax. | ||
</span> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div className="flex space-between mt-3"> | ||
<FlaggedFeature flag={FEATURE_FLAGS.PATH_CLEANING_AI_REGEX}> | ||
<AiRegexHelper onApply={setRegex} /> | ||
<AiRegexHelperButton /> | ||
</FlaggedFeature> | ||
|
||
<div className="flex flex-1 justify-end gap-2"> | ||
<LemonButton type="secondary" onClick={onClose}> | ||
Cancel | ||
</LemonButton> | ||
<LemonButton | ||
type="primary" | ||
onClick={() => onSave({ alias, regex })} | ||
disabledReason={disabledReason} | ||
> | ||
Save | ||
</LemonButton> | ||
</div> | ||
</div> | ||
</div> | ||
</LemonModal.Content> | ||
</LemonModal> | ||
) | ||
} |
73 changes: 0 additions & 73 deletions
73
frontend/src/lib/components/PathCleanFilters/PathRegexPopover.tsx
This file was deleted.
Oops, something went wrong.
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.