Skip to content

Commit 9102709

Browse files
authored
Merge pull request DSpace#2252 from alexandrevryghem/issue-1671_fix-relationships-not-updating-view-on-submission-form_contribute-main
Adding/removing relationships in the submission form does not update the view automatically
2 parents 12f9023 + c4b2565 commit 9102709

3 files changed

Lines changed: 54 additions & 11 deletions

File tree

src/app/shared/form/form.component.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,20 @@
1313
(ngbEvent)="onCustomEvent($event)">
1414
<ng-template modelType="ARRAY" let-group let-index="index" let-context="context">
1515
<!--Array with repeatable items-->
16-
<div *ngIf="(!context.notRepeatable) && !isVirtual(context, index)"
16+
<div *ngIf="(!context.notRepeatable) && !isVirtual(context, index) && group.context.groups.length !== 1 && !isItemReadOnly(context, index)"
1717
class="col-xs-2 d-flex flex-column justify-content-sm-start align-items-end">
1818
<button type="button" class="btn btn-secondary" role="button"
1919
title="{{'form.remove' | translate}}"
2020
attr.aria-label="{{'form.remove' | translate}}"
21-
(click)="removeItem($event, context, index)"
22-
[disabled]="group.context.groups.length === 1 || isItemReadOnly(context, index)">
21+
(click)="removeItem($event, context, index)">
2322
<span><i class="fas fa-trash" aria-hidden="true"></i></span>
2423
</button>
2524
</div>
26-
<div *ngIf="(!context.notRepeatable) && index === (group.context.groups.length - 1)" class="clearfix pl-4 w-100">
25+
<div *ngIf="(!context.notRepeatable) && index === (group.context.groups.length - 1) && !isItemReadOnly(context, index)" class="clearfix pl-4 w-100">
2726
<div class="btn-group" role="group">
2827
<button type="button" role="button" class="ds-form-add-more btn btn-link"
2928
title="{{'form.add' | translate}}"
3029
attr.aria-label="{{'form.add' | translate}}"
31-
[disabled]="isItemReadOnly(context, index)"
3230
(click)="insertItem($event, group.context, group.context.groups.length)">
3331
<span><i class="fas fa-plus"></i> {{'form.add' | translate}}</span>
3432
</button>

src/app/submission/sections/form/section-form.component.spec.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ describe('SubmissionSectionFormComponent test suite', () => {
294294
'dc.title': [new FormFieldMetadataValueObject('test')]
295295
};
296296
compAsAny.formData = {};
297-
compAsAny.sectionMetadata = ['dc.title'];
297+
compAsAny.sectionData.data = {
298+
'dc.title': [new FormFieldMetadataValueObject('test')]
299+
};
298300
spyOn(compAsAny, 'inCurrentSubmissionScope').and.callThrough();
299301

300302
expect(comp.hasMetadataEnrichment(newSectionData)).toBeTruthy();
@@ -306,7 +308,9 @@ describe('SubmissionSectionFormComponent test suite', () => {
306308
'dc.title': [new FormFieldMetadataValueObject('test')]
307309
};
308310
compAsAny.formData = newSectionData;
309-
compAsAny.sectionMetadata = ['dc.title'];
311+
compAsAny.sectionData.data = {
312+
'dc.title': [new FormFieldMetadataValueObject('test')]
313+
};
310314
spyOn(compAsAny, 'inCurrentSubmissionScope').and.callThrough();
311315

312316
expect(comp.hasMetadataEnrichment(newSectionData)).toBeFalsy();
@@ -343,6 +347,22 @@ describe('SubmissionSectionFormComponent test suite', () => {
343347
} as FormFieldModel
344348
]
345349
},
350+
{
351+
fields: [
352+
{
353+
selectableMetadata: [{ metadata: 'scoped.workflow.relation' }],
354+
scope: 'WORKFLOW',
355+
} as FormFieldModel,
356+
],
357+
},
358+
{
359+
fields: [
360+
{
361+
selectableMetadata: [{ metadata: 'scoped.workspace.relation' }],
362+
scope: 'WORKSPACE',
363+
} as FormFieldModel,
364+
],
365+
},
346366
{
347367
fields: [
348368
{
@@ -371,6 +391,14 @@ describe('SubmissionSectionFormComponent test suite', () => {
371391
it('should return false for fields scoped to workflow', () => {
372392
expect((comp as any).inCurrentSubmissionScope('scoped.workflow')).toBe(false);
373393
});
394+
395+
it('should return true for relation fields scoped to workspace', () => {
396+
expect((comp as any).inCurrentSubmissionScope('scoped.workspace.relation')).toBe(true);
397+
});
398+
399+
it('should return false for relation fields scoped to workflow', () => {
400+
expect((comp as any).inCurrentSubmissionScope('scoped.workflow.relation')).toBe(false);
401+
});
374402
});
375403

376404
describe('in workflow scope', () => {
@@ -390,6 +418,14 @@ describe('SubmissionSectionFormComponent test suite', () => {
390418
it('should return false for fields scoped to workspace', () => {
391419
expect((comp as any).inCurrentSubmissionScope('scoped.workspace')).toBe(false);
392420
});
421+
422+
it('should return true for relation fields scoped to workflow', () => {
423+
expect((comp as any).inCurrentSubmissionScope('scoped.workflow.relation')).toBe(true);
424+
});
425+
426+
it('should return false for relation fields scoped to workspace', () => {
427+
expect((comp as any).inCurrentSubmissionScope('scoped.workspace.relation')).toBe(false);
428+
});
393429
});
394430
});
395431

src/app/submission/sections/form/section-form.component.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { WorkflowItem } from '../../../core/submission/models/workflowitem.model
3939
import { SubmissionObject } from '../../../core/submission/models/submission-object.model';
4040
import { SubmissionSectionObject } from '../../objects/submission-section-object.model';
4141
import { SubmissionSectionError } from '../../objects/submission-section-error.model';
42+
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
4243

4344
/**
4445
* This component represents a section that contains a Form.
@@ -228,7 +229,9 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
228229

229230
const sectionDataToCheck = {};
230231
Object.keys(sectionData).forEach((key) => {
231-
if (this.sectionMetadata && this.sectionMetadata.includes(key) && this.inCurrentSubmissionScope(key)) {
232+
// todo: removing Relationships works due to a bug -- dspace.entity.type is included in sectionData, which is what triggers the update;
233+
// if we use this.sectionMetadata.includes(key), this field is filtered out and removed Relationships won't disappear from the form.
234+
if (this.inCurrentSubmissionScope(key)) {
232235
sectionDataToCheck[key] = sectionData[key];
233236
}
234237
});
@@ -256,9 +259,15 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
256259
* @private
257260
*/
258261
private inCurrentSubmissionScope(field: string): boolean {
259-
const scope = this.formConfig?.rows.find(row => {
260-
return row.fields?.[0]?.selectableMetadata?.[0]?.metadata === field;
261-
}).fields?.[0]?.scope;
262+
const scope = this.formConfig?.rows.find((row: FormRowModel) => {
263+
if (row.fields?.[0]?.selectableMetadata) {
264+
return row.fields?.[0]?.selectableMetadata?.[0]?.metadata === field;
265+
} else if (row.fields?.[0]?.selectableRelationship) {
266+
return row.fields?.[0]?.selectableRelationship.relationshipType === field.replace(/^relationship\./g, '');
267+
} else {
268+
return false;
269+
}
270+
})?.fields?.[0]?.scope;
262271

263272
switch (scope) {
264273
case SubmissionScopeType.WorkspaceItem: {

0 commit comments

Comments
 (0)