Skip to content

Commit

Permalink
chore(edit-content): sync with master and resolve conflicts #28645
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Jun 6, 2024
2 parents 17e473d + 0ae0052 commit 2552dfc
Show file tree
Hide file tree
Showing 49 changed files with 983 additions and 744 deletions.
2 changes: 1 addition & 1 deletion core-web/libs/edit-content/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"outputs": ["{options.outputFile}"]
}
},
"tags": []
"tags": ["type:feature", "scope:dotcms-ui", "portlet:edit-content"]
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<label
[attr.data-testId]="'label-' + field.variable"
[for]="field.variable"
[checkIsRequiredControl]="field.variable"
dotFieldRequired
>{{ field.name }}</label
>
[for]="field.variable"
dotFieldRequired>
{{ field.name }}
</label>

@switch (field.fieldType) {
@case (fieldTypes.SELECT) {
Expand Down Expand Up @@ -87,6 +87,11 @@
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.CATEGORY) {
<dot-edit-content-category-field
[attr.data-testId]="'field-' + field.variable"
[field]="field" />
}
}
@if (field.hint) {
<small [attr.data-testId]="'hint-' + field.variable">{{ field.hint }}</small>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
@use "variables" as *;

:host {
display: block;
display: flex;
flex-direction: column;
height: fit-content;
margin-bottom: 0;
gap: $spacing-1;

label {
margin: 0;
}

small {
margin: 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DotEditContentFieldComponent } from './dot-edit-content-field.component

import { DotEditContentBinaryFieldComponent } from '../../fields/dot-edit-content-binary-field/dot-edit-content-binary-field.component';
import { DotEditContentCalendarFieldComponent } from '../../fields/dot-edit-content-calendar-field/dot-edit-content-calendar-field.component';
import { DotEditContentCategoryFieldComponent } from '../../fields/dot-edit-content-category-field/dot-edit-content-category-field.component';
import { DotEditContentCheckboxFieldComponent } from '../../fields/dot-edit-content-checkbox-field/dot-edit-content-checkbox-field.component';
import { DotEditContentCustomFieldComponent } from '../../fields/dot-edit-content-custom-field/dot-edit-content-custom-field.component';
import { DotEditContentHostFolderFieldComponent } from '../../fields/dot-edit-content-host-folder-field/dot-edit-content-host-folder-field.component';
Expand Down Expand Up @@ -130,6 +131,9 @@ const FIELD_TYPES_COMPONENTS: Record<FIELD_TYPES, Type<unknown> | DotEditFieldTe
[FIELD_TYPES.WYSIWYG]: {
component: DotEditContentWYSIWYGFieldComponent,
declarations: [MockComponent(EditorComponent)]
},
[FIELD_TYPES.CATEGORY]: {
component: DotEditContentCategoryFieldComponent
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, HostBinding, Input, inject } from '
import { ControlContainer, ReactiveFormsModule } from '@angular/forms';

import { BlockEditorModule } from '@dotcms/block-editor';
import { DotCMSContentTypeField, DotCMSContentlet } from '@dotcms/dotcms-models';
import { DotCMSContentlet, DotCMSContentTypeField } from '@dotcms/dotcms-models';
import { DotFieldRequiredDirective } from '@dotcms/ui';

import { DotEditContentBinaryFieldComponent } from '../../fields/dot-edit-content-binary-field/dot-edit-content-binary-field.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<div class="column" *ngFor="let column of row.columns" data-testId="column">
<dot-edit-content-field
*ngFor="let field of column.fields"
[field]="field"
[contentlet]="formData.contentlet"
[contentType]="formData.contentType.variable"
[contentlet]="formData.contentlet"
[field]="field"
data-testId="field" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="category-field__dialog h-full w-full">
<div class="category-field__left-pane flex flex-column">Search & category tree</div>
<div class="category-field__right-pane flex flex-column">
<div class="category-field__selected-categories flex-1">Selected Categories</div>
<div class="category-field__actions flex justify-content-end">
<button
class="p-button p-button-link"
(click)="dialogRef.close()"
data-testId="cancel-btn"
pButton>
{{ 'edit.content.category-field.cancel' | dm }}
</button>
<button class="p-button" data-testId="apply-btn">
{{ 'edit.content.category-field.apply' | dm }}
</button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@use "variables" as *;

.category-field__dialog {
display: grid;
grid-template-columns: 2fr 1fr;
margin: auto;
}

.category-field__left-pane,
.category-field__right-pane {
padding: $spacing-3;
gap: $spacing-3;
}

.category-field__left-pane {
background-color: $color-palette-gray-300;
}

.category-field__selected-categories {
border: $field-border-size solid $color-palette-gray-400;
border-radius: $border-radius-sm;
padding: $spacing-3;
}

.category-field__actions {
gap: $spacing-1;
}

::ng-deep .category-field__dialog .p-dialog-content {
padding: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect, it } from '@jest/globals';
import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator';
import { mockProvider } from '@ngneat/spectator/jest';

import { DynamicDialogRef } from 'primeng/dynamicdialog';

import { DotMessageService } from '@dotcms/data-access';

import { DotEditContentCategoryFieldDialogComponent } from './dot-edit-content-category-field-dialog.component';

describe('DotEditContentCategoryFieldDialogComponent', () => {
let spectator: Spectator<DotEditContentCategoryFieldDialogComponent>;
let dialogRef: DynamicDialogRef;

const createComponent = createComponentFactory({
component: DotEditContentCategoryFieldDialogComponent,
providers: [
mockProvider(DynamicDialogRef, {
close: jest.fn()
}),
mockProvider(DotMessageService)
]
});

beforeEach(() => {
spectator = createComponent();
dialogRef = spectator.inject(DynamicDialogRef);
});

afterEach(() => {
jest.resetAllMocks();
});

it('should have a cancel button', () => {
expect(spectator.query(byTestId('cancel-btn'))).not.toBeNull();
});
it('should have a apply button', () => {
expect(spectator.query(byTestId('apply-btn'))).not.toBeNull();
});

it('should close the dialog when you click cancel', () => {
const cancelBtn = spectator.query(byTestId('cancel-btn'));
expect(cancelBtn).not.toBeNull();

expect(dialogRef.close).not.toHaveBeenCalled();

spectator.click(cancelBtn);
expect(dialogRef.close).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';

import { ButtonModule } from 'primeng/button';
import { DialogModule } from 'primeng/dialog';
import { DynamicDialogRef } from 'primeng/dynamicdialog';

import { DotMessagePipe } from '@dotcms/ui';

@Component({
selector: 'dot-edit-content-category-field-dialog',
standalone: true,
imports: [DialogModule, ButtonModule, DotMessagePipe],
templateUrl: './dot-edit-content-category-field-dialog.component.html',
styleUrl: './dot-edit-content-category-field-dialog.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DotEditContentCategoryFieldDialogComponent {
protected dialogRef: DynamicDialogRef = inject(DynamicDialogRef);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@if (values.length) {
<div class="dot-category-field__categories" data-testId="category-chip-list">
@for (category of values; track category.id) {
<p-chip
[pTooltip]="category.value"
[removable]="true"
[label]="category.value"
tooltipPosition="top"
styleClass="p-chip-sm" />
}
</div>
}

<div class="dot-category-field__select">
<p-button
[label]="'edit.content.category-field.show-categories-dialog' | dm"
(onClick)="showCategories()"
data-testId="show-dialog-btn"
icon="pi pi-pencil"
styleClass="p-button-sm p-button-text p-button-secondary" />
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@use "variables" as *;

:host {
&.dot-category-field__container--has-categories .dot-category-field__select {
border-radius: 0 0 $border-radius-md $border-radius-md;
}

&.dot-category-field__container--has-categories .dot-category-field__categories {
border-bottom: none;
}
}

.dot-category-field__categories,
.dot-category-field__select {
border: $field-border-size solid $color-palette-gray-400;
display: flex;
flex-wrap: wrap;
align-items: center;
}

.dot-category-field__categories {
padding: $spacing-1;
gap: $spacing-1;
border-radius: $border-radius-md $border-radius-md 0 0;
}

.dot-category-field__select {
height: $field-height-md;
border-radius: $border-radius-md;
padding: 0 $spacing-0;
justify-content: flex-end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect, it } from '@jest/globals';
import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator';
import { mockProvider } from '@ngneat/spectator/jest';

import { DotMessageService } from '@dotcms/data-access';

import { DotEditContentCategoryFieldComponent } from './dot-edit-content-category-field.component';

describe('DotEditContentCategoryFieldComponent', () => {
let spectator: Spectator<DotEditContentCategoryFieldComponent>;

const createComponent = createComponentFactory({
component: DotEditContentCategoryFieldComponent,
providers: [mockProvider(DotMessageService)]
});

beforeEach(() => {
spectator = createComponent();
});

afterEach(() => {
jest.resetAllMocks();
});

it('should have a select categories button', () => {
expect(spectator.query(byTestId('show-dialog-btn'))).not.toBeNull();
});

it('should show the category list wrapper', () => {
spectator.component.values = [];
spectator.detectComponentChanges();
expect(spectator.query(byTestId('category-chip-list'))).toBeNull();

spectator.component.values = [{ id: 1, value: 'Streetwear' }];
spectator.detectComponentChanges();
expect(spectator.query(byTestId('category-chip-list'))).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { NgClass } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject, input } from '@angular/core';
import { ControlContainer, ReactiveFormsModule } from '@angular/forms';

import { ButtonModule } from 'primeng/button';
import { ChipModule } from 'primeng/chip';
import { ChipsModule } from 'primeng/chips';
import { DialogService } from 'primeng/dynamicdialog';
import { TooltipModule } from 'primeng/tooltip';

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

import { DotEditContentCategoryFieldDialogComponent } from './components/dot-edit-content-category-field-dialog/dot-edit-content-category-field-dialog.component';

/**
* Component for editing content category field.
*
* @class
* @name DotEditContentCategoryFieldComponent
*/
@Component({
selector: 'dot-edit-content-category-field',
standalone: true,
imports: [
ChipsModule,
ReactiveFormsModule,
ButtonModule,
ChipModule,
NgClass,
TooltipModule,
DotMessagePipe
],
templateUrl: './dot-edit-content-category-field.component.html',
styleUrl: './dot-edit-content-category-field.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
viewProviders: [
{
provide: ControlContainer,
useFactory: () => inject(ControlContainer, { skipSelf: true })
}
],
providers: [DialogService],
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
'[class.dot-category-field__container--has-categories]': 'hasCategories()',
'[class.dot-category-field__container]': '!hasCategories()'
}
})
export class DotEditContentCategoryFieldComponent {
/**
* The `field` variable is of type `DotCMSContentTypeField` and is a required input.
*
* @name field
* @description The variable represents a field of a DotCMS content type.
*/
field = input.required<DotCMSContentTypeField>();

// TODO: Replace with the content of the selected categories
values = [];

#dialogService = inject(DialogService);

/**
* Checks if the object has categories.
* @returns {boolean} - True if the object has categories, false otherwise.
*/
hasCategories(): boolean {
return this.values.length > 0;
}

/**
* Open the "DotEditContentCategoryFieldDialogComponent" dialog to show categories.
*
* @returns {void}
*/
showCategories(): void {
this.#dialogService.open(DotEditContentCategoryFieldDialogComponent, {
showHeader: false,
styleClass: 'category-field__dialog',
width: '1000px',
height: '600px',
position: 'center'
});
}
}
Loading

0 comments on commit 2552dfc

Please sign in to comment.