Skip to content

Commit

Permalink
[TSVB] fix wrong labels, for values that are implicitly cast to false (
Browse files Browse the repository at this point in the history
…elastic#103631)

* [TSVB] fix wrong labels, for values that are implicitly cast to false

* getMeaningfulValueOrEmpty  -> getValueOrEmpty

* fix CI
  • Loading branch information
alexwizp committed Jun 29, 2021
1 parent b38fd69 commit d6b6132
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/plugins/vis_type_timeseries/common/empty_label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ import { i18n } from '@kbn/i18n';
export const emptyLabel = i18n.translate('visTypeTimeseries.emptyTextValue', {
defaultMessage: '(empty)',
});

export const getValueOrEmpty = (value: unknown) => {
if (value === '' || value === null || value === undefined) {
return emptyLabel;
}
return `${value}`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { set } from '@elastic/safer-lodash-set';
import _ from 'lodash';
import { getLastValue } from '../../../../common/last_value_utils';
import { emptyLabel } from '../../../../common/empty_label';
import { getValueOrEmpty, emptyLabel } from '../../../../common/empty_label';
import { createTickFormatter } from './tick_formatter';
import { labelDateFormatter } from './label_date_formatter';
import moment from 'moment';
Expand All @@ -20,7 +20,12 @@ export const convertSeriesToVars = (series, model, dateFormat = 'lll', getConfig
series
.filter((row) => _.startsWith(row.id, seriesModel.id))
.forEach((row) => {
const label = row.label ? _.snakeCase(row.label) : emptyLabel;
let label = getValueOrEmpty(row.label);

if (label !== emptyLabel) {
label = _.snakeCase(label);
}

const varName = [label, _.snakeCase(seriesModel.var_name)].filter((v) => v).join('.');

const formatter = createTickFormatter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { replaceVars } from '../../lib/replace_vars';
import { fieldFormats } from '../../../../../../../plugins/data/public';
import { FormattedMessage } from '@kbn/i18n/react';
import { getFieldFormats, getCoreStart } from '../../../../services';
import { emptyLabel } from '../../../../../common/empty_label';
import { getValueOrEmpty } from '../../../../../common/empty_label';

function getColor(rules, colorKey, value) {
let color;
Expand Down Expand Up @@ -98,7 +98,7 @@ class TableVis extends Component {
});
return (
<tr key={row.key}>
<td>{rowDisplay || emptyLabel}</td>
<td>{getValueOrEmpty(rowDisplay)}</td>
{columns}
</tr>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useCallback } from 'react';
import { getDisplayName } from './lib/get_display_name';
import { labelDateFormatter } from './lib/label_date_formatter';
import { findIndex, first } from 'lodash';
import { emptyLabel } from '../../../common/empty_label';
import { getValueOrEmpty } from '../../../common/empty_label';
import { getSplitByTermsColor } from '../lib/get_split_by_terms_color';

export function visWithSplits(WrappedComponent) {
Expand Down Expand Up @@ -110,7 +110,7 @@ export function visWithSplits(WrappedComponent) {
visData={newVisData}
onBrush={props.onBrush}
onFilterClick={props.onFilterClick}
additionalLabel={additionalLabel || emptyLabel}
additionalLabel={getValueOrEmpty(additionalLabel)}
backgroundColor={props.backgroundColor}
getConfig={props.getConfig}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PALETTES } from '../../../common/enums';
import type { PanelData } from '../../../common/types';
import { computeGradientFinalColor } from './compute_gradient_final_color';
import { rainbowColors } from './rainbow_colors';
import { emptyLabel } from '../../../common/empty_label';
import { getValueOrEmpty } from '../../../common/empty_label';

interface PaletteParams {
colors: string[];
Expand Down Expand Up @@ -61,7 +61,7 @@ export const getSplitByTermsColor = ({
const outputColor = palettesRegistry?.get(paletteName || 'default').getCategoricalColor(
[
{
name: seriesName || emptyLabel,
name: getValueOrEmpty(seriesName),
rankAtDepth: seriesById.findIndex(({ id }) => id === seriesId),
totalSeriesAtDepth: seriesById.length,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { BarSeriesDecorator } from './decorators/bar_decorator';
import { getStackAccessors } from './utils/stack_format';
import { getBaseTheme, getChartClasses } from './utils/theme';
import { TOOLTIP_MODES } from '../../../../../common/enums';
import { emptyLabel } from '../../../../../common/empty_label';
import { getValueOrEmpty } from '../../../../../common/empty_label';
import { getSplitByTermsColor } from '../../../lib/get_split_by_terms_color';
import { renderEndzoneTooltip } from '../../../../../../charts/public';
import { getAxisLabelString } from '../../../components/lib/get_axis_label_string';
Expand Down Expand Up @@ -237,7 +237,7 @@ export const TimeSeries = ({
key={key}
seriesId={id}
seriesGroupId={groupId}
name={seriesName || emptyLabel}
name={getValueOrEmpty(seriesName)}
data={data}
hideInLegend={hideInLegend}
bars={bars}
Expand All @@ -262,7 +262,7 @@ export const TimeSeries = ({
key={key}
seriesId={id}
seriesGroupId={groupId}
name={seriesName || emptyLabel}
name={getValueOrEmpty(seriesName)}
data={data}
hideInLegend={hideInLegend}
lines={lines}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { getLastValue, isEmptyValue } from '../../../../common/last_value_utils';
import { labelDateFormatter } from '../../components/lib/label_date_formatter';
import { emptyLabel } from '../../../../common/empty_label';
import { getValueOrEmpty } from '../../../../common/empty_label';
import reactcss from 'reactcss';

const RENDER_MODES = {
Expand Down Expand Up @@ -131,7 +131,7 @@ export class TopN extends Component {
return (
<tr key={key} onClick={this.handleClick({ lastValue, ...item })} style={styles.row}>
<td title={item.label} className="tvbVisTopN__label" style={styles.label}>
{label || emptyLabel}
{getValueOrEmpty(label)}
</td>
<td width="100%" className="tvbVisTopN__bar">
<div className="tvbVisTopN__innerBar" style={styles.innerBar}>
Expand Down

0 comments on commit d6b6132

Please sign in to comment.