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

dotCMS/core#25901 Unable to reuse content inside the variants #26450

Merged
merged 3 commits into from Oct 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -107,7 +107,8 @@ const storeMock = jasmine.createSpyObj(
'filterContentlets',
'filterContentTypes',
'loadContentlets',
'switchView'
'switchView',
'switchLanguage'
],
{
vm$: of({
Expand Down Expand Up @@ -234,4 +235,13 @@ describe('DotPaletteComponent', () => {

expect(store.setAllowedContent).toHaveBeenCalledWith(allowedContent);
});

it('should switch language', async () => {
comp.languageId = '2';

fixture.detectChanges();
await fixture.whenStable();

expect(store.switchLanguage).toHaveBeenCalledWith('2');
});
});
@@ -1,7 +1,7 @@
import { Observable } from 'rxjs';

import { animate, AnimationEvent, state, style, transition, trigger } from '@angular/animations';
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { Component, Input, ViewChild } from '@angular/core';

import { LazyLoadEvent } from 'primeng/api';

Expand Down Expand Up @@ -32,23 +32,20 @@ import { DotPaletteState, DotPaletteStore } from './store/dot-palette.store';
])
]
})
export class DotPaletteComponent implements OnInit {
export class DotPaletteComponent {
@Input() set allowedContent(items: string[]) {
this.store.setAllowedContent(items);
}
@Input() languageId: string;
@Input() set languageId(languageId: string) {
this.store.switchLanguage(languageId);
}
vm$: Observable<DotPaletteState> = this.store.vm$;

@ViewChild('contentlets') contentlets: DotPaletteContentletsComponent;
@ViewChild('contentTypes') contentTypes: DotPaletteContentTypeComponent;

constructor(private store: DotPaletteStore) {}

ngOnInit(): void {
this.store.setLanguageId(this.languageId);
this.store.getContenttypesData();
}

/**
* Sets value on store to show/hide components on the UI
*
Expand Down
Expand Up @@ -143,9 +143,11 @@ describe('DotPaletteStore', () => {
});

it('should update languageId', () => {
dotPaletteStore.setLanguageId('1');
dotPaletteStore.setLanguage('4');
dotPaletteStore.state$.subscribe((data) => {
expect(data.languageId).toEqual('1');
expect(data.languageId).toEqual('4');
expect(data.filter).toEqual('');
expect(data.viewContentlet).toEqual('contentlet:out');
});
});

Expand Down
Expand Up @@ -32,6 +32,9 @@ export interface DotPaletteState {
loading: boolean;
}

const CONTENTLET_VIEW_IN = 'contentlet:in';
const CONTENTLET_VIEW_OUT = 'contentlet:out';

@Injectable()
export class DotPaletteStore extends ComponentStore<DotPaletteState> {
readonly vm$ = this.state$;
Expand All @@ -40,8 +43,8 @@ export class DotPaletteStore extends ComponentStore<DotPaletteState> {
return { ...state, filter: data };
});

readonly setLanguageId = this.updater((state: DotPaletteState, data: string) => {
return { ...state, languageId: data };
readonly setLanguage = this.updater((state: DotPaletteState, languageId: string) => {
return { ...state, languageId, viewContentlet: CONTENTLET_VIEW_OUT, filter: '' };
});

readonly setViewContentlet = this.updater((state: DotPaletteState, data: string) => {
Expand All @@ -61,6 +64,7 @@ export class DotPaletteStore extends ComponentStore<DotPaletteState> {
loading: !(ComponentStatus.LOADED === ComponentStatus.LOADED)
};
});

readonly setAllowedContent = this.updater((state: DotPaletteState, data: string[]) => {
return { ...state, allowedContent: data };
});
Expand Down Expand Up @@ -168,11 +172,22 @@ export class DotPaletteStore extends ComponentStore<DotPaletteState> {
filter: '',
languageId: '1',
totalRecords: 0,
viewContentlet: 'contentlet:out',
viewContentlet: CONTENTLET_VIEW_OUT,
loading: false
});
}

/**
* Switch language and request Content Types data.
* @param languageId
*
* @memberof DotPaletteStore
*/
switchLanguage(languageId: string): void {
this.setLanguage(languageId);
this.getContenttypesData();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this method is doing doesn't look like something that belongs to a store, looks very very anti pattern.

}

/**
* Request contentlets data with filter and pagination params.
*
Expand Down Expand Up @@ -289,7 +304,7 @@ export class DotPaletteStore extends ComponentStore<DotPaletteState> {
* @memberof DotPaletteContentletsComponent
*/
switchView(variableName?: string): void {
const viewContentlet = variableName ? 'contentlet:in' : 'contentlet:out';
const viewContentlet = variableName ? CONTENTLET_VIEW_IN : CONTENTLET_VIEW_OUT;
this.setViewContentlet(viewContentlet);
this.setFilter('');
this.loadContentlets(variableName);
Expand Down