97732 Fixed bug where ContextHelpWrapperComponent subscriptions would not properly be initialized if the application launches with help icons hidden by default

This commit is contained in:
Koen Pauwels
2023-01-05 12:06:14 +01:00
parent e16a3edf78
commit 920e36ecf2
12 changed files with 56 additions and 41 deletions

View File

@@ -65,6 +65,7 @@
<ul class="footer-info list-unstyled small d-flex justify-content-center mb-0"> <ul class="footer-info list-unstyled small d-flex justify-content-center mb-0">
<li> <li>
<a *dsContextHelp="{content: 'context-help.multi-para.test', <a *dsContextHelp="{content: 'context-help.multi-para.test',
id: 'show-cookie-settings',
tooltipPlacement: 'top', tooltipPlacement: 'top',
iconPlacement: 'left' iconPlacement: 'left'
}" }"

View File

@@ -2,7 +2,9 @@
<a href="javascript:void(0);" <a href="javascript:void(0);"
role="button" role="button"
(click)="onClick()" (click)="onClick()"
[attr.aria-label]="'nav.context-help-toggle' | translate"
[title]="'nav.context-help-toggle' | translate"
> >
<i class="fas fa-question-circle ds-context-help-toggle"></i> <i class="fas fa-lg fa-fw fa-question-circle ds-context-help-toggle"></i>
</a> </a>
</div> </div>

View File

@@ -1,8 +1,8 @@
.ds-context-help-toggle { .ds-context-help-toggle {
color: var(--ds-header-icon-color); color: var(--ds-header-icon-color);
background-color: var(--ds-header-bg); background-color: var(--ds-header-bg);
}
.ds-context-help-toggle:hover { &:hover, &focus {
color: var(--ds-header-icon-color-hover); color: var(--ds-header-icon-color-hover);
}
} }

View File

@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ContextHelpService } from '../../shared/context-help.service'; import { ContextHelpService } from '../../shared/context-help.service';
import { TranslateService } from '@ngx-translate/core';
@Component({ @Component({
selector: 'ds-context-help-toggle', selector: 'ds-context-help-toggle',
@@ -9,14 +10,14 @@ import { ContextHelpService } from '../../shared/context-help.service';
export class ContextHelpToggleComponent implements OnInit { export class ContextHelpToggleComponent implements OnInit {
constructor( constructor(
private contextHelpService: ContextHelpService private contextHelpService: ContextHelpService,
private translateService: TranslateService
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
} }
onClick() { onClick() {
console.log('toggling icons');
this.contextHelpService.toggleIcons(); this.contextHelpService.toggleIcons();
} }
} }

View File

@@ -1,5 +1,4 @@
<div class="page-internal-server-error container"> <div class="page-internal-server-error container">
<ds-context-help-toggle></ds-context-help-toggle>
<h1>500</h1> <h1>500</h1>
<h2><small *dsContextHelp="{content: 'context-help.multi-para.test', id: 'server-error'}">{{"500.page-internal-server-error" | translate}}</small></h2> <h2><small *dsContextHelp="{content: 'context-help.multi-para.test', id: 'server-error'}">{{"500.page-internal-server-error" | translate}}</small></h2>
<br/> <br/>

View File

@@ -13,7 +13,6 @@
border-radius: 50%; border-radius: 50%;
} }
.ds-context-help-icon-left { .ds-context-help-icon-left {
left: var(--ds-context-x-offset); left: var(--ds-context-x-offset);
} }

View File

@@ -19,7 +19,7 @@ import { ContextHelp } from '../context-help.model';
templateUrl: './context-help-wrapper.component.html', templateUrl: './context-help-wrapper.component.html',
styleUrls: ['./context-help-wrapper.component.scss'], styleUrls: ['./context-help-wrapper.component.scss'],
}) })
export class ContextHelpWrapperComponent implements OnInit, AfterViewInit, OnDestroy { export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
/** /**
* Template reference for the wrapped element. * Template reference for the wrapped element.
*/ */
@@ -46,11 +46,9 @@ export class ContextHelpWrapperComponent implements OnInit, AfterViewInit, OnDes
*/ */
@Input() dontParseLinks?: boolean; @Input() dontParseLinks?: boolean;
@ViewChild('tooltip', { static: false }) tooltip: NgbTooltip;
shouldShowIcon$: Observable<boolean>; shouldShowIcon$: Observable<boolean>;
private subs: Subscription[] = []; tooltip: NgbTooltip;
// TODO: dependent on evaluation order of input setters? // TODO: dependent on evaluation order of input setters?
parsedContent$: Observable<(string | {href: string, text: string})[]> = observableOf([]); parsedContent$: Observable<(string | {href: string, text: string})[]> = observableOf([]);
@@ -62,6 +60,9 @@ export class ContextHelpWrapperComponent implements OnInit, AfterViewInit, OnDes
); );
} }
private subs: {always: Subscription[], tooltipBound: Subscription[]}
= {always: [], tooltipBound: []};
constructor( constructor(
private translateService: TranslateService, private translateService: TranslateService,
private contextHelpService: ContextHelpService private contextHelpService: ContextHelpService
@@ -69,18 +70,21 @@ export class ContextHelpWrapperComponent implements OnInit, AfterViewInit, OnDes
ngOnInit() { ngOnInit() {
this.shouldShowIcon$ = this.contextHelpService.shouldShowIcons$(); this.shouldShowIcon$ = this.contextHelpService.shouldShowIcons$();
this.subs.push(this.shouldShowIcon$.subscribe()); this.subs.always = [this.shouldShowIcon$.subscribe()];
} }
ngAfterViewInit() { @ViewChild('tooltip', { static: false }) set setTooltip(tooltip: NgbTooltip) {
this.subs.push( this.tooltip = tooltip;
this.clearSubs('tooltipBound');
if (this.tooltip !== undefined) {
this.subs.tooltipBound = [
this.contextHelpService.getContextHelp$(this.id) this.contextHelpService.getContextHelp$(this.id)
.pipe(hasValueOperator()) .pipe(hasValueOperator())
.subscribe((ch: ContextHelp) => { .subscribe((ch: ContextHelp) => {
if (ch.isTooltipVisible && !this.tooltip.isOpen()) { if (ch.isTooltipVisible && !this.tooltip.isOpen()) {
this.tooltip.open(); this.tooltip.open();
} else if (!ch.isTooltipVisible && this.tooltip.isOpen()) { } else if (!ch.isTooltipVisible && this.tooltip.isOpen()) {
this.tooltip.close() this.tooltip.close();
} }
}), }),
@@ -91,13 +95,12 @@ export class ContextHelpWrapperComponent implements OnInit, AfterViewInit, OnDes
this.tooltip.hidden.subscribe(() => { this.tooltip.hidden.subscribe(() => {
this.contextHelpService.hideTooltip(this.id); this.contextHelpService.hideTooltip(this.id);
}) })
); ];
}
} }
ngOnDestroy() { ngOnDestroy() {
for (let sub of this.subs) { this.clearSubs();
sub.unsubscribe();
}
} }
onClick() { onClick() {
@@ -146,7 +149,14 @@ export class ContextHelpWrapperComponent implements OnInit, AfterViewInit, OnDes
: ({href: match[2], text: match[1]}); : ({href: match[2], text: match[1]});
}); });
} }
private clearSubs(filter: null | 'tooltipBound' = null) {
if (filter === null) {
[].concat(...Object.values(this.subs)).forEach(sub => sub.unsubscribe());
this.subs = {always: [], tooltipBound: []};
} else {
this.subs[filter].forEach(sub => sub.unsubscribe());
this.subs[filter] = [];
}
}
} }

