Skip to content

Commit

Permalink
Merge branch 'main' into bump-eslint-jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Watson authored Jul 28, 2023
2 parents a6d03ca + 9584a3a commit 0f9aec2
Show file tree
Hide file tree
Showing 120 changed files with 4,490 additions and 1,266 deletions.
10 changes: 10 additions & 0 deletions examples/response_stream/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export const PLUGIN_ID = 'response-stream';
export const PLUGIN_NAME = 'response stream';
31 changes: 9 additions & 22 deletions examples/response_stream/public/components/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,21 @@

import * as React from 'react';

import {
EuiPageBody,
EuiPageContent_Deprecated as EuiPageContent,
EuiPageContentBody_Deprecated as EuiPageContentBody,
EuiPageHeader,
EuiPageHeaderSection,
EuiTitle,
} from '@elastic/eui';
import { EuiPageTemplate, EuiTitle } from '@elastic/eui';

export interface PageProps {
title?: React.ReactNode;
}

export const Page: React.FC<PageProps> = ({ title = 'Untitled', children }) => {
return (
<EuiPageBody>
<EuiPageHeader>
<EuiPageHeaderSection>
<EuiTitle size="l">
<h1>{title}</h1>
</EuiTitle>
</EuiPageHeaderSection>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentBody style={{ maxWidth: 800, margin: '0 auto' }}>
{children}
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
<>
<EuiPageTemplate.Header>
<EuiTitle size="l">
<h1>{title}</h1>
</EuiTitle>
</EuiPageTemplate.Header>
<EuiPageTemplate.Section>{children}</EuiPageTemplate.Section>
</>
);
};
10 changes: 6 additions & 4 deletions examples/response_stream/public/containers/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React from 'react';
import { Redirect } from 'react-router-dom';
import { BrowserRouter as Router, Routes, Route } from '@kbn/shared-ux-router';
import { EuiPage } from '@elastic/eui';
import { EuiPageTemplate } from '@elastic/eui';
import { useDeps } from '../../hooks/use_deps';
import { Sidebar } from './sidebar';
import { routes } from '../../routes';
Expand All @@ -26,13 +26,15 @@ export const App: React.FC = () => {

return (
<Router basename={appBasePath}>
<EuiPage>
<Sidebar />
<EuiPageTemplate restrictWidth={true} offset={0}>
<EuiPageTemplate.Sidebar sticky={true}>
<Sidebar />
</EuiPageTemplate.Sidebar>
<Routes>
{routeElements}
<Redirect to="/simple-string-stream" />
</Routes>
</EuiPage>
</EuiPageTemplate>
</Router>
);
};
6 changes: 3 additions & 3 deletions examples/response_stream/public/containers/app/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
*/

import React from 'react';
import { EuiPageSideBar_Deprecated as EuiPageSideBar, EuiSideNav } from '@elastic/eui';
import { EuiPageSidebar, EuiSideNav } from '@elastic/eui';
import { useHistory } from 'react-router-dom';
import { routes } from '../../routes';

export const Sidebar: React.FC = () => {
const history = useHistory();

return (
<EuiPageSideBar>
<EuiPageSidebar>
<EuiSideNav
items={routes.map(({ id, title, items }) => ({
id,
Expand All @@ -29,6 +29,6 @@ export const Sidebar: React.FC = () => {
})),
}))}
/>
</EuiPageSideBar>
</EuiPageSidebar>
);
};
16 changes: 16 additions & 0 deletions examples/response_stream/public/mount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { CoreSetup, CoreStart, AppMountParameters } from '@kbn/core/public';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { PLUGIN_NAME } from '../common/constants';
import { ResponseStreamStartPlugins } from './plugin';
import { App } from './containers/app';

