Skip to content

Commit

Permalink
fixing bug: templates are not updated when moving between steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 20, 2024
1 parent b62ef38 commit d12499e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export abstract class PayloadProcessorInbound {
mapping.mapDeviceIdentifier
) {
let sourceId: string;
const identity = {
externalId: substituteValue.value.toString(),
type: mapping.externalIdType
};
try {
const identity = {
externalId: substituteValue.value.toString(),
type: mapping.externalIdType
};
sourceId = await this.c8yClient.resolveExternalId2GlobalId(
identity,
context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
selectedResult$: BehaviorSubject<number> = new BehaviorSubject<number>(0);
sourceSystem: string;
targetSystem: string;
currentSourceTemplate: any;
currentMapping: any;
editorOptionsTesting: any = {};

@ViewChild('editorTestingPayload', { static: false })
Expand Down Expand Up @@ -111,8 +111,8 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
readOnly: true
};

this.editorTestingPayloadTemplateEmitter.subscribe((template) => {
this.currentSourceTemplate = template;
this.editorTestingPayloadTemplateEmitter.subscribe((current) => {
this.currentMapping = current;
const editorTestingRequestRef =
this.elementRef.nativeElement.querySelector('#editorTestingRequest');
if (editorTestingRequestRef != null) {
Expand All @@ -121,7 +121,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
getSchema(this.mapping.targetAPI, this.mapping.direction, true)
);
this.testingModel = {
payload: this.currentSourceTemplate,
payload: JSON.parse(this.currentMapping.source),
results: [],
selectedResult: -1,
request: {},
Expand All @@ -134,7 +134,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {

async onTestTransformation() {
const testProcessingContext = await this.mappingService.testResult(
this.mapping,
this.currentMapping,
false
);
this.testingModel.results = testProcessingContext.requests;
Expand Down Expand Up @@ -185,7 +185,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {

onResetTransformation() {
this.testingModel = {
payload: this.currentSourceTemplate,
payload: this.currentMapping,
results: [],
request: {},
response: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ <h4 class="text-medium">
[editorTestingPayloadTemplateEmitter]="
editorTestingPayloadTemplateEmitter
"
[mapping]="getCurrentMapping(true)"
[mapping]="mapping"
(testResult)="updateTestResult($event)"
[stepperConfiguration]="stepperConfiguration"
></d11r-mapping-testing>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,24 +516,10 @@ export class MappingStepperComponent implements OnInit, OnDestroy {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
onTemplateSourceChanged(content: Content) {
// if (_.has(content, 'text') && content['text']) {
// this.templateSource = JSON.parse(content['text']);
// // this.mapping.source = content['text'];‚
// } else {
// this.templateSource = content['json'];
// // this.mapping.source = JSON.stringify(content['json']);
// }
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
onTemplateTargetChanged(content: Content) {
// if (_.has(content, 'text') && content['text']) {
// this.templateTarget = JSON.parse(content['text']);
// // this.mapping.target = content['text'];
// } else {
// this.templateTarget = content['json'];
// // this.mapping.target = JSON.stringify(content['json']);
// }
}

async updateTargetExpressionResult() {
Expand Down Expand Up @@ -584,7 +570,7 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
}

getCurrentMapping(patched: boolean): Mapping {
return {
const current = {
...this.mapping,
source: reduceSourceTemplate(
this.editorSourceStep4 ? this.editorSourceStep4?.get() : {},
Expand All @@ -593,10 +579,11 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
target: reduceTargetTemplate(this.editorTargetStep4?.get(), patched), // remove patched attributes, since it should not be stored
lastUpdate: Date.now()
};
return current;
}

async onCommitButton() {
this.commit.emit(this.getCurrentMapping(false));
// this.commit.emit(this.getCurrentMapping(false));
}

async onSampleTargetTemplatesButton() {
Expand Down Expand Up @@ -676,17 +663,7 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
}
} else if (this.step == 'General settings') {
this.templateModel.mapping = this.mapping;
// console.log(
// 'Populate jsonPath if wildcard:',
// isWildcardTopic(this.mapping.direction == Direction.INBOUND? this.mapping.subscriptionTopic :this.mapping.publishTopic ),
// this.mapping.substitutions.length
// );
// console.log(
// 'Templates from mapping:',
// this.mapping.target,
// this.mapping.source,
// this.mapping
// );

this.expandTemplates();
this.extensions =
(await this.extensionService.getProcessorExtensions()) as any;
Expand All @@ -704,13 +681,8 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
}
event.stepper.next();
} else if (this.step == 'Define substitutions') {
this.expandTemplates();
this.getTemplateForm();
// const testSourceTemplate = this.editorSourceStep4
// ? this.editorSourceStep4.get()
// : {};
// this.editorTestingPayloadTemplateEmitter.emit(testSourceTemplate);
this.editorTestingPayloadTemplateEmitter.emit(this.templateSource);
this.editorTestingPayloadTemplateEmitter.emit(this.getCurrentMapping(true));
this.onSelectSubstitution(0);
event.stepper.next();
} else if (this.step == 'Select templates') {
Expand All @@ -721,7 +693,7 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
event.step.label,
this.mapping,
this.editorSourceStep3?.get(),
this.getCurrentMapping(true),
//this.getCurrentMapping(true),
this.templateSource,
this.templateTarget
);
Expand All @@ -735,41 +707,16 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
stepper: C8yStepper;
step: CdkStep;
}): Promise<void> {
// console.log(
// 'onBackStep before',
// event.step.label,
// this.mapping,
// this.getCurrentMapping(false),
// this.getCurrentMapping(true),
// this.templateSource,
// this.templateTarget
// );

this.step = event.step.label;
if (this.step == 'Test mapping') {
const editorTestingRequestRef =
this.elementRef.nativeElement.querySelector('#editorTestingRequest');
if (editorTestingRequestRef != null) {
editorTestingRequestRef.setAttribute('schema', undefined);
}
} else if (this.step == 'Select templates') {
// this.mapping = this.getCurrentMapping(true);
// this.expandTemplates();
} else if (this.step == 'Define substitutions') {
// this.mapping = this.getCurrentMapping(true);
// this.expandTemplates();
}

this.mapping = this.getCurrentMapping(true);
this.expandTemplates();
// console.log(
// 'onBackStep after',
// event.step.label,
// this.mapping,
// this.getCurrentMapping(false),
// this.getCurrentMapping(true),
// this.templateSource,
// this.templateTarget
// );
}
event.stepper.previous();
}

Expand Down

0 comments on commit d12499e

Please sign in to comment.