97732 Context help toggle button only appears when there is at least one element with a tooltip on the page

This commit is contained in:
Koen Pauwels
2023-01-27 11:59:24 +01:00
parent e717e610f9
commit bceca43580
6 changed files with 17 additions and 33 deletions

View File

@@ -2,6 +2,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
import { ContextHelpService } from '../../shared/context-help.service';
import { Observable, Subscription, BehaviorSubject } from 'rxjs';
import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
/**
* Renders a "context help toggle" button that toggles the visibility of tooltip buttons on the page.
@@ -13,23 +14,17 @@ import { combineLatest } from 'rxjs';
styleUrls: ['./context-help-toggle.component.scss']
})
export class ContextHelpToggleComponent implements OnInit, OnDestroy {
buttonDisabled$: Observable<boolean>;
buttonVisible$: Observable<boolean>;
constructor(
private contextHelpService: ContextHelpService,
) { }
private clickEvents: BehaviorSubject<null> = new BehaviorSubject(null);
private subs: Subscription[];
ngOnInit(): void {
this.buttonDisabled$ = this.contextHelpService.contextHelpEmpty$();
this.subs = [
this.buttonDisabled$.subscribe(),
combineLatest([this.clickEvents, this.buttonDisabled$])
.subscribe(([_, disabled]) =>
disabled ? null : this.contextHelpService.toggleIcons())
];
this.buttonVisible$ = this.contextHelpService.tooltipCount$().pipe(map(x => x > 0));
this.subs = [this.buttonVisible$.subscribe()];
}
ngOnDestroy() {
@@ -37,6 +32,6 @@ export class ContextHelpToggleComponent implements OnInit, OnDestroy {
}
onClick() {
this.clickEvents.next(null);
this.contextHelpService.toggleIcons();
}
}