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

Feature/tooltip-section: Added tooltip options for various charts #952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useCallback, useMemo } from 'react';
import { EuiAccordion, EuiSpacer, htmlIdGenerator } from '@elastic/eui';
import { ButtonGroupItem } from './config_button_group';
import { IConfigPanelOptionSection } from '../../../../../../../../common/types/explorer';

export const ConfigTooltip = ({ schemas, vizState, handleConfigChange }: any) => {
const handleConfigurationChange = useCallback(
(stateFiledName) => {
return (changes: any) => {
handleConfigChange({
...vizState,
[stateFiledName]: changes,
});
};
},
[handleConfigChange, vizState]
);

const dimensions = useMemo(() => {
return schemas.map((schema: IConfigPanelOptionSection, index: number) => {
const DimensionComponent = schema.component || ButtonGroupItem;
const params = {
title: schema.name,
legend: schema.name,
groupOptions: schema?.props?.options.map((btn: { name: string }) => ({
...btn,
label: btn.name,
})),
idSelected: vizState[schema.mapTo] || schema?.props?.defaultSelections[0]?.id,
handleButtonChange: handleConfigurationChange(schema.mapTo),
vizState,
...schema.props,
};
return (
<div id={htmlIdGenerator('dimension__component')()}>
<DimensionComponent key={`viz-series-${index}`} {...params} />
<EuiSpacer size="s" />
</div>
);
});
}, [schemas, vizState, handleConfigurationChange]);

return (
<EuiAccordion
initialIsOpen
id={htmlIdGenerator('configPanel__tooltip')()}
buttonContent="Tooltip options"
paddingSize="s"
>
{dimensions}
</EuiAccordion>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { ConfigGaugeValueOptions } from './config_gauge_options';
export { ColorPalettePicker } from './config_color_palette_picker';
export { ConfigLineChartStyles } from './config_line_chart_styles';
export { ConfigLegend } from './config_legend';
export { ConfigTooltip } from './config_tooltip';
export { HeatmapColorPalettePicker } from './config_heatmap_color_palette_picker';
export { SingleColorPicker } from './config_single_color_picker';
export { PanelItem } from './config_panel_item';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { HttpStart } from '../../../../../../src/core/public';
import PPLService from '../../../services/requests/ppl';
import { TIME_INTERVAL_OPTIONS } from '../../../../common/constants/explorer';
import { PPL_DATE_FORMAT, PPL_INDEX_REGEX } from '../../../../common/constants/shared';
import { ConfigTooltip } from '../explorer/visualizations/config_panel/config_panes/config_controls';

// Create Individual table rows for events datagrid and flyouts
export const getTrs = (
Expand Down Expand Up @@ -318,3 +319,38 @@ export const lightenColor = (color: string, percent: number) => {
.slice(1)
);
};

// Get config objects according to specific editor
export const fetchConfigObject = (editor: string, propsOptions: any) => {
switch (editor) {
case 'Tooltip':
return {
id: 'tooltip_options',
name: 'Tooltip options',
editor: ConfigTooltip,
mapTo: 'tooltipOptions',
schemas: [
{
name: 'Tooltip mode',
component: null,
mapTo: 'tooltipMode',
props: {
options: [
{ name: 'Show', id: 'show' },
{ name: 'Hidden', id: 'hidden' },
],
defaultSelections: [{ name: 'Show', id: 'show' }],
},
},
{
name: 'Tooltip text',
component: null,
mapTo: 'tooltipText',
props: propsOptions,
},
],
};
default:
return null;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,64 @@ exports[`Bar component Renders bar component 1`] = `
"mapTo": "dataConfig",
"name": "Data",
"sections": Array [
Object {
"editor": [Function],
"id": "tooltip_options",
"mapTo": "tooltipOptions",
"name": "Tooltip options",
"schemas": Array [
Object {
"component": null,
"mapTo": "tooltipMode",
"name": "Tooltip mode",
"props": Object {
"defaultSelections": Array [
Object {
"id": "show",
"name": "Show",
},
],
"options": Array [
Object {
"id": "show",
"name": "Show",
},
Object {
"id": "hidden",
"name": "Hidden",
},
],
},
},
Object {
"component": null,
"mapTo": "tooltipText",
"name": "Tooltip text",
"props": Object {
"defaultSelections": Array [
Object {
"id": "all",
"name": "All",
},
],
"options": Array [
Object {
"id": "all",
"name": "All",
},
Object {
"id": "x",
"name": "Dimension",
},
Object {
"id": "y",
"name": "Metrics",
},
],
},
},
],
},
Object {
"editor": [Function],
"id": "legend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,64 @@ exports[`Heatmap component Renders heatmap component 1`] = `
"mapTo": "dataConfig",
"name": "Data",
"sections": Array [
Object {
"editor": [Function],
"id": "tooltip_options",
"mapTo": "tooltipOptions",
"name": "Tooltip options",
"schemas": Array [
Object {
"component": null,
"mapTo": "tooltipMode",
"name": "Tooltip mode",
"props": Object {
"defaultSelections": Array [
Object {
"id": "show",
"name": "Show",
},
],
"options": Array [
Object {
"id": "show",
"name": "Show",
},
Object {
"id": "hidden",
"name": "Hidden",
},
],
},
},
Object {
"component": null,
"mapTo": "tooltipText",
"name": "Tooltip text",
"props": Object {
"defaultSelections": Array [
Object {
"id": "all",
"name": "All",
},
],
"options": Array [
Object {
"id": "all",
"name": "All",
},
Object {
"id": "x",
"name": "Dimension",
},
Object {
"id": "y",
"name": "Metrics",
},
],
},
},
],
},
Object {
"editor": [Function],
"id": "legend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,64 @@ exports[`Histogram component Renders histogram component 1`] = `
"mapTo": "dataConfig",
"name": "Data",
"sections": Array [
Object {
"editor": [Function],
"id": "tooltip_options",
"mapTo": "tooltipOptions",
"name": "Tooltip options",
"schemas": Array [
Object {
"component": null,
"mapTo": "tooltipMode",
"name": "Tooltip mode",
"props": Object {
"defaultSelections": Array [
Object {
"id": "show",
"name": "Show",
},
],
"options": Array [
Object {
"id": "show",
"name": "Show",
},
Object {
"id": "hidden",
"name": "Hidden",
},
],
},
},
Object {
"component": null,
"mapTo": "tooltipText",
"name": "Tooltip text",
"props": Object {
"defaultSelections": Array [
Object {
"id": "all",
"name": "All",
},
],
"options": Array [
Object {
"id": "all",
"name": "All",
},
Object {
"id": "x",
"name": "Dimension",
},
Object {
"id": "y",
"name": "Metrics",
},
],
},
},
],
},
Object {
"editor": [Function],
"id": "legend",
Expand Down Expand Up @@ -480,6 +538,7 @@ exports[`Histogram component Renders histogram component 1`] = `
data={
Array [
Object {
"hoverinfo": "all",
"marker": Object {
"color": "rgba(60,161,199,0.2)",
"line": Object {
Expand Down Expand Up @@ -532,6 +591,7 @@ exports[`Histogram component Renders histogram component 1`] = `
data={
Array [
Object {
"hoverinfo": "all",
"marker": Object {
"color": "rgba(60,161,199,0.2)",
"line": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,64 @@ exports[`Line component Renders line component 1`] = `
"mapTo": "dataConfig",
"name": "Data",
"sections": Array [
Object {
"editor": [Function],
"id": "tooltip_options",
"mapTo": "tooltipOptions",
"name": "Tooltip options",
"schemas": Array [
Object {
"component": null,
"mapTo": "tooltipMode",
"name": "Tooltip mode",
"props": Object {
"defaultSelections": Array [
Object {
"id": "show",
"name": "Show",
},
],
"options": Array [
Object {
"id": "show",
"name": "Show",
},
Object {
"id": "hidden",
"name": "Hidden",
},
],
},
},
Object {
"component": null,
"mapTo": "tooltipText",
"name": "Tooltip text",
"props": Object {
"defaultSelections": Array [
Object {
"id": "all",
"name": "All",
},
],
"options": Array [
Object {
"id": "all",
"name": "All",
},
Object {
"id": "x",
"name": "Dimension",
},
Object {
"id": "y",
"name": "Metrics",
},
],
},
},
],
},
Object {
"editor": [Function],
"id": "legend",
Expand Down
Loading