Skip to content

Commit 32df659

Browse files
authored
Merge pull request #60 from UiPath/fix/ui_suggest_toggle_disable
fix(suggest): toggle disable state on searchable
2 parents e7381ce + e7c22c5 commit 32df659

File tree

6 files changed

+142
-76
lines changed

6 files changed

+142
-76
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v0.10.12 (2019-10-24)
2+
* **suggest** fix `loading` state on toggle disabled
3+
14
# v0.10.11 (2019-10-24)
25
* **testing** define `keyCode` and bind correct `code` in generator
36

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-components",
3-
"version": "0.10.11",
3+
"version": "0.10.12",
44
"author": {
55
"name": "UiPath Inc",
66
"url": "https://uipath.com"

projects/angular/components/ui-suggest/src/ui-suggest.component.spec.ts

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
import {
2-
Component,
3-
ViewChild,
2+
Component,
3+
ViewChild,
44
} from '@angular/core';
55
import {
6-
async,
7-
ComponentFixture,
8-
discardPeriodicTasks,
9-
fakeAsync,
10-
TestBed,
11-
tick,
6+
async,
7+
ComponentFixture,
8+
discardPeriodicTasks,
9+
fakeAsync,
10+
TestBed,
11+
tick,
1212
} from '@angular/core/testing';
1313
import {
14-
FormBuilder,
15-
FormGroup,
16-
ReactiveFormsModule,
14+
FormBuilder,
15+
FormGroup,
16+
ReactiveFormsModule,
1717
} from '@angular/forms';
1818
import { MatInputModule } from '@angular/material/input';
1919
import { By } from '@angular/platform-browser';
2020
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
2121
import {
22-
EventGenerator,
23-
Key,
22+
EventGenerator,
23+
Key,
2424
} from '@uipath/angular/testing';
2525

2626
import * as faker from 'faker';
2727
import { VirtualScrollItemStatus } from 'projects/angular/directives/ui-virtual-scroll-range-loader/src/public_api';
2828
import {
29-
Observable,
30-
of,
29+
Observable,
30+
of,
3131
} from 'rxjs';
3232
import {
33-
delay,
34-
finalize,
35-
map,
36-
skip,
37-
take,
33+
delay,
34+
finalize,
35+
map,
36+
skip,
37+
take,
3838
} from 'rxjs/operators';
3939

4040
import {
41-
ISuggestValue,
42-
ISuggestValues,
41+
ISuggestValue,
42+
ISuggestValues,
4343
} from './models';
4444
import {
45-
generateSuggestionItem,
46-
generateSuggetionItemList,
45+
generateSuggestionItem,
46+
generateSuggetionItemList,
4747
} from './test';
4848
import { UiSuggestComponent } from './ui-suggest.component';
4949
import { UiSuggestModule } from './ui-suggest.module';
@@ -527,6 +527,57 @@ const sharedSpecifications = (
527527
});
528528
});
529529

