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

[Canvas] Expression error #103048

Merged
merged 44 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
71db0fc
Basic setup of error plugin.
Kuznietsov Jun 23, 2021
f90a298
Removed not used `function` files at `error` expression.
Kuznietsov Jun 23, 2021
4a77b19
Moved related components from canvas.
Kuznietsov Jun 23, 2021
41876e8
Changed imports of components.
Kuznietsov Jun 23, 2021
e691da4
Fixed renderer and storybook.
Kuznietsov Jun 23, 2021
1a2ff9f
Fixed types errors.
Kuznietsov Jun 23, 2021
a5d08e5
Added limits.
Kuznietsov Jun 23, 2021
90497e7
Removed useless translations and fixed .i18nrc.json
Kuznietsov Jun 23, 2021
c6489e6
added `done` handler call.
Kuznietsov Jun 23, 2021
a5ba653
Added more fixes fo i18nc.
Kuznietsov Jun 23, 2021
381f7fd
Added docs.
Kuznietsov Jun 23, 2021
21a5fac
More fixes of i18nrc.
Kuznietsov Jun 23, 2021
8959908
Fixed async functions.
Kuznietsov Jun 23, 2021
5627f8b
Fixed one test with Expression input.
Kuznietsov Jun 24, 2021
3f75dbb
Fixed storybook error.
Kuznietsov Jun 24, 2021
2f11ad8
More fixes.
Kuznietsov Jun 24, 2021
0d07ce5
removed unused translations.
Kuznietsov Jun 24, 2021
8eff35d
Removed handlers and changed the way of handling `resize` and calling…
Kuznietsov Jun 30, 2021
bb2a9f3
Merge branch 'master' into expression_error
Kuznietsov Jul 2, 2021
655ca03
Fixed i18n error.
Kuznietsov Jul 2, 2021
d33124d
Merge branch 'master' into expression_error
kibanamachine Jul 5, 2021
26d3468
Fixed storybook.
Kuznietsov Jul 6, 2021
2e65ee2
Merge branch 'expression_error' of github.com:Kunzetsov/kibana into e…
Kuznietsov Jul 6, 2021
7773815
Merge branch 'master' into expression_error
Kuznietsov Jul 6, 2021
288a899
Replaced Popover with EuiPopover.
Kuznietsov Jul 7, 2021
eefb9a4
Moved `Popover` back to `canvas`
Kuznietsov Jul 7, 2021
3e88c7e
Removed `Popover` export from presentation_utils components.
Kuznietsov Jul 7, 2021
e191b16
Moved error_component and debug_component from presentation_util to e…
Kuznietsov Jul 7, 2021
daa49ef
Fixed translations and imports.
Kuznietsov Jul 7, 2021
2925183
Moved `debug renderer` to `expression_error` plugin.
Kuznietsov Jul 7, 2021
55152f0
Fixed error.
Kuznietsov Jul 7, 2021
7a632e1
Fixed lazy exports.
Kuznietsov Jul 7, 2021
872f647
Fixed imports
Kuznietsov Jul 7, 2021
6a8c5c4
Merge branch 'master' into expression_error
kibanamachine Jul 7, 2021
52505f4
Merge remote-tracking branch 'upstream/master' into expression_error
Kuznietsov Jul 9, 2021
a023ed7
Merge branch 'expression_error' of github.com:Kunzetsov/kibana into e…
Kuznietsov Jul 9, 2021
0f0c41a
Fixed storybook snapshot.
Kuznietsov Jul 9, 2021
a0dffa4
Removed `.i18nrc.json`.
Kuznietsov Jul 9, 2021
ecacdcd
Fixed color of `error`.
Kuznietsov Jul 9, 2021
c9bdadd
Merge branch 'master' into expression_error
Kuznietsov Jul 9, 2021
3d963bd
Merge branch 'master' into expression_error
kibanamachine Jul 12, 2021
03603ac
Merge branch 'master' into expression_error
Kuznietsov Jul 13, 2021
ddfc586
Merge branch 'master' into expression_error
Kuznietsov Jul 14, 2021
6744b26
Exported concrete elements from popover.
Kuznietsov Jul 15, 2021
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
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"esUi": "src/plugins/es_ui_shared",
"devTools": "src/plugins/dev_tools",
"expressions": "src/plugins/expressions",
"expressionError": "src/plugins/expression_error",
"expressionRevealImage": "src/plugins/expression_reveal_image",
"inputControl": "src/plugins/input_control_vis",
"inspector": "src/plugins/inspector",
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ This API doesn't support angular, for registering angular dev tools, bootstrap a
|This plugin contains reusable code in the form of self-contained modules (or libraries). Each of these modules exports a set of functionality relevant to the domain of the module.


