Skip to content

Commit

Permalink
Merge pull request #4656 from activepieces/fix/duplicate-pieces-icons…
Browse files Browse the repository at this point in the history
…-in-flow-table

fix: flow table pieces icons were being duplicated
  • Loading branch information
abuaboud committed May 9, 2024
2 parents 64d7546 + 5b10de4 commit 30ac6a1
Showing 1 changed file with 24 additions and 2 deletions.
@@ -1,7 +1,11 @@
import { Component, Input, OnInit } from '@angular/core';
import {
Action,
ActionType,
FlowVersion,
FlowVersionTemplate,
Trigger,
TriggerType,
flowHelper,
} from '@activepieces/shared';
import { Observable, forkJoin, map } from 'rxjs';
Expand Down Expand Up @@ -34,7 +38,7 @@ export class PiecesIconsFromFlowComponent implements OnInit {

constructor(private pieceService: PieceMetadataService) { }
ngOnInit(): void {
const steps = flowHelper.getAllSteps(this.flowVersion.trigger);
const steps = this.filterOutDuplicates(flowHelper.getAllSteps(this.flowVersion.trigger));
const stepMetadata$: Observable<FlowItemDetails>[] = steps.map((step) => this.pieceService.getStepDetails(step));
this.urlsToLoad$ = forkJoin(stepMetadata$).pipe(
map((items) => items.map((item) => item.logoUrl!).slice(0, this.maxNumberOfIconsToLoad)));
Expand All @@ -46,11 +50,29 @@ export class PiecesIconsFromFlowComponent implements OnInit {
const stepsAppsNames = items.map((item) => item.name);
if (stepsAppsNames.length === 1) {
return stepsAppsNames[0]!;
} else if (stepsAppsNames.length < 7) {
} else if (stepsAppsNames.length <= 7) {
return stepsAppsNames.slice(0, stepsAppsNames.length - 1).join(', ') +
` and ${stepsAppsNames[stepsAppsNames.length - 1]}`;
} else {
return stepsAppsNames.join(', ') + ' and others';
}
}

private filterOutDuplicates(steps: (Action | Trigger)[])
{
const seen = new Set<string>();
return steps.filter((step) => {
let isDuplicate = false;
if(step.type === ActionType.PIECE || step.type === TriggerType.PIECE)
{
isDuplicate = seen.has(step.settings.pieceName);
seen.add(step.settings.pieceName);
}
else{
isDuplicate = seen.has(step.type);
seen.add(step.type);
}
return !isDuplicate;
});
}
}

0 comments on commit 30ac6a1

Please sign in to comment.