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

Rubenr/bug 318014 repeatable bekreftelse #169

Merged
merged 2 commits into from
Feb 19, 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
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 14.0.8

---

- Bugfix: When Confirmation is repeatable, the added items now have a initial value of false

## 14.0.7

---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helsenorge/refero",
"version": "14.0.7",
"version": "14.0.8",
"engines": {
"node": "^18.0.0",
"npm": ">=9.0.0"
Expand Down
22 changes: 15 additions & 7 deletions src/reducers/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
REMOVE_ATTACHMENT_VALUE,
} from '../actions/newValue';
import { syncQuestionnaireResponse } from '../actions/syncQuestionnaireResponse';
import itemType from '../constants/itemType';
import { GlobalState } from '../reducers/index';
import { createQuestionnaireResponseAnswer } from '../util/createQuestionnaireResponseAnswer';
import { getMinOccursExtensionValue } from '../util/extension';
Expand Down Expand Up @@ -124,38 +125,45 @@ function getArrayToAddGroupTo(itemToAddTo: QuestionnaireResponseItem | undefined
}

function processAddRepeatItemAction(action: NewValueAction, state: Form): Form {
const { parentPath, responseItems, item } = action;
return produce(state, draft => {
if (!action.parentPath) {
if (!parentPath) {
return state;
}

let arrayToAddItemTo: Array<QuestionnaireResponseItem> | undefined = [];
if (action.parentPath.length === 0 && draft.FormData.Content) {
if (parentPath.length === 0 && draft.FormData.Content) {
arrayToAddItemTo = draft.FormData.Content.item;
} else if (action.parentPath.length > 0) {
} else if (parentPath.length > 0) {
// length >1 means group wrapped in group
const itemToAddTo = getResponseItemWithPath(action.parentPath, draft.FormData);
const itemToAddTo = getResponseItemWithPath(parentPath, draft.FormData);
arrayToAddItemTo = getArrayToAddGroupTo(itemToAddTo);
}

if (!arrayToAddItemTo || arrayToAddItemTo.length === 0) {
return;
}

if (!action.responseItems || action.responseItems.length === 0) {
if (!responseItems || responseItems.length === 0) {
return;
}

const newItem = copyItem(
action.responseItems[0],
responseItems[0],
undefined,
draft.FormDefinition.Content as Questionnaire,
state.FormDefinition.Content as Questionnaire
);
if (!newItem) {
return;
}

if (item?.type === itemType.BOOLEAN) {
if (item.initial && item.initial.length > 0 && item.initial[0].valueBoolean !== undefined) {
newItem.answer = [{ valueBoolean: item.initial[0]?.valueBoolean }];
} else {
newItem.answer = [{ valueBoolean: false }];
}
}
const indexToInsert = arrayToAddItemTo.map(o => o.linkId).lastIndexOf(newItem.linkId);
arrayToAddItemTo.splice(indexToInsert + 1, 0, newItem);
});
Expand Down
Loading