Skip to content

Commit

Permalink
Merge branch 'main' into security-in-core/osquery-server-plugin-server
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan authored Jun 26, 2024
2 parents 13634bb + dd48f04 commit a38b956
Show file tree
Hide file tree
Showing 71 changed files with 938 additions and 398 deletions.
2 changes: 1 addition & 1 deletion docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6267,7 +6267,7 @@ Before you upgrade to 8.1.0, review the breaking changes, then mitigate the impa
The `/api/reporting/generate/csv` endpoint has been removed. For more information, refer to {kibana-pull}121435[#121435].
*Impact* +
If you are using 7.13.0 and earlier, {kibana-ref-all}/8.1/automating-report-generation.html[regenerate the POST URLs] that you use to automatatically generate CSV reports.
If you are using 7.13.0 and earlier, {kibana-ref-all}/8.1/automating-report-generation.html[regenerate the POST URLs] that you use to automatically generate CSV reports.
====

[discrete]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import { i18n } from '@kbn/i18n';
import { apiIsPresentationContainer } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import {
IncompatibleActionError,
UiActionsStart,
ADD_PANEL_TRIGGER,
} from '@kbn/ui-actions-plugin/public';
import { embeddableExamplesGrouping } from '../embeddable_examples_grouping';
import { ADD_DATA_TABLE_ACTION_ID, DATA_TABLE_ID } from './constants';

Expand Down Expand Up @@ -39,5 +43,5 @@ export const registerCreateDataTableAction = (uiActions: UiActionsStart) => {
defaultMessage: 'Data table',
}),
});
uiActions.attachAction('ADD_PANEL_TRIGGER', ADD_DATA_TABLE_ACTION_ID);
uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_DATA_TABLE_ACTION_ID);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const embeddableExamplesGrouping = {
id: 'embeddableExamples',
getIconType: () => 'documentation',
getDisplayName: () => 'Embeddable examples',
order: -10,
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import { i18n } from '@kbn/i18n';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import {
IncompatibleActionError,
UiActionsStart,
ADD_PANEL_TRIGGER,
} from '@kbn/ui-actions-plugin/public';
import { embeddableExamplesGrouping } from '../embeddable_examples_grouping';
import { ADD_EUI_MARKDOWN_ACTION_ID, EUI_MARKDOWN_ID } from './constants';
import { MarkdownEditorSerializedState } from './types';
Expand Down Expand Up @@ -41,7 +45,7 @@ export const registerCreateEuiMarkdownAction = (uiActions: UiActionsStart) => {
defaultMessage: 'EUI Markdown',
}),
});
uiActions.attachAction('ADD_PANEL_TRIGGER', ADD_EUI_MARKDOWN_ACTION_ID);
uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_EUI_MARKDOWN_ACTION_ID);
if (uiActions.hasTrigger('ADD_CANVAS_ELEMENT_TRIGGER')) {
// Because Canvas is not enabled in Serverless, this trigger might not be registered - only attach
// the create action if the Canvas-specific trigger does indeed exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { i18n } from '@kbn/i18n';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { IncompatibleActionError, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
import { UiActionsPublicStart } from '@kbn/ui-actions-plugin/public/plugin';
import { embeddableExamplesGrouping } from '../embeddable_examples_grouping';
import { ADD_FIELD_LIST_ACTION_ID, FIELD_LIST_ID } from './constants';
Expand All @@ -34,5 +34,5 @@ export const registerCreateFieldListAction = (uiActions: UiActionsPublicStart) =
defaultMessage: 'Field list',
}),
});
uiActions.attachAction('ADD_PANEL_TRIGGER', ADD_FIELD_LIST_ACTION_ID);
uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_FIELD_LIST_ACTION_ID);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CoreStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { apiIsPresentationContainer } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { IncompatibleActionError, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
import { UiActionsPublicStart } from '@kbn/ui-actions-plugin/public/plugin';
import { embeddableExamplesGrouping } from '../embeddable_examples_grouping';
import {
Expand Down Expand Up @@ -67,5 +67,5 @@ export const registerCreateSavedBookAction = (uiActions: UiActionsPublicStart, c
defaultMessage: 'Book',
}),
});
uiActions.attachAction('ADD_PANEL_TRIGGER', ADD_SAVED_BOOK_ACTION_ID);
uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_SAVED_BOOK_ACTION_ID);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import {
IncompatibleActionError,
type UiActionsStart,
ADD_PANEL_TRIGGER,
} from '@kbn/ui-actions-plugin/public';
import { embeddableExamplesGrouping } from '../embeddable_examples_grouping';
import { ADD_SEARCH_ACTION_ID, SEARCH_EMBEDDABLE_ID } from './constants';
import { SearchSerializedState } from './types';
Expand All @@ -33,7 +37,7 @@ export const registerAddSearchPanelAction = (uiActions: UiActionsStart) => {
);
},
});
uiActions.attachAction('ADD_PANEL_TRIGGER', ADD_SEARCH_ACTION_ID);
uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_SEARCH_ACTION_ID);
if (uiActions.hasTrigger('ADD_CANVAS_ELEMENT_TRIGGER')) {
// Because Canvas is not enabled in Serverless, this trigger might not be registered - only attach
// the create action if the Canvas-specific trigger does indeed exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import type { Trigger } from '@kbn/ui-actions-plugin/public';
import { Trigger } from '.';

export const ADD_PANEL_TRIGGER = 'ADD_PANEL_TRIGGER';

export const addPanelMenuTrigger: Trigger = {
id: ADD_PANEL_TRIGGER,
title: i18n.translate('dashboard.addPanelMenuTrigger.title', {
title: i18n.translate('uiActions.triggers.dashboard.addPanelMenu.title', {
defaultMessage: 'Add panel menu',
}),
description: i18n.translate('dashboard.addPanelMenuTrigger.description', {
description: i18n.translate('uiActions.triggers.dashboard.addPanelMenu.description', {
defaultMessage: "A new action will appear to the dashboard's add panel menu",
}),
};
1 change: 1 addition & 0 deletions packages/kbn-ui-actions-browser/src/triggers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './row_click_trigger';
export * from './default_trigger';
export * from './visualize_field_trigger';
export * from './visualize_geo_field_trigger';
export * from './dashboard_app_panel_trigger';
1 change: 0 additions & 1 deletion src/plugins/dashboard/public/dashboard_actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { CoreStart } from '@kbn/core/public';
import { CONTEXT_MENU_TRIGGER, PANEL_NOTIFICATION_TRIGGER } from '@kbn/embeddable-plugin/public';

import { DashboardStartDependencies } from '../plugin';
import { AddToLibraryAction } from './add_to_library_action';
import { LegacyAddToLibraryAction } from './legacy_add_to_library_action';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { getMockPresentationContainer } from '@kbn/presentation-containers/mocks';
import { getAddPanelActionMenuItems } from './add_panel_action_menu_items';
import { getAddPanelActionMenuItemsGroup } from './add_panel_action_menu_items';

describe('getAddPanelActionMenuItems', () => {
it('returns the items correctly', async () => {
Expand Down Expand Up @@ -54,52 +54,62 @@ describe('getAddPanelActionMenuItems', () => {
],
},
];
const [items, grouped] = getAddPanelActionMenuItems(
const grouped = getAddPanelActionMenuItemsGroup(
getMockPresentationContainer(),
registeredActions,
jest.fn()
);
expect(items).toStrictEqual([
{
'data-test-subj': 'create-action-Action name',
icon: 'pencil',
name: 'Action name',
onClick: expect.any(Function),
toolTipContent: 'Action tooltip',
},
]);

expect(grouped).toStrictEqual({
groupedAddPanelAction: {
id: 'groupedAddPanelAction',
title: 'Custom group',
icon: 'logoElasticsearch',
order: 0,
'data-test-subj': 'dashboardEditorMenu-groupedAddPanelActionGroup',
items: [
{
'data-test-subj': 'create-action-Action name 01',
icon: 'pencil',
id: 'TEST_ACTION_01',
name: 'Action name 01',
onClick: expect.any(Function),
toolTipContent: 'Action tooltip',
description: 'Action tooltip',
order: 0,
},
{
'data-test-subj': 'create-action-Action name',
icon: 'empty',
id: 'TEST_ACTION_02',
name: 'Action name',
onClick: expect.any(Function),
description: 'Action tooltip',
order: 0,
},
],
},
other: {
id: 'other',
title: 'Other',
order: -1,
'data-test-subj': 'dashboardEditorMenu-otherGroup',
items: [
{
id: 'ACTION_CREATE_ESQL_CHART',
name: 'Action name',
icon: 'pencil',
description: 'Action tooltip',
onClick: expect.any(Function),
toolTipContent: 'Action tooltip',
'data-test-subj': 'create-action-Action name',
order: 0,
},
],
},
});
});

it('returns empty array if no actions have been registered', async () => {
const [items, grouped] = getAddPanelActionMenuItems(
getMockPresentationContainer(),
[],
jest.fn()
);
expect(items).toStrictEqual([]);
const grouped = getAddPanelActionMenuItemsGroup(getMockPresentationContainer(), [], jest.fn());

expect(grouped).toStrictEqual({});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { ActionExecutionContext, Action } from '@kbn/ui-actions-plugin/public';

import {
type ActionExecutionContext,
type Action,
addPanelMenuTrigger,
} from '@kbn/ui-actions-plugin/public';
import { PresentationContainer } from '@kbn/presentation-containers';
import type {
EuiContextMenuPanelDescriptor,
EuiContextMenuPanelItemDescriptor,
} from '@elastic/eui';
import { addPanelMenuTrigger } from '../../triggers';
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import type { IconType, CommonProps } from '@elastic/eui';
import React, { type MouseEventHandler } from 'react';

export interface PanelSelectionMenuItem extends Pick<CommonProps, 'data-test-subj'> {
id: string;
name: string;
icon: IconType;
onClick: MouseEventHandler;
description?: string;
isDisabled?: boolean;
isDeprecated?: boolean;
order: number;
}

export type GroupedAddPanelActions = Pick<
PanelSelectionMenuItem,
'id' | 'isDisabled' | 'data-test-subj' | 'order'
> & {
title: string;
items: PanelSelectionMenuItem[];
};

const onAddPanelActionClick =
(action: Action, context: ActionExecutionContext<object>, closePopover: () => void) =>
Expand All @@ -30,56 +52,66 @@ const onAddPanelActionClick =
} else action.execute(context);
};

export type GroupedAddPanelActions = EuiContextMenuPanelDescriptor & {
icon?: string;
};

export const getAddPanelActionMenuItems = (
export const getAddPanelActionMenuItemsGroup = (
api: PresentationContainer,
actions: Array<Action<object>> | undefined,
closePopover: () => void
): [EuiContextMenuPanelItemDescriptor[], Record<string, GroupedAddPanelActions>] => {
const ungrouped: EuiContextMenuPanelItemDescriptor[] = [];
) => {
const grouped: Record<string, GroupedAddPanelActions> = {};

const context = {
embeddable: api,
trigger: addPanelMenuTrigger,
};

const getMenuItem = (item: Action<object>) => {
const getMenuItem = (item: Action<object>): PanelSelectionMenuItem => {
const actionName = item.getDisplayName(context);

return {
id: item.id,
name: actionName,
icon:
(typeof item.getIconType === 'function' ? item.getIconType(context) : undefined) ?? 'empty',
onClick: onAddPanelActionClick(item, context, closePopover),
'data-test-subj': `create-action-${actionName}`,
toolTipContent: item?.getDisplayNameTooltip?.(context),
description: item?.getDisplayNameTooltip?.(context),
order: item.order ?? 0,
};
};

actions?.forEach((item) => {
if (Array.isArray(item.grouping)) {
item.grouping.forEach((group) => {
if (!grouped[group.id]) {
grouped[group.id] = {
id: group.id,
icon:
(typeof group.getIconType === 'function' ? group.getIconType(context) : undefined) ??
'empty',
title: group.getDisplayName ? group.getDisplayName(context) : undefined,
const groupId = group.id;
if (!grouped[groupId]) {
grouped[groupId] = {
id: groupId,
title: group.getDisplayName ? group.getDisplayName(context) : '',
'data-test-subj': `dashboardEditorMenu-${groupId}Group`,
order: group.order ?? 0,
items: [],
};
}

grouped[group.id]!.items!.push(getMenuItem(item));
});
} else {
ungrouped.push(getMenuItem(item));
// use other group as the default for definitions that don't have a group
const fallbackGroup = COMMON_EMBEDDABLE_GROUPING.other;

if (!grouped[fallbackGroup.id]) {
grouped[fallbackGroup.id] = {
id: fallbackGroup.id,
title: fallbackGroup.getDisplayName?.({ embeddable: api }) || '',
'data-test-subj': `dashboardEditorMenu-${fallbackGroup.id}Group`,
order: fallbackGroup.order || 0,
items: [],
};
}

grouped[fallbackGroup.id].items.push(getMenuItem(item));
}
});

return [ungrouped, grouped];
return grouped;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
@include euiOverflowShadow;
max-height: 60vh;
overflow-y: scroll;
}
}
Loading

0 comments on commit a38b956

Please sign in to comment.