Skip to content

Commit

Permalink
adding show if
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Oct 11, 2024
1 parent 08e4146 commit c4b3210
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions dynamic-mapping-ui/src/mapping/grid/mapping.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
import { Router } from '@angular/router';
import { IIdentified } from '@c8y/client';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { Observable, Subject, take } from 'rxjs';
import { BehaviorSubject, Observable, Subject, take } from 'rxjs';
import { MappingService } from '../core/mapping.service';
import { ImportMappingsComponent } from '../import/import-modal.component';
import { MappingTypeComponent } from '../mapping-type/mapping-type.component';
Expand Down Expand Up @@ -94,7 +94,9 @@ export class MappingComponent implements OnInit, OnDestroy {

isConnectionToMQTTEstablished: boolean;

mappingsEnriched$: Observable<MappingEnriched[]>;
mappingsEnriched$: BehaviorSubject<MappingEnriched[]> = new BehaviorSubject(
[]
);
mappingsCount: number = 0;
mappingToUpdate: Mapping;
subscription: C8YNotificationSubscription;
Expand Down Expand Up @@ -265,13 +267,14 @@ export class MappingComponent implements OnInit, OnDestroy {
this.bulkActionControls.push(
{
type: BuiltInActionType.Delete,
callback: this.deleteMappingBulkWithConfirmation.bind(this),
showIf: (selectedItemIds) => {
const result = true;
// depending on seleted id hide the bulkDelete
console.log('Selected mappings (showIf):', selectedItemIds);
return result;
}
callback: this.deleteMappingBulkWithConfirmation.bind(this)
// showIf: (selectedItemIds: string[]) => {
// // hide bulkDelete if any selected mapping is enabled
// const mappings = this.mappingsEnriched$.getValue();
// const result = mappings?.some((m) => selectedItemIds?.includes(m.id));
// console.log('Selected mappings (showIf):', selectedItemIds);
// return true;
// }
},
{
type: 'ACTIVATE',
Expand All @@ -292,9 +295,9 @@ export class MappingComponent implements OnInit, OnDestroy {
callback: this.exportMappingBulk.bind(this)
}
);
this.mappingsEnriched$ = this.mappingService.getMappingsObservable(
this.stepperConfiguration.direction
);
this.mappingService
.getMappingsObservable(this.stepperConfiguration.direction)
.subscribe((mappings) => this.mappingsEnriched$.next(mappings));

this.mappingsEnriched$.subscribe((maps) => {
this.mappingsCount = maps.length;
Expand Down

0 comments on commit c4b3210

Please sign in to comment.