Skip to content

Commit 9797840

Browse files
committed
Fixes AB#552: Dropdown button title
Adds localization to dropdowns and bookmarks menu
1 parent 07a4b1d commit 9797840

11 files changed

Lines changed: 87 additions & 8 deletions

File tree

src/@batch-flask/ui/activity/activity-monitor-footer/activity-monitor-footer.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ComponentFixture, TestBed, fakeAsync, inject, tick } from "@angular/cor
22
import { By } from "@angular/platform-browser";
33
import { Router } from "@angular/router";
44
import { MaterialModule } from "@batch-flask/core";
5+
import { I18nTestingModule } from "@batch-flask/core/testing";
56
import {
67
Activity,
78
ActivityModule,
@@ -22,7 +23,7 @@ describe("ActivityMonitorFooterComponent", () => {
2223
};
2324

2425
TestBed.configureTestingModule({
25-
imports: [MaterialModule, ActivityModule],
26+
imports: [MaterialModule, ActivityModule, I18nTestingModule],
2627
declarations: [
2728
],
2829
providers: [
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, Type } from "@angular/core";
2+
import { ComponentFixture, TestBed } from "@angular/core/testing";
3+
import { FormsModule } from "@angular/forms";
4+
import { By } from "@angular/platform-browser";
5+
import { I18nTestingModule } from "@batch-flask/core/testing";
6+
import { ButtonsModule } from "../buttons";
7+
import { DropdownComponent } from "./dropdown.component";
8+
9+
describe("DropdownComponent", () => {
10+
let fixture: ComponentFixture<Component>;
11+
12+
function createComponent(comp: Type<Component>) {
13+
TestBed.configureTestingModule({
14+
imports: [FormsModule, ButtonsModule, I18nTestingModule],
15+
declarations: [DropdownComponent, comp],
16+
});
17+
fixture = TestBed.createComponent(comp);
18+
fixture.detectChanges();
19+
}
20+
21+
function $(selector) {
22+
return fixture.debugElement.query(By.css("bl-dropdown"))
23+
.nativeElement.querySelector(selector);
24+
}
25+
26+
it("uses a default title", () => {
27+
createComponent(TestComponent);
28+
29+
expect($(".dropdown-btn-container").getAttribute("title"))
30+
.toEqual("dropdown.button-title");
31+
});
32+
it("uses a host button title", () => {
33+
createComponent(TestComponentWithButton);
34+
35+
expect($(".dropdown-btn-container").getAttribute("title"))
36+
.toEqual("Host title");
37+
});
38+
});
39+
40+
@Component({ template: `<bl-dropdown [title]="title"></bl-dropdown>` })
41+
class TestComponent { }
42+
43+
@Component({
44+
template: `<bl-dropdown [title]="title">
45+
<div bl-dropdown-btn button-title="Host title">Button</div>
46+
</bl-dropdown>`
47+
})
48+
class TestComponentWithButton { }

src/@batch-flask/ui/dropdown/dropdown.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
2-
ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, HostListener, Input, Output,
2+
ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, Input, Output,
33
} from "@angular/core";
4+
import { I18nService } from "@batch-flask/core";
45

56
import "./dropdown.scss";
67

@@ -18,7 +19,11 @@ export class DropdownComponent {
1819
public forcedOpen = false;
1920
public showDropdown = false;
2021

21-
constructor(private changeDetector: ChangeDetectorRef) { }
22+
constructor(
23+
private changeDetector: ChangeDetectorRef,
24+
private elementRef: ElementRef,
25+
private i18n: I18nService,
26+
) { }
2227

2328
public mouseEnter() {
2429
this.showDropdown = true;
@@ -51,6 +56,12 @@ export class DropdownComponent {
5156
}
5257
}
5358

59+
public dropdownButtonTitle() {
60+
const hostTitle = this.elementRef.nativeElement
61+
.querySelector("[bl-dropdown-btn")?.getAttribute("button-title");
62+
return hostTitle || this.i18n.t("dropdown.button-title");
63+
}
64+
5465
public close() {
5566
this.showDropdown = false;
5667
this.changeDetector.markForCheck();

src/@batch-flask/ui/dropdown/dropdown.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<div class="dropdown" (mouseenter)="mouseEnter()" (mouseleave)="mouseLeave()">
2-
<bl-clickable class="dropdown-btn-container" [class.active]="showDropdown" (do)="toggleForceOpen($event)" (dblclick)="dblClick.emit($event)">
2+
<bl-clickable
3+
class="dropdown-btn-container"
4+
[class.active]="showDropdown"
5+
(do)="toggleForceOpen($event)"
6+
(dblclick)="dblClick.emit($event)"
7+
[title]="dropdownButtonTitle()"
8+
>
39
<ng-content select="[bl-dropdown-btn]"></ng-content>
410
</bl-clickable>
511
<div class="dropdown-content" *ngIf="showDropdown" [class.above]="footer" [class.below]="!footer" [attr.align]="align">
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dropdown:
2+
button-title: Dropdown button

src/@batch-flask/ui/dropdown/dropdown.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NgModule } from "@angular/core";
33
import { FormsModule } from "@angular/forms";
44
import { MaterialModule } from "@batch-flask/core";
55
import { ButtonsModule } from "@batch-flask/ui/buttons";
6+
import { I18nUIModule } from "@batch-flask/ui/i18n";
67
import { ScrollableModule } from "../scrollable";
78
import { DropdownComponent } from "./dropdown.component";
89

@@ -19,6 +20,7 @@ import { DropdownComponent } from "./dropdown.component";
1920
MaterialModule,
2021
ScrollableModule,
2122
ButtonsModule,
23+
I18nUIModule
2224
],
2325
})
2426
export class DropdownModule {

src/@batch-flask/ui/sidebar/sidebar-bookmarks/sidebar-bookmarks.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<bl-dropdown [footer]="false" align="right">
2-
<div bl-dropdown-btn attr.aria-label="{{references.length}}-forms in progress">
2+
<div bl-dropdown-btn
3+
[attr.button-title]="'sidebar-bookmarks.dropdown-button-title' | i18n">
34
<i class="fa fa-wpforms"></i>
45
<span class="count" *ngIf="references.length > 0">{{references.length}}</span>
56
</div>
@@ -15,7 +16,7 @@
1516
</div>
1617

1718
<div *ngIf="references.length === 0" class="dropdown-item no-bookmarks">
18-
<div> No forms in progress</div>
19+
<div>{{'sidebar-bookmarks.no-references' | i18n }}</div>
1920
</div>
2021
</div>
2122
</bl-dropdown>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sidebar-bookmarks:
2+
dropdown-button-title: Toggle bookmarks menu
3+
no-references: No bookmark references

src/@batch-flask/ui/sidebar/sidebar.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NgModule } from "@angular/core";
33
import { FormsModule } from "@angular/forms";
44
import { MaterialModule } from "@batch-flask/core";
55
import { DropdownModule } from "@batch-flask/ui/dropdown";
6+
import { I18nUIModule } from "@batch-flask/ui/i18n";
67
import { SidebarBookmarksComponent } from "./sidebar-bookmarks";
78
import { SidebarContentComponent } from "./sidebar-content";
89
import { SidebarManager } from "./sidebar-manager";
@@ -26,6 +27,7 @@ const privateComponents = [];
2627
FormsModule,
2728
DropdownModule,
2829
MaterialModule,
30+
I18nUIModule
2931
],
3032
providers: [
3133
SidebarManager, // This needs to be here otherwise entry components in lazy loaded doesn't work

src/app/components/layout/pinned-entity-dropdown/pinned-dropdown.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
33
import { By } from "@angular/platform-browser";
44
import { RouterTestingModule } from "@angular/router/testing";
55
import { NavigableRecord, PinnableEntity, PinnedEntityType } from "@batch-flask/core";
6+
import { I18nTestingModule } from "@batch-flask/core/testing";
67
import { ContextMenuService } from "@batch-flask/ui";
78
import { DropdownModule } from "@batch-flask/ui/dropdown";
89
import { BatchAccountService, PinnedEntityService } from "app/services";
@@ -54,7 +55,7 @@ describe("PinnedDropDownComponent", () => {
5455
};
5556

5657
TestBed.configureTestingModule({
57-
imports: [DropdownModule, RouterTestingModule],
58+
imports: [DropdownModule, RouterTestingModule, I18nTestingModule],
5859
declarations: [PinnedDropDownComponent, TestComponent],
5960
providers: [
6061
{ provide: BatchAccountService, useValue: accountServiceSpy },

0 commit comments

Comments
 (0)