Skip to content

Commit b318d72

Browse files
101654: Fixed relationship fields not being hidden when they are out of scope
1 parent a6a1020 commit b318d72

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,22 @@ describe('SubmissionSectionFormComponent test suite', () => {
347347
} as FormFieldModel
348348
]
349349
},
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+
},
350366
{
351367
fields: [
352368
{
@@ -375,6 +391,14 @@ describe('SubmissionSectionFormComponent test suite', () => {
375391
it('should return false for fields scoped to workflow', () => {
376392
expect((comp as any).inCurrentSubmissionScope('scoped.workflow')).toBe(false);
377393
});
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+
});
378402
});
379403

380404
describe('in workflow scope', () => {
@@ -394,6 +418,14 @@ describe('SubmissionSectionFormComponent test suite', () => {
394418
it('should return false for fields scoped to workspace', () => {
395419
expect((comp as any).inCurrentSubmissionScope('scoped.workspace')).toBe(false);
396420
});
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+
});
397429
});
398430
});
399431

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { WorkflowItem } from '../../../core/submission/models/workflowitem.model
3838
import { SubmissionObject } from '../../../core/submission/models/submission-object.model';
3939
import { SubmissionSectionObject } from '../../objects/submission-section-object.model';
4040
import { SubmissionSectionError } from '../../objects/submission-section-error.model';
41+
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
4142

4243
/**
4344
* This component represents a section that contains a Form.
@@ -255,9 +256,15 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
255256
* @private
256257
*/
257258
private inCurrentSubmissionScope(field: string): boolean {
258-
const scope = this.formConfig?.rows.find(row => {
259-
return row.fields?.[0]?.selectableMetadata?.[0]?.metadata === field;
260-
}).fields?.[0]?.scope;
259+
const scope = this.formConfig?.rows.find((row: FormRowModel) => {
260+
if (row.fields?.[0]?.selectableMetadata) {
261+
return row.fields?.[0]?.selectableMetadata?.[0]?.metadata === field;
262+
} else if (row.fields?.[0]?.selectableRelationship) {
263+
return row.fields?.[0]?.selectableRelationship.relationshipType === field.replace(/^relationship\./g, '');
264+
} else {
265+
return false;
266+
}
267+
})?.fields?.[0]?.scope;
261268

262269
switch (scope) {
263270
case SubmissionScopeType.WorkspaceItem: {

0 commit comments

Comments
 (0)