Skip to content

Commit

Permalink
Give server rowIndex for validateRow trigger (#682)
Browse files Browse the repository at this point in the history
* Give server rowIndex for validateRow trigger

* Always update group validations

* send all rowIndices

* use splitDashedKey instead
  • Loading branch information
bjosttveit authored Nov 23, 2022
1 parent 4d73928 commit b12cbe6
Showing 1 changed file with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,21 +510,27 @@ export function* updateRepeatingGroupEditIndexSaga({
payload: { group, index, validate },
}: PayloadAction<IUpdateRepeatingGroupsEditIndex>): SagaIterator {
try {
if (validate) {
const state: IRuntimeState = yield select();
const state: IRuntimeState = yield select();
const rowIndex = state.formLayout.uiConfig.repeatingGroups?.[group].editIndex;

if (validate && typeof rowIndex === 'number' && rowIndex > -1) {
const validations: IValidations = state.formValidations.validations;
const currentView = state.formLayout.uiConfig.currentView;
const rowIndex = state.formLayout.uiConfig.repeatingGroups?.[group].editIndex;

const frontendValidations: IValidations = validateGroup(
group,
state,
validate === Triggers.ValidateRow ? rowIndex : undefined,
);

// Get group's rowIndices to send to server for validations
const { depth: rowIndices } = splitDashedKey(group);
rowIndices.push(rowIndex);

const options: AxiosRequestConfig = {
headers: {
ComponentId: group,
RowIndex: rowIndices.join(','),
},
};

Expand Down Expand Up @@ -562,25 +568,26 @@ export function* updateRepeatingGroupEditIndexSaga({
state.formLayout.layouts,
state.textResources.resources,
);
const finalServerValidations: IValidations = filterValidationsByRow(
mappedServerValidations,
state.formLayout.layouts[currentView],
state.formLayout.uiConfig.repeatingGroups,
group,
validate === Triggers.ValidateRow ? rowIndex : undefined,
);

const combinedValidations = mergeValidationObjects(frontendValidations, finalServerValidations);
const combinedValidations = mergeValidationObjects(frontendValidations, mappedServerValidations);

// only overwrite validtions specific to the group - leave all other untouched
const newValidations = {
...validations,
[currentView]: {
...validations[currentView],
...combinedValidations[currentView],
},
};
yield put(ValidationActions.updateValidations({ validations: newValidations }));

const rowValidations = filterValidationsByRow(
combinedValidations,
state.formLayout.layouts[currentView],
state.formLayout.uiConfig.repeatingGroups,
group,
// Only compute if not already filtered
validate === Triggers.Validation ? rowIndex : undefined,
rowIndex,
);

if (canFormBeSaved({ validations: rowValidations, invalidDataTypes: false }, 'Complete')) {
yield put(
FormLayoutActions.updateRepeatingGroupsEditIndexFulfilled({
Expand All @@ -595,17 +602,6 @@ export function* updateRepeatingGroupEditIndexSaga({
}),
);
}
if (!canFormBeSaved({ validations: combinedValidations, invalidDataTypes: false }, 'Complete')) {
// only overwrite validtions specific to the group - leave all other untouched
const newValidations = {
...validations,
[currentView]: {
...validations[currentView],
...combinedValidations[currentView],
},
};
yield put(ValidationActions.updateValidations({ validations: newValidations }));
}
} else {
yield put(
FormLayoutActions.updateRepeatingGroupsEditIndexFulfilled({
Expand Down

0 comments on commit b12cbe6

Please sign in to comment.