Skip to content

Commit

Permalink
Merge branch 'master' into prevent-common-code-to-import-server-or-pu…
Browse files Browse the repository at this point in the history
…blic-code
  • Loading branch information
elasticmachine authored Jun 3, 2020
2 parents a7e8ff1 + 43c5466 commit e60f18d
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Route } from 'react-router-dom';

import { CoreStart, AppMountParams } from 'src/core/public';
import { CoreStart, AppMountParameters } from 'src/core/public';
import { MyPluginDepsStart } from './plugin';

export renderApp = ({ element, history, onAppLeave }: AppMountParams) => {
export renderApp = ({ element, history, onAppLeave }: AppMountParameters) => {
const { renderApp, hasUnsavedChanges } = await import('./application');
onAppLeave(actions => {
if(hasUnsavedChanges()) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"@elastic/eui": "23.3.1",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
"@elastic/numeral": "2.4.0",
"@elastic/numeral": "^2.5.0",
"@elastic/request-crypto": "1.1.4",
"@elastic/ui-ace": "0.2.3",
"@hapi/good-squeeze": "5.2.1",
Expand Down Expand Up @@ -365,7 +365,6 @@
"@types/node": ">=10.17.17 <10.20.0",
"@types/node-forge": "^0.9.0",
"@types/normalize-path": "^3.0.0",
"@types/numeral": "^0.0.26",
"@types/opn": "^5.1.0",
"@types/pegjs": "^0.10.1",
"@types/pngjs": "^3.3.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-config-kibana/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ module.exports = {
to: false,
disallowedMessage: `Don't use 'mkdirp', use the new { recursive: true } option of Fs.mkdir instead`
},
{
from: 'numeral',
to: '@elastic/numeral',
},
{
from: '@kbn/elastic-idx',
to: false,
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Moment.tz.load(require('moment-timezone/data/packed/latest.json'));
// big deps which are locked to a single version
export const Rxjs = require('rxjs');
export const RxjsOperators = require('rxjs/operators');
export const ElasticNumeral = require('@elastic/numeral');
export const ElasticCharts = require('@elastic/charts');
export const ElasticEui = require('@elastic/eui');
export const ElasticEuiLibServices = require('@elastic/eui/lib/services');
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-ui-shared-deps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ exports.externals = {
*/
rxjs: '__kbnSharedDeps__.Rxjs',
'rxjs/operators': '__kbnSharedDeps__.RxjsOperators',
numeral: '__kbnSharedDeps__.ElasticNumeral',
'@elastic/numeral': '__kbnSharedDeps__.ElasticNumeral',
'@elastic/charts': '__kbnSharedDeps__.ElasticCharts',
'@elastic/eui': '__kbnSharedDeps__.ElasticEui',
'@elastic/eui/lib/services': '__kbnSharedDeps__.ElasticEuiLibServices',
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@elastic/charts": "19.2.0",
"@elastic/eui": "23.3.1",
"@elastic/numeral": "^2.5.0",
"@kbn/i18n": "1.0.0",
"abortcontroller-polyfill": "^1.4.0",
"angular": "^1.7.9",
Expand Down
8 changes: 0 additions & 8 deletions renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,6 @@
'@types/normalize-path',
],
},
{
groupSlug: 'numeral',
groupName: 'numeral related packages',
packageNames: [
'numeral',
'@types/numeral',
],
},
{
groupSlug: 'object-hash',
groupName: 'object-hash related packages',
Expand Down
10 changes: 7 additions & 3 deletions src/core/CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,21 @@ leverage this pattern.

import React from 'react';
import ReactDOM from 'react-dom';
import { CoreStart, AppMountParams } from '../../src/core/public';
import { CoreStart, AppMountParameters } from 'src/core/public';

import { MyAppRoot } from './components/app.ts';

/**
* This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle.
*/
export const renderApp = (core: CoreStart, deps: MyPluginDepsStart, { element, history }: AppMountParams) => {
export const renderApp = (
core: CoreStart,
deps: MyPluginDepsStart,
{ element, history }: AppMountParameters
) => {
ReactDOM.render(<MyAppRoot core={core} deps={deps} routerHistory={history} />, element);
return () => ReactDOM.unmountComponentAtNode(element);
}
};
```

```ts
Expand Down
8 changes: 6 additions & 2 deletions src/core/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,14 @@ The more interesting logic is in `renderApp`:
import React from 'react';
import ReactDOM from 'react-dom';

import { AppMountParams, CoreStart } from 'src/core/public';
import { AppMountParameters, CoreStart } from 'src/core/public';
import { AppRoot } from './components/app_root';

export const renderApp = ({ element, history }: AppMountParams, core: CoreStart, plugins: MyPluginDepsStart) => {
export const renderApp = (
{ element, history }: AppMountParameters,
core: CoreStart,
plugins: MyPluginDepsStart
) => {
// Hide the chrome while this app is mounted for a full screen experience
core.chrome.setIsVisible(false);

Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/scoped_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class ScopedHistory<HistoryLocationState = unknown>
prompt?: boolean | string | TransitionPromptHook<HistoryLocationState>
): UnregisterCallback => {
throw new Error(
`history.block is not supported. Please use the AppMountParams.onAppLeave API.`
`history.block is not supported. Please use the AppMountParameters.onAppLeave API.`
);
};

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 @@ -453,10 +453,10 @@ export interface AppMountParameters<HistoryLocationState = unknown> {
* import ReactDOM from 'react-dom';
* import { BrowserRouter, Route } from 'react-router-dom';
*
* import { CoreStart, AppMountParams } from 'src/core/public';
* import { CoreStart, AppMountParameters } from 'src/core/public';
* import { MyPluginDepsStart } from './plugin';
*
* export renderApp = ({ element, history, onAppLeave }: AppMountParams) => {
* export renderApp = ({ element, history, onAppLeave }: AppMountParameters) => {
* const { renderApp, hasUnsavedChanges } = await import('./application');
* onAppLeave(actions => {
* if(hasUnsavedChanges()) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ const MS_METRIC = {

test('general metric', () => {
const component = shallow(<MetricTile metric={GENERAL_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});

test('byte metric', () => {
const component = shallow(<MetricTile metric={BYTE_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});

test('float metric', () => {
const component = shallow(<MetricTile metric={FLOAT_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});

test('millisecond metric', () => {
const component = shallow(<MetricTile metric={MS_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import numeral from 'numeral';
import numeral from '@elastic/numeral';

export default function formatNumber(num, which) {
let format = '0.00';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,42 @@ import formatNumber from './format_number';

describe('format byte', () => {
test('zero', () => {
expect(formatNumber(0, 'byte')).toEqual('0.00 B');
expect(formatNumber(0, 'byte')).toMatchInlineSnapshot(`"0.00 B"`);
});

test('mb', () => {
expect(formatNumber(181142512, 'byte')).toEqual('181.14 MB');
expect(formatNumber(181142512, 'byte')).toMatchInlineSnapshot(`"172.75 MB"`);
});

test('gb', () => {
expect(formatNumber(273727485000, 'byte')).toEqual('273.73 GB');
expect(formatNumber(273727485000, 'byte')).toMatchInlineSnapshot(`"254.93 GB"`);
});
});

describe('format ms', () => {
test('zero', () => {
expect(formatNumber(0, 'ms')).toEqual('0.00 ms');
expect(formatNumber(0, 'ms')).toMatchInlineSnapshot(`"0.00 ms"`);
});

test('sub ms', () => {
expect(formatNumber(0.128, 'ms')).toEqual('0.13 ms');
expect(formatNumber(0.128, 'ms')).toMatchInlineSnapshot(`"0.13 ms"`);
});

test('many ms', () => {
expect(formatNumber(3030.284, 'ms')).toEqual('3030.28 ms');
expect(formatNumber(3030.284, 'ms')).toMatchInlineSnapshot(`"3030.28 ms"`);
});
});

describe('format integer', () => {
test('zero', () => {
expect(formatNumber(0, 'integer')).toEqual('0');
expect(formatNumber(0, 'integer')).toMatchInlineSnapshot(`"0"`);
});

test('sub integer', () => {
expect(formatNumber(0.728, 'integer')).toEqual('1');
expect(formatNumber(0.728, 'integer')).toMatchInlineSnapshot(`"1"`);
});

test('many integer', () => {
expect(formatNumber(3030.284, 'integer')).toEqual('3030');
expect(formatNumber(3030.284, 'integer')).toMatchInlineSnapshot(`"3030"`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';
import _ from 'lodash';
import numeral from 'numeral';
import numeral from '@elastic/numeral';
import { renderToStaticMarkup } from 'react-dom/server';

import { FormattedMessage, I18nProvider } from '@kbn/i18n/react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import d3 from 'd3';
import _ from 'lodash';
import $ from 'jquery';
import numeral from 'numeral';
import numeral from '@elastic/numeral';
import { PieContainsAllZeros, ContainerTooSmall } from '../errors';
import { Chart } from './_chart';
import { truncateLabel } from '../components/labels/truncate_labels';
Expand Down
20 changes: 0 additions & 20 deletions webpackShims/numeral.js

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"@elastic/filesaver": "1.1.2",
"@elastic/maki": "6.3.0",
"@elastic/node-crypto": "1.1.1",
"@elastic/numeral": "2.4.0",
"@elastic/numeral": "^2.5.0",
"@kbn/babel-preset": "1.0.0",
"@kbn/config-schema": "1.0.0",
"@kbn/i18n": "1.0.0",
Expand Down
20 changes: 0 additions & 20 deletions x-pack/plugins/apm/typings/numeral.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function agentCheckin(
const updateData: {
last_checkin: string;
default_api_key?: string;
default_api_key_id?: string;
local_metadata?: AgentMetadata;
current_error_events?: string;
} = {
Expand All @@ -51,11 +52,13 @@ export async function agentCheckin(
// Assign output API keys
// We currently only support default ouput
if (!defaultApiKey) {
updateData.default_api_key = await APIKeysService.generateOutputApiKey(
const outputAPIKey = await APIKeysService.generateOutputApiKey(
soClient,
'default',
agent.id
);
updateData.default_api_key = outputAPIKey.key;
updateData.default_api_key_id = outputAPIKey.id;
}
// Mutate the config to set the api token for this agent
config.outputs.default.api_key = defaultApiKey || updateData.default_api_key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateOutputApiKey(
soClient: SavedObjectsClientContract,
outputId: string,
agentId: string
): Promise<string> {
): Promise<{ key: string; id: string }> {
const name = `${agentId}:${outputId}`;
const key = await createAPIKey(soClient, name, {
'fleet-output': {
Expand All @@ -35,7 +35,7 @@ export async function generateOutputApiKey(
throw new Error('Unable to create an output api key');
}

return `${key.id}:${key.api_key}`;
return { key: `${key.id}:${key.api_key}`, id: key.id };
}

export async function generateAccessApiKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ export async function mountManagementSection(
},
};

return renderApp(element, appDependencies);
const unmountAppCallback = renderApp(element, appDependencies);

return () => {
// Change tab label back to Kibana.
docTitle.reset();
unmountAppCallback();
};
}
Loading

0 comments on commit e60f18d

Please sign in to comment.