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

feat(edit-content): implement relationship field data table with mock data #30825

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
79afd2f
chore(edit-content): UI with mock data #30515
nicobytes Nov 27, 2024
c709fae
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Nov 27, 2024
76e2429
chore(edit-content): add format date #30215
nicobytes Nov 27, 2024
053b1fc
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Nov 27, 2024
af35245
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Nov 28, 2024
bf66229
chore(edit-content): create mock data for relationships fields #30515
nicobytes Nov 28, 2024
4e3dd97
chore(edit-content): fix sonar issue #30515
nicobytes Nov 28, 2024
446b52b
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Nov 28, 2024
3cc17d4
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Nov 29, 2024
df02687
chore(edit-content): fix unit tests errors #30215
nicobytes Nov 29, 2024
c5fa146
chore(edit-content): fix colors #30515
nicobytes Nov 29, 2024
398f82a
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Dec 2, 2024
d22a8e8
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Dec 2, 2024
87905c9
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Dec 3, 2024
ef75bcd
Merge branch 'main' into 30515-create-basic-relationship-field-struct…
nicobytes Dec 3, 2024
4667c16
chore(edit-content): add js docs #30515
nicobytes Dec 3, 2024
6184a79
chore(edit-content): apply format #30515
nicobytes Dec 3, 2024
6eeae97
Merge branch 'main' into 30523-implement-relationship-field-data-tabl…
nicobytes Dec 3, 2024
87f81e2
Merge branch '30523-implement-relationship-field-data-table-with-mock…
nicobytes Dec 3, 2024
be38079
chore(edit-content): sync with main #30523
nicobytes Dec 3, 2024
a9356ea
refactor(edit-content): update relationship field component and style…
nicobytes Dec 4, 2024
59dc1ca
chore(edit-content): enhance relationship field component with reorde…
nicobytes Dec 4, 2024
2aa42d0
chore(edit-content): enhance relationship field component with pagina…
nicobytes Dec 4, 2024
820c9c6
Merge branch 'main' into 30523-implement-relationship-field-data-tabl…
nicobytes Dec 4, 2024
69e594d
Merge branch 'main' into 30523-implement-relationship-field-data-tabl…
nicobytes Dec 5, 2024
4d8615b
chore(edit-content): update content retrieval to use dynamic ID and i…
nicobytes Dec 5, 2024
0924d1c
Merge branch '30523-implement-relationship-field-data-table-with-mock…
nicobytes Dec 6, 2024
14bfdca
Merge branch 'main' into 30523-implement-relationship-field-data-tabl…
nicobytes Dec 6, 2024
f8dd26d
Merge branches '30523-implement-relationship-field-data-table-with-mo…
nicobytes Dec 6, 2024
6d03522
chore(edit-content): Update test specifications and improve HTTP clie…
nicobytes Dec 6, 2024
38fe39e
chore(edit-content): fix format errors
nicobytes Dec 6, 2024
b4f93d6
Merge branch 'main' into 30523-implement-relationship-field-data-tabl…
nicobytes Dec 6, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,5 @@ dotCMS/dependencies.gradle
!/examples/nextjs/.npmrc

.nx/
.cursorrules
.cursorignore
2 changes: 1 addition & 1 deletion core-web/libs/dotcms-scss/shared/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $color-palette-primary-op-90: var(--color-palette-primary-op-90);

$color-palette-primary-shade: $color-palette-primary-600;
$color-palette-primary: $color-palette-primary-500;
$color-palette-primary-tint: $color-palette-primary-200;
$color-palette-primary-tint: $color-palette-primary-100;

