Skip to content

Commit

Permalink
Merge branch 'main' into elastic#79656
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Sep 14, 2022
2 parents b4303bc + 42e9292 commit 4adc17e
Show file tree
Hide file tree
Showing 524 changed files with 8,400 additions and 4,042 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,4 @@ enabled:
- x-pack/test/performance/journeys/many_fields_discover/config.ts
- x-pack/test/performance/journeys/promotion_tracking_dashboard/config.ts
- x-pack/test/performance/journeys/web_logs_dashboard/config.ts
- x-pack/test/performance/journeys/data_stress_test_lens/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ This error happens when the `xpack.encryptedSavedObjects.encryptionKey` value us
*Problem*:

Alerting rules that were created or edited in 8.2 stop running after you upgrade
to later releases. The following error occurs:
to 8.3.0 or 8.3.1. The following error occurs:

[source,text]
----
Expand All @@ -283,6 +283,7 @@ to later releases. The following error occurs:

*Solution*:

Upgrade to 8.3.2 or later releases, then go to *{stack-manage-app} > {rules-ui}* and multi-select the failed rules. Choose
Upgrade to 8.3.2 or later releases to avoid the problem. To fix failing rules,
go to *{stack-manage-app} > {rules-ui}* and multi-select the rules. Choose
**Manage rules > Update API Keys** to generate new API keys. For more details
about API key authorization, refer to <<alerting-authorization>>.
1 change: 1 addition & 0 deletions src/plugins/dashboard/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ module.exports = {
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/dashboard',
coverageReporters: ['text', 'html'],
collectCoverageFrom: ['<rootDir>/src/plugins/dashboard/{common,public,server}/**/*.{ts,tsx}'],
setupFiles: ['<rootDir>/src/plugins/dashboard/jest_setup.ts'],
};
12 changes: 12 additions & 0 deletions src/plugins/dashboard/jest_setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { pluginServices } from './public/services/plugin_services';
import { registry } from './public/services/plugin_services.stub';

pluginServices.setRegistry(registry.start({}));
13 changes: 0 additions & 13 deletions src/plugins/dashboard/public/application/_dashboard_app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,3 @@
flex-direction: column;
}
}

// Temporary fix for two tone icons to make them monochrome
.dshSolutionToolbar__editorContextMenu--dark {
.euiIcon path {
fill: $euiColorGhost;
}
}

