Skip to content

Commit

Permalink
Merge pull request #400 from beda-software/readonly-qrform-choicecolumn
Browse files Browse the repository at this point in the history
Fix getting display for readonly qrform choice and reference  with ch…
  • Loading branch information
vesnushka authored Dec 5, 2024
2 parents f6c7392 + 348b976 commit 64b8fcb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import s from './ReadonlyWidgets.module.scss';
import { S } from './ReadonlyWidgets.styles';

export function QuestionChoice({ parentPath, questionItem }: QuestionItemProps) {
const { linkId, text, repeats, hidden } = questionItem;
const { linkId, text, repeats, hidden, choiceColumn } = questionItem;
const fieldName = repeats ? [...parentPath, linkId] : [...parentPath, linkId, 0];
const { value } = useFieldController(fieldName, questionItem);

Expand All @@ -20,14 +20,14 @@ export function QuestionChoice({ parentPath, questionItem }: QuestionItemProps)
return (
<S.Question className={classNames(s.question, s.row, 'form__question')}>
<span className={s.questionText}>{text}</span>
<span className={s.answer}>{getArrayDisplay(value) || '-'}</span>
<span className={s.answer}>{getArrayDisplay(value, choiceColumn) || '-'}</span>
</S.Question>
);
} else {
return (
<S.Question className={classNames(s.question, s.row, 'form__question')}>
<span className={s.questionText}>{text}</span>
<span className={s.answer}>{getDisplay(value?.value) || '-'}</span>
<span className={s.answer}>{getDisplay(value?.value, choiceColumn) || '-'}</span>
</S.Question>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import { AnswerReferenceProps, useAnswerReference } from '../widgets/reference';
function QuestionReferenceUnsafe<R extends Resource = any, IR extends Resource = any>(
props: AnswerReferenceProps<R, IR>,
) {
const { fieldController, text, repeats } = useAnswerReference(props);
const { fieldController, text, repeats, choiceColumn } = useAnswerReference(props);

if (repeats) {
return (
<S.Question className={classNames(s.question, s.row, 'form__question')}>
<span className={s.questionText}>{text}</span>
<span className={s.answer}>{getArrayDisplay(fieldController.value?.value) || '-'}</span>
<span className={s.answer}>{getArrayDisplay(fieldController.value?.value, choiceColumn) || '-'}</span>
</S.Question>
);
} else {
return (
<S.Question className={classNames(s.question, s.row, 'form__question')}>
<span className={s.questionText}>{text}</span>
<span className={s.answer}>{getDisplay(fieldController.value?.value) || '-'}</span>
<span className={s.answer}>{getDisplay(fieldController.value?.value, choiceColumn) || '-'}</span>
</S.Question>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export function useAnswerReference<R extends Resource = any, IR extends Resource
text,
repeats,
placeholder: entryFormat,
choiceColumn,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/questionnaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export function getDisplay(
return '';
}

export function getArrayDisplay(options?: QuestionnaireResponseItemAnswer[]): string | null {
export function getArrayDisplay(options?: QuestionnaireResponseItemAnswer[], choiceColumn?: QuestionnaireItemChoiceColumn[]): string | null {
if (!options) {
return null;
}

return options.map((v: QuestionnaireResponseItemAnswer) => getDisplay(v.value)).join(', ');
return options.map((v: QuestionnaireResponseItemAnswer) => getDisplay(v.value, choiceColumn)).join(', ');
}

export function questionnaireItemsToValidationSchema(questionnaireItems: QuestionnaireItem[]) {
Expand Down

0 comments on commit 64b8fcb

Please sign in to comment.