Skip to content

Commit

Permalink
fix(#2235): Use lodash for deep copy (#2238)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe authored Nov 29, 2023
1 parent 0f845b7 commit e3257a2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 57 deletions.
1 change: 1 addition & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"jshint": "^2.13.6",
"konva": "9.2.0",
"leaflet": "1.9.3",
"lodash": "4.17.21",
"material-icons": "^1.13.1",
"ngx-color-picker": "^14.0.0",
"ngx-echarts": "^15.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/

import { JsplumbBridge } from '../../services/jsplumb-bridge.service';
import { JsplumbService } from '../../services/jsplumb.service';
import { PipelineValidationService } from '../../services/pipeline-validation.service';
import { RestApi } from '../../../services/rest-api.service';
import {
Component,
Expand All @@ -41,6 +39,7 @@ import {
SpDataStream,
WildcardTopicDefinition,
} from '@streampipes/platform-services';
import { cloneDeep } from 'lodash';
import { EditorService } from '../../services/editor.service';
import { DialogService, PanelType } from '@streampipes/shared-ui';
import { CompatibleElementsComponent } from '../../dialog/compatible-elements/compatible-elements.component';
Expand Down Expand Up @@ -91,23 +90,21 @@ export class PipelineElementOptionsComponent implements OnInit, OnDestroy {

pipelineElementConfiguredObservable: Subscription;

JsplumbBridge: JsplumbBridge;
jsplumbBridge: JsplumbBridge;

constructor(
private objectProvider: ObjectProvider,
private pipelineElementRecommendationService: PipelineElementRecommendationService,
private dialogService: DialogService,
private editorService: EditorService,
private jsplumbFactoryService: JsplumbFactoryService,
private jsplumbService: JsplumbService,
private pipelineValidationService: PipelineValidationService,
private restApi: RestApi,
) {
this.recommendationsAvailable = false;
this.possibleElements = [];
this.recommendedElements = [];
this.recommendationsShown = false;
this.JsplumbBridge = this.jsplumbFactoryService.getJsplumbBridge(false);
this.jsplumbBridge = this.jsplumbFactoryService.getJsplumbBridge(false);
}

ngOnInit() {
Expand Down Expand Up @@ -158,22 +155,22 @@ export class PipelineElementOptionsComponent implements OnInit, OnDestroy {
// this.EditorDialogManager.showCustomizeStreamDialog(this.pipelineElement.payload);
}

initRecs(pipelineElementDomId) {
const clonedModel: PipelineElementConfig[] = this.deepCopy(
initRecs(pipelineElementDomId: string) {
const clonedModel: PipelineElementConfig[] = cloneDeep(
this.rawPipelineModel,
);
const currentPipeline = this.objectProvider.makePipeline(clonedModel);
this.editorService
.recommendPipelineElement(currentPipeline, pipelineElementDomId)
.subscribe(result => {
if (result.success) {
this.possibleElements = this.deepCopy(
this.possibleElements = cloneDeep(
this.pipelineElementRecommendationService.collectPossibleElements(
this.allElements,
result.possibleElements,
),
);
this.recommendedElements = this.deepCopy(
this.recommendedElements = cloneDeep(
this.pipelineElementRecommendationService.populateRecommendedList(
this.allElements,
result.recommendedElements,
Expand Down Expand Up @@ -203,16 +200,6 @@ export class PipelineElementOptionsComponent implements OnInit, OnDestroy {
e.stopPropagation();
}

isRootElement() {
return (
this.JsplumbBridge.getConnections({
source: document.getElementById(
this.pipelineElement.payload.dom,
),
}).length === 0
);
}

isWildcardTopic() {
return (
(this.pipelineElement.payload as SpDataStream).eventGrounding
Expand All @@ -224,28 +211,4 @@ export class PipelineElementOptionsComponent implements OnInit, OnDestroy {
ngOnDestroy(): void {
this.pipelineElementConfiguredObservable.unsubscribe();
}

deepCopy(obj) {
let clone: any = {};
if (
obj === null ||
typeof obj !== 'object' ||
Array.isArray(obj) ||
obj === undefined
) {
return obj;
}

if (Array.isArray(obj)) {
clone = obj.map(item => this.deepCopy(item));
}

for (const key in obj) {
if (obj.hasOwnProperty(key)) {
clone[key] = this.deepCopy(obj[key]);
}
}

return clone;
}
}
1 change: 0 additions & 1 deletion ui/src/app/editor/services/jsplumb-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class JsplumbBridge {

setEndpointType(endpointId: string, endpointType: string) {
const endpoint = this.getEndpointById(endpointId);
// @ts-ignore
endpoint.setType(endpointType);
}

Expand Down
28 changes: 16 additions & 12 deletions ui/src/app/editor/services/object-provider.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

import { Injectable } from '@angular/core';
import { RestApi } from '../../services/rest-api.service';
import {
InvocablePipelineElementUnion,
PipelineElementConfig,
Expand All @@ -29,7 +28,6 @@ import { JsplumbFactoryService } from './jsplumb-factory.service';
@Injectable({ providedIn: 'root' })
export class ObjectProvider {
constructor(
private restApi: RestApi,
private editorService: EditorService,
private jsplumbFactoryService: JsplumbFactoryService,
) {}
Expand All @@ -50,11 +48,11 @@ export class ObjectProvider {
return pipeline;
}

makeFinalPipeline(currentPipelineElements) {
makeFinalPipeline(currentPipelineElements: PipelineElementConfig[]) {
return this.makePipeline(currentPipelineElements);
}

makePipeline(currentPipelineElements): Pipeline {
makePipeline(currentPipelineElements: PipelineElementConfig[]): Pipeline {
let pipeline = this.preparePipeline();
pipeline = this.addElementNew(pipeline, currentPipelineElements);
return pipeline;
Expand Down Expand Up @@ -100,28 +98,34 @@ export class ObjectProvider {
pipeline,
currentPipelineElements: PipelineElementConfig[],
): Pipeline {
const JsplumbBridge =
const jsplumbBridge =
this.jsplumbFactoryService.getJsplumbBridge(false);
currentPipelineElements.forEach(pe => {
if (pe.settings.disabled === undefined || !pe.settings.disabled) {
if (pe.type === 'sepa' || pe.type === 'action') {
let payload = pe.payload;
currentPipelineElements.forEach(pipelineElementConfig => {
if (
pipelineElementConfig.settings.disabled === undefined ||
!pipelineElementConfig.settings.disabled
) {
if (
pipelineElementConfig.type === 'sepa' ||
pipelineElementConfig.type === 'action'
) {
let payload = pipelineElementConfig.payload;
payload = this.prepareElement(
payload as InvocablePipelineElementUnion,
);
const connections = JsplumbBridge.getConnections({
const connections = jsplumbBridge.getConnections({
target: document.getElementById(payload.dom),
});
for (let i = 0; i < connections.length; i++) {
payload.connectedTo.push(connections[i].sourceId);
}
if (payload.connectedTo && payload.connectedTo.length > 0) {
pe.type === 'action'
pipelineElementConfig.type === 'action'
? pipeline.actions.push(payload)
: pipeline.sepas.push(payload);
}
} else {
pipeline.streams.push(pe.payload);
pipeline.streams.push(pipelineElementConfig.payload);
}
}
});
Expand Down

0 comments on commit e3257a2

Please sign in to comment.