Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/table-2
Browse files Browse the repository at this point in the history
  • Loading branch information
rinrub committed Feb 20, 2024
2 parents eecc2d6 + a460af1 commit e30751a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

- fixed the sorting for tables and also changed logic for standardtable

## 14.0.8

---

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

## 14.0.7

---
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

0 comments on commit e30751a

Please sign in to comment.