From c2919aadeba8baae89b5b2f96465487f67aa735f Mon Sep 17 00:00:00 2001 From: ck-c8y Date: Fri, 20 Dec 2024 18:56:00 +0100 Subject: [PATCH] hide requestthat setup a device in the mock inventory --- .../payload-processor-inbound.service.ts | 5 +- .../mapping/core/processor/processor.model.ts | 1 + .../step-testing/mapping-testing.component.ts | 75 ++++++++++++------- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/dynamic-mapping-ui/src/mapping/core/processor/payload-processor-inbound.service.ts b/dynamic-mapping-ui/src/mapping/core/processor/payload-processor-inbound.service.ts index e19d9556..e6968bf9 100644 --- a/dynamic-mapping-ui/src/mapping/core/processor/payload-processor-inbound.service.ts +++ b/dynamic-mapping-ui/src/mapping/core/processor/payload-processor-inbound.service.ts @@ -164,7 +164,8 @@ export abstract class PayloadProcessorInbound { source: device.value, externalIdType: mapping.externalIdType, request, - targetAPI: API.INVENTORY.name + targetAPI: API.INVENTORY.name, + hide: true }); const response = await this.c8yClient.upsertDevice( { @@ -176,7 +177,7 @@ export abstract class PayloadProcessorInbound { context.requests[newPredecessor - 1].response = response; substitute.value = response.id as any; } catch (e) { - console.log ("Error", e); + console.log("Error", e); } } if (!sourceId.value && mapping.createNonExistingDevice) { diff --git a/dynamic-mapping-ui/src/mapping/core/processor/processor.model.ts b/dynamic-mapping-ui/src/mapping/core/processor/processor.model.ts index b8813f6a..38f646c4 100644 --- a/dynamic-mapping-ui/src/mapping/core/processor/processor.model.ts +++ b/dynamic-mapping-ui/src/mapping/core/processor/processor.model.ts @@ -29,6 +29,7 @@ export interface C8YRequest { response?: any; targetAPI?: string; error?: string; + hide?:boolean; } export interface ProcessingContext { diff --git a/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts b/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts index 201982b0..41ac3d8c 100644 --- a/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts +++ b/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts @@ -204,37 +204,54 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy { } onNextTestResult() { - if ( - this.testingModel.selectedResult >= - this.testingModel.results.length - 1 - ) { - this.testingModel.selectedResult = -1; - } - this.testingModel.selectedResult++; - this.selectedResult$.next(this.testingModel.selectedResult + 1); - if ( - this.testingModel.selectedResult >= 0 && - this.testingModel.selectedResult < this.testingModel.results.length - ) { - this.testingModel.request = - this.testingModel.results[this.testingModel.selectedResult].request; - this.testingModel.response = - this.testingModel.results[this.testingModel.selectedResult].response; - this.editorTestingRequest.setSchema( - getSchema( - this.testingModel.results[this.testingModel.selectedResult].targetAPI, - this.mapping.direction, - true, true - ) - ); - this.testingModel.errorMsg = - this.testingModel.results[this.testingModel.selectedResult].error; + const { testingModel } = this; + const { results, selectedResult } = testingModel; + + // Function to find next visible result + const findNextVisibleResult = (currentIndex: number): number => { + let nextIndex = currentIndex; + do { + nextIndex = (nextIndex >= results.length - 1) ? 0 : nextIndex + 1; + if (!results[nextIndex].hide) { + return nextIndex; + } + } while (nextIndex !== currentIndex); + + // If all results are hidden, return the current index + return currentIndex; + }; + + // Update selected result index with wrapping, skipping hidden results + testingModel.selectedResult = findNextVisibleResult(selectedResult); + + this.selectedResult$.next(testingModel.selectedResult + 1); + + // Check if selected result is valid + const currentResult = results[testingModel.selectedResult]; + + if (currentResult) { + // Valid result - set properties from current result + const { request, response, targetAPI, error } = currentResult; + + testingModel.request = request; + testingModel.response = response; + testingModel.errorMsg = error; + + this.editorTestingRequest.setSchema( + getSchema( + targetAPI, + this.mapping.direction, + true, + true + ) + ); } else { - this.testingModel.request = JSON.parse('{}'); - this.testingModel.response = JSON.parse('{}'); - this.testingModel.errorMsg = undefined; + // Invalid result - reset properties + testingModel.request = {}; + testingModel.response = {}; + testingModel.errorMsg = undefined; } - } +} ngOnDestroy() { this.selectedResult$.complete();