From ed064918446065e4ada0f677d410ac51434744b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Enrique=20Colina=20Rodr=C3=ADguez?= Date: Tue, 5 Mar 2024 17:45:17 +0100 Subject: [PATCH 1/7] feat(CLI): #27286 deploy cli on new merged code into master (#27825) * #27286 Creating `publish npm package` workflow. * #27286 Testing `publish npm package` workflow from `cli-release-process`. * #27286 Creating a workflow to be trigger when a new merged is done. * #27286 Testing `cli-build-artifacts` workflow from `cli-release-process`. * #27286 Testing `cli-build-artifacts` workflow from `cli-release-process`. +1. * #27286 Testing `cli-build-artifacts` workflow from `cli-release-process`. +2. * #27286 Testing `cli-build-artifacts` workflow from `cli-release-process`. +3. * #27286 Testing `cli-build-artifacts` workflow from `cli-release-process`. +4. * #27286 Preparing triggering `cli-deploy-artifacts` test. * #27286 Removing the testing branch from trigger event branches. --------- Co-authored-by: Daniel Colina --- .github/workflows/cli-build-artifacts.yml | 28 ++++++-- .github/workflows/cli-deploy-artifacts.yml | 21 ++++++ .github/workflows/cli-release-process.yml | 26 ++++---- .github/workflows/publish-npm-package.yml | 75 ++++++++++++++++++++++ tools/dotcms-cli/jreleaser.yml | 2 - 5 files changed, 132 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/cli-deploy-artifacts.yml create mode 100644 .github/workflows/publish-npm-package.yml diff --git a/.github/workflows/cli-build-artifacts.yml b/.github/workflows/cli-build-artifacts.yml index ab0a6a510952..8ccb5762aae9 100644 --- a/.github/workflows/cli-build-artifacts.yml +++ b/.github/workflows/cli-build-artifacts.yml @@ -10,6 +10,19 @@ on: type: boolean branch: type: string + secrets: + dotcms-license: + description: 'DotCMS License Key' + required: true + artifactory-repo-username: + description: 'Artifactory Repository Username' + required: true + artifactory-repo-password: + description: 'Artifactory Repository Password' + required: true + github-token: + description: 'GitHub Token' + required: true env: JAVA_VERSION: 11 @@ -158,7 +171,7 @@ jobs: - name: 'Prepare dotCMS license' if: ${{ inputs.skipTests == false }} env: - DOTCMS_LICENSE_KEY: ${{ secrets.DOTCMS_LICENSE }} + DOTCMS_LICENSE_KEY: ${{ secrets.dotcms-license }} run: | DOTCMS_LICENSE_PATH=${{ github.workspace }}/tools/dotcms-cli/license mkdir -p ${DOTCMS_LICENSE_PATH} @@ -251,12 +264,17 @@ jobs: - name: 'Upload to Artifactory' env: - JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JRELEASER_ARTIFACTORY_USERNAME: ${{ secrets.EE_REPO_USERNAME }} - JRELEASER_ARTIFACTORY_PASSWORD: ${{ secrets.EE_REPO_PASSWORD }} + JRELEASER_GITHUB_TOKEN: ${{ secrets.github-token }} + JRELEASER_ARTIFACTORY_USERNAME: ${{ secrets.artifactory-repo-username }} + JRELEASER_ARTIFACTORY_PASSWORD: ${{ secrets.artifactory-repo-password }} working-directory: ${{ github.workspace }} run: | - tools/dotcms-cli/mvnw -B -Prelease jreleaser:upload -DartifactsDir=artifacts -Djreleaser.git.root.search=true -pl :dotcms-cli-parent -Dmaven.plugin.validation=VERBOSE + if [[ "${{ inputs.buildNativeImage }}" == "true" ]]; then + DOTCMS_CLI_NATIVE_ACTIVE=ALWAYS + else + DOTCMS_CLI_NATIVE_ACTIVE=NEVER + fi + tools/dotcms-cli/mvnw -B -Prelease jreleaser:upload -DartifactsDir=artifacts -Djreleaser.distributions.dotcms.cli.native.active=$DOTCMS_CLI_NATIVE_ACTIVE -Djreleaser.git.root.search=true -pl :dotcms-cli-parent -Dmaven.plugin.validation=VERBOSE - name: 'Cleanup' run: | diff --git a/.github/workflows/cli-deploy-artifacts.yml b/.github/workflows/cli-deploy-artifacts.yml new file mode 100644 index 000000000000..4446f9b4e38a --- /dev/null +++ b/.github/workflows/cli-deploy-artifacts.yml @@ -0,0 +1,21 @@ +name: 'CLI Deploy Artifacts' +on: + push: + branches: + - 'master' + - 'main' + - 'trunk' + - 'release-*' +jobs: + build: + uses: ./.github/workflows/cli-build-artifacts.yml + with: + skipTests: true + buildNativeImage: false + uploadArtifacts: true + branch: ${{ github.ref_name }} + secrets: + dotcms-license: ${{ secrets.DOTCMS_LICENSE }} + artifactory-repo-username: ${{ secrets.EE_REPO_USERNAME }} + artifactory-repo-password: ${{ secrets.EE_REPO_PASSWORD }} + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/cli-release-process.yml b/.github/workflows/cli-release-process.yml index fd42d393e693..0f29ec9bf92d 100644 --- a/.github/workflows/cli-release-process.yml +++ b/.github/workflows/cli-release-process.yml @@ -347,55 +347,55 @@ jobs: # Distinguishes between snapshots and releases - name: 'Dynamic configuration of NPM package Version and Tag' run: | - MVN_PACKAGE_VERSION=$(echo ${{ github.event.inputs.version }} | tr '[:lower:]' '[:upper:]') + MVN_PACKAGE_VERSION=$(echo ${{ github.event.inputs.version }} | tr '[:lower:]' '[:upper:]') PACKAGE_FULL_NAME=${{ env.NPM_PACKAGE_SCOPE }}/${{ env.NPM_PACKAGE_NAME }} - + # Check if the npm package exists if ! npm view $PACKAGE_FULL_NAME &> /dev/null; then echo "::error::The package $PACKAGE_FULL_NAME does not exist on npm." exit 1 fi - + # Check if the package is a snapshot REGEX="([0-9]+\.[0-9]+\.[0-9]+)-SNAPSHOT" - + if [[ $MVN_PACKAGE_VERSION =~ $REGEX ]]; then echo "::debug::Snapshot version found." - + NPM_PACKAGE_VERSION_TAG="rc" MVN_BASE_VERSION="${BASH_REMATCH[1]}" - + # Use regular expression to extract version components if [[ $MVN_BASE_VERSION =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then MAJOR=$(echo "${BASH_REMATCH[1]}" | sed "s/\b0\+\([1-9]\)/\1/g") MINOR=$(echo "${BASH_REMATCH[2]}" | sed "s/\b0\+\([1-9]\)/\1/g") PATCH=$(echo "${BASH_REMATCH[3]}" | sed "s/\b0\+\([1-9]\)/\1/g") VERSION_NPM_FORMAT="${MAJOR}.${MINOR}.${PATCH}" - + echo "::debug::VERSION_NPM_FORMAT: ${VERSION_NPM_FORMAT}" else echo "::error::Invalid Maven version format: $MVN_BASE_VERSION" exit 1 fi - + LAST_RC_VERSION=$(npm view $PACKAGE_FULL_NAME versions --json | jq -r 'map(select(test("-rc\\d+$"))) | max') - + if [[ $LAST_RC_VERSION == "$VERSION_NPM_FORMAT"* ]]; then NEXT_RC_VERSION=$(echo "$LAST_RC_VERSION" | awk -F '-rc' '{print $1 "-rc" $2 + 1}') RC_SUFFIX=$(echo "$NEXT_RC_VERSION" | sed -n 's/.*-rc\([0-9]*\)/-rc\1/p') else RC_SUFFIX="-rc1" fi; - + NPM_PACKAGE_VERSION=${MVN_BASE_VERSION}${RC_SUFFIX} else echo "::debug::Release version found." NPM_PACKAGE_VERSION_TAG="latest" NPM_PACKAGE_VERSION=${MVN_PACKAGE_VERSION} - fi; + fi; echo "::debug::NPM_PACKAGE_VERSION: $NPM_PACKAGE_VERSION" echo "::debug::NPM_PACKAGE_VERSION_TAG: $NPM_PACKAGE_VERSION_TAG" - + echo "NPM_PACKAGE_VERSION=$NPM_PACKAGE_VERSION" >> $GITHUB_ENV echo "NPM_PACKAGE_VERSION_TAG=$NPM_PACKAGE_VERSION_TAG" >> $GITHUB_ENV @@ -449,4 +449,4 @@ jobs: - name: 'Delete release auxiliary branch - ${{ needs.precheck.outputs.AUXILIARY_BRANCH }}' run: | - git push origin --delete ${{ needs.precheck.outputs.AUXILIARY_BRANCH }} + git push origin --delete ${{ needs.precheck.outputs.AUXILIARY_BRANCH }} \ No newline at end of file diff --git a/.github/workflows/publish-npm-package.yml b/.github/workflows/publish-npm-package.yml new file mode 100644 index 000000000000..9d48ba6ae0d4 --- /dev/null +++ b/.github/workflows/publish-npm-package.yml @@ -0,0 +1,75 @@ +name: 'Publish NPM Package' +on: + workflow_call: + inputs: + ref: + description: 'Ref to checkout' + required: true + type: string + artifact-id: + description: 'Artifact id' + required: true + type: string + run-id: + description: 'Run id' + required: true + type: number + npm-package-version-tag: + description: 'NPM package version tag' + required: true + type: string + secrets: + gh-pat: + description: 'GitHub Personal Access Token' + required: true + npm-token: + description: 'NPM registry token' + required: false + +env: + NODE_VERSION: 19 + +jobs: + publish-npm-package: + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + + - uses: ./.github/actions/cleanup-runner + + - name: 'Set up Node.js' + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: 'Download all build artifacts' + uses: actions/download-artifact@v4 + with: + path: ${{ github.workspace }}/npm-package + name: ${{ inputs.artifact-id }} + run-id: ${{ inputs.run-id }} + github-token: ${{ secrets.gh-pat }} # token with actions:read permissions on target repo + + - name: 'Validate NPM package' + run: | + echo "::group::NPM package contents" + if [ ! -f ${{ github.workspace }}/npm-package/package.json ]; then + echo "::error::NPM package not found. Exiting..." + exit 1 + else + echo "::notice::NPM package found. Proceeding..." + cat ${{ github.workspace }}/npm-package/package.json + fi + + - name: 'Publish to NPM registry' + if: success() + working-directory: ${{ github.workspace }}/npm-package + env: + NPM_AUTH_TOKEN: ${{ secrets.npm-token }} + NPM_PACKAGE_VERSION_TAG: ${{ inputs.npm-package-version-tag }} + run: | + echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > ~/.npmrc + npm publish --access public --tag ${NPM_PACKAGE_VERSION_TAG} diff --git a/tools/dotcms-cli/jreleaser.yml b/tools/dotcms-cli/jreleaser.yml index f482e44b78a0..fd73ce2ce21e 100644 --- a/tools/dotcms-cli/jreleaser.yml +++ b/tools/dotcms-cli/jreleaser.yml @@ -58,8 +58,6 @@ distributions: platform: 'osx-x86_64' - path: '{{artifactsDir}}/distributions/dotcms-cli-{{projectVersion}}-linux-x86_64.zip' platform: 'linux-x86_64' -# - path: '{{artifactsDir}}/distributions/dotcms-cli-{{projectVersion}}-windows-x86_64.zip' -# platform: 'windows-x86_64' upload: artifactory: From 2501582bdcb40ece155dd777b54a32a15eb3dea0 Mon Sep 17 00:00:00 2001 From: spbolton Date: Tue, 5 Mar 2024 11:48:41 -0500 Subject: [PATCH 2/7] chore: fix ide docker run (#27779) * fix it test in docker ide * fix ide docker run * fix merge conflict --- dotcms-integration/pom.xml | 15 +------ justfile | 16 ++++---- parent/pom.xml | 80 +++++++------------------------------- 3 files changed, 23 insertions(+), 88 deletions(-) diff --git a/dotcms-integration/pom.xml b/dotcms-integration/pom.xml index dd7c3a3b23ef..803039b807a8 100644 --- a/dotcms-integration/pom.xml +++ b/dotcms-integration/pom.xml @@ -196,18 +196,6 @@ - - - - - run-it-tests - - - coreit.test.skip - !true - - - org.apache.maven.plugins @@ -477,8 +465,7 @@ - - + quick-test diff --git a/justfile b/justfile index bdd8baebb6cf..66ef3510b060 100644 --- a/justfile +++ b/justfile @@ -30,7 +30,7 @@ build: # Builds the project without running tests, skip using docker or creating image build-no-docker: - ./mvnw -DskipTests clean install -Dskip.docker=true + ./mvnw -DskipTests clean install -Dxd=true # Builds the project and runs the default test suite build-test: @@ -60,15 +60,15 @@ build-select-module-deps module=":dotcms-core": # Starts the dotCMS application in a Docker container on a dynamic port, running in the foreground dev-run: - ./mvnw -pl :dotcms-core -Pdocker-run + ./mvnw -pl :dotcms-core -Pdocker-start # Maps paths in the docker container to local paths, useful for development dev-run-map-dev-paths: - ./mvnw -pl :dotcms-core -Pdocker-run -Pmap-dev-paths + ./mvnw -pl :dotcms-core -Pocker-start -Pmap-dev-paths # Starts the dotCMS application in debug mode with suspension, useful for troubleshooting dev-run-debug-suspend: - ./mvnw -pl :dotcms-core -Pdocker-run,debug-suspend + ./mvnw -pl :dotcms-core -Pdocker-start,debug-suspend # Starts the dotCMS Docker container in the background dev-start: @@ -92,12 +92,12 @@ dev-tomcat-stop: # Testing Commands # Executes a specified set of Postman tests -test-postman collections='': +test-postman collections='page': ./mvnw -pl :dotcms-postman verify -Dpostman.test.skip=false -Pdebug -Dpostman.collections={{ collections }} # Stops Postman-related Docker containers postman-stop: - ./mvnw -pl :dotcms-postman -Pdocker-stop + ./mvnw -pl :dotcms-postman -Pdocker-stop -Dpostman.test.skip=false # Runs all integration tests test-integration: @@ -109,11 +109,11 @@ test-integration-debug-suspend: # Prepares the environment for running integration tests in an IDE test-integration-ide: - ./mvnw -pl :dotcms-integration -Pdocker-start + ./mvnw -pl :dotcms-integration -Pdocker-start -Dcoreit.test.skip=false # Stops integration test services test-integration-stop: - ./mvnw -pl :dotcms-integration -Pdocker-stop + ./mvnw -pl :dotcms-integration -Pdocker-stop -Dcoreit.test.skip=false # Docker Commands # Runs a published dotCMS Docker image on a dynamic port diff --git a/parent/pom.xml b/parent/pom.xml index afe88a1ed2d1..e954abc22e98 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1342,25 +1342,30 @@ io.fabric8 docker-maven-plugin - + + false + - docker-pre-stop + docker-pre-stop-runner stop validate + false true - docker-start + docker-start-runner start validate - + + false + @@ -1390,66 +1395,7 @@ - - docker-run - - false - - - true - - - validate - - - io.fabric8 - docker-maven-plugin - - - - docker-pre-stop - - stop - - validate - - - - docker-start - - run - - validate - - - - - - org.apache.maven.plugins - maven-antrun-plugin - - - - run - - validate - - - - - - - - - - - - - - - - - + docker-stop @@ -1480,7 +1426,9 @@ io.fabric8 docker-maven-plugin - + + false + docker-stop @@ -1510,7 +1458,7 @@ - docker-stop + docker-stop-runner stop From 4db85b173cfce807417e05ba334979e8fb58a328 Mon Sep 17 00:00:00 2001 From: Rafael Velazco Date: Tue, 5 Mar 2024 13:33:14 -0400 Subject: [PATCH 3/7] feat(edit-page): Edit content shortcut when edit url content map page (#27789) * feat: add Edit URL Content Button * chore: code cleanup * feat: let user edit url content map * chore: code cleanup * chore: code cleanup * chore: fix tests * chore: add tests * chore: add tests * chore: code cleanup * chore: fix tests * feedback v1 * feedback v2 --- .../dot-ema-dialog.component.spec.ts | 15 +- .../dot-ema-dialog.component.ts | 21 +- .../store/dot-ema-dialog.store.spec.ts | 17 ++ .../store/dot-ema-dialog.store.ts | 32 ++- .../dot-ema-shell/dot-ema-shell.component.ts | 10 +- .../dot-ema-shell/store/dot-ema.store.spec.ts | 34 +++- .../lib/dot-ema-shell/store/dot-ema.store.ts | 24 ++- .../edit-ema-editor.component.html | 9 +- .../edit-ema-editor.component.spec.ts | 184 +++++++++++++----- .../edit-ema-editor.component.ts | 101 ++++++---- .../src/lib/services/dot-page-api.service.ts | 2 + .../edit-ema/portlet/src/lib/shared/models.ts | 5 + .../WEB-INF/messages/Language.properties | 1 + .../ext/contentlet/edit_contentlet_js_inc.jsp | 18 +- 14 files changed, 366 insertions(+), 107 deletions(-) diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.spec.ts b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.spec.ts index adf4d13caf69..59ae21eaf96d 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.spec.ts +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.spec.ts @@ -8,7 +8,7 @@ import { By } from '@angular/platform-browser'; import { DotMessageService } from '@dotcms/data-access'; import { CoreWebService } from '@dotcms/dotcms-js'; -import { DotCMSBaseTypesContentTypes } from '@dotcms/dotcms-models'; +import { DotCMSBaseTypesContentTypes, DotCMSContentlet } from '@dotcms/dotcms-models'; import { MockDotMessageService } from '@dotcms/utils-testing'; import { DotEmaDialogComponent } from './dot-ema-dialog.component'; @@ -154,7 +154,18 @@ describe('DotEmaDialogComponent', () => { it('should trigger editContentlet in the store', () => { const editContentletSpy = jest.spyOn(storeSpy, 'editContentlet'); - component.editContentlet(PAYLOAD_MOCK); + component.editContentlet(PAYLOAD_MOCK.contentlet); + + expect(editContentletSpy).toHaveBeenCalledWith({ + inode: PAYLOAD_MOCK.contentlet.inode, + title: PAYLOAD_MOCK.contentlet.title + }); + }); + + it('should trigger editContentlet in the store for url Map', () => { + const editContentletSpy = jest.spyOn(storeSpy, 'editUrlContentMapContentlet'); + + component.editUrlContentMapContentlet(PAYLOAD_MOCK.contentlet as DotCMSContentlet); expect(editContentletSpy).toHaveBeenCalledWith({ inode: PAYLOAD_MOCK.contentlet.inode, diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.ts b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.ts index d4981df3abb4..e087fc21ab6e 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.ts +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/dot-ema-dialog.component.ts @@ -15,7 +15,7 @@ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'; import { DialogModule } from 'primeng/dialog'; -import { DotCMSBaseTypesContentTypes } from '@dotcms/dotcms-models'; +import { DotCMSBaseTypesContentTypes, DotCMSContentlet } from '@dotcms/dotcms-models'; import { DotSpinnerModule, SafeUrlPipe } from '@dotcms/ui'; import { @@ -111,16 +111,29 @@ export class DotEmaDialogComponent { /** * Edit contentlet * - * @param {ActionPayload} payload - * @memberof EditEmaEditorComponent + * @param {Partial} contentlet + * @memberof DotEmaDialogComponent */ - editContentlet({ contentlet }: Partial) { + editContentlet(contentlet: Partial) { this.store.editContentlet({ inode: contentlet.inode, title: contentlet.title }); } + /** + * Edit URL Content Map Contentlet + * + * @param {DotCMSContentlet} { inode, title } + * @memberof DotEmaDialogComponent + */ + editUrlContentMapContentlet({ inode, title }: DotCMSContentlet) { + this.store.editUrlContentMapContentlet({ + inode, + title + }); + } + /** * Create contentlet form * diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.spec.ts b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.spec.ts index c5cd64096c14..e7bc9267aa3d 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.spec.ts +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.spec.ts @@ -80,6 +80,23 @@ describe('DotEmaDialogStoreService', () => { }); }); + it('should initialize with edit iframe properties', (done) => { + spectator.service.editUrlContentMapContentlet({ + inode: '123', + title: 'test' + }); + + spectator.service.dialogState$.subscribe((state) => { + expect(state).toEqual({ + url: EDIT_CONTENTLET_URL + '123&isURLMap=true', + status: DialogStatus.LOADING, + header: 'test', + type: 'content' + }); + done(); + }); + }); + it('should initialize with addA iframe properties', (done) => { spectator.service.addContentlet({ containerId: '1234', diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.ts b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.ts index 797b40cef42f..686f72bb6969 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.ts +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/components/dot-ema-dialog/store/dot-ema-dialog.store.ts @@ -34,6 +34,11 @@ export interface CreateFromPaletteAction { payload: ActionPayload; } +interface EditContentletPayload { + inode: string; + title: string; +} + @Injectable() export class DotEmaDialogStore extends ComponentStore { constructor() { @@ -122,16 +127,35 @@ export class DotEmaDialogStore extends ComponentStore { * * @memberof DotEmaDialogStore */ - readonly editContentlet = this.updater((state, payload: { inode: string; title: string }) => { + readonly editContentlet = this.updater((state, { inode, title }: EditContentletPayload) => { return { ...state, - header: payload.title, + header: title, status: DialogStatus.LOADING, - url: this.createEditContentletUrl(payload.inode), - type: 'content' + type: 'content', + url: this.createEditContentletUrl(inode) }; }); + /** + * This method is called when the user clicks on the edit URL Content Map button + * + * @memberof DotEmaDialogStore + */ + readonly editUrlContentMapContentlet = this.updater( + (state, { inode, title }: EditContentletPayload) => { + const url = this.createEditContentletUrl(inode) + '&isURLMap=true'; + + return { + ...state, + header: title, + status: DialogStatus.LOADING, + type: 'content', + url + }; + } + ); + /** * This method is called when the user clicks on the [+ add] button * diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/dot-ema-shell.component.ts b/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/dot-ema-shell.component.ts index b7d7afdd679d..2f72ada597b1 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/dot-ema-shell.component.ts +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/dot-ema-shell.component.ts @@ -155,12 +155,10 @@ export class DotEmaShellComponent implements OnInit, OnDestroy { label: 'editema.editor.navbar.properties', action: () => { this.dialog.editContentlet({ - contentlet: { - inode: page.inode, - title: page.title, - identifier: page.identifier, - contentType: page.contentType - } + inode: page.inode, + title: page.title, + identifier: page.identifier, + contentType: page.contentType }); } } diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.spec.ts b/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.spec.ts index e0b35a29f784..620f93fb0b7c 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.spec.ts +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.spec.ts @@ -190,6 +190,36 @@ describe('EditEmaStore', () => { }); }); + it('should handle successful data reload', (done) => { + const dotPageApiService = spectator.inject(DotPageApiService); + const spyWhenReloaded = jest.fn(); + const spyGetPage = jest + .spyOn(dotPageApiService, 'get') + .mockReturnValue(of(MOCK_RESPONSE_HEADLESS)); + const params = { + language_id: '1', + url: 'test-url', + 'com.dotmarketing.persona.id': '123' + }; + + spectator.service.reload({ + params, + whenReloaded: spyWhenReloaded + }); + + spectator.service.state$.subscribe((state) => { + expect(state).toEqual({ + clientHost: 'http://localhost:3000', + editor: MOCK_RESPONSE_HEADLESS, + isEnterpriseLicense: true, + editorState: EDITOR_STATE.LOADED + }); + expect(spyGetPage).toHaveBeenCalledWith(params); + expect(spyWhenReloaded).toHaveBeenCalled(); + done(); + }); + }); + it("should call save method from dotPageApiService when 'save' action is dispatched", () => { const dotPageApiService = spectator.inject(DotPageApiService); const mockResponse = { @@ -490,7 +520,7 @@ describe('EditEmaStore', () => { clientHost: undefined, editor: MOCK_RESPONSE_VTL, apiURL: 'http://localhost/api/v1/page/json/test-url?language_id=1&com.dotmarketing.persona.id=modes.persona.no.persona&mode=EDIT_MODE', - iframeURL: null, + iframeURL: '', isEnterpriseLicense: true, favoritePageURL: '/test-url?host_id=123-xyz-567-xxl&language_id=1', state: EDITOR_STATE.LOADED @@ -509,7 +539,7 @@ describe('EditEmaStore', () => { clientHost: undefined, editor: MOCK_RESPONSE_VTL, apiURL: 'http://localhost/api/v1/page/json/test-url?language_id=1&com.dotmarketing.persona.id=modes.persona.no.persona&mode=EDIT_MODE', - iframeURL: null, + iframeURL: '', isEnterpriseLicense: true, favoritePageURL: '/test-url?host_id=123-xyz-567-xxl&language_id=1', state: EDITOR_STATE.LOADED diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.ts b/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.ts index a69c572c5d5a..fba02fc84d7b 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.ts +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/dot-ema-shell/store/dot-ema.store.ts @@ -18,7 +18,7 @@ import { } from '../../services/dot-page-api.service'; import { DEFAULT_PERSONA } from '../../shared/consts'; import { EDITOR_STATE } from '../../shared/enums'; -import { ActionPayload, SavePagePayload } from '../../shared/models'; +import { ActionPayload, ReloadPagePayload, SavePagePayload } from '../../shared/models'; import { insertContentletInContainer, sanitizeURL, getPersonalization } from '../../utils'; export interface EditEmaState { @@ -86,7 +86,7 @@ export class EditEmaStore extends ComponentStore { siteId: state.editor.site.identifier }); - const iframeURL = state.clientHost ? `${state.clientHost}/${pageURL}` : null; + const iframeURL = state.clientHost ? `${state.clientHost}/${pageURL}` : ''; return { clientHost: state.clientHost, @@ -105,6 +105,8 @@ export class EditEmaStore extends ComponentStore { }; }); + readonly clientHost$ = this.select((state) => state.clientHost); + readonly layoutProperties$ = this.select((state) => ({ layout: state.editor.layout, themeId: state.editor.template.theme, @@ -174,6 +176,24 @@ export class EditEmaStore extends ComponentStore { } ); + readonly reload = this.effect((payload$: Observable) => { + return payload$.pipe( + tap(() => this.updateEditorState(EDITOR_STATE.LOADING)), + switchMap(({ params, whenReloaded }) => { + return this.dotPageApiService.get(params).pipe( + tapResponse({ + next: (editor) => + this.patchState({ editor, editorState: EDITOR_STATE.LOADED }), + error: ({ status }: HttpErrorResponse) => + this.createEmptyState({ canEdit: false, canRead: false }, status), + finalize: () => whenReloaded?.() + }), + catchError(() => EMPTY) + ); + }) + ); + }); + /** * Saves data to a page. * Calls `whenSaved` callback on success or error. diff --git a/core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-editor/edit-ema-editor.component.html b/core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-editor/edit-ema-editor.component.html index 6bd1856597be..c5201b72061c 100644 --- a/core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-editor/edit-ema-editor.component.html +++ b/core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-editor/edit-ema-editor.component.html @@ -15,6 +15,13 @@ icon="pi pi-desktop" styleClass="p-button-text p-button-sm" data-testId="ema-preview" /> +