Skip to content

Commit

Permalink
Auto interval on date histogram is getting displayed as timestamp per…
Browse files Browse the repository at this point in the history
… 0 milliseconds when x-axis bucket is collapsed

Closes elastic#57822
  • Loading branch information
DianaDerevyankina committed Mar 3, 2020
1 parent 4226b6f commit 3831f21
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { DefaultEditorAggCommonProps } from './agg_common_props';
import { AGGS_ACTION_KEYS, AggsAction } from './agg_group_state';
import { RowsOrColumnsControl } from './controls/rows_or_columns';
import { RadiusRatioOptionControl } from './controls/radius_ratio_option';
import { TimeRange } from '../../../../../plugins/data/common';

export interface DefaultEditorAggProps extends DefaultEditorAggCommonProps {
agg: IAggConfig;
Expand All @@ -45,6 +46,7 @@ export interface DefaultEditorAggProps extends DefaultEditorAggCommonProps {
isLastBucket: boolean;
isRemovable: boolean;
setAggsState: React.Dispatch<AggsAction>;
timeRange?: TimeRange;
}

function DefaultEditorAgg({
Expand All @@ -67,6 +69,7 @@ function DefaultEditorAgg({
onToggleEnableAgg,
removeAgg,
setAggsState,
timeRange,
}: DefaultEditorAggProps) {
const [isEditorOpen, setIsEditorOpen] = useState((agg as any).brandNew);
const [validState, setValidState] = useState(true);
Expand Down Expand Up @@ -114,6 +117,12 @@ function DefaultEditorAgg({
}
}

// Passed timeRange value is required to update agg.params.timeRange to the actual data,
// so makeLabel could return the relevant interval description.
useEffect(() => {
agg.params.timeRange = timeRange;
}, [agg.params.timeRange, timeRange]);

useEffect(() => {
if (isLastBucketAgg && ['date_histogram', 'histogram'].includes(aggName)) {
setAggParamValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ import {
getEnabledMetricAggsCount,
} from './agg_group_helper';
import { aggGroupReducer, initAggsState, AGGS_ACTION_KEYS } from './agg_group_state';
import { TimeRange } from '../../../../../plugins/data/common';

export interface DefaultEditorAggGroupProps extends DefaultEditorAggCommonProps {
schemas: Schema[];
addSchema: AddSchema;
reorderAggs: ReorderAggs;
setValidity(modelName: string, value: boolean): void;
setTouched(isTouched: boolean): void;
timeRange?: TimeRange;
}

function DefaultEditorAggGroup({
Expand All @@ -66,6 +68,7 @@ function DefaultEditorAggGroup({
reorderAggs,
setTouched,
setValidity,
timeRange,
}: DefaultEditorAggGroupProps) {
const groupNameLabel = (aggGroupNamesMap() as any)[groupName];
// e.g. buckets can have no aggs
Expand Down Expand Up @@ -179,6 +182,7 @@ function DefaultEditorAggGroup({
onToggleEnableAgg={onToggleEnableAgg}
removeAgg={removeAgg}
setAggsState={setAggsState}
timeRange={timeRange}
/>
)}
</EuiDraggable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
toggleEnabledAgg,
} from './state';
import { AddSchema, ReorderAggs, DefaultEditorAggCommonProps } from '../agg_common_props';
import { TimeRange } from '../../../../../../plugins/data/common';

export interface DefaultEditorDataTabProps {
dispatch: React.Dispatch<EditorAction>;
Expand All @@ -51,6 +52,7 @@ export interface DefaultEditorDataTabProps {
setTouched(isTouched: boolean): void;
setValidity(modelName: string, value: boolean): void;
setStateValue: DefaultEditorAggCommonProps['setStateParamValue'];
timeRange: TimeRange;
}

function DefaultEditorDataTab({
Expand All @@ -62,6 +64,7 @@ function DefaultEditorDataTab({
setTouched,
setValidity,
setStateValue,
timeRange,
}: DefaultEditorDataTabProps) {
const lastParentPipelineAgg = useMemo(
() =>
Expand Down Expand Up @@ -129,6 +132,7 @@ function DefaultEditorDataTab({
groupName={AggGroupNames.Buckets}
schemas={schemas.buckets}
{...commonProps}
timeRange={timeRange}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DefaultEditorAggCommonProps } from '../agg_common_props';
import { SidebarTitle } from './sidebar_title';
import { SavedSearch } from '../../../../kibana/public/discover/np_ready/types';
import { PersistedState } from '../../../../../../plugins/visualizations/public';
import { TimeRange } from '../../../../../../plugins/data/common';

interface DefaultEditorSideBarProps {
isCollapsed: boolean;
Expand All @@ -40,6 +41,7 @@ interface DefaultEditorSideBarProps {
vis: Vis;
isLinkedSearch: boolean;
savedSearch?: SavedSearch;
timeRange: TimeRange;
}

function DefaultEditorSideBar({
Expand All @@ -50,6 +52,7 @@ function DefaultEditorSideBar({
vis,
isLinkedSearch,
savedSearch,
timeRange,
}: DefaultEditorSideBarProps) {
const [selectedTab, setSelectedTab] = useState(optionTabs[0].name);
const [isDirty, setDirty] = useState(false);
Expand Down Expand Up @@ -193,6 +196,7 @@ function DefaultEditorSideBar({
<Editor
isTabSelected={isTabSelected}
{...(name === 'data' ? dataTabProps : optionTabProps)}
timeRange={timeRange}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function DefaultEditor({
uiState={uiState}
isLinkedSearch={linked}
savedSearch={savedSearch}
timeRange={timeRange}
/>
</Panel>
</PanelsContainer>
Expand Down

0 comments on commit 3831f21

Please sign in to comment.