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

Handle 2 workflows for 1 contenttype #30658

Merged
merged 26 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
daa1fb7
feat(edit-content) handle 2 workflows for 1 contenttype
oidacra Nov 14, 2024
79eb402
feat(edit-content) add test
oidacra Nov 14, 2024
f6a70bd
feat(edit-content) remove duplicated interface
oidacra Nov 14, 2024
57108fb
feat(edit-content) use sass variables
oidacra Nov 14, 2024
bde7551
feat(edit-content) add tests
oidacra Nov 15, 2024
bf86da2
feat(edit-content) fix bug in actions button
oidacra Nov 15, 2024
6855696
feat(edit-content) cleanup and reoder store
oidacra Nov 15, 2024
06ac74d
feat(edit-content) clean up
oidacra Nov 15, 2024
6237dfd
feat(edit-content) test working
oidacra Nov 18, 2024
f110ad7
feat(edit-content) test working
oidacra Nov 18, 2024
07b75c7
feat(edit-content) fix sq
oidacra Nov 18, 2024
1a1f188
chore add data-access lib to skip lint tag
oidacra Nov 18, 2024
f7e4078
feat(edit-content) fix lint
oidacra Nov 18, 2024
53da662
feat(edit-content) clean up, add more test
oidacra Nov 19, 2024
c4d25a8
feat(edit-content) clean up, add more test
oidacra Nov 19, 2024
32f78b8
feat(edit-content) fix sq problem
oidacra Nov 19, 2024
df25e30
feat(edit-content) add more test
oidacra Nov 19, 2024
5348a2d
feat(edit-content) fix lint
oidacra Nov 19, 2024
1cd3ee9
feat(edit-content) fix comments
oidacra Nov 19, 2024
ae05a8a
feat(edit-content) fix bug
oidacra Nov 19, 2024
e3dc902
feat(edit-content) fix tests
oidacra Nov 20, 2024
4d8b577
feat(edit-content) fix comments
oidacra Nov 21, 2024
bc57c7e
feat(edit-content) apply format and lint
oidacra Nov 21, 2024
5a6bdd2
feat(edit-content) fix lint and test
oidacra Nov 21, 2024
7de6c07
feat(edit-content) fix tests
oidacra Nov 21, 2024
74ed6e0
feat(edit-content) fix lint
oidacra Nov 22, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator/jest';

import { DotCMSWorkflowAction } from '@dotcms/dotcms-models';
import { mockWorkflows, mockWorkflowsActions } from '@dotcms/utils-testing';
import {
MOCK_SINGLE_WORKFLOW_ACTIONS,
mockWorkflows,
mockWorkflowsActions
} from '@dotcms/utils-testing';

import { DotWorkflowsActionsService } from './dot-workflows-actions.service';

