-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(surveys): adds targeting changes to the survey revision history #23834
Conversation
…bvious way. And I need to add the UI for pulling data from featureflag serialization
@@ -260,6 +260,22 @@ export function flagActivityDescriber(logItem: ActivityLogItem, asNotification?: | |||
return { description: null } | |||
} | |||
|
|||
if (logItem.activity === 'created') { |
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.
updated <strong>{questionChanges.length}</strong> question{questionChanges.length !== 1 ? 's' : ''}: | ||
<ul className="bullet-list"> | ||
{questionChanges.map(({ index, changes }) => ( | ||
<li key={index}> | ||
Question {index}: | ||
<ul className="bullet-list"> | ||
{changes.map((changeItem, changeIndex) => ( | ||
<li key={changeIndex}>{changeItem}</li> |
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.
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.
I like it :)
|
||
// Use JSON.stringify for deep comparison of objects | ||
if (JSON.stringify(beforeConditions?.events) !== JSON.stringify(afterConditions?.events)) { | ||
changes.push(<>modified event conditions</>) |
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.
elected to not go into details about the event condition changes, just letting users know that they were changed at all.
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.
reasonable for now 👍
] | ||
: [] | ||
|
||
const specificChanges = match([before, after] as const) |
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.
some cool shit in here with ts-pattern
that lets me match a tuple of types with a very nice combinator-style developer experience.
return [...commonChanges, ...typeChangeDescription, ...specificChanges, ...describeBranchingChanges(before, after)] | ||
} | ||
|
||
export function describeCommonChanges(before: SurveyQuestion, after: SurveyQuestion): JSX.Element[] { |
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.
I still have functions that are comparing outcomes conditionally, but now that they can be flattened by the .with()
combinator, this whole chunk of code gets easier to read.
📸 UI snapshots have been updated1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
Triggered by this commit. |
…tHog/posthog into feat/add-targeting-to-survey-history
Size Change: 0 B Total Size: 1.07 MB ℹ️ View Unchanged
|
expect(getTextContent(changes[0])).toBe( | ||
'changed question text from "What is your favorite color?" to "What is your favorite animal?"' | ||
) | ||
expect(getTextContent(changes[1])).toBe('updated description') |
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.
why not also include the before/after description, like with the question change above?
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.
overlooked it; great feedback. Will add.
expect(changes).toHaveLength(3) | ||
expect(getTextContent(changes[0])).toBe('changed rating display from emoji to number') | ||
expect(getTextContent(changes[1])).toBe('changed rating scale from 5 to 10') | ||
expect(getTextContent(changes[2])).toBe('updated rating labels from Poor-Excellent to Bad-Good') |
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.
Multi-word labels will be rendered like this ...from Very bad-Very good to Quite bad-Quite good
I'd suggest double quotes here: ...from "Very bad"-"Very good" to "Quite bad"-"Quite good"
if (value.length <= 50) { | ||
return <strong>"{value}"</strong> | ||
} | ||
return <strong>"{value.slice(0, 50)}..."</strong> |
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.
nit: you can use this handy utility function
posthog/frontend/src/lib/utils.tsx
Line 640 in 86ac919
export function truncate(str: string, maxLength: number): string { |
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.
fantastic work 🙌 a few minor comments
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
📸 UI snapshots have been updated1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
Triggered by this commit. |
…tHog/posthog into feat/add-targeting-to-survey-history
📸 UI snapshots have been updated1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
Triggered by this commit. |
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
📸 UI snapshots have been updated1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
Triggered by this commit. |
…23834) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
…ostHog#23834) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Closes #23725
A few interesting things that I did (things worth looking at in greater depth IMO)
surveys.py
to handle manually inserting changelog entries whenever we make changes to the survey targeting (this has to be done manually because the existingchanges_between
abstraction only supports calculating changes within an existing model, and doesn't support foreign key relationships. I wrote a test for this new behavior.surveyActivityDescriber
to handle displaying changes to survey components in a easy-to-digest way. Outside of just writing a lot of code, these changes included:activity_log
changes_between
method to prevent it from failing when it tried to look up objects that didn't exist. That's by design!Changes
Feel free to pull this to your local branch and add some targeting behavior yourself, here's what my survey history looks like after a bunch of manual testing
Does this work well for both Cloud and self-hosted?
Yes
How did you test this code?
surveyActivityDescriber