.dshSolutionToolbar__editorContextMenu--light {
.euiIcon path {
fill: $euiColorInk;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
import { AddToLibraryAction } from '.';
import { DashboardContainer } from '../embeddable/dashboard_container';
import { getSampleDashboardInput } from '../test_helpers';

import { CoreStart } from '@kbn/core/public';

import { coreMock, uiSettingsServiceMock } from '@kbn/core/public/mocks';
import { embeddablePluginMock } from '@kbn/embeddable-plugin/public/mocks';
import { getStubPluginServices } from '@kbn/presentation-util-plugin/public';
import { screenshotModePluginMock } from '@kbn/screenshot-mode-plugin/public/mocks';

import {
EmbeddableInput,
Expand All @@ -24,53 +18,38 @@ import {
isErrorEmbeddable,
ReferenceOrValueEmbeddable,
ViewMode,
} from '../../services/embeddable';
} from '@kbn/embeddable-plugin/public';
import {
ContactCardEmbeddable,
ContactCardEmbeddableFactory,
ContactCardEmbeddableInput,
ContactCardEmbeddableOutput,
CONTACT_CARD_EMBEDDABLE,
} from '../../services/embeddable_test_samples';

const { setup, doStart } = embeddablePluginMock.createInstance();
setup.registerEmbeddableFactory(
CONTACT_CARD_EMBEDDABLE,
new ContactCardEmbeddableFactory((() => null) as any, {} as any)
);
const start = doStart();
} from '@kbn/embeddable-plugin/public/lib/test_samples/embeddables';
import { pluginServices } from '../../services/plugin_services';

const embeddableFactory = new ContactCardEmbeddableFactory((() => null) as any, {} as any);
pluginServices.getServices().embeddable.getEmbeddableFactory = jest
.fn()
.mockReturnValue(embeddableFactory);
let container: DashboardContainer;
let embeddable: ContactCardEmbeddable & ReferenceOrValueEmbeddable;
let coreStart: CoreStart;
let capabilities: CoreStart['application']['capabilities'];

beforeEach(async () => {
coreStart = coreMock.createStart();
capabilities = {
...coreStart.application.capabilities,
visualize: { save: true },
maps: { save: true },
};
const defaultCapabilities = {
advancedSettings: {},
visualize: { save: true },
maps: { save: true },
navLinks: {},
};

const containerOptions = {
ExitFullScreenButton: () => null,
SavedObjectFinder: () => null,
application: {} as any,
embeddable: start,
inspector: {} as any,
notifications: {} as any,
overlays: coreStart.overlays,
savedObjectMetaData: {} as any,
uiActions: {} as any,
uiSettings: uiSettingsServiceMock.createStartContract(),
http: coreStart.http,
theme: coreStart.theme,
presentationUtil: getStubPluginServices(),
screenshotMode: screenshotModePluginMock.createSetupContract(),
};
Object.defineProperty(pluginServices.getServices().application, 'capabilities', {
value: defaultCapabilities,
});

beforeEach(async () => {
pluginServices.getServices().application.capabilities = defaultCapabilities;

container = new DashboardContainer(getSampleDashboardInput(), containerOptions);
container = new DashboardContainer(getSampleDashboardInput());

const contactCardEmbeddable = await container.addNewEmbeddable<
ContactCardEmbeddableInput,
Expand All @@ -95,10 +74,7 @@ beforeEach(async () => {
});

test('Add to library is incompatible with Error Embeddables', async () => {
const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities,
});
const action = new AddToLibraryAction();
const errorEmbeddable = new ErrorEmbeddable(
'Wow what an awful error',
{ id: ' 404' },
Expand All @@ -108,36 +84,28 @@ test('Add to library is incompatible with Error Embeddables', async () => {
});

test('Add to library is incompatible on visualize embeddable without visualize save permissions', async () => {
const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities: { ...capabilities, visualize: { save: false } },
});
pluginServices.getServices().application.capabilities = {
...defaultCapabilities,
visualize: { save: false },
};
const action = new AddToLibraryAction();
expect(await action.isCompatible({ embeddable })).toBe(false);
});

test('Add to library is compatible when embeddable on dashboard has value type input', async () => {
const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities,
});
const action = new AddToLibraryAction();
embeddable.updateInput(await embeddable.getInputAsValueType());
expect(await action.isCompatible({ embeddable })).toBe(true);
});

test('Add to library is not compatible when embeddable input is by reference', async () => {
const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities,
});
const action = new AddToLibraryAction();
embeddable.updateInput(await embeddable.getInputAsRefType());
expect(await action.isCompatible({ embeddable })).toBe(false);
});

test('Add to library is not compatible when view mode is set to view', async () => {
const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities,
});
const action = new AddToLibraryAction();
embeddable.updateInput(await embeddable.getInputAsRefType());
embeddable.updateInput({ viewMode: ViewMode.VIEW });
expect(await action.isCompatible({ embeddable })).toBe(false);
Expand All @@ -158,10 +126,7 @@ test('Add to library is not compatible when embeddable is not in a dashboard con
mockedByReferenceInput: { savedObjectId: 'test', id: orphanContactCard.id },
mockedByValueInput: { firstName: 'Kibanana', id: orphanContactCard.id },
});
const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities,
});
const action = new AddToLibraryAction();
expect(await action.isCompatible({ embeddable: orphanContactCard })).toBe(false);
});

