All files / list-details/si-details-pane si-details-pane.component.ts

100% Statements 13/13
100% Branches 1/1
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                                                    1x 21x   21x   21x   21x     21x 21x 21x 2x 2x 2x     4x            
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  contentChild,
  DestroyRef,
  effect,
  inject
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { RouterOutlet } from '@angular/router';
import { Subscription } from 'rxjs';
 
import { SiListDetailsComponent } from '../si-list-details.component';
 
/** @experimental */
@Component({
  selector: 'si-details-pane',
  imports: [],
  templateUrl: './si-details-pane.component.html',
  styleUrl: './si-details-pane.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    '[class.expanded]': 'parent.hasLargeSize()',
    '[class.details-active]': 'parent.detailsActive() && !parent.hasLargeSize()',
    '[attr.inert]': '!parent.hasLargeSize() && !parent.detailsActive() ? "" : null',
    '[style.flex-basis.%]':
      'parent.hasLargeSize() && parent.disableResizing() ?  100 - parent.listWidth() : undefined'
  }
})
export class SiDetailsPaneComponent {
  protected parent = inject(SiListDetailsComponent);
 
  private readonly routerOutlet = contentChild(RouterOutlet);
  private subscription?: Subscription;
  private destroyer = inject(DestroyRef);
  /** @internal */
  readonly isRouterBased = computed(() => !!this.routerOutlet());
 
  constructor() {
    effect(() => {
      const outlet = this.routerOutlet();
      if (outlet) {
        this.parent.detailsActive.set(!outlet.activatedRouteData.SI_EMPTY_DETAILS);
        this.subscription?.unsubscribe();
        this.subscription = outlet.activateEvents
          .pipe(takeUntilDestroyed(this.destroyer))
          .subscribe(() =>
            this.parent.detailsActive.set(!outlet.activatedRouteData.SI_EMPTY_DETAILS)
          );
      }
    });
  }
}