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) refactor to use signal store as store Edit Content #30201

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -36,7 +36,7 @@ <h2>{{ 'Workflow' | dm }}</h2>
<div class="content-aside__close">
<button
class="p-button p-button-sm p-button-text p-button-rounded p-button-icon-only"
(click)="$toggle.emit(!$collapsed())"
(click)="$toggle.emit()"
data-testId="toggle-button">
<svg
width="16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, input, output } from '@angular/core

import { TabViewModule } from 'primeng/tabview';

import { DotCMSContentType, DotCMSContentlet } from '@dotcms/dotcms-models';
import { DotCMSContentlet, DotCMSContentType } from '@dotcms/dotcms-models';
import { DotMessagePipe } from '@dotcms/ui';

import { DotContentAsideInformationComponent } from './components/dot-content-aside-information/dot-content-aside-information.component';
Expand Down Expand Up @@ -37,13 +37,8 @@ export class DotEditContentAsideComponent {
*/
$loading = input.required<boolean>({ alias: 'loading' });

/**
* A variable to control the collapsed state
*/
$collapsed = input.required<boolean>({ alias: 'collapsed' });

/**
* A variable to control the toggle state
*/
$toggle = output<boolean>({ alias: 'toggle' });
$toggle = output<void>({ alias: 'toggle' });
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '../../models/dot-edit-content-field.constant';
import { FIELD_TYPES } from '../../models/dot-edit-content-field.enum';
import { FILTERED_TYPES } from '../../models/dot-edit-content-form.enum';
import { EditContentPayload } from '../../models/dot-edit-content-form.interface';
import { EditContentForm } from '../../models/dot-edit-content-form.interface';
import { getFinalCastedValue, transformLayoutToTabs } from '../../utils/functions.util';
import { DotEditContentAsideComponent } from '../dot-edit-content-aside/dot-edit-content-aside.component';
import { DotEditContentFieldComponent } from '../dot-edit-content-field/dot-edit-content-field.component';
Expand All @@ -54,8 +54,10 @@ import { DotEditContentFieldComponent } from '../dot-edit-content-field/dot-edit
})
export class DotEditContentFormComponent implements OnInit {
@Input()
formData!: EditContentPayload;
formData!: EditContentForm;
oidacra marked this conversation as resolved.
Show resolved Hide resolved

@Output() changeValue = new EventEmitter();

form!: FormGroup;
readonly fieldTypes = FIELD_TYPES;
readonly filteredTypes = FILTERED_TYPES;
Expand Down
6 changes: 5 additions & 1 deletion core-web/libs/edit-content/src/lib/edit-content.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const DotEditContentRoutes: Route[] = [
title: 'Create Content',
component: EditContentLayoutComponent
},
{ path: ':id', title: 'Edit Content', component: EditContentLayoutComponent }
{
path: ':id',
title: 'Edit Content',
component: EditContentLayoutComponent
oidacra marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
];
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
@if (vm$ | async; as vm) {
@if (vm?.contentType?.metadata?.[$featuredFlagContentKEY()]) {
<!--Todo: handle Loading and Saving state-->
@if ($store.isLoaded()) {
@let formData = $store.formData();
@let contentType = $store.contentType();
@let variable = contentType.variable;
@let contentlet = $store.contentlet();
@let actionsByContentTypeOrContent = $store.actions();
@let showSidebar = $store.showSidebar();
@let isLoading = $store.isLoading();

@if ($store.isEnabledNewContentEditor()) {
<p-messages
class="topBar"
class="edit-content-layout__topBar"
styleClass="p-message-border-y"
severity="success"
data-testId="topBar">
data-testId="edit-content-layout__topBar">
<ng-template pTemplate>
<i class="pi pi-info-circle"></i>
<div>
<span [innerHTML]="('edit.content.layout.beta.message' | dm) + ' '"></span>
<a
[routerLink]="'/content-types-angular/edit/' + vm.contentType.variable"
[routerLink]="'/content-types-angular/edit/' + variable"
data-testId="content-type">
{{ 'edit.content.layout.beta.message.switch' | dm }}
</a>
Expand All @@ -23,17 +32,17 @@
(actionFired)="
fireWorkflowAction({
actionId: $event.id,
inode: vm.contentlet?.inode,
contentType: vm.contentType.variable
inode: contentlet?.inode,
contentType: variable
})
"
[actions]="vm.actions"
class="header"
[class.showSidebar]="vm.layout.showSidebar">
[actions]="actionsByContentTypeOrContent"
data-testId="edit-content-layout__header"
class="edit-content-layout__header">
<button
[class.showSidebar]="vm.layout.showSidebar"
class="edit-content-layout__sidebar-btn p-button p-button-sm p-button-text p-button-rounded p-button-icon-only content-aside__closeBtn"
(click)="toggleSidebar()"
[class.hide]="showSidebar"
class="edit-content-layout__sidebar--btn p-button p-button-sm p-button-text p-button-rounded p-button-icon-only"
(click)="$store.toggleSidebar()"
data-testId="sidebar-toggle">
<svg
width="16"
Expand Down Expand Up @@ -65,17 +74,29 @@
</svg>
</button>
</dot-edit-content-toolbar>
<dot-edit-content-form (changeValue)="setFormValue($event)" [formData]="vm" class="body" />
<dot-edit-content-aside
[loading]="vm.loading"
[contentlet]="vm.contentlet"
[contentType]="vm.contentType"
[collapsed]="vm.layout.showSidebar"
(toggle)="toggleSidebar()"
class="sidebar" />
} @else {

<dot-edit-content-form
(changeValue)="setFormValue($event)"
[formData]="formData"
data-testId="edit-content-layout__body"
class="edit-content-layout__body" />

@if (showSidebar) {
@defer (when showSidebar) {
<dot-edit-content-aside
[loading]="isLoading"
[contentlet]="contentlet"
[contentType]="contentType"
(toggle)="$store.toggleSidebar()"
data-testId="edit-content-layout__sidebar"
class="edit-content-layout__sidebar" />
}
}
}

@if ($store.hasError()) {
{{ 'edit.content.layout.no.content.to.show ' | dm }}
}

<p-toast></p-toast>
<p-toast />
<p-confirmDialog />
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,19 @@
"topBar topBar"
"header sidebar"
"body sidebar";
grid-template-columns: 1fr 21.875rem;
grid-template-columns: 1fr 0;
grid-template-rows: auto auto 1fr;
padding-bottom: 0;
height: 100%;
width: 100%;
}

.edit-content-layout__sidebar-btn {
rect {
stroke: $color-palette-primary;
}
transition: grid-template-columns $basic-speed ease-in-out;

path {
fill: $color-palette-primary;
}
transition: all 300ms ease-in-out;
&.showSidebar {
width: 0;
min-width: 0;
height: 0;
padding: 0;
visibility: hidden;
&.edit-content--with-sidebar {
grid-template-columns: 1fr 21.875rem;
}
}

.topBar {
.edit-content-layout__topBar {
grid-area: topBar;

.pi {
Expand All @@ -40,14 +27,33 @@
}
}

.header {
.edit-content-layout__header {
grid-area: header;
}

.body {
.edit-content-layout__body {
grid-area: body;
}

.sidebar {
.edit-content-layout__sidebar {
grid-area: sidebar;
}

.edit-content-layout__sidebar--btn {
rect {
stroke: $color-palette-primary;
}

path {
fill: $color-palette-primary;
}
transition: all $basic-speed ease-in-out;

&.hide {
width: 0;
min-width: 0;
height: 0;
padding: 0;
visibility: hidden;
}
}
Loading