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

Fix #26442: Edit Contentlet Add Text Area and enhance Text Field #26446

Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0aafb87
dev (edit content lib): add text area, default value and inputmode/ty…
zJaaal Oct 16, 2023
f27895d
dev (dot edit content field): add comments to new code
zJaaal Oct 16, 2023
0d99c58
dev (dot edit content form): add comment
zJaaal Oct 16, 2023
839fee7
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 16, 2023
c651085
dev (dot edit content field): change steps from any to 0.1 in decimals
zJaaal Oct 17, 2023
0735f3e
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 17, 2023
a5f47b2
dev (dot edit content lib): create field wrappers for text area and t…
zJaaal Oct 17, 2023
ed70cbc
dev (dot edit content): add and clean test cases
zJaaal Oct 17, 2023
10ae5dd
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 17, 2023
984cff9
dev (edit content mock): remove duplicated code
zJaaal Oct 17, 2023
6743ae8
dev (edit content): address feedback
zJaaal Oct 18, 2023
b425de0
fix (edit-content-form): styles were off
zJaaal Oct 18, 2023
3999d88
fix (edit content text area): min height was too high
zJaaal Oct 18, 2023
5fbc7ce
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 18, 2023
6459fa9
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 19, 2023
261a696
dev (edit content field): address feedback
zJaaal Oct 19, 2023
fb9988f
dev (mocks): separate fields
zJaaal Oct 19, 2023
82797b4
dev (edit content field): enhance testing
zJaaal Oct 19, 2023
5eda501
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 19, 2023
a0daa16
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 19, 2023
2034bc5
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 20, 2023
d4da395
dev (edit content): general clean up
zJaaal Oct 20, 2023
4a16f5c
dev (edit content form): delete todo
zJaaal Oct 20, 2023
d120cd1
Merge branch 'master' into 26442-edit-content-render-textfield-and-te…
zJaaal Oct 20, 2023
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<ng-container [ngSwitch]="field.fieldType">
<div class="field" *ngSwitchCase="'Text'">
<div class="field">
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
<label
[attr.data-testId]="'label-' + field.variable"
[for]="field.variable"
[checkIsRequiredControl]="field.variable"
dotFieldRequired
>{{ field.name }}</label
>
<input
[id]="field.variable"
[formControlName]="field.variable"
[attr.data-testId]="'input-' + field.variable"
type="text"
pInputText />
<dot-edit-content-text-field
*ngSwitchCase="fieldTypes.TEXT"
[field]="field"
[attr.data-testId]="'field-' + field.variable"></dot-edit-content-text-field>
<dot-edit-content-text-area
*ngSwitchCase="fieldTypes.TEXTAREA"
[field]="field"
[attr.data-testId]="'field-' + field.variable"></dot-edit-content-text-area>
<small *ngIf="field.hint" [attr.data-testId]="'hint-' + field.variable">{{
field.hint
}}</small>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:host {
display: block;
height: fit-content;
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,32 @@
import { describe } from '@jest/globals';
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
import { Spectator, byTestId, createComponentFactory } from '@ngneat/spectator';

import { CommonModule } from '@angular/common';
import {
ControlContainer,
FormControl,
FormGroup,
FormGroupDirective,
ReactiveFormsModule
} from '@angular/forms';

import { InputTextModule } from 'primeng/inputtext';

import { DotCMSContentTypeField } from '@dotcms/dotcms-models';
import { DotFieldRequiredDirective } from '@dotcms/ui';
import { ControlContainer, FormGroupDirective } from '@angular/forms';
import { By } from '@angular/platform-browser';

import { DotEditContentFieldComponent } from './dot-edit-content-field.component';
import { FIELD_TYPES, FIELD_TYPES_COMPONENTS } from './utils';

export const FIELD_MOCK: DotCMSContentTypeField = {
clazz: 'com.dotcms.contenttype.model.field.ImmutableTextField',
contentTypeId: 'd46d6404125ac27e6ab68fad09266241',
dataType: 'TEXT',
fieldType: 'Text',
fieldTypeLabel: 'Text',
fieldVariables: [],
fixed: false,
iDate: 1696896882000,
id: 'c3b928bc2b59fc22c67022de4dd4b5c4',
indexed: false,
listed: false,
hint: 'A helper text',
modDate: 1696896882000,
name: 'testVariable',
readOnly: false,
required: false,
searchable: false,
sortOrder: 2,
unique: false,
variable: 'testVariable'
};
import { FIELDS_MOCK, createFormGroupDirectiveMock } from '../../utils/mocks';

const FORM_GROUP_MOCK = new FormGroup({
testVariable: new FormControl('')
describe('FIELD_TYPES and FIELDS_MOCK', () => {
it('should be in sync', () => {
expect(
Object.values(FIELD_TYPES).every((fieldType) =>
FIELDS_MOCK.find((f) => f.fieldType === fieldType)
)
).toBeTruthy();
});
});
const FORM_GROUP_DIRECTIVE_MOCK: FormGroupDirective = new FormGroupDirective([], []);
FORM_GROUP_DIRECTIVE_MOCK.form = FORM_GROUP_MOCK;

describe('DotFieldComponent', () => {
describe.each([...FIELDS_MOCK])('DotFieldComponent', (fieldMock) => {
let spectator: Spectator<DotEditContentFieldComponent>;
const createComponent = createComponentFactory({
component: DotEditContentFieldComponent,
imports: [
DotEditContentFieldComponent,
CommonModule,
ReactiveFormsModule,
InputTextModule,
DotFieldRequiredDirective
],
componentViewProviders: [
{
provide: ControlContainer,
useValue: FORM_GROUP_DIRECTIVE_MOCK
useValue: createFormGroupDirectiveMock()
}
],
providers: [FormGroupDirective]
Expand All @@ -68,26 +35,31 @@ describe('DotFieldComponent', () => {
beforeEach(async () => {
spectator = createComponent({
props: {
field: FIELD_MOCK
field: fieldMock
}
});
});

it('should render the label', () => {
spectator.detectChanges();
const label = spectator.query(byTestId(`label-${FIELD_MOCK.variable}`));
expect(label?.textContent).toContain(FIELD_MOCK.name);
const label = spectator.query(byTestId(`label-${fieldMock.variable}`));
expect(label?.textContent).toContain(fieldMock.name);
});

it('should render the hint', () => {
spectator.detectChanges();
const hint = spectator.query(byTestId(`hint-${FIELD_MOCK.variable}`));
expect(hint?.textContent).toContain(FIELD_MOCK.hint);
const hint = spectator.query(byTestId(`hint-${fieldMock.variable}`));
expect(hint?.textContent).toContain(fieldMock.hint);
});

it('should render the input', () => {
it('should render the correct field type', () => {
spectator.detectChanges();
const input = spectator.query(byTestId(`input-${FIELD_MOCK.variable}`));
expect(input).toBeDefined();
const field = spectator.debugElement.query(
By.css(`[data-testId="field-${fieldMock.variable}"]`)
);

expect(
field.componentInstance instanceof FIELD_TYPES_COMPONENTS[fieldMock.fieldType]
).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { CommonModule } from '@angular/common';
import { NgIf, NgSwitch, NgSwitchCase } from '@angular/common';
import { ChangeDetectionStrategy, Component, Input, inject } from '@angular/core';
import { ControlContainer, ReactiveFormsModule } from '@angular/forms';

import { InputTextModule } from 'primeng/inputtext';

import { DotCMSContentTypeField } from '@dotcms/dotcms-models';
import { DotFieldRequiredDirective } from '@dotcms/ui';

import { FIELD_TYPES } from './utils';

import { DotEditContentFieldsModule } from '../../fields/dot-edit-content-fields.module';

@Component({
selector: 'dot-edit-content-field',
standalone: true,
imports: [CommonModule, ReactiveFormsModule, InputTextModule, DotFieldRequiredDirective],
imports: [
NgSwitch,
NgSwitchCase,
NgIf,
ReactiveFormsModule,
DotEditContentFieldsModule,
DotFieldRequiredDirective
],
templateUrl: './dot-edit-content-field.component.html',
styleUrls: ['./dot-edit-content-field.component.scss'],
viewProviders: [
Expand All @@ -23,4 +32,5 @@ import { DotFieldRequiredDirective } from '@dotcms/ui';
})
export class DotEditContentFieldComponent {
@Input() field!: DotCMSContentTypeField;
readonly fieldTypes = FIELD_TYPES;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Type } from '@angular/core';

import { DotEditContentTextAreaComponent } from '../../fields/dot-edit-content-text-area/dot-edit-content-text-area.component';
import { DotEditContentTextFieldComponent } from '../../fields/dot-edit-content-text-field/dot-edit-content-text-field.component';

export enum FIELD_TYPES {
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
TEXT = 'Text',
TEXTAREA = 'Textarea'
}

// This holds the mapping between the field type and the component that should be used to render it.
export const FIELD_TYPES_COMPONENTS: Record<FIELD_TYPES, Type<unknown>> = {
// We had to use unknown because components have different types.
[FIELD_TYPES.TEXT]: DotEditContentTextFieldComponent,
[FIELD_TYPES.TEXTAREA]: DotEditContentTextAreaComponent
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
grid-template-columns: 1fr 16rem;
gap: $spacing-4;
padding: $spacing-4;
padding-bottom: 0;
height: 100%;
zJaaal marked this conversation as resolved.
Show resolved Hide resolved

form {
overflow: auto;
padding-right: $spacing-4;
}
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
}

.row {
Expand All @@ -14,7 +21,8 @@
gap: $spacing-2;

.column {
display: grid;
min-height: $spacing-7;
display: flex;
flex-direction: column;
gap: $spacing-3;
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading