Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofocus filter input #5030

Merged
merged 2 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions i18n/de/messages.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,15 @@
<target>Filter</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>Objekte nach Namen filtern</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="1baabee7b86d4d0935657f254c3b17b5fe4d1257" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/fr/messages.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1015,15 +1015,15 @@
<target>Filtrer</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>Filtrer les objets par nom</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="1baabee7b86d4d0935657f254c3b17b5fe4d1257" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/ja/messages.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,15 @@
<target>フィルター</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>名前による絞り込み</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/ko/messages.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@
<target>필터</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>이름으로 오브젝트 필터하기</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,14 @@
<source>Filter</source>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/zh-Hans-SG/messages.zh-Hans-SG.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@
<target>过滤</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>按名称过滤对象</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/zh-Hans/messages.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@
<target>过滤</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>按名称过滤对象</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/zh-Hant-HK/messages.zh-Hant-HK.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@
<target>過濾</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>按名字過濾對象</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/zh-Hant/messages.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@
<target>過濾</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>按名字過濾對象</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
4 changes: 2 additions & 2 deletions i18n/zh/messages.zh.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@
<target>过滤</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">28</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="0b5c5a43ccd2f696d6e0ad2b745bcc9041d6e380" datatype="html">
<source>Filter objects by name</source>
<target>按名称过滤对象</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/common/components/list/filter/template.html</context>
<context context-type="linenumber">32</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="5403a767248e304199592271bba3366d2ca3f903" datatype="html">
Expand Down
38 changes: 19 additions & 19 deletions src/app/frontend/common/components/list/filter/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';

