Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* change parameter of content type and update selector * #23443 show correct content types and remove base types and add content type selector component and test cases * #23443 add search filter on dropdond add add test case * #23443 remove unnecessary import and fix typo * #23927 fixed github issues and typo * #23927 fixed github issues and typo
- Loading branch information
1 parent
ceafccb
commit 0ffabd8
Showing
11 changed files
with
180 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,6 @@ | |
height: 100%; | ||
} | ||
|
||
dot-base-type-selector { | ||
dot-content-type-selector { | ||
margin-right: $spacing-3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...rc/app/view/components/dot-content-type-selector/dot-content-type-selector.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<p-dropdown | ||
[options]="options$ | async" | ||
[style]="{ width: '155px' }" | ||
[filter]="true" | ||
[showClear]="true" | ||
(onChange)="change($event)" | ||
filterBy="label" | ||
> | ||
</p-dropdown> |
Empty file.
82 changes: 82 additions & 0 deletions
82
...app/view/components/dot-content-type-selector/dot-content-type-selector.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { of as observableOf } from 'rxjs'; | ||
|
||
import { DebugElement, Injectable } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
import { SelectItem } from 'primeng/api'; | ||
import { Dropdown, DropdownModule } from 'primeng/dropdown'; | ||
|
||
import { DotContentTypeService, DotMessageService } from '@dotcms/data-access'; | ||
import { MockDotMessageService } from '@dotcms/utils-testing'; | ||
|
||
import { DotContentTypeSelectorComponent } from './dot-content-type-selector.component'; | ||
|
||
@Injectable() | ||
class MockDotContentTypeService { | ||
getContentTypes = jasmine.createSpy('getContentTypes').and.returnValue( | ||
observableOf([ | ||
{ name: 'FORM', variable: 'Form' }, | ||
{ name: 'WIDGET', variable: 'Widget' } | ||
]) | ||
); | ||
} | ||
|
||
describe('DotContentTypeSelectorComponent', () => { | ||
let component: DotContentTypeSelectorComponent; | ||
let fixture: ComponentFixture<DotContentTypeSelectorComponent>; | ||
let de: DebugElement; | ||
const allContentTypesItem: SelectItem = { label: 'Any Content Type', value: '' }; | ||
const messageServiceMock = new MockDotMessageService({ | ||
'contenttypes.selector.any.content.type': 'Any Content Type' | ||
}); | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [DotContentTypeSelectorComponent], | ||
imports: [BrowserAnimationsModule, DropdownModule], | ||
providers: [ | ||
{ | ||
provide: DotMessageService, | ||
useValue: messageServiceMock | ||
}, | ||
{ | ||
provide: DotContentTypeService, | ||
useClass: MockDotContentTypeService | ||
} | ||
] | ||
}); | ||
|
||
fixture = TestBed.createComponent(DotContentTypeSelectorComponent); | ||
component = fixture.componentInstance; | ||
de = fixture.debugElement; | ||
}); | ||
|
||
it('should emit the selected content type', () => { | ||
const pDropDown: DebugElement = de.query(By.css('p-dropdown')); | ||
spyOn(component.selected, 'emit'); | ||
spyOn(component, 'change').and.callThrough(); | ||
pDropDown.triggerEventHandler('onChange', allContentTypesItem); | ||
|
||
expect(component.change).toHaveBeenCalledWith(allContentTypesItem); | ||
expect(component.selected.emit).toHaveBeenCalledWith(allContentTypesItem.value); | ||
}); | ||
|
||
it('should add All Content Types option as first position', () => { | ||
fixture.detectChanges(); | ||
|
||
component.options$.subscribe((options) => { | ||
expect(options[0]).toEqual(allContentTypesItem); | ||
}); | ||
}); | ||
|
||
it('should set attributes to dropdown', () => { | ||
fixture.detectChanges(); | ||
const pDropDown: Dropdown = de.query(By.css('p-dropdown')).componentInstance; | ||
expect(pDropDown.filter).toBeDefined(); | ||
expect(pDropDown.filterBy).toBeDefined(); | ||
expect(pDropDown.showClear).toBeDefined(); | ||
expect(pDropDown.style).toEqual({ width: '155px' }); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
.../src/app/view/components/dot-content-type-selector/dot-content-type-selector.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||
|
||
import { SelectItem } from 'primeng/api'; | ||
|
||
import { map, take } from 'rxjs/operators'; | ||
|
||
import { DotContentTypeService, DotMessageService } from '@dotcms/data-access'; | ||
import { DotCMSContentType } from '@dotcms/dotcms-models'; | ||
|
||
@Component({ | ||
selector: 'dot-content-type-selector', | ||
templateUrl: './dot-content-type-selector.component.html', | ||
styleUrls: ['./dot-content-type-selector.component.scss'] | ||
}) | ||
export class DotContentTypeSelectorComponent implements OnInit { | ||
@Input() value: SelectItem; | ||
@Output() selected = new EventEmitter<string>(); | ||
|
||
options$: Observable<SelectItem[]>; | ||
|
||
constructor( | ||
private dotContentTypeService: DotContentTypeService, | ||
private dotMessageService: DotMessageService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.options$ = this.dotContentTypeService.getContentTypes({ page: 999 }).pipe( | ||
take(1), | ||
map((contentTypes: DotCMSContentType[]) => this.setOptions(contentTypes)) | ||
); | ||
} | ||
|
||
change(item: SelectItem) { | ||
this.selected.emit(item.value); | ||
} | ||
|
||
setOptions(contentTypes: DotCMSContentType[]): SelectItem[] { | ||
return [ | ||
{ | ||
label: this.dotMessageService.get('contenttypes.selector.any.content.type'), | ||
value: '' | ||
}, | ||
...contentTypes.map((contentType: DotCMSContentType) => ({ | ||
label: contentType.name, | ||
value: contentType.variable | ||
})) | ||
]; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...-ui/src/app/view/components/dot-content-type-selector/dot-content-type-selector.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
import { DropdownModule } from 'primeng/dropdown'; | ||
|
||
import { DotContentTypeSelectorComponent } from './dot-content-type-selector.component'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, DropdownModule, FormsModule], | ||
declarations: [DotContentTypeSelectorComponent], | ||
exports: [DotContentTypeSelectorComponent] | ||
}) | ||
export class DotContentTypeSelectorModule {} |
1 change: 1 addition & 0 deletions
1
core-web/apps/dotcms-ui/src/app/view/components/dot-content-type-selector/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dot-content-type-selector.module'; |