Expand All @@ -24,6 +25,21 @@ export const mount =
async ({ appBasePath, element }: AppMountParameters) => {
const [core, plugins] = await coreSetup.getStartServices();
const deps: ResponseStreamDeps = { appBasePath, core, plugins };

core.chrome.setBreadcrumbs([
{
text: 'Developer examples',
href: `/app/developerExamples`,
onClick: (e) => {
e.preventDefault();
core.application.navigateToApp('developerExamples');
},
},
{
text: PLUGIN_NAME,
},
]);

const reactElement = (
<KibanaContextProvider services={deps}>
<App />
Expand Down
9 changes: 5 additions & 4 deletions examples/response_stream/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Plugin, CoreSetup, AppNavLinkStatus } from '@kbn/core/public';
import { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public';
import { PLUGIN_ID, PLUGIN_NAME } from '../common/constants';
import { mount } from './mount';

export interface ResponseStreamSetupPlugins {
Expand All @@ -23,15 +24,15 @@ export class ResponseStreamPlugin implements Plugin {
{ developerExamples }: ResponseStreamSetupPlugins
) {
core.application.register({
id: 'response-stream',
title: 'response stream',
id: PLUGIN_ID,
title: PLUGIN_NAME,
navLinkStatus: AppNavLinkStatus.hidden,
mount: mount(core),
});

developerExamples.register({
appId: 'response-stream',
title: 'response stream',
appId: PLUGIN_ID,
title: PLUGIN_NAME,
description:
'This example demonstrates how to stream chunks of data to the client with just a single request.',
links: [
Expand Down
5 changes: 3 additions & 2 deletions examples/response_stream/public/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React from 'react';
import { PLUGIN_ID, PLUGIN_NAME } from '../common/constants';
import { PageSimpleStringStream } from './containers/app/pages/page_simple_string_stream';
import { PageReducerStream } from './containers/app/pages/page_reducer_stream';

Expand All @@ -24,8 +25,8 @@ interface RouteDef {

export const routes: RouteSectionDef[] = [
{
title: 'response stream',
id: 'responseStream',
title: PLUGIN_NAME,
id: PLUGIN_ID,
items: [
{
title: 'Simple string stream',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@
"@cypress/webpack-preprocessor": "^5.12.2",
"@elastic/eslint-plugin-eui": "0.0.2",
"@elastic/makelogs": "^6.1.1",
"@elastic/synthetics": "^1.0.0-beta.39",
"@elastic/synthetics": "^1.3.0",
"@emotion/babel-preset-css-prop": "^11.11.0",
"@emotion/jest": "^11.11.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
Expand Down Expand Up @@ -1498,7 +1498,7 @@
"pirates": "^4.0.1",
"piscina": "^3.2.0",
"pixelmatch": "^5.3.0",
"playwright": "^1.26.0",
"playwright": "^1.35.0",
"pngjs": "^3.4.0",
"postcss": "^8.4.14",
"postcss-loader": "^4.2.0",
Expand Down
35 changes: 19 additions & 16 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ describe('actionTypeRegistry', () => {
isSystemAction: false,
},
{
actionTypeId: '.cases',
actionTypeId: 'test.system-action',
config: {},
id: 'system-connector-.cases',
name: 'System action: .cases',
id: 'system-connector-test.system-action',
name: 'System action: test.system-action',
secrets: {},
isPreconfigured: false,
isDeprecated: false,
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('actionTypeRegistry', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);

actionTypeRegistry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -410,7 +410,7 @@ describe('actionTypeRegistry', () => {

expect(actionTypes).toEqual([
{
id: '.cases',
id: 'test.system-action',
name: 'Cases',
enabled: true,
enabledInConfig: true,
Expand Down Expand Up @@ -497,13 +497,16 @@ describe('actionTypeRegistry', () => {
expect(actionTypeRegistry.isActionExecutable('my-slack1', 'foo')).toEqual(true);
});

test('should return true when isActionTypeEnabled is false and isLicenseValidForActionType is true and it has system connectors', async () => {
test('should return false when isActionTypeEnabled is false and isLicenseValidForActionType is true and it has system connectors', async () => {
mockedActionsConfig.isActionTypeEnabled.mockReturnValue(false);
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });

expect(
actionTypeRegistry.isActionExecutable('system-connector-.cases', 'system-action-type')
).toEqual(true);
actionTypeRegistry.isActionExecutable(
'system-connector-test.system-action',
'system-action-type'
)
).toEqual(false);
});

test('should call isLicenseValidForActionType of the license state with notifyUsage false by default', async () => {
Expand Down Expand Up @@ -662,7 +665,7 @@ describe('actionTypeRegistry', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -675,7 +678,7 @@ describe('actionTypeRegistry', () => {
executor,
});

const result = registry.isSystemActionType('.cases');
const result = registry.isSystemActionType('test.system-action');
expect(result).toBe(true);
});

Expand Down Expand Up @@ -720,7 +723,7 @@ describe('actionTypeRegistry', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -734,15 +737,15 @@ describe('actionTypeRegistry', () => {
executor,
});

const result = registry.getSystemActionKibanaPrivileges('.cases');
const result = registry.getSystemActionKibanaPrivileges('test.system-action');
expect(result).toEqual(['test/create']);
});

it('should return an empty array if the system action does not define any kibana privileges', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -755,7 +758,7 @@ describe('actionTypeRegistry', () => {
executor,
});

const result = registry.getSystemActionKibanaPrivileges('.cases');
const result = registry.getSystemActionKibanaPrivileges('test.system-action');
expect(result).toEqual([]);
});

Expand Down Expand Up @@ -784,7 +787,7 @@ describe('actionTypeRegistry', () => {
const getKibanaPrivileges = jest.fn().mockReturnValue(['test/create']);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -798,7 +801,7 @@ describe('actionTypeRegistry', () => {
executor,
});

registry.getSystemActionKibanaPrivileges('.cases', { foo: 'bar' });
registry.getSystemActionKibanaPrivileges('test.system-action', { foo: 'bar' });
expect(getKibanaPrivileges).toHaveBeenCalledWith({ params: { foo: 'bar' } });
});
});
Expand Down
13 changes: 7 additions & 6 deletions x-pack/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,21 @@ export class ActionTypeRegistry {
}

/**
* Returns true if action type is enabled or it is an in memory action type.
* Returns true if action type is enabled or preconfigured.
* An action type can be disabled but used with a preconfigured action.
* This does not apply to system actions as those can be disabled.
*/
public isActionExecutable(
actionId: string,
actionTypeId: string,
options: { notifyUsage: boolean } = { notifyUsage: false }
) {
const actionTypeEnabled = this.isActionTypeEnabled(actionTypeId, options);
return (
actionTypeEnabled ||
(!actionTypeEnabled &&
this.inMemoryConnectors.find((inMemoryConnector) => inMemoryConnector.id === actionId) !==
undefined)
const inMemoryConnector = this.inMemoryConnectors.find(
(connector) => connector.id === actionId
);

return actionTypeEnabled || (!actionTypeEnabled && inMemoryConnector?.isPreconfigured === true);
}

/**
Expand Down
Loading

0 comments on commit 0f9aec2

Please sign in to comment.