Skip to content

Commit

Permalink
hide requestthat setup a device in the mock inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Dec 20, 2024
1 parent e0c3982 commit c2919aa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface C8YRequest {
response?: any;
targetAPI?: string;
error?: string;
hide?:boolean;
}

export interface ProcessingContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c2919aa

Please sign in to comment.