Skip to content

Commit

Permalink
Cover case with override_index_pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Oct 14, 2021
1 parent b5ae872 commit cdb7a15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,5 @@ export interface Panel {
time_range_mode?: string;
tooltip_mode?: TOOLTIP_MODES;
type: PANEL_TYPES;
isNew?: boolean;
use_kibana_indexes?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { YesNo } from './yes_no';
import { LastValueModePopover } from './last_value_mode_popover';
import { KBN_FIELD_TYPES } from '../../../../../data/public';
import { FormValidationContext } from '../contexts/form_validation_context';
import { PanelModelContext } from '../contexts/panel_model_context';
import { isGteInterval, validateReInterval, isAutoInterval } from './lib/get_interval';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -77,7 +76,6 @@ export const IndexPattern = ({
const maxBarsName = `${prefix}max_bars`;
const dropBucketName = `${prefix}drop_last_bucket`;
const updateControlValidity = useContext(FormValidationContext);
const panelModel = useContext(PanelModelContext);

const uiRestrictions = get(useContext(VisDataContext), 'uiRestrictions');
const maxBarsUiSettings = config.get(UI_SETTINGS.HISTOGRAM_MAX_BARS);
Expand Down Expand Up @@ -118,13 +116,7 @@ export const IndexPattern = ({
[intervalName]: AUTO_INTERVAL,
[dropBucketName]: 0,
[maxBarsName]: config.get(UI_SETTINGS.HISTOGRAM_BAR_TARGET),
// we should set default value for 'time_range_mode' in model so that when user save visualization
// we set right mode in savedObject
// ternary operator needed because old visualization have 'time_range_mode' as undefined for 'last_value'
// but for creating new visaulization we should use 'entire_timerange' as default.
[TIME_RANGE_MODE_KEY]: panelModel.isNew
? TIME_RANGE_DATA_MODES.ENTIRE_TIME_RANGE
: TIME_RANGE_DATA_MODES.LAST_VALUE,
[TIME_RANGE_MODE_KEY]: timeRangeOptions[0].value,
};

const model = { ...defaults, ..._model };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { IndexPatternValue, TimeseriesVisData } from '../../../common/types
import { VisEditorVisualization } from './vis_editor_visualization';
import { PanelConfig } from './panel_config';
import { extractIndexPatternValues } from '../../../common/index_patterns_utils';
import { TIME_RANGE_DATA_MODES, TIME_RANGE_MODE_KEY } from '../../../common/enums';
import { VisPicker } from './vis_picker';
import { fetchFields, VisFields } from '../lib/fetch_fields';
import { getDataStart, getCoreStart } from '../../services';
Expand Down Expand Up @@ -69,8 +70,24 @@ export class VisEditor extends Component<TimeseriesEditorProps, TimeseriesEditor
autoApply: true,
dirty: false,
model: {
isNew: !this.props.vis.id,
// we should set default value for 'time_range_mode' in model so that when user save visualization
// we set right mode in savedObject
// ternary operator needed because old visualization have 'time_range_mode' as undefined for 'last_value'
// but for creating new visaulization we should use 'entire_timerange' as default.
[TIME_RANGE_MODE_KEY]:
this.props.vis.title && this.props.vis.params.type !== 'timeseries'
? TIME_RANGE_DATA_MODES.LAST_VALUE
: TIME_RANGE_DATA_MODES.ENTIRE_TIME_RANGE,
...this.props.vis.params,
series: this.props.vis.params.series.map((val) => ({
[TIME_RANGE_MODE_KEY]:
this.props.vis.title &&
this.props.vis.params.type !== 'timeseries' &&
val.override_index_pattern
? TIME_RANGE_DATA_MODES.LAST_VALUE
: TIME_RANGE_DATA_MODES.ENTIRE_TIME_RANGE,
...val,
})),
},
extractedIndexPatterns: [''],
};
Expand Down

0 comments on commit cdb7a15

Please sign in to comment.