Skip to content

Commit

Permalink
Merge branch 'main' into add-tags-to-card
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Jul 22, 2024
2 parents 7fd07d9 + 0db883a commit ae5a621
Show file tree
Hide file tree
Showing 29 changed files with 272 additions and 162 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
* Side Public License, v 1.
*/

import { getApmConfigMock } from './http_resources_service.test.mocks';

import type { RouteConfig } from '@kbn/core-http-server';

import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { httpServiceMock, httpServerMock } from '@kbn/core-http-server-mocks';
import { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
Expand All @@ -29,11 +26,6 @@ describe('HttpResources service', () => {
let router: ReturnType<typeof httpServiceMock.createRouter>;
const kibanaRequest = httpServerMock.createKibanaRequest();
const context = createCoreRequestHandlerContextMock();
const apmConfig = { mockApmConfig: true };

beforeEach(() => {
getApmConfigMock.mockReturnValue(apmConfig);
});

describe('#createRegistrar', () => {
beforeEach(() => {
Expand Down Expand Up @@ -93,9 +85,6 @@ describe('HttpResources service', () => {
},
{
isAnonymousPage: false,
vars: {
apmConfig,
},
}
);
});
Expand All @@ -118,9 +107,6 @@ describe('HttpResources service', () => {
},
{
isAnonymousPage: true,
vars: {
apmConfig,
},
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import type {

import type { InternalHttpResourcesSetup } from './types';

import { getApmConfig } from './get_apm_config';

/**
* @internal
*/
Expand Down Expand Up @@ -112,13 +110,9 @@ export class HttpResourcesService implements CoreService<InternalHttpResourcesSe
): HttpResourcesServiceToolkit {
return {
async renderCoreApp(options: HttpResourcesRenderOptions = {}) {
const apmConfig = getApmConfig(request.url.pathname);
const { uiSettings } = await context.core;
const body = await deps.rendering.render(request, uiSettings, {
isAnonymousPage: false,
vars: {
apmConfig,
},
includeExposedConfigKeys: options.includeExposedConfigKeys,
});

Expand All @@ -128,13 +122,9 @@ export class HttpResourcesService implements CoreService<InternalHttpResourcesSe
});
},
async renderAnonymousCoreApp(options: HttpResourcesRenderOptions = {}) {
const apmConfig = getApmConfig(request.url.pathname);
const { uiSettings } = await context.core;
const body = await deps.rendering.render(request, uiSettings, {
isAnonymousPage: true,
vars: {
apmConfig,
},
includeExposedConfigKeys: options.includeExposedConfigKeys,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"**/*.ts",
],
"kbn_references": [
"@kbn/apm-config-loader",
"@kbn/logging",
"@kbn/core-http-server",
"@kbn/core-http-resources-server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,79 +159,3 @@ describe('setup.getLegacyMetadata()', () => {
}).toThrowError();
});
});

describe('setup.getInjectedVar()', () => {
it('returns values from injectedMetadata.vars', () => {
const setup = new InjectedMetadataService({
injectedMetadata: {
vars: {
foo: {
bar: '1',
},
'baz:box': {
foo: 2,
},
},
},
} as any).setup();

expect(setup.getInjectedVar('foo')).toEqual({
bar: '1',
});
expect(setup.getInjectedVar('foo.bar')).toBe('1');
expect(setup.getInjectedVar('baz:box')).toEqual({
foo: 2,
});
expect(setup.getInjectedVar('')).toBe(undefined);
});

it('returns read-only values', () => {
const setup = new InjectedMetadataService({
injectedMetadata: {
vars: {
foo: {
bar: 1,
},
},
},
} as any).setup();

const foo: any = setup.getInjectedVar('foo');
expect(() => {
foo.bar = 2;
}).toThrowErrorMatchingInlineSnapshot(
`"Cannot assign to read only property 'bar' of object '#<Object>'"`
);
expect(() => {
foo.newProp = 2;
}).toThrowErrorMatchingInlineSnapshot(
`"Cannot add property newProp, object is not extensible"`
);
});
});

describe('setup.getInjectedVars()', () => {
it('returns all injected vars, readonly', () => {
const setup = new InjectedMetadataService({
injectedMetadata: {
vars: {
foo: {
bar: 1,
},
},
},
} as any).setup();

const vars: any = setup.getInjectedVars();
expect(() => {
vars.foo = 2;
}).toThrowErrorMatchingInlineSnapshot(
`"Cannot assign to read only property 'foo' of object '#<Object>'"`
);
expect(() => {
vars.newProp = 2;
}).toThrowErrorMatchingInlineSnapshot(
`"Cannot add property newProp, object is not extensible"`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import { get } from 'lodash';
import { deepFreeze } from '@kbn/std';
import type { InjectedMetadata } from '@kbn/core-injected-metadata-common-internal';
import type {
Expand Down Expand Up @@ -76,14 +75,6 @@ export class InjectedMetadataService {
return this.state.legacyMetadata;
},

getInjectedVar: (name: string, defaultValue?: any): unknown => {
return get(this.state.vars, name, defaultValue);
},

getInjectedVars: () => {
return this.state.vars;
},

getKibanaBuildNumber: () => {
return this.state.buildNumber;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ export interface InternalInjectedMetadataSetup {
user?: Record<string, any> | undefined;
};
};
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getInjectedVars: () => {
[key: string]: unknown;
};
getCustomBranding: () => CustomBranding;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const createSetupContractMock = () => {
getLegacyMetadata: jest.fn(),
getTheme: jest.fn(),
getPlugins: jest.fn(),
getInjectedVar: jest.fn(),
getInjectedVars: jest.fn(),
getKibanaBuildNumber: jest.fn(),
getCustomBranding: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface InjectedMetadata {
warnLegacyBrowsers: boolean;
};
externalUrl: { policy: InjectedMetadataExternalUrlPolicy[] };
vars: Record<string, any>;
apmConfig: Record<string, unknown> | null;
uiPlugins: InjectedMetadataPlugin[];
legacyMetadata: {
uiSettings: {
Expand Down
Loading

0 comments on commit ae5a621

Please sign in to comment.