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

🐛 Fully unique ids for answer selections #1387

Merged
merged 4 commits into from
Sep 21, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ export const MultiInputSelection: React.FC<MultiInputSelectionProps> = ({

const isArchetype = useIsArchetype();
const { t } = useTranslation();

return (
<Stack>
{sortedOptions.map((option, i) => (
<StackItem key={option.text} className="pf-v5-u-pb-xs">
<StackItem key={`${questionFieldName}-${i}`} className="pf-v5-u-pb-xs">
<HookFormPFGroupController
control={control}
name={questionFieldName as `questions.${string}`}
fieldId="stakeholders"
fieldId={`${questionFieldName}-${i}`}
renderInput={({ field: { value, onChange } }) => (
<Radio
id={`${option.text}`}
id={`${questionFieldName}-${option.order}`}
name={questionFieldName}
isChecked={value === option.text}
onChange={(checked, e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import HelpIcon from "@patternfly/react-icons/dist/esm/icons/help-icon";
import { MultiInputSelection } from "./multi-input-selection";
import { Question, QuestionHeader, QuestionBody } from "./question";
import { getCommentFieldName } from "../../form-utils";
import { getCommentFieldName, getQuestionFieldName } from "../../form-utils";
import { HookFormPFTextInput } from "@app/components/HookFormPFFields";
import { useFormContext } from "react-hook-form";
import { Section } from "@app/api/models";
Expand Down Expand Up @@ -54,7 +54,7 @@ export const QuestionnaireForm: React.FC<QuestionnaireFormProps> = ({
</TextContent>
</StackItem>
{sortedQuestions.map((question) => (
<StackItem key={question.text}>
<StackItem key={question.order}>
<Question cy-data="question">
<QuestionHeader>
<Split hasGutter>
Expand All @@ -74,7 +74,10 @@ export const QuestionnaireForm: React.FC<QuestionnaireFormProps> = ({
</Split>
</QuestionHeader>
<QuestionBody>
<MultiInputSelection question={question} />
<MultiInputSelection
key={getQuestionFieldName(question, true)}
question={question}
/>
</QuestionBody>
</Question>
</StackItem>
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/pages/assessment/form-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ describe("Application assessment - form utils", () => {

it("getQuestionFieldName: fullName", () => {
const fieldName = getQuestionFieldName(question, true);
expect(fieldName).toBe("questions.question-Question 321");
expect(fieldName).toBe("questions.question-1");
});

it("getQuestionFieldName: singleName", () => {
const fieldName = getQuestionFieldName(question, false);
expect(fieldName).toBe("question-Question 321");
expect(fieldName).toBe("question-1");
});
});
2 changes: 1 addition & 1 deletion client/src/app/pages/assessment/form-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const getCommentFieldName = (section: Section, fullName: boolean) => {
};

export const getQuestionFieldName = (question: Question, fullName: boolean) => {
const fieldName = `question-${question.text}`;
const fieldName = `question-${question.order}`;
return fullName ? `${QUESTIONS_KEY}.${fieldName}` : fieldName;
};
Loading