-
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.
Merge branch 'main' into 9761-store-time-with-search
- Loading branch information
Showing
64 changed files
with
1,941 additions
and
288 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
..._partition_vis/common/expression_functions/__snapshots__/mosaic_vis_function.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...partition_vis/common/expression_functions/__snapshots__/treemap_vis_function.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/canvas/canvas_plugin_src/elements/pie_vis/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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { ElementFactory } from '../../../types'; | ||
|
||
export const pieVis: ElementFactory = () => ({ | ||
name: 'pieVis', | ||
displayName: '(New) Pie Vis', | ||
type: 'chart', | ||
help: 'Pie visualization', | ||
icon: 'visPie', | ||
expression: `kibana | ||
| selectFilter | ||
| demodata | ||
| head 10 | ||
| pieVis metric={visdimension "age"} buckets={visdimension "project"} buckets={visdimension "cost"} legendDisplay="default" | ||
| render`, | ||
}); |
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
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/partition_labels/default_expression.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,25 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { ExpressionAstExpression } from '@kbn/expressions-plugin/common'; | ||
|
||
export const defaultExpression = (): ExpressionAstExpression => ({ | ||
type: 'expression', | ||
chain: [ | ||
{ | ||
type: 'function', | ||
function: 'partitionLabels', | ||
arguments: { | ||
show: [true], | ||
position: ['default'], | ||
values: [true], | ||
percentDecimals: [2], | ||
valuesFormat: ['percent'], | ||
}, | ||
}, | ||
], | ||
}); |
154 changes: 154 additions & 0 deletions
154
x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/partition_labels/extended_template.tsx
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,154 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React, { ChangeEvent, MouseEvent, FunctionComponent, useCallback, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
EuiFormRow, | ||
EuiRange, | ||
EuiSelect, | ||
EuiSelectOption, | ||
EuiSpacer, | ||
EuiSwitch, | ||
EuiSwitchEvent, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { ExpressionAstExpression } from '@kbn/expressions-plugin/common'; | ||
import { set } from 'lodash'; | ||
import { defaultExpression } from './default_expression'; | ||
import { Fields } from './types'; | ||
import { getFieldPath, getFieldValue } from './utils'; | ||
import { ArgumentStrings } from '../../../../i18n'; | ||
|
||
const { PartitionLabels: strings } = ArgumentStrings; | ||
|
||
export interface Props { | ||
onValueChange: (argValue: ExpressionAstExpression) => void; | ||
argValue: null | ExpressionAstExpression; | ||
} | ||
|
||
const SHOW_FIELD = 'show'; | ||
const POSITION_FIELD = 'position'; | ||
const VALUES_FIELD = 'values'; | ||
const VALUES_FORMAT_FIELD = 'valuesFormat'; | ||
const PERCENT_DECIMALS_FIELD = 'percentDecimals'; | ||
|
||
export const ExtendedTemplate: FunctionComponent<Props> = ({ onValueChange, argValue }) => { | ||
const showLabels = getFieldValue(argValue, SHOW_FIELD); | ||
const showValues = getFieldValue(argValue, VALUES_FIELD); | ||
const valueFormat = getFieldValue(argValue, VALUES_FORMAT_FIELD); | ||
const percentDecimals = getFieldValue(argValue, PERCENT_DECIMALS_FIELD); | ||
|
||
const positions: EuiSelectOption[] = [ | ||
{ text: strings.getPositionDefaultLabel(), value: 'default' }, | ||
{ text: strings.getPositionInsideLabel(), value: 'inside' }, | ||
]; | ||
|
||
const valuesFormats: EuiSelectOption[] = [ | ||
{ text: strings.getValuesFormatValueLabel(), value: 'value' }, | ||
{ text: strings.getValuesFormatPercentLabel(), value: 'percent' }, | ||
]; | ||
|
||
useEffect(() => { | ||
if (!argValue) { | ||
onValueChange(defaultExpression()); | ||
} | ||
}, [argValue, onValueChange]); | ||
|
||
const onChangeField = useCallback( | ||
(field: Fields, value: unknown) => { | ||
const path = getFieldPath(field); | ||
const oldArgValue = argValue ?? defaultExpression(); | ||
const newArgValue = set(oldArgValue, path, value); | ||
|
||
onValueChange(newArgValue); | ||
}, | ||
[argValue, onValueChange] | ||
); | ||
|
||
const onToggleFieldChange = useCallback( | ||
(field: Fields) => (event: EuiSwitchEvent) => { | ||
onChangeField(field, event.target.checked); | ||
}, | ||
[onChangeField] | ||
); | ||
|
||
const onCommonFieldChange = useCallback( | ||
(field: Fields) => | ||
( | ||
event: ChangeEvent<HTMLInputElement | HTMLSelectElement> | MouseEvent<HTMLButtonElement> | ||
) => { | ||
onChangeField(field, event.currentTarget.value); | ||
}, | ||
[onChangeField] | ||
); | ||
|
||
if (!showLabels) { | ||
return ( | ||
<EuiText color="subdued" size="xs"> | ||
<p>{strings.getSwitchedOffShowLabelsLabel()}</p> | ||
</EuiText> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiFormRow label={strings.getPositionLabel()} display="columnCompressed"> | ||
<EuiSelect | ||
compressed | ||
value={getFieldValue(argValue, POSITION_FIELD)} | ||
options={positions} | ||
onChange={onCommonFieldChange(POSITION_FIELD)} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="s" /> | ||
<EuiFormRow label={strings.getValuesLabel()} display="columnCompressedSwitch"> | ||
<EuiSwitch | ||
compressed | ||
checked={showValues} | ||
onChange={onToggleFieldChange(VALUES_FIELD)} | ||
label={strings.getValuesToggle()} | ||
/> | ||
</EuiFormRow> | ||
{showValues && ( | ||
<EuiFormRow label={strings.getValuesFormatLabel()} display="columnCompressed"> | ||
<EuiSelect | ||
compressed | ||
value={valueFormat} | ||
options={valuesFormats} | ||
onChange={onCommonFieldChange(VALUES_FORMAT_FIELD)} | ||
/> | ||
</EuiFormRow> | ||
)} | ||
{showValues && valueFormat === 'percent' && ( | ||
<EuiFormRow label={strings.getPercentDecimalsLabel()} display="columnCompressed"> | ||
<EuiRange | ||
compressed | ||
min={0} | ||
max={10} | ||
step={1} | ||
showLabels | ||
showInput | ||
value={percentDecimals} | ||
onChange={(e, isValid) => { | ||
if (isValid) { | ||
onCommonFieldChange(PERCENT_DECIMALS_FIELD)(e); | ||
} | ||
}} | ||
/> | ||
</EuiFormRow> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
ExtendedTemplate.propTypes = { | ||
onValueChange: PropTypes.func.isRequired, | ||
argValue: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]).isRequired, | ||
}; | ||
|
||
ExtendedTemplate.displayName = 'PartitionLabelsExtendedArg'; |
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/partition_labels/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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; | ||
import { ExtendedTemplate } from './extended_template'; | ||
import { SimpleTemplate } from './simple_template'; | ||
import { ArgumentStrings } from '../../../../i18n'; | ||
|
||
const { PartitionLabels: strings } = ArgumentStrings; | ||
|
||
export const partitionLabels = () => ({ | ||
name: 'partitionLabels', | ||
displayName: strings.getDisplayName(), | ||
help: strings.getHelp(), | ||
simpleTemplate: templateFromReactComponent(SimpleTemplate), | ||
template: templateFromReactComponent(ExtendedTemplate), | ||
}); |
Oops, something went wrong.