530+
describe('Scenario: toggle disabled state', () => {
531+
it('should toggle loading state if it is searchable with items', async () => {
532+
const items = generateSuggetionItemList();
533+
component.items = items;
534+
component.disabled = true;
535+
component.searchable = true;
536+
537+
fixture.detectChanges();
538+
539+
expect(uiSuggest.disabled).toBeTruthy();
540+
expect(uiSuggest.loading$.value).toBeTruthy();
541+
542+
component.disabled = false;
543+
fixture.detectChanges();
544+
545+
expect(uiSuggest.disabled).toBeFalsy();
546+
547+
const display = fixture.debugElement.query(By.css('.display'));
548+
display.nativeElement.dispatchEvent(EventGenerator.click);
549+
550+
expect(uiSuggest.loading$.value).toBeFalsy();
551+
});
552+
553+
it('should not be in loading state if it has a searchSourceFactory', async () => {
554+
const items = generateSuggetionItemList();
555+
component.disabled = true;
556+
uiSuggest.searchSourceFactory = (term) => {
557+
return of([...items]).pipe(
558+
map(itemList => ({
559+
data: itemList.filter(item => item.text.includes(term as string)),
560+
total: itemList.length,
561+
}) as ISuggestValues<any>),
562+
);
563+
};
564+
565+
fixture.detectChanges();
566+
expect(uiSuggest.disabled).toBeTruthy();
567+
568+
component.disabled = false;
569+
fixture.detectChanges();
570+
expect(uiSuggest.disabled).toBeFalsy();
571+
572+
const display = fixture.debugElement.query(By.css('.display'));
573+
display.nativeElement.dispatchEvent(EventGenerator.click);
574+
await fixture.whenStable();
575+
576+
expect(uiSuggest.loading$.value).toBeFalsy();
577+
});
578+
});
579+
580+
530581
it('should not open on first click and close on the second', () => {
531582
fixture.detectChanges();
532583

projects/angular/components/ui-suggest/src/ui-suggest.component.ts

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ import { LiveAnnouncer } from '@angular/cdk/a11y';
22
import { ListRange } from '@angular/cdk/collections';
33
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';
44
import {
5-
AfterViewInit,
6-
ChangeDetectionStrategy,
7-
ChangeDetectorRef,
8-
Component,
9-
ContentChild,
10-
ElementRef,
11-
EventEmitter,
12-
HostBinding,
13-
Input,
14-
isDevMode,
15-
OnDestroy,
16-
OnInit,
17-
Optional,
18-
Output,
19-
Self,
20-
TemplateRef,
21-
ViewChild,
22-
ViewEncapsulation,
5+
AfterViewInit,
6+
ChangeDetectionStrategy,
7+
ChangeDetectorRef,
8+
Component,
9+
ContentChild,
10+
ElementRef,
11+
EventEmitter,
12+
HostBinding,
13+
Input,
14+
isDevMode,
15+
OnDestroy,
16+
OnInit,
17+
Optional,
18+
Output,
19+
Self,
20+
TemplateRef,
21+
ViewChild,
22+
ViewEncapsulation,
2323
} from '@angular/core';
2424
import {
25-
FormGroupDirective,
26-
NgControl,
27-
NgForm,
25+
FormGroupDirective,
26+
NgControl,
27+
NgForm,
2828
} from '@angular/forms';
2929
import { ErrorStateMatcher } from '@angular/material/core';
3030
import { MatFormFieldControl } from '@angular/material/form-field';
@@ -33,44 +33,44 @@ import { VirtualScrollItemStatus } from '@uipath/angular/directives/ui-virtual-s
3333
import cloneDeep from 'lodash-es/cloneDeep';
3434
import isEqual from 'lodash-es/isEqual';
3535
import {
36-
BehaviorSubject,
37-
combineLatest,
38-
merge,
39-
Observable,
40-
Subject,
41-
Subscription,
36+
BehaviorSubject,
37+
combineLatest,
38+
merge,
39+
Observable,
40+
Subject,
41+
Subscription,
4242
} from 'rxjs';
4343
import {
44-
debounceTime,
45-
delay,
46-
distinctUntilChanged,
47-
filter,
48-
finalize,
49-
map,
50-
retry,
51-
startWith,
52-
takeUntil,
53-
tap,
44+
debounceTime,
45+
delay,
46+
distinctUntilChanged,
47+
filter,
48+
finalize,
49+
map,
50+
retry,
51+
startWith,
52+
takeUntil,
53+
tap,
5454
} from 'rxjs/operators';
5555

5656
import {
57-
ISuggestValue,
58-
ISuggestValues,
59-
SuggestDirection,
57+
ISuggestValue,
58+
ISuggestValues,
59+
SuggestDirection,
6060
} from './models';
6161
import { UI_SUGGEST_ANIMATIONS } from './ui-suggest.animations';
6262
import { UiSuggestIntl } from './ui-suggest.intl';
6363
import { UiSuggestMatFormField } from './ui-suggest.mat-form-field';
6464
import {
65-
caseInsensitiveCompare,
66-
generateLoadingInitialCollection,
67-
inMemorySearch,
68-
mapInitialItems,
69-
resetUnloadedState,
70-
setLoadedState,
71-
setPendingState,
72-
sortByPriorityAndDirection,
73-
toSuggestValue,
65+
caseInsensitiveCompare,
66+
generateLoadingInitialCollection,
67+
inMemorySearch,
68+
mapInitialItems,
69+
resetUnloadedState,
70+
setLoadedState,
71+
setPendingState,
72+
sortByPriorityAndDirection,
73+
toSuggestValue,
7474
} from './utils';
7575

7676
/**
@@ -113,6 +113,8 @@ export class UiSuggestComponent extends UiSuggestMatFormField
113113
return this._disabled;
114114
}
115115
public set disabled(value) {
116+
if (this._disabled === !!value) { return; }
117+
116118
this._disabled = !!value;
117119
if (
118120
value &&
@@ -123,6 +125,16 @@ export class UiSuggestComponent extends UiSuggestMatFormField
123125

124126
this._cd.markForCheck();
125127
this.stateChanges.next();
128+
129+
if (value || !this.searchable) {
130+
return;
131+
}
132+
133+
if (this.searchSourceFactory) {
134+
this.fetch();
135+
} else {
136+
this.loading$.next(false);
137+
}
126138
}
127139

128140
/**

projects/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uipath/angular",
3-
"version": "0.10.11",
3+
"version": "0.10.12",
44
"license": "MIT",
55
"author": {
66
"name": "UiPath Inc",

0 commit comments

Comments
 (0)