Skip to content

Commit

Permalink
chore(edit-content): apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Dec 18, 2024
1 parent 4644fab commit be975f3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</th>
}
<th scope="col" pFrozenColumn alignFrozen="right" [frozen]="true">
Menu
{{ 'dot.file.relationship.dialog.menu.column' | dm }}
</th>
</tr>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class DotSelectExistingContentComponent {
* A required input that holds the content id.
* It is used to get the content type fields.
*/
$contentId = input.required<string | null>({ alias: 'contentId' });
$contentTypeId = input.required<string | null>({ alias: 'contentTypeId' });

/**
* A computed signal that determines the label for the apply button.
Expand Down Expand Up @@ -141,6 +141,6 @@ export class DotSelectExistingContentComponent {
*/
onShowDialog() {
this.store.applyInitialState();
this.store.loadContent(this.$contentId());
this.store.loadContent(this.$contentTypeId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ export const ExistingContentStore = signalStore(
loadContent: rxMethod<string>(
pipe(
tap(() => patchState(store, { status: ComponentStatus.LOADING })),
tap((contentId) => {
if (!contentId) {
tap((contentTypeId) => {
if (!contentTypeId) {
patchState(store, {
status: ComponentStatus.ERROR,
errorMessage: 'dot.file.relationship.dialog.content.id.required'
});
}
}),
filter((contentId) => !!contentId),
switchMap((contentId) =>
relationshipFieldService.getColumnsAndContent(contentId).pipe(
filter((contentTypeId) => !!contentTypeId),
switchMap((contentTypeId) =>
relationshipFieldService.getColumnsAndContent(contentTypeId).pipe(
tapResponse({
next: ([columns, data]) => {
patchState(store, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@
</p-table>

<dot-select-existing-content
[contentId]="$contentId()"
[contentTypeId]="$contentTypeId()"
[(visible)]="$showExistingContentDialog"
(onSelectItems)="store.addData($event)" />
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export class DotEditContentRelationshipFieldComponent implements ControlValueAcc
*/
$field = input.required<DotCMSContentTypeField>({ alias: 'field' });

$contentId = computed(() => {
/**
* A computed signal that holds the content type id for the relationship field.
* This id is used to get the content type fields.
*/
$contentTypeId = computed(() => {
const field = this.$field();

return field?.relationships?.velocityVar || null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { faker } from '@faker-js/faker';
import { forkJoin, Observable } from 'rxjs';

import { formatDate } from '@angular/common';
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';

import { map, pluck } from 'rxjs/operators';
import { catchError, map, pluck } from 'rxjs/operators';

import { DotContentSearchService, DotFieldService, DotLanguagesService } from '@dotcms/data-access';

import { DotContentSearchService, DotFieldService, DotHttpErrorManagerService, DotLanguagesService } from '@dotcms/data-access';
import { DotCMSContentlet, DotCMSContentTypeField } from '@dotcms/dotcms-models';
import { RelationshipFieldItem } from '@dotcms/edit-content/fields/dot-edit-content-relationship-field/models/relationship.models';

Expand All @@ -16,6 +17,7 @@ import {
} from '../dot-edit-content-relationship-field.constants';
import { Column } from '../models/column.model';


type LanguagesMap = Record<number, string>;

@Injectable({
Expand All @@ -25,6 +27,7 @@ export class RelationshipFieldService {
readonly #fieldService = inject(DotFieldService);
readonly #contentSearchService = inject(DotContentSearchService);
readonly #dotLanguagesService = inject(DotLanguagesService);
readonly #httpErrorManagerService = inject(DotHttpErrorManagerService);

/**
* Gets relationship content items
Expand All @@ -46,7 +49,7 @@ export class RelationshipFieldService {
* @param contentTypeId The content type ID
* @returns Observable of [Column[], RelationshipFieldItem[]]
*/
getColumnsAndContent(contentTypeId: string): Observable<[Column[], RelationshipFieldItem[]]> {
getColumnsAndContent(contentTypeId: string): Observable<[Column[], RelationshipFieldItem[]] | null> {
return forkJoin([
this.getColumns(contentTypeId),
this.getContent(contentTypeId),
Expand All @@ -55,7 +58,12 @@ export class RelationshipFieldService {
map(([columns, content, languages]) => [
columns,
this.#matchColumnsWithContent(columns, content, languages)
])
]),
catchError((error: HttpErrorResponse) => {
return this.#httpErrorManagerService.handle(error).pipe(
map(() => null)
);
})
);
}

Expand Down Expand Up @@ -155,20 +163,4 @@ export class RelationshipFieldService {
return relationshipItem;
});
}

#getRandomState(): { label: string; styleClass: string } {
const label = faker.helpers.arrayElement(['Changed', 'Published', 'Draft', 'Archived']);

const styleClasses = {
Changed: 'p-chip-sm p-chip-blue',
Published: 'p-chip-sm p-chip-success',
Draft: 'p-chip-sm p-chip-warning',
Archived: 'p-chip-sm p-chip-error'
};

return {
label,
styleClass: styleClasses[label]
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ dot.file.relationship.dialog.search=Search
dot.file.relationship.dialog.search.empty.content=No related content available
dot.file.relationship.dialog.content.id.required=ContentId is required
dot.file.relationship.dialog.content.request.failed=Failed to load content
dot.file.relationship.dialog.menu.column=Menu
dot.common.apply=Apply
dot.common.archived=Archived
dot.common.cancel=Cancel
Expand Down

0 comments on commit be975f3

Please sign in to comment.