Skip to content

Commit

Permalink
chore(edit-content): sync with master #30216
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Nov 8, 2024
2 parents f87007a + 7a5f044 commit 8d4f59b
Show file tree
Hide file tree
Showing 52 changed files with 1,102 additions and 778 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
computed,
inject,
input,
model,
Expand Down Expand Up @@ -56,18 +55,7 @@ export class DotSideBarComponent {
*/
$fakeColumns = signal<string[]>(Array.from({ length: 50 }).map((_) => this.getPercentage()));

$state = computed(() => {
const folders = this.$folders();

console.log(folders);

return {
folders,
defaultFile: folders.find((folder) => folder.data.identifier === 'SYSTEM_HOST')
};
});

$selectedFile = model<TreeNode | null>(this.$state().defaultFile);
$selectedFile = model<TreeNode | null>(null);

/**
* Event emitter for when a tree node is expanded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { Tooltip } from 'primeng/tooltip';
import {
DotExperimentsService,
DotHttpErrorManagerService,
DotMessageService,
DotSessionStorageService
DotMessageService
} from '@dotcms/data-access';
import {
DEFAULT_VARIANT_ID,
Expand Down Expand Up @@ -77,7 +76,6 @@ describe('DotExperimentsConfigurationVariantsComponent', () => {
let dotExperimentsService: SpyObject<DotExperimentsService>;
let router: Router;

let dotSessionStorageService: DotSessionStorageService;
let confirmationService: ConfirmationService;

const createComponent = createComponentFactory({
Expand All @@ -97,7 +95,6 @@ describe('DotExperimentsConfigurationVariantsComponent', () => {
mockProvider(DotExperimentsService),
mockProvider(MessageService),
mockProvider(DotHttpErrorManagerService),
mockProvider(DotSessionStorageService),
mockProvider(Router)
]
});
Expand All @@ -112,7 +109,6 @@ describe('DotExperimentsConfigurationVariantsComponent', () => {
store = spectator.inject(DotExperimentsConfigurationStore);
router = spectator.inject(Router);

dotSessionStorageService = spectator.inject(DotSessionStorageService);
confirmationService = spectator.inject(ConfirmationService);

dotExperimentsService = spectator.inject(DotExperimentsService);
Expand Down Expand Up @@ -247,7 +243,6 @@ describe('DotExperimentsConfigurationVariantsComponent', () => {
it('should goToEditPage emit a variant and mode(preview) when View button is clicked', () => {
spectator.click(byTestId('variant-preview-button'));

expect(dotSessionStorageService.setVariationId).toHaveBeenCalledWith(variants[0].id);
expect(router.navigate).toHaveBeenCalledWith(['edit-page/content'], {
queryParams: {
mode: DotPageMode.PREVIEW,
Expand All @@ -261,7 +256,6 @@ describe('DotExperimentsConfigurationVariantsComponent', () => {
it('should goToEditPage emit a variant and mode(edit) when edit button is clicked', () => {
spectator.click(byTestId('variant-edit-button'));

expect(dotSessionStorageService.setVariationId).toHaveBeenCalledWith(variants[1].id);
expect(router.navigate).toHaveBeenCalledWith(['edit-page/content'], {
queryParams: {
mode: DotPageMode.EDIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TooltipModule } from 'primeng/tooltip';

import { tap } from 'rxjs/operators';

import { DotMessageService, DotSessionStorageService } from '@dotcms/data-access';
import { DotMessageService } from '@dotcms/data-access';
import {
ComponentStatus,
DEFAULT_VARIANT_NAME,
Expand Down Expand Up @@ -85,7 +85,6 @@ export class DotExperimentsConfigurationVariantsComponent {
constructor(
private readonly dotExperimentsConfigurationStore: DotExperimentsConfigurationStore,
private readonly confirmationService: ConfirmationService,
private readonly dotSessionStorageService: DotSessionStorageService,
private readonly dotMessageService: DotMessageService,
private readonly router: Router,
private readonly route: ActivatedRoute
Expand Down Expand Up @@ -157,7 +156,6 @@ export class DotExperimentsConfigurationVariantsComponent {
* @memberof DotExperimentsConfigurationVariantsComponent
*/
goToEditPageVariant(variant: Variant, mode: DotPageMode) {
this.dotSessionStorageService.setVariationId(variant.id);
this.router.navigate(['edit-page/content'], {
queryParams: {
variantName: variant.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { of } from 'rxjs';

import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { signal } from '@angular/core';
import { By } from '@angular/platform-browser';

import { MessageService } from 'primeng/api';
Expand Down Expand Up @@ -42,6 +43,7 @@ import { DotEmaWorkflowActionsService } from '../../services/dot-ema-workflow-ac
import { FormStatus, NG_CUSTOM_EVENTS } from '../../shared/enums';
import { MOCK_RESPONSE_HEADLESS, PAYLOAD_MOCK } from '../../shared/mocks';
import { DotPage } from '../../shared/models';
import { UVEStore } from '../../store/dot-uve.store';

describe('DotEmaDialogComponent', () => {
let spectator: Spectator<DotEmaDialogComponent>;
Expand Down Expand Up @@ -85,6 +87,14 @@ describe('DotEmaDialogComponent', () => {
HttpClient,
DotWorkflowActionsFireService,
MessageService,
{
provide: UVEStore,
useValue: {
params: signal({
variantName: 'DEFAULT' // Is the only thing we need to test the component
})
}
},
{
provide: DotcmsConfigService,
useValue: new DotcmsConfigServiceMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { expect, it, describe } from '@jest/globals';
import { SpectatorService, createServiceFactory } from '@ngneat/spectator/jest';
import { of } from 'rxjs';

import { signal } from '@angular/core';

import { CLIENT_ACTIONS } from '@dotcms/client';
import { DotMessageService } from '@dotcms/data-access';
import { MockDotMessageService } from '@dotcms/utils-testing';
Expand All @@ -13,6 +15,9 @@ import { LAYOUT_URL } from '../../../shared/consts';
import { DialogStatus, FormStatus } from '../../../shared/enums';
import { PAYLOAD_MOCK } from '../../../shared/mocks';
import { DotPage } from '../../../shared/models';
import { UVEStore } from '../../../store/dot-uve.store';

const TEST_VARIANT = 'my-test-variant';

describe('DotEmaDialogStoreService', () => {
let spectator: SpectatorService<DotEmaDialogStore>;
Expand All @@ -21,6 +26,15 @@ describe('DotEmaDialogStoreService', () => {
service: DotEmaDialogStore,
mocks: [DotActionUrlService],
providers: [
{
provide: UVEStore,
useValue: {
params: signal({
variantName: TEST_VARIANT // Is the only thing we need to test the component
})
}
},

{
provide: DotMessageService,
useValue: new MockDotMessageService({
Expand Down Expand Up @@ -108,7 +122,8 @@ describe('DotEmaDialogStoreService', () => {
p_p_mode: 'view',
_content_struts_action: '/ext/contentlet/edit_contentlet',
_content_cmd: 'edit',
inode: '123'
inode: '123',
variantName: TEST_VARIANT
});

spectator.service.dialogState$.subscribe((state) => {
Expand Down Expand Up @@ -141,7 +156,8 @@ describe('DotEmaDialogStoreService', () => {
p_p_mode: 'view',
_content_struts_action: '/ext/contentlet/edit_contentlet',
_content_cmd: 'edit',
inode: '123'
inode: '123',
variantName: TEST_VARIANT
});

spectator.service.dialogState$.subscribe((state) => {
Expand Down Expand Up @@ -173,7 +189,8 @@ describe('DotEmaDialogStoreService', () => {
p_p_mode: 'view',
_content_struts_action: '/ext/contentlet/edit_contentlet',
_content_cmd: 'edit',
inode: '123'
inode: '123',
variantName: TEST_VARIANT
});

spectator.service.dialogState$.subscribe((state) => {
Expand Down Expand Up @@ -202,7 +219,9 @@ describe('DotEmaDialogStoreService', () => {

spectator.service.dialogState$.subscribe((state) => {
expect(state).toEqual({
url: '/html/ng-contentlet-selector.jsp?ng=true&container_id=1234&add=test&language_id=1',
url:
'/html/ng-contentlet-selector.jsp?ng=true&container_id=1234&add=test&language_id=1&' +
new URLSearchParams({ variantName: TEST_VARIANT }).toString(),
header: 'Search Content',
type: 'content',
status: DialogStatus.LOADING,
Expand Down Expand Up @@ -246,7 +265,9 @@ describe('DotEmaDialogStoreService', () => {

spectator.service.dialogState$.subscribe((state) => {
expect(state).toEqual({
url: 'some/really/long/url',
url:
'http://localhost/some/really/long/url?' +
new URLSearchParams({ variantName: TEST_VARIANT }).toString(),
status: DialogStatus.LOADING,
header: 'Create test',
type: 'content',
Expand All @@ -271,7 +292,10 @@ describe('DotEmaDialogStoreService', () => {
spectator.service.dialogState$.subscribe((state) => {
expect(state.header).toBe('Create Blog Posts');
expect(state.status).toBe(DialogStatus.LOADING);
expect(state.url).toBe('some/really/long/url');
expect(state.url).toBe(
'http://localhost/some/really/long/url?' +
new URLSearchParams({ variantName: TEST_VARIANT }).toString()
);
expect(state.type).toBe('content');
expect(state.actionPayload).toEqual(PAYLOAD_MOCK);
done();
Expand All @@ -294,7 +318,10 @@ describe('DotEmaDialogStoreService', () => {
expect(state.header).toBe('Create Blog');
expect(state.status).toBe(DialogStatus.LOADING);

expect(state.url).toBe('https://demo.dotcms.com/jsp.jsp');
expect(state.url).toBe(
'https://demo.dotcms.com/jsp.jsp?' +
new URLSearchParams({ variantName: TEST_VARIANT }).toString()
);
expect(state.type).toBe('content');
expect(state.actionPayload).toEqual(PAYLOAD_MOCK);
done();
Expand Down Expand Up @@ -370,7 +397,8 @@ describe('DotEmaDialogStoreService', () => {
inode: '',
lang: '2',
populateaccept: 'true',
reuseLastLang: 'true'
reuseLastLang: 'true',
variantName: TEST_VARIANT
});

spectator.service.dialogState$.subscribe((state) => {
Expand Down Expand Up @@ -415,7 +443,8 @@ describe('DotEmaDialogStoreService', () => {
inode: '',
lang: '2',
populateaccept: 'true',
reuseLastLang: 'true'
reuseLastLang: 'true',
variantName: TEST_VARIANT
});

spectator.service.dialogState$.subscribe((state) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EditContentletPayload,
EditEmaDialogState
} from '../../../shared/models';
import { UVEStore } from '../../../store/dot-uve.store';

@Injectable()
export class DotEmaDialogStore extends ComponentStore<EditEmaDialogState> {
Expand All @@ -41,6 +42,8 @@ export class DotEmaDialogStore extends ComponentStore<EditEmaDialogState> {

private dotMessageService = inject(DotMessageService);

private uveStore = inject(UVEStore);

readonly dialogState$ = this.select((state) => state);

/**
Expand Down Expand Up @@ -97,9 +100,13 @@ export class DotEmaDialogStore extends ComponentStore<EditEmaDialogState> {
*/
readonly createContentlet = this.updater(
(state, { url, contentType, actionPayload }: CreateContentletAction) => {
const completeURL = new URL(url, window.location.origin);

completeURL.searchParams.set('variantName', this.uveStore.params().variantName);

return {
...state,
url,
url: completeURL.toString(),
actionPayload,
header: this.dotMessageService.get(
'contenttypes.content.create.contenttype',
Expand Down Expand Up @@ -295,7 +302,8 @@ export class DotEmaDialogStore extends ComponentStore<EditEmaDialogState> {
p_p_mode: 'view',
_content_struts_action: '/ext/contentlet/edit_contentlet',
_content_cmd: 'edit',
inode: inode
inode: inode,
variantName: this.uveStore.params().variantName
});

return `${LAYOUT_URL}?${queryParams.toString()}`;
Expand All @@ -322,7 +330,8 @@ export class DotEmaDialogStore extends ComponentStore<EditEmaDialogState> {
ng: 'true',
container_id: containerId,
add: acceptTypes,
language_id
language_id,
variantName: this.uveStore.params().variantName
});

return `${CONTENTLET_SELECTOR_URL}?${queryParams.toString()}`;
Expand All @@ -344,7 +353,8 @@ export class DotEmaDialogStore extends ComponentStore<EditEmaDialogState> {
inode: '',
lang: newLanguage.toString(),
populateaccept: 'true',
reuseLastLang: 'true'
reuseLastLang: 'true',
variantName: this.uveStore.params().variantName
});

return `${LAYOUT_URL}?${queryParams.toString()}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('DotEmaShellComponent', () => {
});

spectator.detectChanges();
expect(store.init).not.toHaveBeenCalledTimes(2); // The first call is on the beforeEach
expect(store.init).toHaveBeenCalled();
});

it('should trigger a load when changing the clientHost and it is on the allowedDevURLs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { switchMap, shareReplay, catchError, tap, take, map } from 'rxjs/operato

import { DotLanguagesService, DotLicenseService, DotExperimentsService } from '@dotcms/data-access';
import { LoginService } from '@dotcms/dotcms-js';
import { DEFAULT_VARIANT_ID } from '@dotcms/dotcms-models';

import { DotPageApiService, DotPageApiParams } from '../../../services/dot-page-api.service';
import { UVE_STATUS } from '../../../shared/enums';
Expand Down Expand Up @@ -140,7 +141,11 @@ export function withLoad() {
currentUser,
experiment,
languages,
params,
params: {
...params,
variantName:
params.variantName || DEFAULT_VARIANT_ID
},
canEditPage,
pageIsLocked,
isTraditionalPage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.dotcms.filters.interceptor;

import com.dotcms.repackage.com.google.common.annotations.VisibleForTesting;
import com.dotcms.rest.config.DotRestApplication;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.RegEX;
import io.vavr.Lazy;
import org.apache.commons.collections.iterators.ReverseListIterator;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -30,6 +34,9 @@ public class SimpleWebInterceptorDelegateImpl implements WebInterceptorDelegate
private final AtomicBoolean reverseOrderForPostInvoke =
new AtomicBoolean(false);

private static final Lazy<Boolean> ENABLE_TELEMETRY_FROM_CORE = Lazy.of(() ->
Config.getBooleanProperty("FEATURE_FLAG_TELEMETRY_CORE_ENABLED", false));

@Override
public void addBefore(final String webInterceptorName, final WebInterceptor webInterceptor) {

Expand Down Expand Up @@ -83,7 +90,11 @@ public void add(final int order, final WebInterceptor webInterceptor) {

@Override
public void addFirst(final WebInterceptor webInterceptor) {

if (Boolean.TRUE.equals(ENABLE_TELEMETRY_FROM_CORE.get()) &&
webInterceptor.getClass().getName().equalsIgnoreCase("com.dotcms.experience.collectors.api.ApiMetricWebInterceptor")) {
Logger.warn(DotRestApplication.class, "Bypassing addition of API Metric Web Interceptor from OSGi");
return;
}
this.interceptors.add(0, webInterceptor);
this.init(webInterceptor);
} // addFirst.
Expand Down
Loading

0 comments on commit 8d4f59b

Please sign in to comment.