Skip to content

Commit 57a8c9b

Browse files
committed
fix(DataMapper): Disallow copy-of and value-of on unselected abstract/choice
Fixes: #3513
1 parent 881f6cb commit 57a8c9b

2 files changed

Lines changed: 59 additions & 10 deletions

File tree

packages/ui/src/services/visualization/mapping-action-registry.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export class MappingActionRegistryService {
134134
},
135135
isAllowed: (n) => {
136136
if (n instanceof AddMappingNodeData) return false;
137+
if (MappingActionRegistryService.isUnselectedWrapperField(n)) return false;
137138
if (!VisualizationUtilService.isMappingNode(n)) return true;
138139
return !MappingActionRegistryService.mappingIsOneOf(
139140
ValueSelector,
@@ -155,6 +156,7 @@ export class MappingActionRegistryService {
155156
},
156157
isAllowed: (n) => {
157158
if (n instanceof AddMappingNodeData) return false;
159+
if (MappingActionRegistryService.isUnselectedWrapperField(n)) return false;
158160
if (!VisualizationUtilService.isMappingNode(n)) return true;
159161
return !MappingActionRegistryService.mappingIsOneOf(
160162
ValueSelector,
@@ -340,6 +342,7 @@ export class MappingActionRegistryService {
340342
isAllowed: (n) => {
341343
if (n instanceof VariableNodeData) return false;
342344
if (n instanceof TargetDocumentNodeData) return false;
345+
if (MappingActionRegistryService.isUnselectedWrapperField(n)) return false;
343346
if (VisualizationUtilService.isFieldNode(n)) return DocumentService.hasChildren(n.field);
344347
return (
345348
VisualizationUtilService.isMappingNode(n) &&

packages/ui/src/services/visualization/mapping-action.service.test.ts

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,15 +2616,17 @@ describe('MappingActionService', () => {
26162616
});
26172617
});
26182618

2619-
describe('getAllowedActions() inner instructions on unselected wrapper fields', () => {
2620-
const innerInstructionKinds = [
2619+
describe('getAllowedActions() on unselected wrapper fields', () => {
2620+
const disallowedOnUnselectedWrapperKinds = [
26212621
MappingActionKind.InnerForEach,
26222622
MappingActionKind.InnerForEachGroup,
26232623
MappingActionKind.InnerChoose,
26242624
MappingActionKind.InnerIf,
2625+
MappingActionKind.ValueSelector,
2626+
MappingActionKind.CopyOfSelector,
26252627
];
26262628

2627-
it('should disallow inner instructions on unselected choice field', () => {
2629+
it('should disallow actions on unselected choice field', () => {
26282630
const document = TestUtil.createTargetOrderDoc();
26292631
const mappingTree = new MappingTree(
26302632
document.documentType,
@@ -2644,12 +2646,12 @@ describe('MappingActionService', () => {
26442646

26452647
const unselectedNode = new TargetChoiceFieldNodeData(docNode, choiceField);
26462648
const allowed = MappingActionRegistryService.getAllowedActions(unselectedNode);
2647-
for (const kind of innerInstructionKinds) {
2649+
for (const kind of disallowedOnUnselectedWrapperKinds) {
26482650
expect(allowed).not.toContain(kind);
26492651
}
26502652
});
26512653

2652-
it('should allow inner instructions on selected choice field', () => {
2654+
it('should allow actions on selected choice field', () => {
26532655
const document = TestUtil.createTargetOrderDoc();
26542656
const mappingTree = new MappingTree(
26552657
document.documentType,
@@ -2670,12 +2672,12 @@ describe('MappingActionService', () => {
26702672
const selectedNode = new TargetChoiceFieldNodeData(docNode, memberA);
26712673
selectedNode.choiceField = choiceField;
26722674
const allowed = MappingActionRegistryService.getAllowedActions(selectedNode);
2673-
for (const kind of innerInstructionKinds) {
2675+
for (const kind of disallowedOnUnselectedWrapperKinds) {
26742676
expect(allowed).toContain(kind);
26752677
}
26762678
});
26772679

2678-
it('should disallow inner instructions on unsubstituted abstract field', () => {
2680+
it('should disallow actions on unsubstituted abstract field', () => {
26792681
const document = TestUtil.createTargetOrderDoc();
26802682
const mappingTree = new MappingTree(
26812683
document.documentType,
@@ -2695,12 +2697,12 @@ describe('MappingActionService', () => {
26952697

26962698
const unselectedNode = new TargetAbstractFieldNodeData(docNode, abstractField);
26972699
const allowed = MappingActionRegistryService.getAllowedActions(unselectedNode);
2698-
for (const kind of innerInstructionKinds) {
2700+
for (const kind of disallowedOnUnselectedWrapperKinds) {
26992701
expect(allowed).not.toContain(kind);
27002702
}
27012703
});
27022704

2703-
it('should allow inner instructions on substituted abstract field', () => {
2705+
it('should allow actions on substituted abstract field', () => {
27042706
const document = TestUtil.createTargetOrderDoc();
27052707
const mappingTree = new MappingTree(
27062708
document.documentType,
@@ -2721,10 +2723,54 @@ describe('MappingActionService', () => {
27212723
const selectedNode = new TargetAbstractFieldNodeData(docNode, candidate);
27222724
selectedNode.abstractField = abstractField;
27232725
const allowed = MappingActionRegistryService.getAllowedActions(selectedNode);
2724-
for (const kind of innerInstructionKinds) {
2726+
for (const kind of disallowedOnUnselectedWrapperKinds) {
27252727
expect(allowed).toContain(kind);
27262728
}
27272729
});
2730+
2731+
it('should disallow Variable on unselected choice field', () => {
2732+
const document = TestUtil.createTargetOrderDoc();
2733+
const mappingTree = new MappingTree(
2734+
document.documentType,
2735+
document.documentId,
2736+
DocumentDefinitionType.XML_SCHEMA,
2737+
);
2738+
const docNode = new TargetDocumentNodeData(document, mappingTree);
2739+
const parentField = document.fields[0];
2740+
2741+
const choiceField = new XmlSchemaField(parentField, 'testChoice', false);
2742+
choiceField.type = Types.Container;
2743+
choiceField.wrapperKind = 'choice';
2744+
const memberA = new XmlSchemaField(choiceField, 'memberA', false);
2745+
memberA.type = Types.String;
2746+
choiceField.fields = [memberA];
2747+
parentField.fields.push(choiceField);
2748+
2749+
const unselectedNode = new TargetChoiceFieldNodeData(docNode, choiceField);
2750+
expect(MappingActionRegistryService.getAllowedActions(unselectedNode)).not.toContain(MappingActionKind.Variable);
2751+
});
2752+
2753+
it('should disallow Variable on unsubstituted abstract field', () => {
2754+
const document = TestUtil.createTargetOrderDoc();
2755+
const mappingTree = new MappingTree(
2756+
document.documentType,
2757+
document.documentId,
2758+
DocumentDefinitionType.XML_SCHEMA,
2759+
);
2760+
const docNode = new TargetDocumentNodeData(document, mappingTree);
2761+
const parentField = document.fields[0];
2762+
2763+
const abstractField = new XmlSchemaField(parentField, 'testAbstract', false);
2764+
abstractField.type = Types.Container;
2765+
abstractField.wrapperKind = 'abstract';
2766+
const candidate = new XmlSchemaField(abstractField, 'ConcreteType', false);
2767+
candidate.type = Types.String;
2768+
abstractField.fields = [candidate];
2769+
parentField.fields.push(abstractField);
2770+
2771+
const unselectedNode = new TargetAbstractFieldNodeData(docNode, abstractField);
2772+
expect(MappingActionRegistryService.getAllowedActions(unselectedNode)).not.toContain(MappingActionKind.Variable);
2773+
});
27282774
});
27292775

27302776
describe('UnknownMappingItem visibility', () => {

0 commit comments

Comments
 (0)