Expand Down Expand Up @@ -38,12 +42,12 @@ describe('DotWorkflowsActionsService', () => {

it('should get default actions by content type', (done) => {
const contentTypeId = '123';
const mockResponse = mockWorkflowsActions.map((action) => ({
action
}));
const mockResponse = {
entity: MOCK_SINGLE_WORKFLOW_ACTIONS
};

spectator.service.getDefaultActions(contentTypeId).subscribe((res) => {
expect(res).toEqual(mockWorkflowsActions);
expect(res).toEqual(MOCK_SINGLE_WORKFLOW_ACTIONS);
done();
});

Expand All @@ -52,8 +56,59 @@ describe('DotWorkflowsActionsService', () => {
`/api/v1/workflow/initialactions/contenttype/${contentTypeId}`,
HttpMethod.GET
)
.flush(mockResponse);
});

it('should get workflow actions by content type name', (done) => {
const contentTypeName = 'Blog';
const mockWorkflowActionsResponse = [
{
scheme: mockWorkflows[0],
action: mockWorkflowsActions[0],
firstStep: {
id: '123',
name: 'First Step',
creationDate: 0,
enableEscalation: false,
escalationAction: null,
escalationTime: 0,
resolved: false,
schemeId: '123',
myOrder: 0
}
}
];

spectator.service.getWorkFlowActions(contentTypeName).subscribe((res) => {
expect(res).toEqual(mockWorkflowActionsResponse);
done();
});

spectator
.expectOne(
`/api/v1/workflow/defaultactions/contenttype/${contentTypeName}`,
HttpMethod.GET
)
.flush({
entity: mockWorkflowActionsResponse
});
});

it('should return empty array when workflow actions response is null', (done) => {
const contentTypeName = 'Blog';

spectator.service.getWorkFlowActions(contentTypeName).subscribe((res) => {
expect(res).toEqual([]);
done();
});

spectator
.expectOne(
`/api/v1/workflow/defaultactions/contenttype/${contentTypeName}`,
HttpMethod.GET
)
.flush({
entity: mockResponse
entity: null
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { Injectable, inject } from '@angular/core';
import { map, pluck } from 'rxjs/operators';

import { DotCMSResponse } from '@dotcms/dotcms-js';
import { DotCMSWorkflowAction, DotCMSWorkflow } from '@dotcms/dotcms-models';
import {
DotCMSContentletWorkflowActions,
DotCMSWorkflow,
DotCMSWorkflowAction
} from '@dotcms/dotcms-models';

export enum DotRenderMode {
LISTING = 'LISTING',
Expand Down Expand Up @@ -51,28 +55,40 @@ export class DotWorkflowsActionsService {

/**
* Returns the workflow actions of the passed contentType
*
* @param {string} inode
* @param {DotRenderMode} [renderMode]
* @returns {Observable<DotCMSWorkflowAction[]>}
* @memberof DotWorkflowsActionsService
*/
getDefaultActions(contentTypeId: string): Observable<DotCMSWorkflowAction[]> {
getDefaultActions(contentTypeId: string): Observable<DotCMSContentletWorkflowActions[]> {
return this.httpClient
.get<
DotCMSResponse<{ action: DotCMSWorkflowAction; scheme: DotCMSWorkflow }[]>
DotCMSResponse<DotCMSContentletWorkflowActions[]>
>(`${this.BASE_URL}/initialactions/contenttype/${contentTypeId}`)
.pipe(
pluck('entity'),
map((res = []) => {
return res.map(({ action }) => {
return action;
});
})
map((res) => res || [])
);
}

private getWorkFlowId(workflow: DotCMSWorkflow): string {
return workflow && workflow.id;
}

/**
* Returns the workflow actions of the passed content type name
*
* @param {string} contentTypeName
* @returns {Observable<DotCMSWorkflowActions>}
*/
getWorkFlowActions(contentTypeName: string): Observable<DotCMSContentletWorkflowActions[]> {
return this.httpClient
.get<
DotCMSResponse<DotCMSContentletWorkflowActions[]>
>(`${this.BASE_URL}/defaultactions/contenttype/${contentTypeName}`)
.pipe(
pluck('entity'),
map((res) => res || [])
);
}
}
20 changes: 20 additions & 0 deletions core-web/libs/dotcms-models/src/lib/dot-workflow-action.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DotCMSContentType } from './dot-content-types.model';
import { DotCMSWorkflow, WorkflowStep } from './dot-workflow.model';

export interface DotCMSWorkflowActionEvent {
workflow: DotCMSWorkflowAction;
Expand All @@ -24,6 +25,19 @@ export interface DotCMSWorkflowAction {
showOn: string[];
actionInputs: DotCMSWorkflowInput[];
metadata?: Record<string, string>;
hasArchiveActionlet?: boolean;
hasCommentActionlet?: boolean;
hasDeleteActionlet?: boolean;
hasDestroyActionlet?: boolean;
hasMoveActionletActionlet?: boolean;
hasMoveActionletHasPathActionlet?: boolean;
hasOnlyBatchActionlet?: boolean;
hasPublishActionlet?: boolean;
hasPushPublishActionlet?: boolean;
hasResetActionlet?: boolean;
hasSaveActionlet?: boolean;
hasUnarchiveActionlet?: boolean;
hasUnpublishActionlet?: boolean;
oidacra marked this conversation as resolved.
Show resolved Hide resolved
}

export enum DotCMSSystemActionType {
Expand Down Expand Up @@ -58,3 +72,9 @@ export interface DotCMSWorkflowInput {
id: string;
body: any;
}

export interface DotCMSContentletWorkflowActions {
scheme: DotCMSWorkflow;
action: DotCMSWorkflowAction;
firstStep: WorkflowStep;
}
1 change: 1 addition & 0 deletions core-web/libs/dotcms-models/src/lib/dot-workflow.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface DotCMSWorkflowStatus {
scheme: DotCMSWorkflow;
step: WorkflowStep;
task: WorkflowTask;
firstStep?: WorkflowStep;
}

export interface WorkflowStep {
Expand Down
Loading
Loading