import {Component, ElementRef, EventEmitter, OnInit, ViewChild} from '@angular/core';
import {Component, ElementRef, EventEmitter, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ReplaySubject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {Subject} from 'rxjs/Subject';

@Component({
selector: 'kd-card-list-filter',
templateUrl: './template.html',
styleUrls: ['style.scss'],
})
export class CardListFilterComponent implements OnInit {
@ViewChild('filterInput', {static: true}) private readonly filterInput_: ElementRef;
private hidden_ = true;
keyUpEvent = new Subject<string>();
export class CardListFilterComponent implements OnInit, OnDestroy {
query = '';
filterEvent: EventEmitter<boolean> = new EventEmitter<boolean>();
keyUpEvent = new Subject<string>();
filterEvent = new EventEmitter<boolean>();
openedChange = new ReplaySubject<boolean>();

private hidden_ = true;
private readonly debounceTime_ = 500;
private readonly unsubscribe_ = new Subject<void>();

ngOnInit(): void {
this.keyUpEvent
.debounceTime(500)
.debounceTime(this.debounceTime_)
.distinctUntilChanged()
.pipe(takeUntil(this.unsubscribe_))
.subscribe(this.onFilterTriggered_.bind(this));
}

Expand All @@ -49,18 +55,7 @@ export class CardListFilterComponent implements OnInit {
switchSearchVisibility(event: Event): void {
event.stopPropagation();
this.hidden_ = !this.hidden_;

if (!this.hidden_) {
this.focusInput();
}
}

focusInput(): void {
// Small timeout is required as input is not yet rendered when method is fired right after
// clicking on filter button.
setTimeout(() => {
this.filterInput_.nativeElement.focus();
}, 150);
this.openedChange.next(!this.hidden_);
}

clearInput(event: Event): void {
Expand All @@ -71,4 +66,9 @@ export class CardListFilterComponent implements OnInit {
this.filterEvent.emit(true);
}
}

ngOnDestroy(): void {
this.unsubscribe_.next();
this.unsubscribe_.complete();
}
}
5 changes: 3 additions & 2 deletions src/app/frontend/common/components/list/filter/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
<div class="kd-search-container"
fxFlex
fxLayoutAlign="flex-end">
<input #filterInput
*ngIf="isSearchVisible()"
<input *ngIf="isSearchVisible()"
(keyup)="keyUpEvent.next($event.target.value)"
(click)="$event.stopPropagation()"
kdAutofocus
[opened]="openedChange"
name="search"
i18n-placeholder
placeholder="Filter"
Expand Down
7 changes: 4 additions & 3 deletions src/app/frontend/common/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import {NgModule} from '@angular/core';

import {SharedModule} from '../../shared.module';
import {DirectivesModule} from '../directives/module';

import {ActionbarComponent} from './actionbar/component';
import {ActionbarDetailActionsComponent} from './actionbar/detailactions/component';
Expand All @@ -29,9 +30,9 @@ import {DefaultActionbar} from './actionbars/default/component';
import {LogsDefaultActionbar} from './actionbars/logsdefault/component';
import {LogsExecDefaultActionbar} from './actionbars/logsexecdefault/component';
import {LogsScaleDefaultActionbar} from './actionbars/logsscaledefault/component';
import {PinDefaultActionbar} from './actionbars/pindefault/component';
import {ScaleDefaultActionbar} from './actionbars/scaledefault/component';
import {TriggerDefaultActionbar} from './actionbars/triggerdefault/component';
import {PinDefaultActionbar} from './actionbars/pindefault/component';
import {BreadcrumbsComponent} from './breadcrumbs/component';
import {CardComponent} from './card/component';
import {ChipDialog} from './chips/chipdialog/dialog';
Expand All @@ -47,7 +48,6 @@ import {GraphComponent} from './graph/component';
import {GraphCardComponent} from './graphcard/component';
import {GraphMetricsComponent} from './graphmetrics/component';
import {HiddenPropertyComponent} from './hiddenproperty/component';
import {HorizontalPodAutoscalerListComponent} from './resourcelist/horizontalpodautoscaler/component';
import {ResourceLimitListComponent} from './limits/component';
import {ColumnComponent} from './list/column/component';
import {MenuComponent} from './list/column/menu/component';
Expand All @@ -72,6 +72,7 @@ import {CronJobListComponent} from './resourcelist/cronjob/component';
import {DaemonSetListComponent} from './resourcelist/daemonset/component';
import {DeploymentListComponent} from './resourcelist/deployment/component';
import {EventListComponent} from './resourcelist/event/component';
import {HorizontalPodAutoscalerListComponent} from './resourcelist/horizontalpodautoscaler/component';
import {IngressListComponent} from './resourcelist/ingress/component';
import {JobListComponent} from './resourcelist/job/component';
import {NamespaceListComponent} from './resourcelist/namespace/component';
Expand Down Expand Up @@ -191,7 +192,7 @@ const components = [
];

@NgModule({
imports: [SharedModule],
imports: [SharedModule, DirectivesModule],
declarations: [...components],
exports: [...components],
entryComponents: [ChipDialog, RowDetailComponent, MenuComponent, NamespaceChangeDialog],
Expand Down
42 changes: 42 additions & 0 deletions src/app/frontend/common/directives/autofocus/directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {AfterViewInit, Directive, ElementRef, Input, OnDestroy} from '@angular/core';
import {Observable, Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';

@Directive({
selector: '[kdAutofocus]',
})
export class AutofocusDirective implements AfterViewInit, OnDestroy {
@Input() opened: Observable<boolean>;

private readonly _unsubscribe = new Subject<void>();

constructor(private readonly _el: ElementRef) {}

ngAfterViewInit(): void {
if (!this.opened) {
throw new Error('[opened] event binding is undefined');
}

this.opened
.pipe(takeUntil(this._unsubscribe))
.subscribe(opened => (opened ? setTimeout(() => this._el.nativeElement.focus()) : null));
}

ngOnDestroy(): void {
this._unsubscribe.next();
this._unsubscribe.complete();
}
}
27 changes: 27 additions & 0 deletions src/app/frontend/common/directives/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {NgModule} from '@angular/core';

import {SharedModule} from '../../shared.module';
import {AutofocusDirective} from './autofocus/directive';

const directives = [AutofocusDirective];

@NgModule({
imports: [SharedModule],
declarations: [...directives],
exports: [...directives],
})
export class DirectivesModule {}