Skip to content

Commit

Permalink
105094: do not count hidden tooltips to hide the context toggle button
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Vannerum committed Apr 12, 2024
1 parent 7bbdd59 commit 3911dc5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/shared/context-help.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ContextHelpDirective implements OnChanges, OnDestroy {
ngOnChanges() {
this.clearMostRecentId();
this.mostRecentId = this.dsContextHelp.id;
this.contextHelpService.add({id: this.dsContextHelp.id, isTooltipVisible: false});
this.contextHelpService.add({id: this.dsContextHelp.id, isTooltipVisible: false, translationKey: this.dsContextHelp.content});

if (this.wrapper === undefined) {
const factory
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/context-help.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class ContextHelp {
id: string;
isTooltipVisible = false;
translationKey: string;
}
28 changes: 22 additions & 6 deletions src/app/shared/context-help.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
ContextHelpHideTooltipAction,
ContextHelpToggleTooltipAction
} from './context-help.actions';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { from, Observable } from 'rxjs';
import {map, mergeAll, reduce, switchMap, } from 'rxjs/operators';
import {TranslateService} from '@ngx-translate/core';

const contextHelpStateSelector =
createFeatureSelector<ContextHelpState>('contextHelp');
Expand All @@ -33,7 +34,8 @@ const allContextHelpSelector = createSelector(
providedIn: 'root'
})
export class ContextHelpService {
constructor(private store: Store<ContextHelpState>) { }
constructor(private store: Store<ContextHelpState>,
private translateService: TranslateService) { }

/**
* Observable keeping track of whether context help icons should be visible globally.
Expand All @@ -52,11 +54,23 @@ export class ContextHelpService {
}

/**
* Observable that yields true iff there are currently no context help entries in the store.
* Observable that emits the number of context help icons that have a translation key different from the key itself.
* This is done since we don't want to count the icons that have no translation key, as they won't be shown.
*/
tooltipCount$(): Observable<number> {
return this.store.pipe(select(allContextHelpSelector))
.pipe(map((models: ContextHelpModels) => Object.keys(models).length));
return this.store.pipe(
select(allContextHelpSelector),
switchMap((models: ContextHelpModels) => {
return from(Object.values(models).map((contextHelp: ContextHelp) => this.translateService.get(contextHelp.translationKey).pipe(
map(translatedText => {
return translatedText !== contextHelp.translationKey ? 1 : 0;
}),
))).pipe(
mergeAll(),
reduce((acc, count) => acc + count, 0),
);
}),
);
}

/**
Expand All @@ -82,6 +96,8 @@ export class ContextHelpService {
*/
remove(id: string) {
this.store.dispatch(new ContextHelpRemoveAction(id));
// When a context help icon is removed, the visible tooltip count should be updated
this.tooltipCount$().subscribe();
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4817,6 +4817,10 @@
"person.orcid.registry.auth": "ORCID Authorizations",
"home.recent-submissions.head": "Recent Submissions",

// Context tooltips
// Uncommenting the translation for a tooltip will enable it and make it visible, so make sure
// to add a translation for each tooltip you want to enable

// "context.help.top-level-community-list": "add your context tip here",
//
// "context.help.recent-item-list": "add your context tip here",
Expand Down

0 comments on commit 3911dc5

Please sign in to comment.