File

feature-libs/product-configurator/rulebased/components/update-message/configurator-update-message.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-update-message
templateUrl ./configurator-update-message.component.html

Index

Properties

Constructor

constructor(configuratorCommonsService: ConfiguratorCommonsService, configRouterExtractorService: ConfiguratorRouterExtractorService, config: ConfiguratorMessageConfig)
Parameters :
Name Type Optional
configuratorCommonsService ConfiguratorCommonsService No
configRouterExtractorService ConfiguratorRouterExtractorService No
config ConfiguratorMessageConfig No

Properties

hasPendingChanges$
Type : Observable<boolean>
Default value : this.configRouterExtractorService .extractRouterData() .pipe( switchMap((routerData) => this.configuratorCommonsService .hasPendingChanges(routerData.owner) .pipe( switchMap((hasPendingChanges) => this.configuratorCommonsService .isConfigurationLoading(routerData.owner) .pipe(map((isLoading) => hasPendingChanges || isLoading)) ) ) ), distinctUntilChanged(), // avoid subsequent emissions of the same value from the source observable switchMap( (isLoading) => isLoading ? of(isLoading).pipe( delay( this.config.productConfigurator?.updateConfigurationMessage ?.waitingTime || 1000 ) ) // delay information if its loading : of(isLoading) // inform disappears immediately if it's not loading anymore ) )
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ConfiguratorRouterExtractorService } from '@spartacus/product-configurator/common';
import { Observable, of } from 'rxjs';
import { delay, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
import { ConfiguratorCommonsService } from '../../core/facade/configurator-commons.service';
import { ConfiguratorMessageConfig } from '../config/configurator-message.config';

@Component({
  selector: 'cx-configurator-update-message',
  templateUrl: './configurator-update-message.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorUpdateMessageComponent {
  hasPendingChanges$: Observable<boolean> = this.configRouterExtractorService
    .extractRouterData()
    .pipe(
      switchMap((routerData) =>
        this.configuratorCommonsService
          .hasPendingChanges(routerData.owner)
          .pipe(
            switchMap((hasPendingChanges) =>
              this.configuratorCommonsService
                .isConfigurationLoading(routerData.owner)
                .pipe(map((isLoading) => hasPendingChanges || isLoading))
            )
          )
      ),
      distinctUntilChanged(), // avoid subsequent emissions of the same value from the source observable
      switchMap(
        (isLoading) =>
          isLoading
            ? of(isLoading).pipe(
                delay(
                  this.config.productConfigurator?.updateConfigurationMessage
                    ?.waitingTime || 1000
                )
              ) // delay information if its loading
            : of(isLoading) // inform disappears immediately if it's not loading anymore
      )
    );

  constructor(
    protected configuratorCommonsService: ConfiguratorCommonsService,
    protected configRouterExtractorService: ConfiguratorRouterExtractorService,
    protected config: ConfiguratorMessageConfig
  ) {}
}
<div class="cx-update-msg" [class.visible]="hasPendingChanges$ | async">
  <cx-spinner></cx-spinner>
  <strong>{{ 'configurator.header.updateMessage' | cxTranslate }}</strong>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""