Skip to content

Commit 4811e51

Browse files
committed
Merge remote-tracking branch 'upstream/master' into task/ingest-68914-datasource-api-hooks
2 parents 4ffeed6 + 9e00da3 commit 4811e51

File tree

26 files changed

+898
-384
lines changed

26 files changed

+898
-384
lines changed

x-pack/plugins/canvas/.storybook/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ function loadStories() {
5959
// Find all files ending in *.examples.ts
6060
const req = require.context('./..', true, /.(stories|examples).tsx$/);
6161
req.keys().forEach(filename => req(filename));
62+
63+
// Import Canvas CSS
64+
require('../public/style/index.scss')
6265
}
6366

6467
// Set up the Storybook environment with custom settings.

x-pack/plugins/canvas/.storybook/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ module.exports = async ({ config }) => {
199199
config.resolve.alias['ui/url/absolute_to_parsed_url'] = path.resolve(__dirname, '../tasks/mocks/uiAbsoluteToParsedUrl');
200200
config.resolve.alias['ui/chrome'] = path.resolve(__dirname, '../tasks/mocks/uiChrome');
201201
config.resolve.alias.ui = path.resolve(KIBANA_ROOT, 'src/legacy/ui/public');
202+
config.resolve.alias['src/legacy/ui/public/styles/styling_constants'] = path.resolve(KIBANA_ROOT, 'src/legacy/ui/public/styles/_styling_constants.scss');
202203
config.resolve.alias.ng_mock$ = path.resolve(KIBANA_ROOT, 'src/test_utils/public/ng_mock');
203204

204205
return config;

x-pack/plugins/canvas/canvas_plugin_src/functions/common/palette.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
8-
import { palettes } from '../../../common/lib/palettes';
8+
import { paulTor14 } from '../../../common/lib/palettes';
99
import { palette } from './palette';
1010

1111
describe('palette', () => {
@@ -25,7 +25,7 @@ describe('palette', () => {
2525

2626
it('defaults to pault_tor_14 colors', () => {
2727
const result = fn(null);
28-
expect(result.colors).toEqual(palettes.paul_tor_14.colors);
28+
expect(result.colors).toEqual(paulTor14.colors);
2929
});
3030
});
3131

@@ -47,17 +47,17 @@ describe('palette', () => {
4747
describe('reverse', () => {
4848
it('reverses order of the colors', () => {
4949
const result = fn(null, { reverse: true });
50-
expect(result.colors).toEqual(palettes.paul_tor_14.colors.reverse());
50+
expect(result.colors).toEqual(paulTor14.colors.reverse());
5151
});
5252

5353
it('keeps the original order of the colors', () => {
5454
const result = fn(null, { reverse: false });
55-
expect(result.colors).toEqual(palettes.paul_tor_14.colors);
55+
expect(result.colors).toEqual(paulTor14.colors);
5656
});
5757

5858
it(`defaults to 'false`, () => {
5959
const result = fn(null);
60-
expect(result.colors).toEqual(palettes.paul_tor_14.colors);
60+
expect(result.colors).toEqual(paulTor14.colors);
6161
});
6262
});
6363
});

x-pack/plugins/canvas/canvas_plugin_src/functions/common/palette.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*/
66

77
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
8-
// @ts-expect-error untyped local
9-
import { palettes } from '../../../common/lib/palettes';
8+
import { paulTor14 } from '../../../common/lib/palettes';
109
import { getFunctionHelp } from '../../../i18n';
1110

1211
interface Arguments {
@@ -52,7 +51,7 @@ export function palette(): ExpressionFunctionDefinition<'palette', null, Argumen
5251
},
5352
fn: (input, args) => {
5453
const { color, reverse, gradient } = args;
55-
const colors = ([] as string[]).concat(color || palettes.paul_tor_14.colors);
54+
const colors = ([] as string[]).concat(color || paulTor14.colors);
5655

5756
return {
5857
type: 'palette',

x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/__examples__/__snapshots__/palette.stories.storyshot

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { storiesOf } from '@storybook/react';
7+
import React from 'react';
8+
import { action } from '@storybook/addon-actions';
9+
import { PaletteArgInput } from '../palette';
10+
import { paulTor14 } from '../../../../common/lib/palettes';
11+
12+
storiesOf('arguments/Palette', module).add('default', () => (
13+
<div className="canvasContainerWrapper" style={{ width: '200px' }}>
14+
<PaletteArgInput
15+
argValue={{
16+
type: 'expression',
17+
chain: [
18+
{
19+
arguments: {
20+
_: paulTor14.colors,
21+
gradient: [paulTor14.gradient],
22+
},
23+
function: 'palette',
24+
type: 'function',
25+
},
26+
],
27+
}}
28+
onValueChange={action('onValueChange')}
29+
renderError={action('renderError')}
30+
/>
31+
</div>
32+
));

x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { imageUpload } from './image_upload';
1515
// @ts-expect-error untyped local
1616
import { number } from './number';
1717
import { numberFormatInitializer } from './number_format';
18-
// @ts-expect-error untyped local
1918
import { palette } from './palette';
2019
// @ts-expect-error untyped local
2120
import { percentage } from './percentage';

x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/palette.js renamed to x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/palette.tsx

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,63 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React from 'react';
7+
import React, { FC } from 'react';
88
import PropTypes from 'prop-types';
99
import { get } from 'lodash';
1010
import { getType } from '@kbn/interpreter/common';
11+
import { ExpressionAstFunction, ExpressionAstExpression } from 'src/plugins/expressions';
1112
import { PalettePicker } from '../../../public/components/palette_picker';
1213
import { templateFromReactComponent } from '../../../public/lib/template_from_react_component';
1314
import { ArgumentStrings } from '../../../i18n';
15+
import { identifyPalette, ColorPalette } from '../../../common/lib';
1416

1517
const { Palette: strings } = ArgumentStrings;
1618

17-
const PaletteArgInput = ({ onValueChange, argValue, renderError }) => {
18-
// Why is this neccesary? Does the dialog really need to know what parameter it is setting?
19-
20-
const throwNotParsed = () => renderError();
19+
interface Props {
20+
onValueChange: (value: ExpressionAstExpression) => void;
21+
argValue: ExpressionAstExpression;
22+
renderError: () => void;
23+
argId?: string;
24+
}
2125

26+
export const PaletteArgInput: FC<Props> = ({ onValueChange, argId, argValue, renderError }) => {
2227
// TODO: This is weird, its basically a reimplementation of what the interpretter would return.
23-
// Probably a better way todo this, and maybe a better way to handle template stype objects in general?
24-
function astToPalette({ chain }) {
28+
// Probably a better way todo this, and maybe a better way to handle template type objects in general?
29+
const astToPalette = ({ chain }: { chain: ExpressionAstFunction[] }): ColorPalette | null => {
2530
if (chain.length !== 1 || chain[0].function !== 'palette') {
26-
throwNotParsed();
31+
renderError();
32+
return null;
2733
}
34+
2835
try {
2936
const colors = chain[0].arguments._.map((astObj) => {
3037
if (getType(astObj) !== 'string') {
31-
throwNotParsed();
38+
renderError();
3239
}
3340
return astObj;
34-
});
41+
}) as string[];
3542

36-
const gradient = get(chain[0].arguments.gradient, '[0]');
43+
const gradient = get<boolean>(chain[0].arguments.gradient, '[0]');
44+
const palette = identifyPalette({ colors, gradient });
3745

38-
return { colors, gradient };
46+
if (palette) {
47+
return palette;
48+
}
49+
50+
return ({
51+
id: 'custom',
52+
label: strings.getCustomPaletteLabel(),
53+
colors,
54+
gradient,
55+
} as any) as ColorPalette;
3956
} catch (e) {
40-
throwNotParsed();
57+
renderError();
4158
}
42-
}
59+
return null;
60+
};
4361

44-
function handleChange(palette) {
45-
const astObj = {
62+
const handleChange = (palette: ColorPalette): void => {
63+
const astObj: ExpressionAstExpression = {
4664
type: 'expression',
4765
chain: [
4866
{
@@ -57,16 +75,20 @@ const PaletteArgInput = ({ onValueChange, argValue, renderError }) => {
5775
};
5876

5977
onValueChange(astObj);
60-
}
78+
};
6179

6280
const palette = astToPalette(argValue);
6381

64-
return (
65-
<PalettePicker value={palette} onChange={handleChange} ariaLabel={strings.getDisplayName()} />
66-
);
82+
if (!palette) {
83+
renderError();
84+
return null;
85+
}
86+
87+
return <PalettePicker id={argId} palette={palette} onChange={handleChange} />;
6788
};
6889

6990
PaletteArgInput.propTypes = {
91+
argId: PropTypes.string,
7092
onValueChange: PropTypes.func.isRequired,
7193
argValue: PropTypes.any.isRequired,
7294
renderError: PropTypes.func,

x-pack/plugins/canvas/common/lib/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export * from './hex_to_rgb';
2626
export * from './httpurl';
2727
// @ts-expect-error missing local definition
2828
export * from './missing_asset';
29-
// @ts-expect-error missing local definition
3029
export * from './palettes';
3130
export * from './pivot_object_array';
3231
// @ts-expect-error missing local definition

0 commit comments

Comments
 (0)