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

Avillk/consume sdk #50

Open
wants to merge 2 commits into
base: kavilla/ci/cypress_input_control'
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
"dns-sync": "^0.2.1",
"elastic-apm-node": "^3.7.0",
"elasticsearch": "^16.7.0",
"http-aws-es": "6.0.0",
"execa": "^4.0.2",
"expiry-js": "0.1.7",
"fast-deep-equal": "^3.1.1",
Expand All @@ -180,6 +179,7 @@
"globby": "^8.0.1",
"handlebars": "4.7.7",
"hjson": "3.2.1",
"http-aws-es": "6.0.0",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^5.0.0",
"inline-style": "^2.0.0",
Expand Down Expand Up @@ -236,6 +236,7 @@
"@elastic/makelogs": "^6.1.0",
"@microsoft/api-documenter": "^7.13.78",
"@microsoft/api-extractor": "^7.19.3",
"@opensearch-project/opensearch-dashboards-sdk": "link:../opensearch-dashboards-sdk-js/",
"@osd/babel-preset": "1.0.0",
"@osd/dev-utils": "1.0.0",
"@osd/eslint-import-resolver-opensearch-dashboards": "2.0.0",
Expand Down Expand Up @@ -285,6 +286,7 @@
"@types/has-ansi": "^3.0.0",
"@types/history": "^4.7.3",
"@types/hjson": "^2.4.2",
"@types/http-aws-es": "6.0.2",
"@types/jest": "^27.4.0",
"@types/joi": "^13.4.2",
"@types/jquery": "^3.3.31",
Expand Down Expand Up @@ -337,7 +339,6 @@
"@types/zen-observable": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^3.10.0",
"@typescript-eslint/parser": "^3.10.0",
"@types/http-aws-es": "6.0.2",
"angular-aria": "^1.8.0",
"angular-mocks": "^1.8.2",
"angular-recursion": "^1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

