Skip to content

Commit

Permalink
fix: integration branch for sdk changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-warner committed Apr 19, 2024
1 parent f168ba6 commit b86495d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 9 deletions.
48 changes: 48 additions & 0 deletions src/lib/components/MediaLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,54 @@ export class MediaLink {
* @param connection message-event-channel connection
*/
constructor(private connection: ClientConnection) {}

/**
* This method will trigger opening the media browser. It returns a promise that will resolve to the chosen Image or Video Link.
*
* Example of fetching media from DC
* ```typescript
* try {
* // open browser and waits for media browser
* // returns object that should be saved to the model
* const video = await sdk.mediaLink.get()
*
* } catch (e) {
* // no media returned
* }
* ```
*/
async get(): Promise<MediaImageLink | MediaVideoLink> {
return this.connection.request(MEDIA_LINK.GET, null, {
timeout: false,
});
}

/**
* This method will trigger opening the media overlay. It returns a promise that will resolve to the chosen Image and Video Links.
*
* Example of fetching an media from DC
* ```typescript
* try {
* // open browser and waits for media selection
* // returns object that should be saved to the model
* const media = await sdk.mediaLink.getMultiple({ max: 10 })
*
* } catch (e) {
* // no media returned
* }
* ```
*/
async getMultiple(
{ max }: MediaOptions = { max: null }
): Promise<Array<MediaImageLink | MediaImageLink>> {
return this.connection.request(
MEDIA_LINK.GET,
{ max },
{
timeout: false,
}
);
}
/**
* This method will trigger an image browser. It returns a promise that will resolve to the chosen Image Link.
*
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum CONTENT_ITEM {
export enum MEDIA_LINK {
IMAGE_GET = 'media-image-get',
VIDEO_GET = 'media-video-get',
GET = 'media-get',
}

export enum CONTENT_LINK {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export interface ContentEditorContextObject<ParamType extends Params = Params>
locales: LocalesModel;
stagingEnvironment: string;
visualisation: string;
locationHref: string;
readOnly: boolean;
hub: Hub;
collaspseByDefault: boolean;
}

export function isContentEditorContextObject(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ClientConnection } from 'message-event-channel';
import { ContentItem } from '../../components/ContentItem';
import { ContentEditorExtension } from './ContentEditorExtension';
import { Field } from '../../components/Field';
import { ContentEditorForm } from '../../components/ContentEditorForm';
import { Frame } from '../../components/Frame';
import { ContentReference } from '../../components/ContentReference';
import { ContentLink } from '../../components/ContentLink';
import { MediaLink } from '../../components/MediaLink';
Expand Down Expand Up @@ -36,13 +34,15 @@ describe('ContentEditorExtension', () => {
},
locales: {
default: ['en'],
available: [{ locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true }],
available: [
{ locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true, label: '' },
],
},
stagingEnvironment: 'https://test-staging-environment',
visualisation: 'test-visualization',
readOnly: true,
hub: { id: 'hubId', name: 'hubName' },
locationHref: '#!',
collaspseByDefault: false,
};

const options = {
Expand Down
8 changes: 7 additions & 1 deletion src/lib/extensions/content-editor/ContentEditorExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export class ContentEditorExtension<ParamType extends Params = Params> extends E
*/
public applicationNavigator!: ContentEditorApplicationNavigator;

/**
* CollaspseByDefault - global setting for whether or not form fields should be open or closed by default
*/
public collaspseByDefault!: boolean;

constructor(options: ExtensionOptions, context: ContentEditorContextObject<ParamType>) {
super(options, context);

Expand All @@ -111,12 +116,12 @@ export class ContentEditorExtension<ParamType extends Params = Params> extends E
const {
schema,
params,
locationHref,
locales,
stagingEnvironment,
readOnly,
visualisation,
hub,
collaspseByDefault,
} = context;

this.assets = new Assets(this.connection);
Expand All @@ -127,6 +132,7 @@ export class ContentEditorExtension<ParamType extends Params = Params> extends E
this.locales = locales;
this.visualisation = visualisation;
this.stagingEnvironment = stagingEnvironment;
this.collaspseByDefault = collaspseByDefault;
this.hub = hub;

this.applicationNavigator = new ContentEditorApplicationNavigator(this.connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ContentFieldContextObject<ParamType extends Params = Params>
visualisation: string;
readOnly: boolean;
hub: Hub;
locationHref: string;
collaspseByDefault: boolean;
}

export function isContentFieldContextObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ describe('ContentFieldExtension', () => {
},
locales: {
default: ['en'],
available: [{ locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true }],
available: [
{ locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true, label: '' },
],
},
locationHref: '#!',
stagingEnvironment: 'https://test-staging-environment',
visualisation: 'test-visualization',
readOnly: true,
hub: { id: 'hubId', name: 'hubName' },
collaspseByDefault: false,
};
it('should create a new instance of ContentFieldExtension', () => {
const connection = new ClientConnection(options);
Expand Down
7 changes: 6 additions & 1 deletion src/lib/extensions/content-field/ContentFieldExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class ContentFieldExtension<
* Hub - Hub id and Hub name
*/
public hub!: Hub;
/**
* CollaspseByDefault - global setting for whether or not form fields should be open or closed by default
*/
public collaspseByDefault!: boolean;

/**
* ApplicationNavigator - used to navigate within the form
Expand All @@ -106,8 +110,8 @@ export class ContentFieldExtension<
stagingEnvironment,
readOnly,
visualisation,
locationHref,
hub,
collaspseByDefault,
} = context;

this.assets = new Assets(this.connection);
Expand All @@ -119,6 +123,7 @@ export class ContentFieldExtension<
this.locales = locales;
this.visualisation = visualisation;
this.stagingEnvironment = stagingEnvironment;
this.collaspseByDefault = collaspseByDefault;
this.hub = hub;
}
}
1 change: 1 addition & 0 deletions src/lib/models/Locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface LocalModel {
language: string;
country: string;
index: number;
label: string;
selected: boolean;
master?: boolean;
}

0 comments on commit b86495d

Please sign in to comment.