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(surveys): add support for a 7 point likert scale #1319

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/extensions/surveys/components/QuestionTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function RatingQuestion({
className="rating-options-number"
style={{ gridTemplateColumns: `repeat(${scale - starting + 1}, minmax(0, 1fr))` }}
>
{(question.scale === 5 ? fiveScaleNumbers : tenScaleNumbers).map((number, idx) => {
{getScaleNumbers(question.scale).map((number, idx) => {
const active = rating === number
return (
<RatingButton
Expand Down Expand Up @@ -369,4 +369,18 @@ export function MultipleChoiceQuestion({
const threeScaleEmojis = [dissatisfiedEmoji, neutralEmoji, satisfiedEmoji]
const fiveScaleEmojis = [veryDissatisfiedEmoji, dissatisfiedEmoji, neutralEmoji, satisfiedEmoji, verySatisfiedEmoji]
const fiveScaleNumbers = [1, 2, 3, 4, 5]
const sevenScaleNumbers = [1, 2, 3, 4, 5, 6, 7]
const tenScaleNumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

function getScaleNumbers(scale: number): number[] {
switch (scale) {
case 5:
return fiveScaleNumbers
case 7:
return sevenScaleNumbers
case 10:
return tenScaleNumbers
default:
return fiveScaleNumbers
}
}
2 changes: 1 addition & 1 deletion src/posthog-surveys-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface LinkSurveyQuestion extends SurveyQuestionBase {
export interface RatingSurveyQuestion extends SurveyQuestionBase {
type: SurveyQuestionType.Rating
display: 'number' | 'emoji'
scale: number
scale: 3 | 5 | 7 | 10
lowerBoundLabel: string
upperBoundLabel: string
}
Expand Down
Loading