Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue-30521-Create-content-analy…
Browse files Browse the repository at this point in the history
…tics-query-endpoint-that-doesnt-require-map' into issue-30521-Create-content-analytics-query-endpoint-that-doesnt-require-map
  • Loading branch information
jcastro-dotcms committed Dec 5, 2024
2 parents f0e627e + 87b25ad commit 70194b1
Show file tree
Hide file tree
Showing 60 changed files with 4,682 additions and 1,461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import {
} from '@dotcms/dotcms-models';

export enum DotRenderMode {
LOCKED = 'LOCKED',
LISTING = 'LISTING',
ARCHIVED = 'ARCHIVED',
UNPUBLISHED = 'UNPUBLISHED',
PUBLISHED = 'PUBLISHED',
UNLOCKED = 'UNLOCKED',
NEW = 'NEW',
EDITING = 'EDITING'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
MOCK_CONTENTLET_1_TAB as MOCK_CONTENTLET_1_OR_2_TABS,
MOCK_CONTENTTYPE_1_TAB,
MOCK_CONTENTTYPE_2_TABS,
MOCK_WORKFLOW_ACTIONS_NEW_ITEMNTTYPE_1_TAB
MOCK_WORKFLOW_ACTIONS_NEW_ITEMNTTYPE_1_TAB,
MOCK_WORKFLOW_STATUS
} from '../../utils/edit-content.mock';
import { MockResizeObserver } from '../../utils/mocks';

