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

Bug/range slider issue #1122

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.

Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ export const ConfigBarChartStyles = ({
const { data: vizData = {}, metadata: { fields = [] } = {} } = data?.rawVizData;

const handleConfigurationChange = useCallback(
(stateFieldName) => {
(stateFieldName, max) => {
return (changes) => {
handleConfigChange({
...vizState,
[stateFieldName]: changes,
});
if (!max || changes <= max) {
handleConfigChange({
...vizState,
[stateFieldName]: changes,
});
} else {
handleConfigChange({
...vizState,
});
}
};
},
[handleConfigChange, vizState]
Expand Down Expand Up @@ -68,15 +74,15 @@ export const ConfigBarChartStyles = ({
label: btn.name,
})),
idSelected: vizState[schema.mapTo] || schema?.props?.defaultSelections[0]?.id,
handleButtonChange: handleConfigurationChange(schema.mapTo),
handleButtonChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
return createDimensionComponent(params);
}
if (schema.eleType === 'input') {
params = {
title: schema.name,
numValue: vizState[schema.mapTo] || '',
handleInputChange: handleConfigurationChange(schema.mapTo),
handleInputChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
vizState,
...schema.props,
};
Expand All @@ -91,7 +97,7 @@ export const ConfigBarChartStyles = ({
currentRange: vizState[schema.mapTo] || schema?.defaultState,
ticks: schema?.props?.ticks,
showTicks: schema?.props?.showTicks || false,
handleSliderChange: handleConfigurationChange(schema.mapTo),
handleSliderChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
return createDimensionComponent(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ export const ConfigChartOptions = ({
const { data: vizData = {}, metadata: { fields = [] } = {}, tree_map } = data?.rawVizData;

const handleConfigurationChange = useCallback(
(stateFiledName) => {
(stateFiledName, max) => {
return (changes) => {
handleConfigChange({
...vizState,
[stateFiledName]: changes,
});
if (!max || changes <= max) {
handleConfigChange({
...vizState,
[stateFiledName]: changes,
});
} else {
handleConfigChange({
...vizState,
});
}
};
},
[handleConfigChange, vizState]
Expand Down Expand Up @@ -60,15 +66,15 @@ export const ConfigChartOptions = ({
...params,
colorPalettes: schema.options || [],
selectedColor: vizState[schema.mapTo] || schema.defaultState,
onSelectChange: handleConfigurationChange(schema.mapTo),
onSelectChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

case ConfigChartOptionsEnum.singleColorPicker:
params = {
...params,
selectedColor: vizState[schema.mapTo] || schema.defaultState,
onSelectChange: handleConfigurationChange(schema.mapTo),
onSelectChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

Expand All @@ -77,7 +83,7 @@ export const ConfigChartOptions = ({
...params,
selectedColor: vizState[schema.mapTo] || schema?.defaultState,
colorPalettes: schema.options || [],
onSelectChange: handleConfigurationChange(schema.mapTo),
onSelectChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

Expand All @@ -89,7 +95,7 @@ export const ConfigChartOptions = ({
numberOfParents:
(tree_map?.dataConfig?.dimensions !== undefined &&
tree_map?.dataConfig.dimensions[0].parentFields.length) | 0,
onSelectChange: handleConfigurationChange(schema.mapTo),
onSelectChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

Expand All @@ -98,7 +104,7 @@ export const ConfigChartOptions = ({
...params,
currentValue: vizState[schema.mapTo] || '',
numValue: vizState[schema.mapTo] || '',
handleInputChange: handleConfigurationChange(schema.mapTo),
handleInputChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
minLimit: schema.props?.hasOwnProperty('minLimit')
? schema.props.minLimit
: NUMBER_INPUT_MIN_LIMIT,
Expand All @@ -110,7 +116,7 @@ export const ConfigChartOptions = ({
...params,
currentValue: vizState[schema.mapTo] || '',
name: schema.mapTo,
handleInputChange: handleConfigurationChange(schema.mapTo),
handleInputChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

Expand All @@ -119,7 +125,7 @@ export const ConfigChartOptions = ({
...params,
maxRange: schema.props.max,
currentRange: vizState[schema.mapTo] || schema?.defaultState,
handleSliderChange: handleConfigurationChange(schema.mapTo),
handleSliderChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

Expand All @@ -128,7 +134,7 @@ export const ConfigChartOptions = ({
...params,
title: schema.name,
currentValue: vizState[schema.mapTo],
onToggle: handleConfigurationChange(schema.mapTo),
onToggle: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

Expand All @@ -142,7 +148,7 @@ export const ConfigChartOptions = ({
label: btn.name,
})),
idSelected: vizState[schema.mapTo] || schema?.props?.defaultSelections[0]?.id,
handleButtonChange: handleConfigurationChange(schema.mapTo),
handleButtonChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
break;

Expand All @@ -152,7 +158,7 @@ export const ConfigChartOptions = ({
paddingTitle: schema.name,
advancedTitle: 'advancedTitle',
dropdownList: schema?.options || fields,
onSelectChange: handleConfigurationChange(schema.mapTo),
onSelectChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
isSingleSelection: schema.isSingleSelection,
selectedAxis: vizState[schema.mapTo] || schema.defaultState,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ export const ConfigLineChartStyles = ({
const { data: vizData = {}, metadata: { fields = [] } = {} } = data?.rawVizData;

const handleConfigurationChange = useCallback(
(stateFiledName) => {
(stateFiledName, max) => {
return (changes) => {
handleConfigChange({
...vizState,
[stateFiledName]: changes,
});
if (!max || changes <= max) {
handleConfigChange({
...vizState,
[stateFiledName]: changes,
});
} else {
handleConfigChange({
...vizState,
});
}
};
},
[handleConfigChange, vizState]
Expand Down Expand Up @@ -82,7 +88,7 @@ export const ConfigLineChartStyles = ({
label: btn.name,
})),
idSelected: vizState[schema.mapTo] || schema?.props?.defaultSelections[0]?.id,
handleButtonChange: handleConfigurationChange(schema.mapTo),
handleButtonChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
} else if (schema.eleType === 'slider') {
params = {
Expand All @@ -93,18 +99,18 @@ export const ConfigLineChartStyles = ({
currentRange: vizState[schema.mapTo] || schema?.defaultState,
ticks: schema?.props?.ticks,
showTicks: schema?.props?.showTicks || false,
handleSliderChange: handleConfigurationChange(schema.mapTo),
handleSliderChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
} else if (schema.eleType === 'input') {
params = {
...params,
numValue: vizState[schema.mapTo] || '',
handleInputChange: handleConfigurationChange(schema.mapTo),
handleInputChange: handleConfigurationChange(schema.mapTo, schema?.props?.max),
};
}
return (
<Fragment key={`viz-series-${index}`}>
<DimensionComponent {...params} />
<DimensionComponent {...params} />
<EuiSpacer size="s" />
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useCallback, useState, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import { EuiFieldText, EuiForm, EuiFormRow, EuiTextArea, EuiAccordion } from '@elastic/eui';
import { VIS_CHART_TYPES } from '../../../../../../../../common/constants/shared';
import { DEFAULT_GAUGE_CHART_PARAMETERS } from '../../../../../../../../common/constants/explorer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

import React, { ReactNode } from 'react';
import { EuiTitle, EuiSpacer, EuiRange, htmlIdGenerator } from '@elastic/eui';
import { EuiTitle, EuiSpacer, EuiRange, htmlIdGenerator, EuiToolTip, EuiIcon } from '@elastic/eui';
const tooltipIcon = <EuiIcon type="iInCircle" color="text" size="m" className="info-icon" />;

export interface EuiRangeTick {
value: number;
Expand All @@ -24,6 +25,12 @@ interface Props {
) => void;
}

const rangeToolTip = (message: string) => (
<EuiToolTip position="top" content={message} delay="regular" anchorClassName="eui-textTruncate">
{tooltipIcon}
</EuiToolTip>
);

export const SliderConfig: React.FC<Props> = ({
title,
currentRange,
Expand All @@ -35,9 +42,12 @@ export const SliderConfig: React.FC<Props> = ({
step,
}) => (
<>
<EuiTitle size="xxs">
<h3>{title}</h3>
</EuiTitle>
<div style={{ display: 'flex' }}>
<EuiTitle size="xxs">
<h3>{title}</h3>
</EuiTitle>
{rangeToolTip(`Value must be in the range of ${minRange} to ${maxRange}`)}
</div>
<EuiSpacer size="s" />
<EuiRange
aria-label="change lineWidth slider"
Expand Down