-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(edit-content) Add Tags Field #26526
* dev (dot select item directive): create directive to add items to autocomplete on enter * dev (add styles classed dialog): add the directive on template builder autocomplete * fix (autocomplete styles): fix spacings of util icons * dev (edit content tag component): create component for tag * dev (edit content): add tag component to form * fix (edit content form): save contentlet was not working for tags * fix (edit content): fix after merge conflcits * dev (autocomplete styles): fix positioning of icons and buttons * dev (autocomplete styles): fix margin * clean up (functon utils): reduce cyclomatic complexity * clean up: (autocomplete styles)
- Loading branch information
1 parent
341b358
commit 97a64fb
Showing
19 changed files
with
334 additions
and
60 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
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
11 changes: 11 additions & 0 deletions
11
...ntent/src/lib/fields/dot-edit-content-tag-field/dot-edit-content-tag-field.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,11 @@ | ||
<!-- TODO: We need to review the tags endpoint and use it here. --> | ||
<p-autoComplete | ||
[formControlName]="field.variable" | ||
[id]="field.variable" | ||
[inputId]="field.variable" | ||
[attr.data-testId]="field.variable" | ||
[suggestions]="[]" | ||
[multiple]="true" | ||
[unique]="true" | ||
[showClear]="true" | ||
dotSelectItem></p-autoComplete> |
Empty file.
80 changes: 80 additions & 0 deletions
80
...nt/src/lib/fields/dot-edit-content-tag-field/dot-edit-content-tag-field.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,80 @@ | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { Spectator, byTestId, createComponentFactory } from '@ngneat/spectator'; | ||
|
||
import { ControlContainer, FormGroupDirective } from '@angular/forms'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { AutoComplete } from 'primeng/autocomplete'; | ||
|
||
import { DotEditContentTagFieldComponent } from './dot-edit-content-tag-field.component'; | ||
|
||
import { createFormGroupDirectiveMock, TAG_FIELD_MOCK } from '../../utils/mocks'; | ||
|
||
describe('DotEditContentTagFieldComponent', () => { | ||
let spectator: Spectator<DotEditContentTagFieldComponent>; | ||
let autoCompleteElement: Element; | ||
let autoCompleteComponent: AutoComplete; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: DotEditContentTagFieldComponent, | ||
componentViewProviders: [ | ||
{ | ||
provide: ControlContainer, | ||
useValue: createFormGroupDirectiveMock() | ||
} | ||
], | ||
providers: [FormGroupDirective] | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent({ | ||
props: { | ||
field: TAG_FIELD_MOCK | ||
} | ||
}); | ||
|
||
autoCompleteElement = spectator.query(byTestId(TAG_FIELD_MOCK.variable)); | ||
|
||
autoCompleteComponent = spectator.debugElement.query( | ||
By.css(`[data-testId="${TAG_FIELD_MOCK.variable}"]`) | ||
).componentInstance; | ||
}); | ||
|
||
test.each([ | ||
{ | ||
variable: TAG_FIELD_MOCK.variable, | ||
attribute: 'id' | ||
}, | ||
{ | ||
variable: TAG_FIELD_MOCK.variable, | ||
attribute: 'ng-reflect-name' | ||
} | ||
])('should have the $variable as $attribute', ({ variable, attribute }) => { | ||
expect(autoCompleteElement.getAttribute(attribute)).toBe(variable); | ||
}); | ||
|
||
it('should has multiple as true', () => { | ||
expect(autoCompleteComponent.multiple).toBe(true); | ||
}); | ||
|
||
it('should has unique as true', () => { | ||
expect(autoCompleteComponent.unique).toBe(true); | ||
}); | ||
|
||
it('should has showClear as true', () => { | ||
expect(autoCompleteComponent.showClear).toBe(true); | ||
}); | ||
|
||
it('should trigger selectItem on enter pressed', () => { | ||
const selectItemMock = jest.spyOn(autoCompleteComponent, 'selectItem'); | ||
|
||
spectator.triggerEventHandler('p-autocomplete', 'onKeyUp', { | ||
key: 'Enter', | ||
target: { | ||
value: 'test' | ||
} | ||
}); | ||
|
||
expect(selectItemMock).toBeCalledWith('test'); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
...content/src/lib/fields/dot-edit-content-tag-field/dot-edit-content-tag-field.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,26 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { ChangeDetectionStrategy, Component, Input, inject } from '@angular/core'; | ||
import { ControlContainer, ReactiveFormsModule } from '@angular/forms'; | ||
|
||
import { AutoCompleteModule } from 'primeng/autocomplete'; | ||
|
||
import { DotCMSContentTypeField } from '@dotcms/dotcms-models'; | ||
import { DotSelectItemDirective } from '@dotcms/ui'; | ||
|
||
@Component({ | ||
selector: 'dot-edit-content-tag-field', | ||
standalone: true, | ||
imports: [CommonModule, AutoCompleteModule, DotSelectItemDirective, ReactiveFormsModule], | ||
templateUrl: './dot-edit-content-tag-field.component.html', | ||
styleUrls: ['./dot-edit-content-tag-field.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
viewProviders: [ | ||
{ | ||
provide: ControlContainer, | ||
useFactory: () => inject(ControlContainer, { skipSelf: true }) | ||
} | ||
] | ||
}) | ||
export class DotEditContentTagFieldComponent { | ||
@Input() field: DotCMSContentTypeField; | ||
} |
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
Oops, something went wrong.