Expand All @@ -52,6 +53,7 @@ describe('DotFormComponent', () => {
let workflowActionsService: SpyObject<DotWorkflowsActionsService>;
let workflowActionsFireService: SpyObject<DotWorkflowActionsFireService>;
let dotEditContentService: SpyObject<DotEditContentService>;
let dotWorkflowService: SpyObject<DotWorkflowService>;
let router: SpyObject<Router>;

const createComponent = createComponentFactory({
Expand All @@ -71,6 +73,7 @@ describe('DotFormComponent', () => {
mockProvider(DotWorkflowService),
mockProvider(MessageService),
mockProvider(DotContentletService),

{
provide: ActivatedRoute,
useValue: {
Expand All @@ -95,6 +98,7 @@ describe('DotFormComponent', () => {
workflowActionsService = spectator.inject(DotWorkflowsActionsService);
dotEditContentService = spectator.inject(DotEditContentService);
workflowActionsFireService = spectator.inject(DotWorkflowActionsFireService);
dotWorkflowService = spectator.inject(DotWorkflowService);
router = spectator.inject(Router);
});

Expand All @@ -112,6 +116,7 @@ describe('DotFormComponent', () => {
workflowActionsService.getWorkFlowActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
dotWorkflowService.getWorkflowStatus.mockReturnValue(of(MOCK_WORKFLOW_STATUS));

store.initializeExistingContent(MOCK_CONTENTLET_1_OR_2_TABS.inode); // called with the inode of the contentlet

Expand Down Expand Up @@ -189,6 +194,7 @@ describe('DotFormComponent', () => {
workflowActionsService.getWorkFlowActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
dotWorkflowService.getWorkflowStatus.mockReturnValue(of(MOCK_WORKFLOW_STATUS));

store.initializeExistingContent(MOCK_CONTENTLET_1_OR_2_TABS.inode); // called with the inode of the contentlet
spectator.detectChanges();
Expand Down Expand Up @@ -279,6 +285,7 @@ describe('DotFormComponent', () => {
workflowActionsService.getWorkFlowActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
dotWorkflowService.getWorkflowStatus.mockReturnValue(of(MOCK_WORKFLOW_STATUS));

store.initializeExistingContent(MOCK_CONTENTLET_1_OR_2_TABS.inode);
spectator.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
FLATTENED_FIELD_TYPES
} from '../../models/dot-edit-content-field.constant';
import { FIELD_TYPES } from '../../models/dot-edit-content-field.enum';
import { FormValues } from '../../models/dot-edit-content-form.interface';
import { DotWorkflowActionParams } from '../../models/dot-edit-content.model';
import { getFinalCastedValue, isFilteredType } from '../../utils/functions.util';
import { DotEditContentFieldComponent } from '../dot-edit-content-field/dot-edit-content-field.component';
Expand Down Expand Up @@ -98,7 +99,7 @@ export class DotEditContentFormComponent implements OnInit {
*
* @memberof DotEditContentFormComponent
*/
changeValue = output<Record<string, string>>();
changeValue = output<FormValues>();

/**
* Computed property that retrieves the filtered fields from the store.
Expand All @@ -110,6 +111,10 @@ export class DotEditContentFormComponent implements OnInit {
() => this.$store.contentType()?.fields?.filter(isFilteredType) ?? []
);

$formFields = computed(
() => this.$store.contentType()?.fields?.filter((field) => !isFilteredType(field)) ?? []
);

/**
* FormGroup instance that contains the form controls for the fields in the content type
*
Expand Down Expand Up @@ -158,72 +163,62 @@ export class DotEditContentFormComponent implements OnInit {
}

/**
* Initializes a listener for form value changes.
* When the form value changes, it calls the onFormChange method with the new value.
* The listener is automatically unsubscribed when the component is destroyed.
* Handles form value changes and emits the processed value.
*
* @private
* @param {Record<string, any>} value The raw form value
* @memberof DotEditContentFormComponent
*/
private initializeFormListener() {
this.form.valueChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((value) => {
const processedValue = this.processFormValue(value);
this.changeValue.emit(processedValue);
});
onFormChange(value: Record<string, string>) {
const processedValue = this.processFormValue(value);
this.changeValue.emit(processedValue);
}

/**
* Emits the form value through the `formSubmit` event.
* Initializes a listener for form value changes.
*
* @param {*} value
* @private
* @memberof DotEditContentFormComponent
*/
onFormChange(value) {
this.$filteredFields().forEach(({ variable, fieldType }) => {
if (FLATTENED_FIELD_TYPES.includes(fieldType as FIELD_TYPES)) {
value[variable] = value[variable]?.join(',');
}

if (CALENDAR_FIELD_TYPES.includes(fieldType as FIELD_TYPES)) {
value[variable] = value[variable]
?.toISOString()
.replace(/T|\.\d{3}Z/g, (match: string) => (match === 'T' ? ' ' : '')); // To remove the T and .000Z from the date)
}
private initializeFormListener() {
this.form.valueChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((value) => {
this.onFormChange(value);
});

this.changeValue.emit(value);
}

/**
* Processes the form value, applying specific transformations for certain field types.
*
* @private
* @param {Record<string, any>} value The raw form value
* @param {Record<string, string>} value The raw form value
* @returns {Record<string, string>} The processed form value
* @memberof DotEditContentFormComponent
*/
private processFormValue(
value: Record<string, string | string[] | Date | null | undefined>
): Record<string, string> {
): FormValues {
return Object.fromEntries(
this.$filteredFields().map(({ variable, fieldType }) => {
let fieldValue = value[variable];
Object.entries(value).map(([key, fieldValue]) => {
const field = this.$formFields().find((f) => f.variable === key);

if (!field) {
return [key, fieldValue];
}

if (
Array.isArray(fieldValue) &&
FLATTENED_FIELD_TYPES.includes(fieldType as FIELD_TYPES)
FLATTENED_FIELD_TYPES.includes(field.fieldType as FIELD_TYPES)
) {
fieldValue = fieldValue.join(',');
} else if (
fieldValue instanceof Date &&
CALENDAR_FIELD_TYPES.includes(fieldType as FIELD_TYPES)
CALENDAR_FIELD_TYPES.includes(field.fieldType as FIELD_TYPES)
) {
fieldValue = fieldValue
.toISOString()
.replace(/T|\.\d{3}Z/g, (match) => (match === 'T' ? ' ' : ''));
}

return [variable, fieldValue?.toString() ?? ''];
return [key, fieldValue ?? ''];
})
);
}
Expand All @@ -236,13 +231,15 @@ export class DotEditContentFormComponent implements OnInit {
* @memberof DotEditContentFormComponent
*/
private initializeForm() {
this.form = this.#fb.group({});
this.$store.contentType().fields.forEach((field) => {
if (!isFilteredType(field)) {
const control = this.createFormControl(field);
this.form.addControl(field.variable, control);
}
});
const controls = this.$formFields().reduce(
(acc, field) => ({
...acc,
[field.variable]: this.createFormControl(field)
}),
{}
);

this.form = this.#fb.group(controls);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
@let scheme = $workflow().scheme;
@let task = $workflow().task;

@let workflow = $workflow();
@let isLoading = $isLoading();
@let noWorkflowSelectedYet = $noWorkflowSelectedYet();
@let currentStep = $workflow().step;
@let workflowSelection = $workflowSelection();

<dl class="workflow-list">
<dt class="workflow-column__title" id="workflow-title">{{ 'Workflow' | dm }}</dt>
Expand All @@ -13,7 +10,7 @@
data-testId="workflow-name">
@if (isLoading) {
<p-skeleton />
} @else if (noWorkflowSelectedYet) {
} @else if (workflowSelection.isWorkflowSelected) {
<a
href="#"
class="select-workflow-link"
Expand All @@ -23,33 +20,44 @@
{{ 'edit.content.sidebar.workflow.select.workflow' | dm }}
</a>
} @else {
{{ scheme?.name }}
{{ workflow.scheme?.name }}

<!-- While not step, is consider as New contentlet -->
@if ($showWorkflowDialogIcon()) {
@if ($showWorkflowSelection()) {
<p-button
data-testId="edit-workflow-button"
(click)="showDialog()"
pButton
styleClass="p-button-link"
icon="pi pi-pencil"></p-button>
}

@if (workflow.resetAction) {
<p-button
(click)="onResetWorkflow.emit(workflow.resetAction.id.toString())"
pButton
styleClass="p-button-link"
data-testId="reset-workflow-button"
icon="pi pi-replay"></p-button>
}
}
</dd>

@if (!noWorkflowSelectedYet) {
<dt class="workflow-column__title" id="step-title">{{ 'Step' | dm }}</dt>
@if (!workflowSelection.isWorkflowSelected) {
<dt class="workflow-column__title" id="step-title">
{{ 'Step' | dm }}
</dt>
<dd
class="workflow-column__description"
aria-labelledby="step-title"
data-testId="workflow-step">
@if (isLoading) {
<p-skeleton />
} @else {
{{ currentStep?.name }}
{{ workflow.step?.name }}
}
</dd>

@if (task) {
@if (workflow.task) {
<dt class="workflow-column__title" id="assignee-title">{{ 'Assignee' | dm }}</dt>
<dd
class="workflow-column__description"
Expand All @@ -58,7 +66,7 @@
@if (isLoading) {
<p-skeleton />
} @else {
{{ task.assignedTo }}
{{ workflow.task.assignedTo }}
}
</dd>
}
Expand All @@ -81,7 +89,7 @@
<p-dropdown
id="workflow"
appendTo="body"
[options]="$workflowSchemeOptions()"
[options]="workflowSelection.schemeOptions"
optionLabel="label"
[(ngModel)]="$selectedWorkflow"
placeholder="{{
Expand Down
Loading

0 comments on commit 70194b1

Please sign in to comment.