-
Notifications
You must be signed in to change notification settings - Fork 150
fix: refactor canRenderSurvey and move logic to SurveyManager #1897
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size Change: -4.05 kB (-0.11%) Total Size: 3.68 MB
ℹ️ View Unchanged
|
@@ -552,74 +552,6 @@ describe('SurveyManager', () => { | |||
}) | |||
}) | |||
|
|||
describe('canRenderSurvey', () => { |
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.
tests removed as I moved that method to posthog-surveys.test.ts
to stop duplicating rendering logic
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.
PR Summary
This PR refactors the survey eligibility logic in posthog-js by centralizing it in the posthog-surveys.ts
file, eliminating duplication between getActiveMatchingSurveys
and canRenderSurvey
functions.
- Added new
checkSurveyEligibility
method inPostHogSurveys
class that serves as a single source of truth for determining survey eligibility - Moved survey condition matching logic from
extensions/surveys.tsx
toposthog-surveys.ts
with helper methods like_isSurveyConditionMatched
and_internalFlagCheckSatisfied
- Added utility functions in
survey-utils.ts
includingdoesSurveyMatchSelector
,isSurveyRunning
,doesSurveyActivateByEvent
, anddoesSurveyActivateByAction
- Enhanced logging in
survey-event-receiver.ts
for better debugging of survey activation events - Added comprehensive tests in
posthog-surveys.test.ts
to verify the refactored eligibility logic works correctly
9 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
can we do it the other way around? so we get the refactoring gains without increasing the main bundle? |
@marandaneto @ioannisj I decided to move more business logic to the |
@@ -14,6 +14,7 @@ import { | |||
import { DeadClicksAutocapture, isDeadClicksEnabledForAutocapture } from './extensions/dead-clicks-autocapture' | |||
import { ExceptionObserver } from './extensions/exception-autocapture' | |||
import { errorToProperties } from './extensions/exception-autocapture/error-conversion' | |||
import { HistoryAutocapture } from './extensions/history-autocapture' |
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.
Most of your PRs auto-format the imports, which adds noise to the PR review.
Can you double-check that your auto-format config is the same as everyone else's?
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.
it's caused by a setting I have on VS Code. I created a PR to prevent it from having effect in this repo
nice, left 2 comments otherwise LGTM |
Co-authored-by: Manoel Aranda Neto <[email protected]>
Changes
both
getActiveMatchingSurveys
andcanRenderSurvey
share a lot of similarities around business logic. Since their goal is to get check if a survey is eligible for an user or not.However, we had duplicated business logic happening on both.
So, I decided to remove
canRenderSurvey
fromposthog-surveys.ts
toextenstions/surveys.tsx
, to centralize the logic in one place and also reduce the main bundle size, by only downloading it if there are surveys enabled.I also did the same to
getActiveMatchingSurveys
. No need to have this logic be onposthog-surveys.ts
since it's only relevant if surveys are actually loaded.Checklist