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

Reduce Beats management plugin entry bundle #79092

Merged
merged 2 commits into from
Oct 4, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import { get } from 'lodash';
import React from 'react';

import { EuiLink } from '@elastic/eui';
Expand All @@ -31,7 +31,7 @@ export const ConnectedLinkComponent = ({
}

// Shorthand for pathname
const pathname = path || _.get(props.to, 'pathname') || location.pathname;
const pathname = path || get(props.to, 'pathname') || location.pathname;

return (
<Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Tags Client Domain Lib', () => {
});

it('should use helper function to convert users yaml in tag to config object', async () => {
const convertedBlocks = lib.userConfigsToJson([
const convertedBlocks = await lib.userConfigsToJson([
{
id: 'foo',
tag: 'basic',
Expand All @@ -42,7 +42,7 @@ describe('Tags Client Domain Lib', () => {
});

it('should use helper function to convert user config to json with undefined `other`', async () => {
const convertedTag = lib.userConfigsToJson([
const convertedTag = await lib.userConfigsToJson([
{
id: 'foo',
tag: 'basic',
Expand All @@ -61,7 +61,7 @@ describe('Tags Client Domain Lib', () => {
});

it('should use helper function to convert users yaml in tag to config object, where empty other leads to no other fields saved', async () => {
const convertedTag = lib.userConfigsToJson([
const convertedTag = await lib.userConfigsToJson([
{
id: 'foo',
tag: 'basic',
Expand All @@ -83,7 +83,7 @@ describe('Tags Client Domain Lib', () => {
});

it('should convert tokenized fields to JSON', async () => {
const convertedTag = lib.userConfigsToJson([
const convertedTag = await lib.userConfigsToJson([
{
id: 'foo',
tag: 'basic',
Expand All @@ -106,7 +106,7 @@ describe('Tags Client Domain Lib', () => {
});

it('should use helper function to convert config object to users yaml', async () => {
const convertedTag = lib.jsonConfigToUserYaml([
const convertedTag = await lib.jsonConfigToUserYaml([
{
id: 'foo',
tag: 'basic',
Expand All @@ -127,7 +127,7 @@ describe('Tags Client Domain Lib', () => {
});

it('should use helper function to convert config object to users yaml with empty `other`', async () => {
const convertedTag = lib.jsonConfigToUserYaml([
const convertedTag = await lib.jsonConfigToUserYaml([
{
id: 'foo',
tag: 'basic',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import yaml from 'js-yaml';
import { set } from '@elastic/safer-lodash-set';
import { get, has, omit } from 'lodash';
import { ConfigBlockSchema, ConfigurationBlock } from '../../common/domain_types';
Expand All @@ -19,16 +18,17 @@ export class ConfigBlocksLib {
) {}

public upsert = async (blocks: ConfigurationBlock[]) => {
return await this.adapter.upsert(this.userConfigsToJson(blocks));
return await this.adapter.upsert(await this.userConfigsToJson(blocks));
};

public getForTags = async (tagIds: string[], page: number) => {
const result = await this.adapter.getForTags(tagIds, page);
result.list = this.jsonConfigToUserYaml(result.list);
result.list = await this.jsonConfigToUserYaml(result.list);
return result;
};

public jsonConfigToUserYaml(blocks: ConfigurationBlock[]): ConfigurationBlock[] {
public async jsonConfigToUserYaml(blocks: ConfigurationBlock[]): Promise<ConfigurationBlock[]> {
const yaml = await import('js-yaml');
// configuration_blocks yaml, JS cant read YAML so we parse it into JS,
// because beats flattens all fields, and we need more structure.
// we take tagConfigs, grab the config that applies here, render what we can into
Expand Down Expand Up @@ -73,7 +73,8 @@ export class ConfigBlocksLib {
});
}

public userConfigsToJson(blocks: ConfigurationBlock[]): ConfigurationBlock[] {
public async userConfigsToJson(blocks: ConfigurationBlock[]): Promise<ConfigurationBlock[]> {
const yaml = await import('js-yaml');
// configurations is the JS representation of the config yaml,
// so here we take that JS and convert it into a YAML string.
// we do so while also flattening "other" into the flat yaml beats expect
Expand Down