Skip to content

Commit

Permalink
feat(insight): added hosted insight version API (#748)
Browse files Browse the repository at this point in the history
* feat(insight): added hosted insight version API

* feat(insight): import path fix

* feat(insight): import path fix

* feat(insight): new setting as optional on update

* feat(insight): proper types

* feat(insight): rename arg
  • Loading branch information
nathanlb authored Oct 12, 2023
1 parent 108f500 commit 721351f
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export interface HostedInterfaceConfiguration {
id: string;

/**
* The name of the insight panel interface configuration.
* The name of the interface configuration.
*/
name: string;

Expand Down
128 changes: 128 additions & 0 deletions src/resources/HostedInterfacesCore/HostedInterfaceVersionsCore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import {Paginated} from '../BaseInterfaces.js';

export interface HostedInterfaceChangeInfo {
/**
* The change date and time in ISO-8601 format.
*/
date: string;
/**
* The user identity in the following form: `user@domain-provider`.
*/
by: string;
/**
* The user's first name specified in the provider's user profile (e.g., the Google account).
*/
firstName?: string;
/**
* The user's last name specified in the provider's user profile (e.g., the Google account).
*/
lastName?: string;
}

export interface HostedInterfaceVersionInfo {
/**
* The version number.
*/
version: number;
/**
* The optional version label.
*/
label?: string;
/**
* The version creation information.
*/
created: HostedInterfaceChangeInfo;
/**
* The version update information.
*/
updated: HostedInterfaceChangeInfo;
/**
* Indicates whether the version is currently published.
*/
isPublished: boolean;
}

/**
* @param <T> - Hosted interface config model
*/
export interface HostedInterfaceVersion<T> {
/**
* The version number.
*/
version: number;
/**
* The optional version label.
*/
label?: string;
/**
* The version creation information.
*/
created: HostedInterfaceChangeInfo;
/**
* The version update information.
*/
updated: HostedInterfaceChangeInfo;
/**
* Indicates whether the version is currently published.
*/
isPublished: boolean;
/**
* This version's interface config.
*/
configuration: T;
/**
* When an interface is restored, indicates the source version number.
*/
restoredFromVersion?: number;
}

export interface ListHostedInterfaceVersionsParams extends Paginated {
/**
* The zero-based page to retrieve.
*
* @default `0`
*/
page?: number;
/**
* The number of versions to return per page.
*
* @default `10`
*/
perPage?: number;
/**
* A substring that must appear in a version label for this configuration to appear in results.
*/
filter?: string;
/**
* The sort order to apply on the interface version number.
*
* **Allowed values:**
* - `undefined`: Configurations are returned in no specific order.
* - `asc`: Sort version by number in ascending order.
* - `desc`: Sort version by number in descending order.
*
* @default `undefined`
*/
order?: 'asc' | 'desc';
}

export interface UpdateVersionedHostedInterfaceExtraParams {
/**
* The label to describe this particular interface version being created.
*/
versionLabel?: string;
}

export interface UpdateInterfaceVersionLabelParams {
/**
* The optional version label.
*/
label?: string;
}

export interface RestoreInterfaceVersionParams {
/**
* The optional version label.
*/
label?: string;
}
1 change: 1 addition & 0 deletions src/resources/HostedInterfacesCore/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './HostedInterfaceCoreConfig.model.js';
export * from './HostedInterfaceVersionsCore.js';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
HostedInterfaceResultTemplateBadge,
HostedInterfaceResultTemplateDetail,
HostedInterfaceTab,
HostedInterfaceVersion,
ListHostedInterfacesParams,
UpdateVersionedHostedInterfaceExtraParams,
} from '../HostedInterfacesCore/index.js';

export enum InsightPanelResultTemplateLayout {
Expand Down Expand Up @@ -150,6 +152,10 @@ export interface InsightPanelSettings {
* An option enabling the use of smart snippets.
*/
smartSnippets: InsightPanelOption;
/**
* Indicates whether dynamic facet navigation is disabled.
*/
disableDynamicNavigation: InsightPanelOption;
}

export interface InsightPanelInterfaceConfiguration extends HostedInterfaceConfiguration {
Expand All @@ -172,14 +178,23 @@ export interface InsightPanelInterfaceConfiguration extends HostedInterfaceConfi
* The insight panel settings.
*/
settings: InsightPanelSettings;

/**
* This config's published version.
* This is usually the latest version.
*/
publishedVersion?: number;
}

export interface IListInsightPanelInterfacesParameters extends ListHostedInterfacesParams {}

export interface InsightPanelInterfaceConfigurationUpdateParams
extends Omit<InsightPanelInterfaceConfiguration, 'settings'> {
extends Omit<InsightPanelInterfaceConfiguration, 'settings' | 'publishedVersion'>,
UpdateVersionedHostedInterfaceExtraParams {
/**
* The insight panel settings.
*/
settings: WithOptional<InsightPanelSettings, 'smartSnippets'>;
settings: WithOptional<InsightPanelSettings, 'smartSnippets' | 'disableDynamicNavigation'>;
}

export interface InsightPanelInterfaceVersion extends HostedInterfaceVersion<InsightPanelInterfaceConfiguration> {}
38 changes: 37 additions & 1 deletion src/resources/InsightPanelInterfaces/InsightPanelInterface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import API from '../../APICore.js';
import {New, PageModel} from '../BaseInterfaces.js';
import {ListHostedInterfacesParams} from '../HostedInterfacesCore/index.js';
import {
ListHostedInterfaceVersionsParams,
ListHostedInterfacesParams,
RestoreInterfaceVersionParams,
UpdateInterfaceVersionLabelParams,
} from '../HostedInterfacesCore/index.js';
import Resource from '../Resource.js';
import {
InsightPanelInterfaceConfiguration,
InsightPanelInterfaceConfigurationUpdateParams,
InsightPanelInterfaceVersion,
} from './InsightPanelInterface.model.js';

export default class InsightPanelInterface extends Resource {
Expand Down Expand Up @@ -38,4 +44,34 @@ export default class InsightPanelInterface extends Resource {
body,
);
}

listVersions(insightPanelInterfaceId: string, options: ListHostedInterfaceVersionsParams) {
return this.api.get<PageModel<InsightPanelInterfaceVersion>>(
this.buildPath(`${InsightPanelInterface.baseUrl}/${insightPanelInterfaceId}/versions`, options),
);
}

getVersion(insightPanelInterfaceId: string, versionNumber: number) {
return this.api.get<InsightPanelInterfaceVersion>(
`${InsightPanelInterface.baseUrl}/${insightPanelInterfaceId}/versions/${versionNumber}`,
);
}

restoreVersion(insightPanelInterfaceId: string, versionNumber: number, body: RestoreInterfaceVersionParams) {
return this.api.post<InsightPanelInterfaceConfiguration>(
`${InsightPanelInterface.baseUrl}/${insightPanelInterfaceId}/versions/${versionNumber}/restore`,
body,
);
}

updateVersionLabel(
insightPanelInterfaceId: string,
versionNumber: number,
body: UpdateInterfaceVersionLabelParams,
) {
return this.api.put<InsightPanelInterfaceConfiguration>(
`${InsightPanelInterface.baseUrl}/${insightPanelInterfaceId}/versions/${versionNumber}/label`,
body,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ describe('InsightPanelInterface', () => {
smartSnippets: {
enabled: false,
},
disableDynamicNavigation: {
enabled: false,
},
},
};

Expand Down Expand Up @@ -193,4 +196,97 @@ describe('InsightPanelInterface', () => {
expect(api.delete).toHaveBeenCalledWith(`${InsightPanelInterface.baseUrl}/${id}`);
});
});

describe('listVersions', () => {
const id = 'IPInterface-id-to-get';

it('should make a GET call with all parameters', () => {
insightPanelInterface.listVersions(id, {page: 2, perPage: 10, filter: 'Accounting', order: 'asc'});

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${InsightPanelInterface.baseUrl}/${id}/versions?page=2&perPage=10&filter=Accounting&order=asc`,
);
});

it('should make a GET call with page', () => {
insightPanelInterface.listVersions(id, {page: 2});

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${InsightPanelInterface.baseUrl}/${id}/versions?page=2`);
});

it('should make a GET call with perPage', () => {
insightPanelInterface.listVersions(id, {perPage: 10});

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${InsightPanelInterface.baseUrl}/${id}/versions?perPage=10`);
});

it('should make a GET call with filter', () => {
insightPanelInterface.listVersions(id, {filter: 'Accounting'});

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${InsightPanelInterface.baseUrl}/${id}/versions?filter=Accounting`);
});

it('should make a GET call with order', () => {
insightPanelInterface.listVersions(id, {order: 'asc'});

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${InsightPanelInterface.baseUrl}/${id}/versions?order=asc`);
});
});

describe('getVersion', () => {
it('should make a GET call to the InsightPanelInterface version url', () => {
const id = 'IPInterface-id-to-get';
const versionNumber = 1;

insightPanelInterface.getVersion(id, versionNumber);

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${InsightPanelInterface.baseUrl}/${id}/versions/${versionNumber}`);
});
});

describe('restoreVersion', () => {
it('should make a POST call to the InsightPanelInterface version restore url', () => {
const id = 'IPInterface-id-to-get';
const versionNumber = 2;
const label = 'Some version label';

insightPanelInterface.restoreVersion(id, versionNumber, {
label,
});

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
`${InsightPanelInterface.baseUrl}/${id}/versions/${versionNumber}/restore`,
{
label,
},
);
});
});

describe('updateVersionLabel', () => {
it('should make a PUT call to the InsightPanelInterface version label url', () => {
const id = 'IPInterface-id-to-get';
const versionNumber = 3;
const label = 'some-label';

insightPanelInterface.updateVersionLabel(id, versionNumber, {
label,
});

expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(
`${InsightPanelInterface.baseUrl}/${id}/versions/${versionNumber}/label`,
{
label,
},
);
});
});
});

0 comments on commit 721351f

Please sign in to comment.