|{kib-repo}blob/{branch}/src/plugins/expression_error/README.md[expressionError]
|Expression Error plugin adds an error renderer to the expression plugin. The renderer will display the error image.


|{kib-repo}blob/{branch}/src/plugins/expression_reveal_image/README.md[expressionRevealImage]
|Expression Reveal Image plugin adds a revealImage function to the expression plugin and an associated renderer. The renderer will display the given percentage of a given image.

Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ pageLoadAssetSize:
visTypePie: 35583
expressionRevealImage: 25675
cases: 144442
expressionError: 22127
1 change: 1 addition & 0 deletions src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const storybookAliases = {
dashboard_enhanced: 'x-pack/plugins/dashboard_enhanced/.storybook',
data_enhanced: 'x-pack/plugins/data_enhanced/.storybook',
embeddable: 'src/plugins/embeddable/.storybook',
expression_error: 'src/plugins/expression_error/.storybook',
expression_reveal_image: 'src/plugins/expression_reveal_image/.storybook',
infra: 'x-pack/plugins/infra/.storybook',
security_solution: 'x-pack/plugins/security_solution/.storybook',
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/expression_error/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"prefix": "expressionError",
"paths": {
"expressionError": "."
},
"translations": ["translations/ja-JP.json"]
}
9 changes: 9 additions & 0 deletions src/plugins/expression_error/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# expressionRevealImage

Expression Error plugin adds an `error` renderer to the expression plugin. The renderer will display the error image.

---

## Development

See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment.
9 changes: 9 additions & 0 deletions src/plugins/expression_error/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 = 'expressionError';
export const PLUGIN_NAME = 'expressionError';
9 changes: 9 additions & 0 deletions src/plugins/expression_error/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 * from './constants';
18 changes: 18 additions & 0 deletions src/plugins/expression_error/common/types/expression_renderers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 type OriginString = 'bottom' | 'left' | 'top' | 'right';

export interface ErrorRendererConfig {
error: Error;
}

export interface NodeDimensions {
width: number;
height: number;
}
9 changes: 9 additions & 0 deletions src/plugins/expression_error/common/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 * from './expression_renderers';
13 changes: 13 additions & 0 deletions src/plugins/expression_error/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/src/plugins/expression_error'],
};
10 changes: 10 additions & 0 deletions src/plugins/expression_error/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "expressionError",
"version": "1.0.0",
"kibanaVersion": "kibana",
"server": false,
"ui": true,
"requiredPlugins": ["expressions", "presentationUtil"],
"optionalPlugins": [],
"requiredBundles": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
cursor: pointer;
}
}
}
}
64 changes: 64 additions & 0 deletions src/plugins/expression_error/public/components/error_component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 React, { useState, useEffect, useCallback, MouseEventHandler } from 'react';
import { EuiIcon, useResizeObserver } from '@elastic/eui';
import { IInterpreterRenderHandlers } from 'src/plugins/expressions';
import { ErrorRendererConfig } from '../../common/types';
import {
withSuspense,
LazyErrorComponent,
LazyPopoverComponent,
} from '../../../presentation_util/public';
import './error.scss';

const Error = withSuspense(LazyErrorComponent);
const Popover = withSuspense(LazyPopoverComponent);

interface ErrorComponentProps extends ErrorRendererConfig {
onLoaded: IInterpreterRenderHandlers['done'];
parentNode: HTMLElement;
}

