Skip to content

Commit

Permalink
Fix bug using splice() without specifing the number of elements to re…
Browse files Browse the repository at this point in the history
…move (#6199)

Signed-off-by: Giovanni Ferrari <[email protected]>
  • Loading branch information
quinarygio authored and freddidierRTE committed Mar 27, 2024
1 parent 9756ed6 commit 140cec8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class ConfigService {
(entity) => entity.entityId === supervisedEntity.entityId
);
if (index >= 0) {
this.supervisorConfig.entitiesToSupervise.splice(index);
this.supervisorConfig.entitiesToSupervise.splice(index, 1);
}
this.supervisorConfig.entitiesToSupervise.push(supervisedEntity);
this.save();
Expand All @@ -99,7 +99,7 @@ export default class ConfigService {

const index = this.supervisorConfig.entitiesToSupervise.findIndex((entity) => entity.entityId === entityId);
if (index >= 0) {
this.supervisorConfig.entitiesToSupervise.splice(index);
this.supervisorConfig.entitiesToSupervise.splice(index, 1);
}
this.save();
}
Expand Down
12 changes: 7 additions & 5 deletions node-services/supervisor/src/tests/configService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ class SupervisorDatabaseServiceStub extends SupervisorDatabaseService {
public supervisedEntities: any[] = [];

public async getSupervisedEntities(): Promise<any[]> {
return this.supervisedEntities;
const supervised: any[] = [];
this.supervisedEntities.forEach((entity) => supervised.push(entity));
return supervised;
}

public async saveSupervisedEntity(supervisedEntity: any): Promise<void> {
const index = this.supervisedEntities.findIndex((entity) => entity.entityId === supervisedEntity.entityId);
if (index >= 0) {
this.supervisedEntities.splice(index);
this.supervisedEntities.splice(index, 1);
}
this.supervisedEntities.push(supervisedEntity);
}

public async deleteSupervisedEntity(id: string): Promise<void> {
const index = this.supervisedEntities.findIndex((entity) => entity.entityId === id);
if (index >= 0) {
this.supervisedEntities.splice(index);
this.supervisedEntities.splice(index, 1);
}
}
}
Expand Down Expand Up @@ -124,9 +126,9 @@ describe('config service', function () {
{entityId: 'ENTITY3', supervisors: ['ENTITY2']}
]);

await configService.deleteSupervisedEntity('ENTITY3');
await configService.deleteSupervisedEntity('ENTITY4');
expect(configService.getSupervisorConfig().entitiesToSupervise).toEqual([
{entityId: 'ENTITY4', supervisors: ['ENTITY1']}
{entityId: 'ENTITY3', supervisors: ['ENTITY2']}
]);
});
});
4 changes: 2 additions & 2 deletions ui/main/src/app/business/store/lightcards/lightcards-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class LightCardsStore {
const children = this.childCards.get(card.parentCardId);
if (children) {
const childIndex = children.findIndex((child) => child.id === card.id);
if (childIndex >= 0) children.splice(childIndex);
if (childIndex >= 0) children.splice(childIndex, 1);
children.push(card);
} else {
this.childCards.set(card.parentCardId, [card]);
Expand Down Expand Up @@ -399,7 +399,7 @@ export class LightCardsStore {
if (card?.entitiesAcks && entitiesAcksToRemove) {
entitiesAcksToRemove.forEach((entityToRemove) => {
const indexToRemove = card.entitiesAcks.indexOf(entityToRemove);
if (indexToRemove >= 0) card.entitiesAcks.splice(indexToRemove);
if (indexToRemove >= 0) card.entitiesAcks.splice(indexToRemove, 1);
});
card.hasBeenAcknowledged = AcknowledgeService.isLightCardHasBeenAcknowledgedByUserOrByUserEntity(card);
this.lightCardsEvents.next(this.lightCards);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class CardAckComponent implements OnInit, OnChanges, OnDestroy {
if (lightcard?.entitiesAcks && entitiesAcksToRemove) {
entitiesAcksToRemove.forEach((entityToRemove) => {
const indexToRemove = lightcard.entitiesAcks.indexOf(entityToRemove);
if (indexToRemove >= 0) lightcard.entitiesAcks.splice(indexToRemove);
if (indexToRemove >= 0) lightcard.entitiesAcks.splice(indexToRemove, 1);
});
}
this.card = {
Expand Down

0 comments on commit 140cec8

Please sign in to comment.