Skip to content

Commit

Permalink
feat: adds 'display_timezone' to ContentItemElement class. Fixes mapp…
Browse files Browse the repository at this point in the history
…ing of components in element
  • Loading branch information
Enngage committed Oct 3, 2024
1 parent 482cc01 commit bd1b082
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/contracts/element-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export namespace ElementContracts {
value: string | number | SharedContracts.IReferenceObjectContract[];
components?: IContentItemElementComponent[];
searchableValue?: string;
display_timezone?: string;
mode?: 'autogenerated' | 'custom';
}

Expand Down
11 changes: 3 additions & 8 deletions lib/mappers/elements-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@ export class ElementsMapper extends BaseMapper {

mapElements(elementsRaw: ElementContracts.IContentItemElementContract[]): ElementModels.ContentItemElement[] {
return elementsRaw.map((m) => {
return new ElementModels.ContentItemElement({
element: super.mapReference(m.element),
value: this.mapElementValue(m.value),
components: this.mapElementComponents(m.components ?? []),
mode: m.mode,
searchableValue: m.searchableValue,
_raw: m
});
return this.mapElement(m);
});
}

mapElement(rawElement: ElementContracts.IContentItemElementContract): ElementModels.ContentItemElement {
return new ElementModels.ContentItemElement({
element: super.mapReference(rawElement.element),
value: this.mapElementValue(rawElement.value),
components: this.mapElementComponents(rawElement.components ?? []),
display_timezone: rawElement.display_timezone,
mode: rawElement.mode,
searchableValue: rawElement.searchableValue,
_raw: rawElement
Expand Down
4 changes: 3 additions & 1 deletion lib/models/elements/elements.models.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SharedModels } from '../shared/shared-models';
import { ElementContracts } from '../../contracts';
import { SharedModels } from '../shared/shared-models';

export namespace ElementModels {
export type ElementMode = 'single' | 'multiple';
Expand All @@ -23,6 +23,7 @@ export namespace ElementModels {
public element!: SharedModels.ReferenceObject;
public value?: string | number | SharedModels.ReferenceObject[];
public searchableValue?: string;
public display_timezone?: string;
public components!: ContentItemElementComponent[];
public mode?: 'autogenerated' | 'custom';
public _raw!: ElementContracts.IContentItemElementContract;
Expand All @@ -32,6 +33,7 @@ export namespace ElementModels {
value?: string | number | SharedModels.ReferenceObject[];
components?: ContentItemElementComponent[];
searchableValue?: string;
display_timezone?: string;
mode?: 'autogenerated' | 'custom';
_raw: ElementContracts.IContentItemElementContract;
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"element": {
"id": "4ae5f7a9-fe1f-1e8c-bfec-d321455139c4"
},
"value": "2014-11-07T00:00:00Z"
"value": "2014-11-07T00:00:00Z",
"display_timezone": "Europe/Prague"
},
{
"element": {
Expand Down
5 changes: 5 additions & 0 deletions test/browser/language-variants/view-language-variant.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ describe('View language variant', () => {
} else {
expect(element.value).toEqual(originalElement.value as string | number);
}

const display_timezone = (originalElement as any).display_timezone;
if (display_timezone) {
expect(display_timezone).toEqual(element.display_timezone);
}
});
});
});

0 comments on commit bd1b082

Please sign in to comment.