function ErrorComponent({ onLoaded, parentNode, error }: ErrorComponentProps) {
const getButtonSize = (node: HTMLElement) => Math.min(node.clientHeight, node.clientWidth);
const parentNodeDimensions = useResizeObserver(parentNode);

const [buttonSize, setButtonSize] = useState<number>(getButtonSize(parentNode));

const updateErrorView = useCallback(() => {
setButtonSize(getButtonSize(parentNode));
onLoaded();
}, [parentNode, onLoaded]);

useEffect(() => {
updateErrorView();
}, [parentNodeDimensions, updateErrorView]);

const button = (handleClick: MouseEventHandler<any>) => (
<EuiIcon
className="canvasRenderError__icon"
onClick={handleClick}
style={{
height: buttonSize,
width: buttonSize,
}}
type="alert"
/>
);

return (
<div className="canvasRenderError">
<Popover button={button}>{() => <Error payload={{ error }} />}</Popover>
</div>
);
}

// default export required for React.Lazy
// eslint-disable-next-line import/no-default-export
export { ErrorComponent as default };
9 changes: 9 additions & 0 deletions src/plugins/expression_error/public/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 * from './error_component';
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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 React from 'react';
import { storiesOf } from '@storybook/react';
import { error } from '../';
import { Render } from '../../__stories__/render';
import { errorRenderer } from '../error_renderer';
import { Render } from '../../../../presentation_util/public/__stories__';

storiesOf('renderers/error', module).add('default', () => {
const thrownError = new Error('There was an error');
const config = {
error: thrownError,
};
return <Render renderer={error} config={config} />;
return <Render renderer={errorRenderer} config={config} />;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 React, { lazy } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { I18nProvider } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions';
import { withSuspense } from '../../../presentation_util/public';
import { ErrorRendererConfig } from '../../common/types';

const errorStrings = {
getDisplayName: () =>
i18n.translate('expressionError.renderer.error.displayName', {
defaultMessage: 'Error information',
}),
getHelpDescription: () =>
i18n.translate('expressionError.renderer.error.helpDescription', {
defaultMessage: 'Render error data in a way that is helpful to users',
}),
};

const LazyErrorComponent = lazy(() => import('../components/error_component'));
const ErrorComponent = withSuspense(LazyErrorComponent);

export const errorRenderer = (): ExpressionRenderDefinition<ErrorRendererConfig> => ({
name: 'error',
displayName: errorStrings.getDisplayName(),
help: errorStrings.getHelpDescription(),
reuseDomNode: true,
render: async (
domNode: HTMLElement,
config: ErrorRendererConfig,
handlers: IInterpreterRenderHandlers
) => {
handlers.onDestroy(() => {
unmountComponentAtNode(domNode);
});

render(
<I18nProvider>
<ErrorComponent onLoaded={handlers.done} {...config} parentNode={domNode} />
</I18nProvider>,
domNode
);
},
});
13 changes: 13 additions & 0 deletions src/plugins/expression_error/public/expression_renderers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { errorRenderer } from './error_renderer';

export const renderers = [errorRenderer];

export { errorRenderer };
17 changes: 17 additions & 0 deletions src/plugins/expression_error/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { ExpressionErrorPlugin } from './plugin';

export type { ExpressionErrorPluginSetup, ExpressionErrorPluginStart } from './plugin';

export function plugin() {
return new ExpressionErrorPlugin();
}

export * from './expression_renderers';
33 changes: 33 additions & 0 deletions src/plugins/expression_error/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public';
import { errorRenderer } from './expression_renderers';

interface SetupDeps {
expressions: ExpressionsSetup;
}

interface StartDeps {
expression: ExpressionsStart;
}

export type ExpressionErrorPluginSetup = void;
export type ExpressionErrorPluginStart = void;

export class ExpressionErrorPlugin
implements Plugin<ExpressionErrorPluginSetup, ExpressionErrorPluginStart, SetupDeps, StartDeps> {
public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionErrorPluginSetup {
expressions.registerRenderer(errorRenderer);
}

public start(core: CoreStart): ExpressionErrorPluginStart {}

public stop() {}
}
21 changes: 21 additions & 0 deletions src/plugins/expression_error/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true,
"isolatedModules": true
},
"include": [
"common/**/*",
"public/**/*",
"server/**/*",
],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../presentation_util/tsconfig.json" },
{ "path": "../expressions/tsconfig.json" },
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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 React from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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 largePayload = {
Expand Down
Loading