Skip to content

Commit

Permalink
Move logic about default time range mode inside index pattern component
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Oct 14, 2021
1 parent 4db2437 commit 30f807f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,6 @@ 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,6 +28,7 @@ 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 @@ -76,6 +77,7 @@ 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 @@ -116,7 +118,13 @@ export const IndexPattern = ({
[intervalName]: AUTO_INTERVAL,
[dropBucketName]: 0,
[maxBarsName]: config.get(UI_SETTINGS.HISTOGRAM_BAR_TARGET),
[TIME_RANGE_MODE_KEY]: timeRangeOptions[0].value,
// 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,
};

const model = { ...defaults, ..._model };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,8 @@ export class VisEditor extends Component<TimeseriesEditorProps, TimeseriesEditor
autoApply: true,
dirty: false,
model: {
// 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,
isNew: !this.props.vis.id,
...this.props.vis.params,
},
extractedIndexPatterns: [''],
};
Expand Down

0 comments on commit 30f807f

Please sign in to comment.