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

feat: new filters for surveys answers #28466

Merged
merged 14 commits into from
Feb 17, 2025
Merged

Conversation

lucasheriques
Copy link
Contributor

@lucasheriques lucasheriques commented Feb 8, 2025

Problem

Right now, if you want to filter the survey results, you have to go through a lot of clicks:

  • Select "Add filter"
  • Search for "Survey Response" (not very intuitive)
  • If looking for the second question, it'll be "Survey Response 1", then "Survey Response 2"... etc
  • Click on the answer you want to filter by
  • Select the type of filter
  • Finally, apply

The process is not very intuitive, as we have to select by "Survey Response X" instead of the question name.

It's also painful, as said by other customers too.

Changes

see the demo here

image

Adds a new dedicated filters component for a survey's answers.

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

Yes

How did you test this code?

Unit tests for surveyLogic

Manual tests for all question types

@lucasheriques lucasheriques changed the title feat/new filters for surveys feat: new filters for surveys answers Feb 8, 2025
Copy link
Contributor

github-actions bot commented Feb 8, 2025

Size Change: 0 B

Total Size: 1.21 MB

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

compressed-size-action

@lucasheriques lucasheriques force-pushed the feat/new-filters-for-surveys branch from acbcce5 to b7b1455 Compare February 12, 2025 12:57
@lucasheriques lucasheriques changed the base branch from master to fix/separate-filters-for-survey-logic February 12, 2025 12:57
Base automatically changed from fix/separate-filters-for-survey-logic to master February 12, 2025 15:45
@lucasheriques lucasheriques force-pushed the feat/new-filters-for-surveys branch from b7b1455 to 00c5983 Compare February 12, 2025 19:58
@lucasheriques lucasheriques self-assigned this Feb 12, 2025
@lucasheriques lucasheriques requested a review from a team February 12, 2025 20:05
@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 1)
  • webkit: 0 added, 0 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 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@lucasheriques lucasheriques marked this pull request as ready for review February 13, 2025 00:55
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 introduces a new dedicated survey answer filtering system that significantly improves the user experience. Here's a concise summary of the key changes:

  • Added new SurveyAnswerFilters component with an intuitive table-based UI for filtering survey responses by question
  • Implemented type-specific filter operators (e.g., contains, exact match) for different question types (Open, Rating, SingleChoice, MultipleChoice)
  • Added debounced result reloading when filters change to prevent excessive API calls
  • Added comprehensive test coverage for the new filtering functionality in surveyLogic.test.ts
  • Integrated loading states to provide better feedback during filter operations

The changes make survey result filtering more accessible and efficient by reducing the number of clicks needed and providing question-specific filtering options directly in the UI.

4 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 227 to 236
// Initialize answer filters for all questions
const initialFilters = survey.questions.map((question, index) => ({
key: index === 0 ? '$survey_response' : `$survey_response_${index}`,
operator: DEFAULT_OPERATORS[question.type].value,
type: PropertyFilterType.Event as const,
value: [],
}))
actions.setAnswerFilters(initialFilters)
return survey
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding error handling for invalid question types when initializing filters

@lucasheriques lucasheriques force-pushed the feat/new-filters-for-surveys branch from 0408a4d to 204f715 Compare February 13, 2025 03:45
actions.updateSurvey({ archived: true })
},
loadSurveySuccess: () => {
listeners(({ actions, values }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

miss leading number of lines changed here.

since I added this new function, reloadAllSurveysResults, it shifted a lot of things down.

but the main changes are using switch case instead of multiple ifs and elses, and using this new function on both setPropertyFilters and setAnswersFilters

Copy link
Contributor

@ioannisj ioannisj left a comment

Choose a reason for hiding this comment

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

Just a few minor comments/notes 👍

onSet={(value: any) => handleUpdateFilter(index, 'value', value)}
placeholder={
question.type === SurveyQuestionType.Rating
? 'Enter a number'
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly as a future improvement, but in case of ratings we could borrow some of the filtering logic we use when setting up conditional questions (e.g Detractors, Passives, Promoters or Negative, Neutral, Positive). This way users can quickly filter for those groups of people

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#28813 created as a new issue to address later. I agree, great suggestion

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

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

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@lucasheriques lucasheriques force-pushed the feat/new-filters-for-surveys branch from cd250b4 to d99c052 Compare February 17, 2025 19:04
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

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

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@lucasheriques lucasheriques merged commit e95e4d7 into master Feb 17, 2025
101 checks passed
@lucasheriques lucasheriques deleted the feat/new-filters-for-surveys branch February 17, 2025 19:56
HamedMP pushed a commit that referenced this pull request Feb 19, 2025
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
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