View File

@@ -52,7 +52,7 @@ export class ContextHelpDirective implements OnChanges, OnDestroy {
ngOnChanges() { ngOnChanges() {
this.clearMostRecentId(); this.clearMostRecentId();
this.mostRecentId = this.dsContextHelp.id; this.mostRecentId = this.dsContextHelp.id;
this.contextHelpService.add({id: this.dsContextHelp.id}); // TODO: tooltipVisible field this.contextHelpService.add({id: this.dsContextHelp.id, isTooltipVisible: false});
const factory const factory
= this.componentFactoryResolver.resolveComponentFactory(ContextHelpWrapperComponent); = this.componentFactoryResolver.resolveComponentFactory(ContextHelpWrapperComponent);

View File

@@ -10,8 +10,7 @@ export interface ContextHelpState {
models: ContextHelpModels; models: ContextHelpModels;
} }
// TODO const initialState: ContextHelpState = {allIconsVisible: false, models: {}};
const initialState: ContextHelpState = {allIconsVisible: true, models: {}};
export function contextHelpReducer(state: ContextHelpState = initialState, action: ContextHelpAction): ContextHelpState { export function contextHelpReducer(state: ContextHelpState = initialState, action: ContextHelpAction): ContextHelpState {
switch (action.type) { switch (action.type) {

View File

@@ -2674,6 +2674,8 @@
"nav.community-browse.header": "By Community", "nav.community-browse.header": "By Community",
"nav.context-help-toggle": "Toggle context help",
"nav.language": "Language switch", "nav.language": "Language switch",
"nav.login": "Log In", "nav.login": "Log In",

View File

@@ -8,6 +8,7 @@
<div class="d-flex flex-grow-1 ml-auto justify-content-end align-items-center"> <div class="d-flex flex-grow-1 ml-auto justify-content-end align-items-center">
<ds-search-navbar class="navbar-search"></ds-search-navbar> <ds-search-navbar class="navbar-search"></ds-search-navbar>
<ds-lang-switch></ds-lang-switch> <ds-lang-switch></ds-lang-switch>
<ds-context-help-toggle></ds-context-help-toggle>
<ds-auth-nav-menu></ds-auth-nav-menu> <ds-auth-nav-menu></ds-auth-nav-menu>
<ds-impersonate-navbar></ds-impersonate-navbar> <ds-impersonate-navbar></ds-impersonate-navbar>
<div class="pl-2"> <div class="pl-2">

View File

@@ -14,6 +14,7 @@
</div> </div>
<ds-search-navbar class="navbar-collapsed"></ds-search-navbar> <ds-search-navbar class="navbar-collapsed"></ds-search-navbar>
<ds-lang-switch class="navbar-collapsed"></ds-lang-switch> <ds-lang-switch class="navbar-collapsed"></ds-lang-switch>
<ds-context-help-toggle class="navbar-collapsed"></ds-context-help-toggle>
<ds-auth-nav-menu class="navbar-collapsed"></ds-auth-nav-menu> <ds-auth-nav-menu class="navbar-collapsed"></ds-auth-nav-menu>
<ds-impersonate-navbar class="navbar-collapsed"></ds-impersonate-navbar> <ds-impersonate-navbar class="navbar-collapsed"></ds-impersonate-navbar>
</div> </div>