export { ApplicationService } from './application_service';
export { Capabilities } from './capabilities';
export { ScopedHistory } from './scoped_history';
export { ApplicationScopedHistory } from './scoped_history';
export {
App,
AppMount,
Expand Down
6 changes: 3 additions & 3 deletions src/core/public/application/scoped_history.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
*/

import { Location } from 'history';
import { ScopedHistory } from './scoped_history';
import { ApplicationScopedHistory } from './scoped_history';

export type ScopedHistoryMock = jest.Mocked<ScopedHistory>;
export type ScopedHistoryMock = jest.Mocked<ApplicationScopedHistory>;

const createMock = ({
pathname = '/',
Expand All @@ -40,7 +40,7 @@ const createMock = ({
key,
state,
}: Partial<Location> = {}) => {
const mock: jest.Mocked<Pick<ScopedHistory, keyof ScopedHistory>> = {
const mock: jest.Mocked<Pick<ApplicationScopedHistory, keyof ApplicationScopedHistory>> = {
block: jest.fn(),
createHref: jest.fn(),
createSubHistory: jest.fn(),
Expand Down
50 changes: 25 additions & 25 deletions src/core/public/application/scoped_history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@
* under the License.
*/

import { ScopedHistory } from './scoped_history';
import { ApplicationScopedHistory } from './scoped_history';
import { createMemoryHistory } from 'history';

describe('ScopedHistory', () => {
describe('ApplicationScopedHistory', () => {
describe('construction', () => {
it('succeeds if current location matches basePath', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
expect(() => new ScopedHistory(gh, '/app/wow')).not.toThrow();
expect(() => new ApplicationScopedHistory(gh, '/app/wow')).not.toThrow();
gh.push('/app/wow/');
expect(() => new ScopedHistory(gh, '/app/wow')).not.toThrow();
expect(() => new ApplicationScopedHistory(gh, '/app/wow')).not.toThrow();
gh.push('/app/wow/sub-page');
expect(() => new ScopedHistory(gh, '/app/wow')).not.toThrow();
expect(() => new ApplicationScopedHistory(gh, '/app/wow')).not.toThrow();
});

it('fails if current location does not match basePath', () => {
const gh = createMemoryHistory();
gh.push('/app/other');
expect(() => new ScopedHistory(gh, '/app/wow')).toThrowErrorMatchingInlineSnapshot(
expect(() => new ApplicationScopedHistory(gh, '/app/wow')).toThrowErrorMatchingInlineSnapshot(
`"Browser location [/app/other] is not currently in expected basePath [/app/wow]"`
);
});
Expand All @@ -57,7 +57,7 @@ describe('ScopedHistory', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const pushSpy = jest.spyOn(gh, 'push');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
h.push('/new-page', { some: 'state' });
expect(pushSpy).toHaveBeenCalledWith('/app/wow/new-page', { some: 'state' });
expect(gh.length).toBe(3); // ['', '/app/wow', '/app/wow/new-page']
Expand All @@ -68,7 +68,7 @@ describe('ScopedHistory', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const pushSpy = jest.spyOn(gh, 'push');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
const { push } = h;
push('/new-page', { some: 'state' });
expect(pushSpy).toHaveBeenCalledWith('/app/wow/new-page', { some: 'state' });
Expand All @@ -80,7 +80,7 @@ describe('ScopedHistory', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const replaceSpy = jest.spyOn(gh, 'replace');
const h = new ScopedHistory(gh, '/app/wow'); // ['']
const h = new ApplicationScopedHistory(gh, '/app/wow'); // ['']
h.push('/first-page'); // ['', '/first-page']
h.push('/second-page'); // ['', '/first-page', '/second-page']
h.goBack(); // ['', '/first-page', '/second-page']
Expand All @@ -95,7 +95,7 @@ describe('ScopedHistory', () => {
gh.push('/app/alpha');
gh.push('/app/beta');
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
expect(h.length).toBe(1);
expect(h.location.pathname).toEqual('');
});
Expand All @@ -105,7 +105,7 @@ describe('ScopedHistory', () => {
gh.push('/app/alpha');
gh.push('/app/beta');
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
h.push('/new-page');
expect(h.length).toBe(2);
expect(h.location.pathname).toEqual('/new-page');
Expand All @@ -128,7 +128,7 @@ describe('ScopedHistory', () => {
gh.push('/app/alpha');
gh.push('/app/beta');
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
h.push('/new-page');
expect(h.length).toBe(2);

Expand All @@ -154,7 +154,7 @@ describe('ScopedHistory', () => {
it('reacts to navigations from parent history', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
h.push('/page-1');
h.push('/page-2');

Expand All @@ -178,7 +178,7 @@ describe('ScopedHistory', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
expect(gh.length).toBe(2);
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
expect(h.length).toBe(1);
h.push('/page1');
expect(h.length).toBe(2);
Expand Down Expand Up @@ -210,10 +210,10 @@ describe('ScopedHistory', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
expect(gh.length).toBe(2);
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
gh.push('/app/other');
expect(() => h.location).toThrowErrorMatchingInlineSnapshot(
`"ScopedHistory instance has fell out of navigation scope for basePath: /app/wow"`
`"ApplicationScopedHistory instance has fell out of navigation scope for basePath: /app/wow"`
);
expect(() => h.push('/new-page')).toThrow();
expect(() => h.replace('/new-page')).toThrow();
Expand All @@ -226,7 +226,7 @@ describe('ScopedHistory', () => {
it('calls callback with scoped location', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
const listenPaths: string[] = [];
h.listen((l) => listenPaths.push(l.pathname));
h.push('/first-page');
Expand All @@ -246,7 +246,7 @@ describe('ScopedHistory', () => {
it('stops calling callback after unlisten is called', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
const listenPaths: string[] = [];
const unlisten = h.listen((l) => listenPaths.push(l.pathname));
h.push('/first-page');
Expand All @@ -261,7 +261,7 @@ describe('ScopedHistory', () => {
it('stops calling callback after browser leaves scope', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
const listenPaths: string[] = [];
h.listen((l) => listenPaths.push(l.pathname));
h.push('/first-page');
Expand All @@ -278,7 +278,7 @@ describe('ScopedHistory', () => {
it('creates scoped hrefs', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
expect(h.createHref({ pathname: '' })).toEqual(`/app/wow`);
expect(h.createHref({})).toEqual(`/app/wow`);
expect(h.createHref({ pathname: '/new-page', search: '?alpha=true' })).toEqual(
Expand All @@ -289,7 +289,7 @@ describe('ScopedHistory', () => {
it('behave correctly with slash-ending basePath', () => {
const gh = createMemoryHistory();
gh.push('/app/wow/');
const h = new ScopedHistory(gh, '/app/wow/');
const h = new ApplicationScopedHistory(gh, '/app/wow/');
expect(h.createHref({ pathname: '' })).toEqual(`/app/wow/`);
expect(h.createHref({ pathname: '/new-page', search: '?alpha=true' })).toEqual(
`/app/wow/new-page?alpha=true`
Expand All @@ -299,7 +299,7 @@ describe('ScopedHistory', () => {
it('skips the scoped history path when `prependBasePath` is false', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
expect(h.createHref({ pathname: '' }, { prependBasePath: false })).toEqual(`/`);
expect(
h.createHref({ pathname: '/new-page', search: '?alpha=true' }, { prependBasePath: false })
Expand All @@ -313,7 +313,7 @@ describe('ScopedHistory', () => {
gh.push('/app/wow');
gh.push('/alpha');
gh.goBack();
const h = new ScopedHistory(gh, '/app/wow');
const h = new ApplicationScopedHistory(gh, '/app/wow');
expect(h.action).toBe('POP');
gh.push('/app/wow/page-1');
expect(h.action).toBe('PUSH');
Expand All @@ -327,7 +327,7 @@ describe('ScopedHistory', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const ghPushSpy = jest.spyOn(gh, 'push');
const h1 = new ScopedHistory(gh, '/app/wow');
const h1 = new ApplicationScopedHistory(gh, '/app/wow');
h1.push('/new-page');
const h1PushSpy = jest.spyOn(h1, 'push');
const h2 = h1.createSubHistory('/new-page');
Expand All @@ -343,7 +343,7 @@ describe('ScopedHistory', () => {
const gh = createMemoryHistory();
gh.push('/app/wow');
const ghReplaceSpy = jest.spyOn(gh, 'replace');
const h1 = new ScopedHistory(gh, '/app/wow');
const h1 = new ApplicationScopedHistory(gh, '/app/wow');
h1.push('/new-page');
const h1ReplaceSpy = jest.spyOn(h1, 'replace');
const h2 = h1.createSubHistory('/new-page');
Expand Down
19 changes: 10 additions & 9 deletions src/core/public/application/scoped_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
Href,
Action,
} from 'history';
import { ScopedHistory } from '@opensearch-project/opensearch-dashboards-sdk';

/**
* A wrapper around a `History` instance that is scoped to a particular base path of the history stack. Behaves
Expand All @@ -48,13 +49,13 @@ import {
* This wrapper also allows Core and Plugins to share a single underlying global `History` instance without exposing
* the history of other applications.
*
* The {@link ScopedHistory.createSubHistory | createSubHistory} method is particularly useful for applications that
* The {@link ApplicationScopedHistory.createSubHistory | createSubHistory} method is particularly useful for applications that
* contain any number of "sub-apps" which should not have access to the main application's history or basePath.
*
* @public
*/
export class ScopedHistory<HistoryLocationState = unknown>
implements History<HistoryLocationState> {
export class ApplicationScopedHistory<HistoryLocationState = unknown>
implements ScopedHistory<HistoryLocationState> {
/**
* Tracks whether or not the user has left this history's scope. All methods throw errors if called after scope has
* been left.
Expand Down Expand Up @@ -87,15 +88,15 @@ export class ScopedHistory<HistoryLocationState = unknown>
}

/**
* Creates a `ScopedHistory` for a subpath of this `ScopedHistory`. Useful for applications that may have sub-apps
* Creates a `ApplicationScopedHistory` for a subpath of this `ApplicationScopedHistory`. Useful for applications that may have sub-apps
* that do not need access to the containing application's history.
*
* @param basePath the URL path scope for the sub history
*/
public createSubHistory = <SubHistoryLocationState = unknown>(
basePath: string
): ScopedHistory<SubHistoryLocationState> => {
return new ScopedHistory<SubHistoryLocationState>(this, basePath);
): ApplicationScopedHistory<SubHistoryLocationState> => {
return new ApplicationScopedHistory<SubHistoryLocationState>(this, basePath);
};

/**
Expand Down Expand Up @@ -181,7 +182,7 @@ export class ScopedHistory<HistoryLocationState = unknown>

/**
* Send the user one location back in the history stack. Equivalent to calling
* {@link ScopedHistory.go | ScopedHistory.go(-1)}. If no more entries are available backwards, this is a no-op.
* {@link ApplicationScopedHistory.go | ApplicationScopedHistory.go(-1)}. If no more entries are available backwards, this is a no-op.
*/
public goBack = () => {
this.verifyActive();
Expand All @@ -190,7 +191,7 @@ export class ScopedHistory<HistoryLocationState = unknown>

/**
* Send the user one location forward in the history stack. Equivalent to calling
* {@link ScopedHistory.go | ScopedHistory.go(1)}. If no more entries are available forwards, this is a no-op.
* {@link ApplicationScopedHistory.go | ApplicationScopedHistory.go(1)}. If no more entries are available forwards, this is a no-op.
*/
public goForward = () => {
this.verifyActive();
Expand Down Expand Up @@ -297,7 +298,7 @@ export class ScopedHistory<HistoryLocationState = unknown>
private verifyActive() {
if (!this.isActive) {
throw new Error(
`ScopedHistory instance has fell out of navigation scope for basePath: ${this.basePath}`
`ApplicationScopedHistory instance has fell out of navigation scope for basePath: ${this.basePath}`
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { PluginOpaqueId } from '../plugins';
import { IUiSettingsClient } from '../ui_settings';
import { SavedObjectsStart } from '../saved_objects';
import { AppCategory } from '../../types';
import { ScopedHistory } from './scoped_history';
import { ApplicationScopedHistory } from './scoped_history';

/**
* Accessibility status of an application.
Expand Down Expand Up @@ -388,7 +388,7 @@ export interface AppMountParameters<HistoryLocationState = unknown> {
* }
* ```
*/
history: ScopedHistory<HistoryLocationState>;
history: ApplicationScopedHistory<HistoryLocationState>;

/**
* The route path for configuring navigation to the application.
Expand Down
8 changes: 4 additions & 4 deletions src/core/public/application/ui/app_container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { AppContainer } from './app_container';
import { Mounter, AppMountParameters, AppStatus } from '../types';
import { createMemoryHistory } from 'history';
import { ScopedHistory } from '../scoped_history';
import { ApplicationScopedHistory } from '../scoped_history';

describe('AppContainer', () => {
const appId = 'someApp';
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('AppContainer', () => {
setIsMounting={setIsMounting}
createScopedHistory={(appPath: string) =>
// Create a history using the appPath as the current location
new ScopedHistory(createMemoryHistory({ initialEntries: [appPath] }), appPath)
new ApplicationScopedHistory(createMemoryHistory({ initialEntries: [appPath] }), appPath)
}
/>
);
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('AppContainer', () => {
setIsMounting={setIsMounting}
createScopedHistory={(appPath: string) =>
// Create a history using the appPath as the current location
new ScopedHistory(createMemoryHistory({ initialEntries: [appPath] }), appPath)
new ApplicationScopedHistory(createMemoryHistory({ initialEntries: [appPath] }), appPath)
}
/>
);
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('AppContainer', () => {
setIsMounting={setIsMounting}
createScopedHistory={(appPath: string) =>
// Create a history using the appPath as the current location
new ScopedHistory(createMemoryHistory({ initialEntries: [appPath] }), appPath)
new ApplicationScopedHistory(createMemoryHistory({ initialEntries: [appPath] }), appPath)
}
/>
);
Expand Down
Loading