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

[Security Solution] Eui visual refresh - make palettes theme aware #205873

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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 @@ -8,6 +8,7 @@
import type { IndexPatternMapping } from '../types';
import type { IndexPatternSavedObject } from '../../../../../common/hooks/types';
import { LAYER_TYPE } from '@kbn/maps-plugin/common';
import type { EuiThemeComputed } from '@elastic/eui';

export const mockIndexPatternIds: IndexPatternMapping[] = [
{ title: 'filebeat-*', id: '8c7323ac-97ad-4b53-ac0a-40f8f691a918' },
Expand Down Expand Up @@ -530,3 +531,11 @@ export const mockCommaFilebeatExclusionGlobIndexPattern: IndexPatternSavedObject
title: 'filebeat-*,-filebeat-7.6.0*',
},
};

export const mockEuiTheme: EuiThemeComputed<{}> = {
colors: {
vis: {
euiColorVisNeutral0: '#FFFFFF',
},
},
} as unknown as EuiThemeComputed<{}>;
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('EmbeddedMapComponent', () => {
</TestProviders>
);
await waitFor(() => {
const dataViewArg = (getLayerList as jest.Mock).mock.calls[0][0];
const dataViewArg = (getLayerList as jest.Mock).mock.calls[0][1];
expect(dataViewArg).toEqual([filebeatDataView]);
});
});
Expand All @@ -221,7 +221,7 @@ describe('EmbeddedMapComponent', () => {
</TestProviders>
);
await waitFor(() => {
const dataViewArg = (getLayerList as jest.Mock).mock.calls[0][0];
const dataViewArg = (getLayerList as jest.Mock).mock.calls[0][1];
expect(dataViewArg).toEqual([filebeatDataView]);
});
rerender(
Expand All @@ -231,7 +231,7 @@ describe('EmbeddedMapComponent', () => {
);
await waitFor(() => {
// data view is updated with the returned embeddable.setLayerList callback, which is passesd getLayerList(dataViews)
const dataViewArg = (getLayerList as jest.Mock).mock.calls[1][0];
const dataViewArg = (getLayerList as jest.Mock).mock.calls[1][1];
expect(dataViewArg).toEqual([filebeatDataView, packetbeatDataView]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// embedded map v2

import { EuiAccordion, EuiLink, EuiText } from '@elastic/eui';
import { EuiAccordion, EuiLink, EuiText, useEuiTheme } from '@elastic/eui';
import React, { useCallback, useEffect, useState, useMemo } from 'react';
import { useSelector } from 'react-redux';
import { createHtmlPortalNode, InPortal, OutPortal } from 'react-reverse-portal';
Expand Down Expand Up @@ -106,6 +106,7 @@ export const EmbeddedMapComponent = ({
setQuery,
startDate,
}: EmbeddedMapProps) => {
const { euiTheme } = useEuiTheme();
const { services } = useKibana();
const { storage } = services;

Expand Down Expand Up @@ -136,7 +137,7 @@ export const EmbeddedMapComponent = ({
// ensures only index patterns with maps fields are passed
const goodDataViews = availableDataViews.filter((_, i) => apiResponse[i] ?? false);
if (!canceled) {
setLayerList(getLayerList(goodDataViews));
setLayerList(getLayerList({ euiTheme }, goodDataViews));
}
} catch (e) {
if (!canceled) {
Expand All @@ -152,7 +153,7 @@ export const EmbeddedMapComponent = ({
return () => {
canceled = true;
};
}, [addError, availableDataViews, isFieldInIndexPattern]);
}, [addError, availableDataViews, euiTheme, isFieldInIndexPattern]);

useEffect(() => {
const dataViews = kibanaDataViews.filter((dataView) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
mockLineLayer,
mockServerLayer,
mockSourceLayer,
mockEuiTheme,
} from './__mocks__/mock';

jest.mock('uuid', () => {
Expand All @@ -28,27 +29,36 @@ jest.mock('uuid', () => {
};
});

const layerProviderDependencies = { euiTheme: mockEuiTheme };

describe('map_config', () => {
describe('#getLayerList', () => {
test('it returns the complete layerList with a source, destination, and line layer', () => {
const layerList = getLayerList(mockIndexPatternIds);
const layerList = getLayerList(layerProviderDependencies, mockIndexPatternIds);
expect(layerList).toStrictEqual(mockLayerList);
});

test('it returns the complete layerList for multiple indices', () => {
const layerList = getLayerList([...mockIndexPatternIds, ...mockIndexPatternIds]);
const layerList = getLayerList(layerProviderDependencies, [
...mockIndexPatternIds,
...mockIndexPatternIds,
]);
expect(layerList).toStrictEqual(mockLayerListDouble);
});

test('it returns the complete layerList for multiple indices with custom layer mapping', () => {
const layerList = getLayerList([...mockIndexPatternIds, ...mockAPMIndexPatternIds]);
const layerList = getLayerList(layerProviderDependencies, [
...mockIndexPatternIds,
...mockAPMIndexPatternIds,
]);
expect(layerList).toStrictEqual(mockLayerListMixed);
});
});

describe('#getSourceLayer', () => {
test('it returns a source layer', () => {
const layerList = getSourceLayer(
layerProviderDependencies,
mockIndexPatternIds[0].title,
mockIndexPatternIds[0].id,
mockLayerGroup.id,
Expand All @@ -59,6 +69,7 @@ describe('map_config', () => {

test('it returns a source layer for custom layer mapping', () => {
const layerList = getSourceLayer(
layerProviderDependencies,
mockAPMIndexPatternIds[0].title,
mockAPMIndexPatternIds[0].id,
mockLayerGroup.id,
Expand All @@ -71,6 +82,7 @@ describe('map_config', () => {
describe('#getDestinationLayer', () => {
test('it returns a destination layer', () => {
const layerList = getDestinationLayer(
layerProviderDependencies,
mockIndexPatternIds[0].title,
mockIndexPatternIds[0].id,
mockLayerGroup.id,
Expand All @@ -81,6 +93,7 @@ describe('map_config', () => {

test('it returns a destination layer for custom layer mapping', () => {
const layerList = getDestinationLayer(
layerProviderDependencies,
mockAPMIndexPatternIds[0].title,
mockAPMIndexPatternIds[0].id,
mockLayerGroup.id,
Expand Down
Loading