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

[NAE-2005] Field behavior change does not work correctly with multiple references using taskRef #246

Merged
merged 5 commits into from
Sep 25, 2024
Merged
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 @@ -222,20 +222,19 @@ export abstract class TaskContentService implements OnDestroy {
if (!this._task || !this._task.dataGroups) {
return;
}
// todo actions owner zbytočný?
const frontendActions = chFields.taskId === this.task.stringId && chFields[TaskContentService.FRONTEND_ACTIONS_KEY];
Object.keys(chFields).forEach(changedField => {
if (this.isFieldInTask(chFields.taskId, changedField)) {
if (chFields.taskId === this._task.stringId && this.isFieldInTask(chFields.taskId, changedField)) {
this.updateField(chFields, this.taskFieldsIndex[chFields.taskId].fields[changedField], frontendActions);
} else if (!!this.getReferencedTaskId(changedField)) {
this.updateReferencedField(chFields, this.taskFieldsIndex[this.getReferencedTaskId(changedField)].fields[changedField], frontendActions);
this.updateField(chFields, this.taskFieldsIndex[this.getReferencedTaskId(changedField)].fields[changedField], frontendActions, true);
}
});

this.$shouldCreate.next(this._task.dataGroups);
}

protected updateField(chFields: ChangedFields, field: DataField<any>, frontendActions: Change): void {
protected updateField(chFields: ChangedFields, field: DataField<any>, frontendActions: Change, referenced: boolean = false): void {
if (this._fieldConverterService.resolveType(field) === FieldTypeResource.TASK_REF) {
this._taskDataReloadRequest$.next(frontendActions ? frontendActions : undefined);
return;
Expand All @@ -251,14 +250,14 @@ export abstract class TaskContentService implements OnDestroy {
field.valueWithoutChange(this._fieldConverterService.formatValueFromBackend(field, updatedField[key]));
break;
case 'behavior':
if (updatedField.behavior[this._task.transitionId]) {
// TODO NGSD-489 fix behavior resolution
if (!referenced && updatedField.behavior[this._task.transitionId]) {
field.behavior = updatedField.behavior[this._task.transitionId];
} else {
const transitionId = this.getReferencedTransitionId(field.stringId);
} else if (referenced) {
const taskId = this.getReferencedTaskId(field.stringId);
const taskRef = this.findTaskRefId(taskId, this.taskFieldsIndex[this._task.stringId].fields);
const transitionId = this.taskFieldsIndex[taskId].transitionId;
if (!!transitionId && transitionId !== '' && updatedField.behavior[transitionId])
field.behavior = updatedField.behavior[transitionId];
break;
field.behavior = taskRef.behavior.editable ? updatedField.behavior[transitionId] : taskRef.behavior;
}
break;
case 'choices':
Expand Down Expand Up @@ -297,32 +296,6 @@ export abstract class TaskContentService implements OnDestroy {
});
}

protected updateReferencedField(chFields: ChangedFields, field: DataField<any>, frontendActions: Change): void {
if (this._fieldConverterService.resolveType(field) === FieldTypeResource.TASK_REF) {
this._taskDataReloadRequest$.next(frontendActions ? frontendActions : undefined);
return;
}
const updatedField = chFields[field.stringId];
Object.keys(updatedField).forEach(key => {
switch (key) {
case 'behavior': {
const taskId = this.getReferencedTaskId(field.stringId);
const taskRef = this.findTaskRefId(taskId, this.taskFieldsIndex[this._task.stringId].fields);
const transitionId = this.taskFieldsIndex[taskId].transitionId;
if (!!transitionId && transitionId !== '' && updatedField.behavior[transitionId])
field.behavior = taskRef.behavior.editable ? updatedField.behavior[transitionId] : taskRef.behavior;
break;
}
case 'value':
field.valueWithoutChange(this._fieldConverterService.formatValueFromBackend(field, updatedField[key]));
break;
default:
field[key] = updatedField[key];
}
field.update();
});
}

protected isFieldInTask(taskId: string, changedField: string): boolean {
return !!taskId
&& !!this.taskFieldsIndex[taskId]
Expand Down
Loading