Expand All @@ -170,10 +135,7 @@ test('Add to library replaces embeddableId and retains panel count', async () =>
const originalPanelCount = Object.keys(dashboard.getInput().panels).length;
const originalPanelKeySet = new Set(Object.keys(dashboard.getInput().panels));

const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities,
});
const action = new AddToLibraryAction();
await action.execute({ embeddable });
expect(Object.keys(container.getInput().panels).length).toEqual(originalPanelCount);

Expand All @@ -199,10 +161,7 @@ test('Add to library returns reference type input', async () => {
});
const dashboard = embeddable.getRoot() as IContainer;
const originalPanelKeySet = new Set(Object.keys(dashboard.getInput().panels));
const action = new AddToLibraryAction({
toasts: coreStart.notifications.toasts,
capabilities,
});
const action = new AddToLibraryAction();
await action.execute({ embeddable });
const newPanelId = Object.keys(container.getInput().panels).find(
(key) => !originalPanelKeySet.has(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
* Side Public License, v 1.
*/

import { Action, IncompatibleActionError } from '../../services/ui_actions';
import {
ViewMode,
PanelState,
IEmbeddable,
type PanelState,
type IEmbeddable,
PanelNotFoundError,
EmbeddableInput,
isReferenceOrValueEmbeddable,
type EmbeddableInput,
isErrorEmbeddable,
} from '../../services/embeddable';
import { ApplicationStart, NotificationsStart } from '../../services/core';
isReferenceOrValueEmbeddable,
} from '@kbn/embeddable-plugin/public';
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';

import { dashboardAddToLibraryAction } from '../../dashboard_strings';
import { DashboardPanelState, DASHBOARD_CONTAINER_TYPE, DashboardContainer } from '..';
import { type DashboardPanelState, DASHBOARD_CONTAINER_TYPE, type DashboardContainer } from '..';
import { pluginServices } from '../../services/plugin_services';

export const ACTION_ADD_TO_LIBRARY = 'saveToLibrary';

Expand All @@ -31,12 +32,15 @@ export class AddToLibraryAction implements Action<AddToLibraryActionContext> {
public readonly id = ACTION_ADD_TO_LIBRARY;
public order = 15;

constructor(
private deps: {
toasts: NotificationsStart['toasts'];
capabilities: ApplicationStart['capabilities'];
}
) {}
private applicationCapabilities;
private toastsService;

constructor() {
({
application: { capabilities: this.applicationCapabilities },
notifications: { toasts: this.toastsService },
} = pluginServices.getServices());
}

public getDisplayName({ embeddable }: AddToLibraryActionContext) {
if (!embeddable.getRoot() || !embeddable.getRoot().isContainer) {
Expand All @@ -54,10 +58,8 @@ export class AddToLibraryAction implements Action<AddToLibraryActionContext> {

public async isCompatible({ embeddable }: AddToLibraryActionContext) {
// TODO: Fix this, potentially by adding a 'canSave' function to embeddable interface
const canSave =
embeddable.type === 'map'
? this.deps.capabilities.maps?.save
: this.deps.capabilities.visualize.save;
const { maps, visualize } = this.applicationCapabilities;
const canSave = embeddable.type === 'map' ? maps.save : visualize.save;

return Boolean(
canSave &&
Expand All @@ -75,7 +77,6 @@ export class AddToLibraryAction implements Action<AddToLibraryActionContext> {
if (!isReferenceOrValueEmbeddable(embeddable)) {
throw new IncompatibleActionError();
}

const newInput = await embeddable.getInputAsRefType();

embeddable.updateInput(newInput);
Expand All @@ -95,7 +96,7 @@ export class AddToLibraryAction implements Action<AddToLibraryActionContext> {
const title = dashboardAddToLibraryAction.getSuccessMessage(
embeddable.getTitle() ? `'${embeddable.getTitle()}'` : ''
);
this.deps.toasts.addSuccess({
this.toastsService.addSuccess({
title,
'data-test-subj': 'addPanelToLibrarySuccess',
});
Expand Down
Loading

0 comments on commit 4adc17e

Please sign in to comment.