-
Notifications
You must be signed in to change notification settings - Fork 46
feat: Render PostHog URLs as rich preview chips #2355
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
base: main
Are you sure you want to change the base?
Changes from all commits
39e2405
dd080d5
38f407d
86fe013
c3ca2f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { escapeXmlAttr, unescapeXmlAttr } from "@posthog/shared"; | ||
| import { parsePostHogUrl } from "./posthogUrl"; | ||
|
|
||
| export interface MentionChip { | ||
| type: | ||
|
|
@@ -9,6 +10,16 @@ export interface MentionChip { | |
| | "experiment" | ||
| | "insight" | ||
| | "feature_flag" | ||
| | "dashboard" | ||
| | "recording" | ||
| | "error_tracking" | ||
| | "survey" | ||
| | "notebook" | ||
| | "cohort" | ||
| | "action" | ||
| | "early_access_feature" | ||
| | "person" | ||
| | "group" | ||
| | "github_issue" | ||
| | "github_pr"; | ||
| id: string; | ||
|
|
@@ -67,11 +78,19 @@ export function contentToXml(content: EditorContent): string { | |
| case "error": | ||
| return `<error id="${escapedId}" />`; | ||
| case "experiment": | ||
| return `<experiment id="${escapedId}" />`; | ||
| case "insight": | ||
| return `<insight id="${escapedId}" />`; | ||
| case "feature_flag": | ||
| return `<feature_flag id="${escapedId}" />`; | ||
| case "dashboard": | ||
| case "recording": | ||
| case "error_tracking": | ||
| case "survey": | ||
| case "notebook": | ||
| case "cohort": | ||
| case "action": | ||
| case "early_access_feature": | ||
| case "person": | ||
| case "group": | ||
| return `<${chip.type} id="${escapedId}" label="${escapeXmlAttr(chip.label)}" />`; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/code/src/renderer/features/message-editor/utils/content.ts
Line: 81
Comment:
**"Loading…" placeholder can be persisted in XML**
`chip.label` is written verbatim into the `label` attribute. If the user pastes a PostHog URL and submits the message before `resolvePostHogRefChip` fires (typical API round-trip of 100–500 ms), the label stored in the XML will be `"Feature Flag #42 - Loading..."`. Any later rendering of that message from history will show "Loading…" permanently. The GitHub path avoids this by serialising `number` and `title` separately — a missing title just produces an empty `title` attr and the label is reconstructed cleanly. PostHog chips should apply the same guard, e.g. strip the ` - Loading...` suffix (or fall back to the ID-only label) before persisting.
How can I resolve this? If you propose a fix, please make it concise. |
||
| case "github_issue": | ||
| case "github_pr": { | ||
| const labelMatch = chip.label.match(/^#(\d+)(?:\s*-\s*(.*))?$/); | ||
|
|
@@ -97,7 +116,7 @@ export function contentToXml(content: EditorContent): string { | |
| } | ||
|
|
||
| const CHIP_TAG_REGEX = | ||
| /<(file|folder|error|experiment|insight|feature_flag|github_issue|github_pr)\b([^>]*?)\s*\/>/g; | ||
| /<(file|folder|error|experiment|insight|feature_flag|dashboard|recording|error_tracking|survey|notebook|cohort|action|early_access_feature|person|group|github_issue|github_pr)\b([^>]*?)\s*\/>/g; | ||
| const ATTR_REGEX = /(\w+)="([^"]*)"/g; | ||
|
|
||
| export function deriveFileLabel(filePath: string): string { | ||
|
|
@@ -128,13 +147,28 @@ function chipFromTag(tag: string, rawAttrs: string): MentionChip | null { | |
| if (!path) return null; | ||
| return { type: "folder", id: path, label: deriveFileLabel(path) }; | ||
| } | ||
| case "error": | ||
| case "error": { | ||
| const id = attrs.id; | ||
| if (!id) return null; | ||
| return { type: tag, id, label: id }; | ||
| } | ||
| case "experiment": | ||
| case "insight": | ||
| case "feature_flag": { | ||
| case "feature_flag": | ||
| case "dashboard": | ||
| case "recording": | ||
| case "error_tracking": | ||
| case "survey": | ||
| case "notebook": | ||
| case "cohort": | ||
| case "action": | ||
| case "early_access_feature": | ||
| case "person": | ||
| case "group": { | ||
| const id = attrs.id; | ||
| if (!id) return null; | ||
| return { type: tag, id, label: id }; | ||
| const label = attrs.label || parsePostHogUrl(id)?.label || id; | ||
| return { type: tag, id, label }; | ||
| } | ||
| case "github_issue": | ||
| case "github_pr": { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDefaultProjectIddoes nothing but delegate togetTeamId. The one caller inposthogChip.tscould callgetTeamId()directly (with its ownString()cast), orgetDefaultProjectIdcould at least drop the unnecessaryasynckeyword since it is a singlereturnof an already-Promise-returning method.Prompt To Fix With AI