Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-80132
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 28, 2020
2 parents 6dd427c + d16d005 commit d7a5d3d
Show file tree
Hide file tree
Showing 157 changed files with 7,056 additions and 913 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pageLoadAssetSize:
searchprofiler: 67224
security: 189428
securityOss: 30806
securitySolution: 622387
securitySolution: 283440
share: 99205
snapshotRestore: 79176
spaces: 389643
Expand Down
7 changes: 1 addition & 6 deletions packages/kbn-storybook/lib/default_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
import { StorybookConfig } from '@storybook/core/types';

export const defaultConfig: StorybookConfig = {
addons: [
'@kbn/storybook/preset',
'@storybook/addon-a11y',
'@storybook/addon-knobs',
'@storybook/addon-essentials',
],
addons: ['@kbn/storybook/preset', '@storybook/addon-a11y', '@storybook/addon-essentials'],
stories: ['../**/*.stories.tsx'],
typescript: {
reactDocgen: false,
Expand Down
1 change: 1 addition & 0 deletions src/core/public/apm_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

jest.mock('@elastic/apm-rum');
import { init, apm } from '@elastic/apm-rum';
import { DeeplyMockedKeys } from '../typings';
import { ApmSystem } from './apm_system';

const initMock = init as jest.Mocked<typeof init>;
Expand Down
1 change: 1 addition & 0 deletions src/core/public/chrome/chrome_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { BehaviorSubject } from 'rxjs';
import type { PublicMethodsOf } from '@kbn/utility-types';
import { DeeplyMockedKeys } from '../../typings';
import { ChromeBadge, ChromeBrand, ChromeBreadcrumb, ChromeService, InternalChromeStart } from './';

const createStartContractMock = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import { MockedKeys } from '../../typings';
import {
NotificationsService,
NotificationsSetup,
Expand Down
1 change: 1 addition & 0 deletions src/core/public/overlays/overlay_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import { DeeplyMockedKeys } from '../../typings';
import { OverlayService, OverlayStart } from './overlay_service';
import { overlayBannersServiceMock } from './banners/banners_service.mock';
import { overlayFlyoutServiceMock } from './flyout/flyout_service.mock';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/core_context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { REPO_ROOT } from '@kbn/dev-utils';
import { DeeplyMockedKeys } from '../typings';
import { CoreContext } from './core_context';
import { Env, IConfigService } from './config';
import { configServiceMock, getEnvOptions } from './config/mocks';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/elasticsearch/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { Client, ApiResponse } from '@elastic/elasticsearch';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { DeeplyMockedKeys } from '../../../typings';
import { ElasticsearchClient } from './types';
import { ICustomClusterClient } from './cluster_client';

Expand Down
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { of } from 'rxjs';
import { duration } from 'moment';
import { ByteSizeValue } from '@kbn/config-schema';
import { MockedKeys } from '../typings';
import { PluginInitializerContext, CoreSetup, CoreStart, StartServicesAccessor } from '.';
import { loggingSystemMock } from './logging/logging_system.mock';
import { loggingServiceMock } from './logging/logging_service.mock';
Expand Down
4 changes: 2 additions & 2 deletions src/core/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

type DeeplyMockedKeys<T> = {
export type DeeplyMockedKeys<T> = {
[P in keyof T]: T[P] extends (...args: any[]) => any
? jest.MockInstance<ReturnType<T[P]>, Parameters<T[P]>>
: DeeplyMockedKeys<T[P]>;
} &
T;

type MockedKeys<T> = { [P in keyof T]: jest.Mocked<T[P]> };
export type MockedKeys<T> = { [P in keyof T]: jest.Mocked<T[P]> };
58 changes: 58 additions & 0 deletions src/legacy/server/i18n/get_kibana_translation_paths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { I18N_RC } from './constants';
import { fromRoot } from '../../../core/server/utils';

jest.mock('./get_translation_paths', () => ({ getTranslationPaths: jest.fn() }));
import { getKibanaTranslationPaths } from './get_kibana_translation_paths';
import { getTranslationPaths as mockGetTranslationPaths } from './get_translation_paths';

describe('getKibanaTranslationPaths', () => {
const mockConfig = { get: jest.fn() };

beforeEach(() => {
jest.resetAllMocks();
});

it('calls getTranslationPaths against kibana root and kibana-extra', async () => {
mockConfig.get.mockReturnValue([]);
await getKibanaTranslationPaths(mockConfig);
expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(1, {
cwd: fromRoot('.'),
glob: `*/${I18N_RC}`,
});

expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(2, {
cwd: fromRoot('../kibana-extra'),
glob: `*/${I18N_RC}`,
});
});

it('calls getTranslationPaths for each config returned in plugin.paths and plugins.scanDirs', async () => {
mockConfig.get.mockReturnValueOnce(['a', 'b']).mockReturnValueOnce(['c']);
await getKibanaTranslationPaths(mockConfig);
expect(mockConfig.get).toHaveBeenNthCalledWith(1, 'plugins.paths');
expect(mockConfig.get).toHaveBeenNthCalledWith(2, 'plugins.scanDirs');

expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(2, { cwd: 'a', glob: I18N_RC });
expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(3, { cwd: 'b', glob: I18N_RC });
expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(4, { cwd: 'c', glob: `*/${I18N_RC}` });
});
});
42 changes: 42 additions & 0 deletions src/legacy/server/i18n/get_kibana_translation_paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { KibanaConfig } from '../kbn_server';
import { fromRoot } from '../../../core/server/utils';
import { I18N_RC } from './constants';
import { getTranslationPaths } from './get_translation_paths';

export async function getKibanaTranslationPaths(config: Pick<KibanaConfig, 'get'>) {
return await Promise.all([
getTranslationPaths({
cwd: fromRoot('.'),
glob: `*/${I18N_RC}`,
}),
...(config.get('plugins.paths') as string[]).map((cwd) =>
getTranslationPaths({ cwd, glob: I18N_RC })
),
...(config.get('plugins.scanDirs') as string[]).map((cwd) =>
getTranslationPaths({ cwd, glob: `*/${I18N_RC}` })
),
getTranslationPaths({
cwd: fromRoot('../kibana-extra'),
glob: `*/${I18N_RC}`,
}),
]);
}
63 changes: 63 additions & 0 deletions src/legacy/server/i18n/i18n_mixin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { i18n, i18nLoader } from '@kbn/i18n';
import { basename } from 'path';
import { Server } from 'hapi';
import type { UsageCollectionSetup } from '../../../plugins/usage_collection/server';
import { getKibanaTranslationPaths } from './get_kibana_translation_paths';
import KbnServer, { KibanaConfig } from '../kbn_server';
import { registerLocalizationUsageCollector } from './localization';

export async function i18nMixin(
kbnServer: KbnServer,
server: Server,
config: Pick<KibanaConfig, 'get'>
) {
const locale = config.get('i18n.locale') as string;

const translationPaths = await getKibanaTranslationPaths(config);

const currentTranslationPaths = ([] as string[])
.concat(...translationPaths)
.filter((translationPath) => basename(translationPath, '.json') === locale);
i18nLoader.registerTranslationFiles(currentTranslationPaths);

const translations = await i18nLoader.getTranslationsByLocale(locale);
i18n.init(
Object.freeze({
locale,
...translations,
})
);

const getTranslationsFilePaths = () => currentTranslationPaths;

server.decorate('server', 'getTranslationsFilePaths', getTranslationsFilePaths);

if (kbnServer.newPlatform.setup.plugins.usageCollection) {
const { usageCollection } = kbnServer.newPlatform.setup.plugins as {
usageCollection: UsageCollectionSetup;
};
registerLocalizationUsageCollector(usageCollection, {
getLocale: () => config.get('i18n.locale') as string,
getTranslationsFilePaths,
});
}
}
58 changes: 1 addition & 57 deletions src/legacy/server/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,4 @@
* under the License.
*/

import { i18n, i18nLoader } from '@kbn/i18n';
import { basename } from 'path';
import { Server } from 'hapi';
import { fromRoot } from '../../../core/server/utils';
import type { UsageCollectionSetup } from '../../../plugins/usage_collection/server';
import { getTranslationPaths } from './get_translations_path';
import { I18N_RC } from './constants';
import KbnServer, { KibanaConfig } from '../kbn_server';
import { registerLocalizationUsageCollector } from './localization';

export async function i18nMixin(kbnServer: KbnServer, server: Server, config: KibanaConfig) {
const locale = config.get('i18n.locale') as string;

const translationPaths = await Promise.all([
getTranslationPaths({
cwd: fromRoot('.'),
glob: `*/${I18N_RC}`,
}),
...(config.get('plugins.paths') as string[]).map((cwd) =>
getTranslationPaths({ cwd, glob: I18N_RC })
),
...(config.get('plugins.scanDirs') as string[]).map((cwd) =>
getTranslationPaths({ cwd, glob: `*/${I18N_RC}` })
),
getTranslationPaths({
cwd: fromRoot('../kibana-extra'),
glob: `*/${I18N_RC}`,
}),
]);

const currentTranslationPaths = ([] as string[])
.concat(...translationPaths)
.filter((translationPath) => basename(translationPath, '.json') === locale);
i18nLoader.registerTranslationFiles(currentTranslationPaths);

const translations = await i18nLoader.getTranslationsByLocale(locale);
i18n.init(
Object.freeze({
locale,
...translations,
})
);

const getTranslationsFilePaths = () => currentTranslationPaths;

server.decorate('server', 'getTranslationsFilePaths', getTranslationsFilePaths);

if (kbnServer.newPlatform.setup.plugins.usageCollection) {
const { usageCollection } = kbnServer.newPlatform.setup.plugins as {
usageCollection: UsageCollectionSetup;
};
registerLocalizationUsageCollector(usageCollection, {
getLocale: () => config.get('i18n.locale') as string,
getTranslationsFilePaths,
});
}
}
export { i18nMixin } from './i18n_mixin';
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function LibraryNotificationPopover({
<p>
{i18n.translate('dashboard.panel.libraryNotification.toolTip', {
defaultMessage:
'This panel is linked to a library item. Editing the panel might affect other dashboards.',
'Editing this panel might affect other dashboards. To change to this panel only, unlink it from the library.',
})}
</p>
</EuiText>
Expand Down
Loading

0 comments on commit d7a5d3d

Please sign in to comment.