diff --git a/core-web/apps/dotcms-binary-field-builder/project.json b/core-web/apps/dotcms-binary-field-builder/project.json index 0ce4f73112ef..8de29bdf6508 100644 --- a/core-web/apps/dotcms-binary-field-builder/project.json +++ b/core-web/apps/dotcms-binary-field-builder/project.json @@ -46,7 +46,7 @@ { "type": "initial", "maximumWarning": "500kb", - "maximumError": "2mb" + "maximumError": "2.5mb" }, { "type": "anyComponentStyle", diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.html b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.html index 474a86d1fc92..cf611578ffd5 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.html +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.html @@ -1,121 +1,137 @@ @let data = store.data(); @let pagination = store.pagination(); - - - -
-
-
- +@if ($visible()) { + @defer { + + +
+ + + {{ 'dot.file.relationship.dialog.search' | dm }} + +
+
+ + +
+
+
+ +
+
+

+ {{ + 'dot.file.relationship.dialog.per.page' + | dm: [pagination.rowsPerPage.toString()] + }} +

+
+
+
-
+ + + + + + Title + + + + Step + + + + Description + + + + Last Update + + + Menu + + + + + +
+

+ {{ 'dot.file.relationship.dialog.search.empty.content' | dm }} +

+
+ + +
+ + + + + + +

{{ item.title }}

+ + {{ item.step }} + +

{{ item.description }}

+ + {{ item.lastUpdate | date }} + + + + +
+ + +
+

{{ - 'dot.file.relationship.dialog.per.page' - | dm: [pagination.rowsPerPage.toString()] + 'dot.file.relationship.dialog.selected.items' + | dm: [$selectedItems().length.toString()] }}

-
- -
-
- - - - - Title - - - - Step - - - - Description - - - - Last Update - - - Menu - - - - - -
-

Relate content by clicking on the Plus Button

+
+ +
- - - - - - - - - -

{{ item.title }}

- - {{ item.step }} - -

{{ item.description }}

- - {{ item.lastUpdate | date }} - - - - -
- - -
-
-

- {{ - 'dot.file.relationship.dialog.selected.items' - | dm: [$selectedItems().length.toString()] - }} -

-
-
- - -
-
-
- +
+
+
+ } +} diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.scss b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.scss index c34af3986231..ca07422c372f 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.scss +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.scss @@ -2,12 +2,10 @@ ::ng-deep { p-table { - .p-datatable-sm.p-datatable-existing-content { + .p-datatable-existing-content { .p-datatable-header { background-color: $white; border: 0px; - padding-left: 0px; - padding-right: 0px; } .p-datatable-table { border: 1px solid $color-palette-gray-300; @@ -24,5 +22,10 @@ height: auto; } } + .dotTable.p-datatable { + .p-datatable-tbody > tr > td:first-child:has(p-tableCheckbox) + td { + padding: 0 $spacing-1; + } + } } } diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.spec.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.spec.ts index ec2a9dc5ed84..d4988f8efa21 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.spec.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.spec.ts @@ -1,5 +1,9 @@ import { Spectator, createComponentFactory } from '@ngneat/spectator/jest'; +import { fakeAsync, tick } from '@angular/core/testing'; + +import { Dialog } from 'primeng/dialog'; + 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'; @@ -85,4 +89,61 @@ describe('DotSelectExistingContentComponent', () => { expect(label).toBe('Apply 2 entries'); }); }); + + describe('checkIfSelected', () => { + it('should return true when content is in selectedContent array', () => { + // Arrange + const testContent = mockRelationshipItem('1'); + spectator.component.$selectedItems.set([testContent]); + + // Act + const result = spectator.component.checkIfSelected(testContent); + + // Assert + expect(result).toBe(true); + }); + + it('should return false when content is not in selectedContent array', () => { + // Arrange + const testContent = mockRelationshipItem('123'); + const differentContent = mockRelationshipItem('456'); + spectator.component.$selectedItems.set([differentContent]); + + // Act + const result = spectator.component.checkIfSelected(testContent); + + // Assert + expect(result).toBe(false); + }); + + it('should return false when selectedContent is empty', () => { + // Arrange + const testContent = mockRelationshipItem('123'); + spectator.component.$selectedItems.set([]); + + // Act + const result = spectator.component.checkIfSelected(testContent); + + // Assert + expect(result).toBe(false); + }); + }); + + describe('onShowDialog', () => { + it('should call onShowDialog when dialog is shown', fakeAsync(() => { + // Arrange + spectator.component.$visible.set(true); + + spectator.detectChanges(); + + tick(100); + const spy = jest.spyOn(spectator.component, 'onShowDialog'); + + // Act + spectator.triggerEventHandler(Dialog, 'onShow', null); + + // Assert + expect(spy).toHaveBeenCalled(); + })); + }); }); diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.ts index 0e066ed75105..8917e5db9af7 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/dot-select-existing-content.component.ts @@ -112,4 +112,21 @@ export class DotSelectExistingContentComponent { emitSelectedItems() { this.onSelectItems.emit(this.$selectedItems()); } + + /** + * Checks if an item is selected. + * @param item - The item to check. + * @returns True if the item is selected, false otherwise. + */ + checkIfSelected(item: RelationshipFieldItem) { + return this.$selectedItems().some((selectedItem) => selectedItem.id === item.id); + } + + /** + * Shows the existing content dialog and loads the content. + */ + onShowDialog() { + this.store.applyInitialState(); + this.store.loadContent(); + } } diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/store/existing-content.store.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/store/existing-content.store.ts index c65414f675bc..1c352ef61257 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/store/existing-content.store.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/components/dot-select-existing-content/store/existing-content.store.ts @@ -70,6 +70,12 @@ export const ExistingContentStore = signalStore( ) ) ), + /** + * Applies the initial state for the existing content. + */ + applyInitialState: () => { + patchState(store, initialState); + }, /** * Advances the pagination to the next page and updates the state accordingly. */ diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/dot-edit-content-relationship-field.component.html b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/dot-edit-content-relationship-field.component.html index ccc2e97d92f6..ad9bc0c48fdc 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/dot-edit-content-relationship-field.component.html +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-relationship-field/dot-edit-content-relationship-field.component.html @@ -4,7 +4,7 @@