Skip to content

Commit a6547ae

Browse files
authored
fix: Survey linear scale questions (#1267)
* fix: Use latest linear scale dto from sam * chore: Release 12.0.1 * fix: Survey questionText
1 parent a096e17 commit a6547ae

7 files changed

Lines changed: 54 additions & 53 deletions

File tree

bun.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@equinor/amplify-component-lib",
3-
"version": "12.0.0",
3+
"version": "12.0.1",
44
"description": "Frontend Typescript components for the Amplify team",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -52,7 +52,7 @@
5252
},
5353
"devDependencies": {
5454
"@equinor/eds-icons": "^0.22.0",
55-
"@equinor/subsurface-app-management": "5.4.2",
55+
"@equinor/subsurface-app-management": "5.4.4",
5656
"@eslint/js": "^9.22.0",
5757
"@faker-js/faker": "^9.6.0",
5858
"@storybook/addon-coverage": "^2.0.0",
@@ -114,7 +114,7 @@
114114
"@equinor/eds-core-react": "0.44.0",
115115
"@equinor/eds-data-grid-react": "^0.7.5",
116116
"@equinor/eds-icons": "*",
117-
"@equinor/subsurface-app-management": "^5.4.2",
117+
"@equinor/subsurface-app-management": "^5.4.4",
118118
"@tanstack/react-query": "*",
119119
"@tanstack/react-router": "*",
120120
"@tiptap/core": "^3.1.0",

src/providers/SurveyProvider/SurveyDialog/SurveyDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const SurveyDialog: FC = () => {
126126
<Content>
127127
<SurveyProgress />
128128
<Typography variant="body_short_bold">
129-
{activeSurvey.questions[activeQuestionIndex].text}
129+
{activeSurvey.questions[activeQuestionIndex].questionText}
130130
</Typography>
131131
<SurveyQuestion />
132132
</Content>

src/providers/SurveyProvider/SurveyDialog/SurveyQuestion/SurveyLinearScaleQuestion.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ type SurveyLinearScaleQuestionProps =
3838

3939
export const SurveyLinearScaleQuestion: FC<SurveyLinearScaleQuestionProps> = ({
4040
questionId,
41-
linearScaleConfig,
41+
linearScaleVm,
4242
...rest
4343
}) => {
4444
const { currentAnswer, setCurrentAnswer } = useSurvey();
45-
const rangeAmount = linearScaleConfig.max - linearScaleConfig.min + 1;
45+
const rangeAmount = linearScaleVm.maxValue - linearScaleVm.minValue + 1;
4646

4747
const handleOnAnswer = (numericAnswer: number) => {
4848
if ('answer' in rest && 'setAnswer' in rest) {
@@ -60,11 +60,11 @@ export const SurveyLinearScaleQuestion: FC<SurveyLinearScaleQuestionProps> = ({
6060

6161
return (
6262
<Container $rangeAmount={rangeAmount}>
63-
<Typography>{linearScaleConfig.minLabel}</Typography>
63+
<Typography>{linearScaleVm.minLabel}</Typography>
6464
{Array.from({ length: rangeAmount }).map((_, index) => (
6565
<RadioWrapper key={`range-radio-${index}`}>
6666
<Typography variant="body_short">
67-
{linearScaleConfig.min + index}
67+
{linearScaleVm.minValue + index}
6868
</Typography>
6969
<Radio
7070
data-testid={`range-radio-${questionId.value}`}
@@ -73,15 +73,15 @@ export const SurveyLinearScaleQuestion: FC<SurveyLinearScaleQuestionProps> = ({
7373
checked={
7474
('answer' in rest ? rest.answer : currentAnswer)
7575
?.numericAnswer ===
76-
index + linearScaleConfig.min
76+
index + linearScaleVm.minValue
7777
}
7878
onClick={() => {
79-
handleOnAnswer(linearScaleConfig.min + index);
79+
handleOnAnswer(linearScaleVm.minValue + index);
8080
}}
8181
/>
8282
</RadioWrapper>
8383
))}
84-
<Typography>{linearScaleConfig.maxLabel}</Typography>
84+
<Typography>{linearScaleVm.maxLabel}</Typography>
8585
</Container>
8686
);
8787
};

src/providers/SurveyProvider/SurveyDialog/UmuxDialog.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,15 @@ export const UmuxDialog: FC = () => {
101101
</InformationalNotice>
102102
{activeSurvey.questions.map((question, index) => (
103103
<QuestionWrapper key={question.questionId.value}>
104-
<Typography variant="body_short_bold">{question.text}</Typography>
105-
{question.linearScaleConfig && (
104+
<Typography variant="body_short_bold">
105+
{question.questionText}
106+
</Typography>
107+
{question.linearScaleVm && (
106108
<SurveyLinearScaleQuestion
107109
type={QuestionType.LINEAR_SCALE}
108-
text={question.text}
110+
questionText={question.questionText}
109111
questionId={question.questionId}
110-
linearScaleConfig={{
111-
max: question.linearScaleConfig.max,
112-
min: question.linearScaleConfig.min,
113-
minLabel: question.linearScaleConfig.minLabel,
114-
maxLabel: question.linearScaleConfig.maxLabel,
115-
}}
112+
linearScaleVm={question.linearScaleVm}
116113
answer={answers[index]}
117114
setAnswer={(answer) => {
118115
setAnswers((prev) => {

src/providers/SurveyProvider/SurveyProvider.stories.tsx

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ const standardSurvey: UserSurveyVm = {
8080
},
8181
type: QuestionType.TEXT,
8282
order: 1,
83-
text: 'This is the question text',
83+
questionText: 'This is the question text',
8484
},
8585
{
8686
questionId: { value: 'choiceQuestion' },
8787
type: QuestionType.CHOICE,
88-
text: 'Choose one please',
88+
questionText: 'Choose one please',
8989
order: 2,
9090
options: [
9191
{
@@ -110,11 +110,11 @@ const standardSurvey: UserSurveyVm = {
110110
questionId: { value: 'linearScaleQuestion' },
111111
type: QuestionType.LINEAR_SCALE,
112112
order: 3,
113-
text: 'Is this useful?',
114-
linearScaleConfig: {
115-
min: 1,
113+
questionText: 'Is this useful?',
114+
linearScaleVm: {
115+
minValue: 1,
116116
minLabel: 'Strongly disagree',
117-
max: 7,
117+
maxValue: 7,
118118
maxLabel: 'Strongly agree',
119119
},
120120
},
@@ -157,7 +157,7 @@ export const TestStandard: Story = {
157157
).toBeInTheDocument();
158158

159159
await expect(
160-
await canvas.findByText(standardSurvey.questions[0].text)
160+
await canvas.findByText(standardSurvey.questions[0].questionText)
161161
).toBeInTheDocument();
162162

163163
await expect(
@@ -200,9 +200,13 @@ export const TestStandard: Story = {
200200
'Go back, verify that the text is still there, and click next',
201201
async () => {
202202
await expect(
203-
await canvas.findByText(standardSurvey.questions[1].text, undefined, {
204-
timeout: 1500,
205-
})
203+
await canvas.findByText(
204+
standardSurvey.questions[1].questionText,
205+
undefined,
206+
{
207+
timeout: 1500,
208+
}
209+
)
206210
).toBeInTheDocument();
207211

208212
await userEvent.click(canvas.getByRole('button', { name: /back/i }));
@@ -218,9 +222,13 @@ export const TestStandard: Story = {
218222

219223
await step('Checkbox question and click next', async () => {
220224
await expect(
221-
await canvas.findByText(standardSurvey.questions[1].text, undefined, {
222-
timeout: 1500,
223-
})
225+
await canvas.findByText(
226+
standardSurvey.questions[1].questionText,
227+
undefined,
228+
{
229+
timeout: 1500,
230+
}
231+
)
224232
).toBeInTheDocument();
225233

226234
for (const option of standardSurvey.questions[1].options ?? []) {
@@ -259,17 +267,13 @@ export const TestStandard: Story = {
259267

260268
await step('Linear scale question and complete', async () => {
261269
await expect(
262-
await canvas.findByText(standardSurvey.questions[2].text)
270+
await canvas.findByText(standardSurvey.questions[2].questionText)
263271
).toBeInTheDocument();
264272
await expect(
265-
canvas.getByText(
266-
standardSurvey.questions[2]!.linearScaleConfig!.minLabel
267-
)
273+
canvas.getByText(standardSurvey.questions[2]!.linearScaleVm!.minLabel)
268274
).toBeInTheDocument();
269275
await expect(
270-
canvas.getByText(
271-
standardSurvey.questions[2]!.linearScaleConfig!.maxLabel
272-
)
276+
canvas.getByText(standardSurvey.questions[2]!.linearScaleVm!.maxLabel)
273277
).toBeInTheDocument();
274278

275279
await userEvent.click(canvas.getAllByRole('radio')[0]);
@@ -299,29 +303,29 @@ const umuxSurvey: UserSurveyVm = {
299303
questions: [
300304
{
301305
type: QuestionType.LINEAR_SCALE,
302-
text: 'Acquire is easy to use.',
306+
questionText: 'Acquire is easy to use.',
303307
questionId: {
304308
value: 'someId',
305309
},
306310
order: 1,
307-
linearScaleConfig: {
308-
min: 1,
311+
linearScaleVm: {
312+
minValue: 1,
309313
minLabel: 'Strongly disagree',
310-
max: 7,
314+
maxValue: 7,
311315
maxLabel: 'Strongly agree',
312316
},
313317
},
314318
{
315319
type: QuestionType.LINEAR_SCALE,
316-
text: 'Acquire meets my needs.',
320+
questionText: 'Acquire meets my needs.',
317321
questionId: {
318322
value: 'someOtherId',
319323
},
320324
order: 2,
321-
linearScaleConfig: {
322-
min: 1,
325+
linearScaleVm: {
326+
minValue: 1,
323327
minLabel: 'Strongly disagree',
324-
max: 7,
328+
maxValue: 7,
325329
maxLabel: 'Strongly agree',
326330
},
327331
},

src/providers/SurveyProvider/SurveyProvider.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { QuestionType, QuestionVm } from '@equinor/subsurface-app-management';
22

3-
type QuestionBase = Pick<QuestionVm, 'questionId' | 'text'>;
3+
type QuestionBase = Pick<QuestionVm, 'questionId' | 'questionText'>;
44

55
export type FreeTextQuestion = QuestionBase & {
66
type: QuestionType.TEXT;
@@ -14,5 +14,5 @@ export type ChoiceQuestion = QuestionBase & {
1414

1515
export type LinearScaleQuestion = QuestionBase & {
1616
type: QuestionType.LINEAR_SCALE;
17-
linearScaleConfig: NonNullable<QuestionVm['linearScaleConfig']>;
17+
linearScaleVm: NonNullable<QuestionVm['linearScaleVm']>;
1818
};

0 commit comments

Comments
 (0)