$color-palette-secondary-100: var(--color-palette-secondary-100);
$color-palette-secondary-200: var(--color-palette-secondary-200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@
}
}
}
@if (field.hint) {
@if (field.hint && field.fieldType !== fieldTypes.RELATIONSHIP) {
<small [attr.data-testId]="'hint-' + field.variable">{{ field.hint }}</small>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { EditorComponent } from '@tinymce/tinymce-angular';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { Provider, signal, Type } from '@angular/core';
import { ControlContainer, FormGroupDirective } from '@angular/forms';
import { By } from '@angular/platform-browser';
Expand Down Expand Up @@ -213,7 +214,7 @@ describe.each([...FIELDS_TO_BE_RENDER])('DotEditContentFieldComponent all fields
let spectator: Spectator<DotEditContentFieldComponent>;

const createComponent = createComponentFactory({
imports: [HttpClientTestingModule, ...(fieldTestBed?.imports || [])],
imports: [...(fieldTestBed?.imports || [])],
declarations: [...(fieldTestBed?.declarations || [])],
component: DotEditContentFieldComponent,
componentViewProviders: [
Expand All @@ -222,7 +223,13 @@ describe.each([...FIELDS_TO_BE_RENDER])('DotEditContentFieldComponent all fields
useValue: createFormGroupDirectiveMock()
}
],
providers: [FormGroupDirective, mockProvider(DotHttpErrorManagerService)]
providers: [
FormGroupDirective,
provideHttpClient(),
provideHttpClientTesting(),
...(fieldTestBed?.providers || []),
mockProvider(DotHttpErrorManagerService)
]
});

beforeEach(async () => {
Expand All @@ -242,11 +249,13 @@ describe.each([...FIELDS_TO_BE_RENDER])('DotEditContentFieldComponent all fields
expect(label?.textContent).toContain(fieldMock.name);
});

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

it('should render the correct field type', () => {
spectator.detectChanges();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[header]="'dot.file.relationship.dialog.select.existing.content' | dm"
[modal]="true"
[(visible)]="$visible"
(onHide)="emitSelectedItems()"
dataKey="id"
appendTo="body"
width="90%"
Expand All @@ -14,9 +15,9 @@
[value]="data"
selectionMode="multiple"
[(selection)]="$selectedItems"
[first]="pagination.offset"
[loading]="store.isLoading()"
[paginator]="true"
[first]="pagination.offset"
[rows]="pagination.rowsPerPage"
[globalFilterFields]="['title', 'step', 'description']"
styleClass="p-datatable-sm p-datatable-existing-content">
Expand All @@ -35,13 +36,12 @@
</p>
</div>
</div>
<div>
<dot-pagination
(nextPage)="store.nextPage()"
(previousPage)="store.previousPage()"
[totalPages]="store.totalPages()"
[currentPage]="pagination.currentPage" />
</div>
<dot-pagination
[currentPageReportLayout]="'left'"
(nextPage)="store.nextPage()"
(previousPage)="store.previousPage()"
[totalPages]="store.totalPages()"
[currentPage]="pagination.currentPage" />
</div>
</ng-template>
<ng-template pTemplate="header" styleClass="relative">
Expand Down Expand Up @@ -111,7 +111,10 @@
(onClick)="closeDialog()"
[text]="true"
severity="primary" />
<p-button [disabled]="$isApplyDisabled()" [label]="$applyLabel()" />
<p-button
[disabled]="$isApplyDisabled()"
(onClick)="closeDialog()"
[label]="$applyLabel()" />
</div>
</div>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Spectator, createComponentFactory } from '@ngneat/spectator/jest';

import { DotMessageService } from '@dotcms/data-access';
import { RelationshipFieldItem } from '@dotcms/edit-content/fields/dot-edit-content-relationship-field/models/relationship.models';
import { MockDotMessageService } from '@dotcms/utils-testing';

import { DotSelectExistingContentComponent } from './dot-select-existing-content.component';
import { ExistingContentStore } from './store/existing-content.store';

describe('DotSelectExistingContentComponent', () => {
let spectator: Spectator<DotSelectExistingContentComponent>;
let store: InstanceType<typeof ExistingContentStore>;

const mockRelationshipItem = (id: string): RelationshipFieldItem => ({
id,
title: `Test Content ${id}`,
language: '1',
state: {
label: 'Published',
styleClass: 'small-chip'
},
description: 'Test description',
step: 'Step 1',
lastUpdate: new Date().toISOString()
});

const messageServiceMock = new MockDotMessageService({
'dot.file.relationship.dialog.apply.one.entry': 'Apply 1 entry',
'dot.file.relationship.dialog.apply.entries': 'Apply {0} entries'
});

const createComponent = createComponentFactory({
component: DotSelectExistingContentComponent,
componentProviders: [ExistingContentStore],
providers: [{ provide: DotMessageService, useValue: messageServiceMock }],
detectChanges: false
});

beforeEach(() => {
spectator = createComponent();
store = spectator.inject(ExistingContentStore, true);
spectator.detectChanges();
});

it('should create', () => {
expect(spectator.component).toBeTruthy();
expect(store).toBeTruthy();
});

describe('Dialog Visibility', () => {
it('should set visibility to false when closeDialog is called', () => {
spectator.component.$visible.set(true);
spectator.component.closeDialog();
expect(spectator.component.$visible()).toBeFalsy();
});
});

describe('Selected Items State', () => {
it('should disable apply button when no items are selected', () => {
spectator.component.$selectedItems.set([]);
expect(spectator.component.$isApplyDisabled()).toBeTruthy();
});

it('should enable apply button when items are selected', () => {
const mockContent = [mockRelationshipItem('1')];
spectator.component.$selectedItems.set(mockContent);
expect(spectator.component.$isApplyDisabled()).toBeFalsy();
});
});

describe('Apply Button Label', () => {
it('should show singular label when one item is selected', () => {
const mockContent = [mockRelationshipItem('1')];
spectator.component.$selectedItems.set(mockContent);

const label = spectator.component.$applyLabel();
expect(label).toBe('Apply 1 entry');
});

it('should show plural label when multiple items are selected', () => {
const mockContent = [mockRelationshipItem('1'), mockRelationshipItem('2')];
spectator.component.$selectedItems.set(mockContent);

const label = spectator.component.$applyLabel();
expect(label).toBe('Apply 2 entries');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DatePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, computed, inject, model } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, inject, model, output } from '@angular/core';

import { ButtonModule } from 'primeng/button';
import { DialogModule } from 'primeng/dialog';
Expand All @@ -14,9 +14,11 @@ import { TableModule } from 'primeng/table';
import { DotMessageService } from '@dotcms/data-access';
import { DotMessagePipe } from '@dotcms/ui';

import { PaginationComponent } from './components/pagination/pagination.component';
import { SearchComponent } from './components/search/search.compoment';
import { Content, ExistingContentStore } from './store/existing-content.store';
import { ExistingContentStore } from './store/existing-content.store';

import { RelationshipFieldItem } from '../../models/relationship.models';
import { PaginationComponent } from '../pagination/pagination.component';

@Component({
selector: 'dot-select-existing-content',
Expand Down Expand Up @@ -65,7 +67,7 @@ export class DotSelectExistingContentComponent {
* A signal that holds the selected items.
* It is used to store the selected content items.
*/
$selectedItems = model<Content[]>([]);
$selectedItems = model<RelationshipFieldItem[]>([]);

/**
* A computed signal that determines if the apply button is disabled.
Expand All @@ -88,11 +90,26 @@ export class DotSelectExistingContentComponent {
return this.#dotMessage.get(messageKey, selectedItems.length.toString());
});

/**
* A signal that sends the selected items when the dialog is closed.
* It is used to notify the parent component that the user has selected content items.
*/
onSelectItems = output<RelationshipFieldItem[]>();

/**
* A method that closes the existing content dialog.
* It sets the visibility signal to false, hiding the dialog.
*/
closeDialog() {
this.$visible.set(false);
}

/**
* Closes the existing content dialog and sends the selected items to the parent component.
* It sets the visibility signal to false, hiding the dialog, and emits the selected items
* through the "selectItems" output signal.
*/
emitSelectedItems() {
this.onSelectItems.emit(this.$selectedItems());
}
}
Loading
Loading