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: use question id instead of question index for survey queries #29226

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

lucasheriques
Copy link
Contributor

@lucasheriques lucasheriques commented Feb 25, 2025

Problem

uses the new field question id to make survey queries instead

relates to #27200

Changes

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

@lucasheriques lucasheriques changed the base branch from master to chore/add-question-id-to-surveys February 25, 2025 23:13
@lucasheriques lucasheriques requested a review from a team February 25, 2025 23:14
@lucasheriques lucasheriques self-assigned this Feb 25, 2025
Copy link
Contributor

github-actions bot commented Feb 25, 2025

Size Change: 0 B

Total Size: 9.73 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 9.73 MB

compressed-size-action

@@ -147,7 +148,42 @@ export interface SurveyDateRange {
date_to: string | null
}

const getResponseField = (i: number): string => (i === 0 ? '$survey_response' : `$survey_response_${i}`)
// New function that supports both index-based and ID-based approaches
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all methods here used elsewhere? otherwise we should not default to export

Copy link
Contributor Author

@lucasheriques lucasheriques Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need export to do tests; i can also do a hard copy of them on the test file if preferable though

Copy link
Member

@marandaneto marandaneto Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no hard copying isn't ideal.
I usually would test the 1st method to be called and just assert the final result; your method input has to allow running into all code paths with the inner methods as well of course, it's more like an integration test that tests multiple methods rather than every single method, I usually find this approach better, and a must on SDKs since you cant expose everything otherwise everything is a public API, here is different but I think it still makes sense if easy to apply the same concept

@marandaneto marandaneto requested a review from ioannisj February 26, 2025 06:47
arrayJoin(JSONExtractArrayRaw(properties, '${fields[1] || ''}')),
arrayJoin(JSONExtractArrayRaw(properties, '${fields[0]}'))
)`
}

function duplicateExistingSurvey(survey: Survey | NewSurvey): Partial<Survey> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not in the scope of this PR but when duplicating an existing survey, should we clear question ids?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not super important because questions are just a JSON array and not its own database column but I'd do it anyway

@lucasheriques lucasheriques changed the title chore/use question id instead of question index for survey queries chore: use question id instead of question index for survey queries Feb 27, 2025
@marandaneto
Copy link
Member

Not sure if it's gonna be on this PR (likely a new one), but remember to re-enable the questions reordering drag & drop.

Base automatically changed from chore/add-question-id-to-surveys to master February 28, 2025 13:01
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants