-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Canvas] Expression repeat image (#104255)
* Repeat Image plugin added.
- Loading branch information
1 parent
a8da74d
commit 3e4b64b
Showing
47 changed files
with
667 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
// eslint-disable-next-line import/no-commonjs | ||
module.exports = require('@kbn/storybook').defaultConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# expressionRepeatImage | ||
|
||
Expression Repeat Image plugin adds a `repeatImage` function to the expression plugin and an associated renderer. The renderer will display the given image in mutliple instances. | ||
|
||
--- | ||
|
||
## Development | ||
|
||
See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* 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 = 'expressionRepeatImage'; | ||
export const PLUGIN_NAME = 'expressionRepeatImage'; | ||
|
||
export const CONTEXT = '_context_'; | ||
export const BASE64 = '`base64`'; | ||
export const URL = 'URL'; |
13 changes: 13 additions & 0 deletions
13
src/plugins/expression_repeat_image/common/expression_functions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { repeatImageFunction } from './repeat_image_function'; | ||
|
||
export const functions = [repeatImageFunction]; | ||
|
||
export { repeatImageFunction }; |
35 changes: 19 additions & 16 deletions
35
...src/functions/common/repeat_image.test.js → ...n_functions/repeat_image_function.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/plugins/expression_repeat_image/common/expression_functions/repeat_image_function.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import { | ||
getElasticOutline, | ||
isValidUrl, | ||
resolveWithMissingImage, | ||
} from '../../../presentation_util/common/lib'; | ||
import { CONTEXT, BASE64, URL } from '../constants'; | ||
import { ExpressionRepeatImageFunction } from '../types'; | ||
|
||
export const strings = { | ||
help: i18n.translate('expressionRepeatImage.functions.repeatImageHelpText', { | ||
defaultMessage: 'Configures a repeating image element.', | ||
}), | ||
args: { | ||
emptyImage: i18n.translate( | ||
'expressionRepeatImage.functions.repeatImage.args.emptyImageHelpText', | ||
{ | ||
defaultMessage: | ||
'Fills the difference between the {CONTEXT} and {maxArg} parameter for the element with this image. ' + | ||
'Provide an image asset as a {BASE64} data {URL}, or pass in a sub-expression.', | ||
values: { | ||
BASE64, | ||
CONTEXT, | ||
maxArg: '`max`', | ||
URL, | ||
}, | ||
} | ||
), | ||
image: i18n.translate('expressionRepeatImage.functions.repeatImage.args.imageHelpText', { | ||
defaultMessage: | ||
'The image to repeat. Provide an image asset as a {BASE64} data {URL}, or pass in a sub-expression.', | ||
values: { | ||
BASE64, | ||
URL, | ||
}, | ||
}), | ||
max: i18n.translate('expressionRepeatImage.functions.repeatImage.args.maxHelpText', { | ||
defaultMessage: 'The maximum number of times the image can repeat.', | ||
}), | ||
size: i18n.translate('expressionRepeatImage.functions.repeatImage.args.sizeHelpText', { | ||
defaultMessage: | ||
'The maximum height or width of the image, in pixels. ' + | ||
'When the image is taller than it is wide, this function limits the height.', | ||
}), | ||
}, | ||
}; | ||
|
||
const errors = { | ||
getMissingMaxArgumentErrorMessage: () => | ||
i18n.translate('expressionRepeatImage.error.repeatImage.missingMaxArgument', { | ||
defaultMessage: '{maxArgument} must be set if providing an {emptyImageArgument}', | ||
values: { | ||
maxArgument: '`max`', | ||
emptyImageArgument: '`emptyImage`', | ||
}, | ||
}), | ||
}; | ||
|
||
export const repeatImageFunction: ExpressionRepeatImageFunction = () => { | ||
const { help, args: argHelp } = strings; | ||
|
||
return { | ||
name: 'repeatImage', | ||
aliases: [], | ||
type: 'render', | ||
inputTypes: ['number'], | ||
help, | ||
args: { | ||
emptyImage: { | ||
types: ['string', 'null'], | ||
help: argHelp.emptyImage, | ||
default: null, | ||
}, | ||
image: { | ||
types: ['string', 'null'], | ||
help: argHelp.image, | ||
default: null, | ||
}, | ||
max: { | ||
types: ['number', 'null'], | ||
help: argHelp.max, | ||
default: 1000, | ||
}, | ||
size: { | ||
types: ['number'], | ||
default: 100, | ||
help: argHelp.size, | ||
}, | ||
}, | ||
fn: async (count, args) => { | ||
if (args.emptyImage !== null && isValidUrl(args.emptyImage) && args.max === null) { | ||
throw new Error(errors.getMissingMaxArgumentErrorMessage()); | ||
} | ||
const { elasticOutline } = await getElasticOutline(); | ||
return { | ||
type: 'render', | ||
as: 'repeatImage', | ||
value: { | ||
count: Math.floor(count), | ||
...args, | ||
image: resolveWithMissingImage(args.image, elasticOutline), | ||
emptyImage: resolveWithMissingImage(args.emptyImage), | ||
}, | ||
}; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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'; | ||
export * from './types'; | ||
export * from './expression_functions'; |
30 changes: 30 additions & 0 deletions
30
src/plugins/expression_repeat_image/common/types/expression_functions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 { ExpressionFunctionDefinition, ExpressionValueRender } from '../../../expressions'; | ||
|
||
interface Arguments { | ||
image: string | null; | ||
size: number; | ||
max: number | null; | ||
emptyImage: string | null; | ||
} | ||
|
||
export interface Return { | ||
count: number; | ||
image: string; | ||
size: number; | ||
max: number; | ||
emptyImage: string | null; | ||
} | ||
|
||
export type ExpressionRepeatImageFunction = () => ExpressionFunctionDefinition< | ||
'repeatImage', | ||
number, | ||
Arguments, | ||
Promise<ExpressionValueRender<Arguments>> | ||
>; |
21 changes: 21 additions & 0 deletions
21
src/plugins/expression_repeat_image/common/types/expression_renderers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 RepeatImageRendererConfig { | ||
max: number; | ||
count: number; | ||
emptyImage: string; | ||
image: string; | ||
size: number; | ||
} | ||
|
||
export interface NodeDimensions { | ||
width: number; | ||
height: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_functions'; | ||
export * from './expression_renderers'; |
Oops, something went wrong.