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

Auto interval on date histogram is getting displayed as timestamp per… #59171

Merged
merged 17 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import React, { useState, useEffect, useCallback } from 'react';
import React, { useState, useEffect, useCallback, createContext } from 'react';
import {
EuiAccordion,
EuiToolTip,
Expand All @@ -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/public';

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

export const DefaultEditorAggParamsContext = createContext({} as any);
DianaDerevyankina marked this conversation as resolved.
Show resolved Hide resolved

function DefaultEditorAgg({
agg,
aggIndex,
Expand All @@ -67,9 +71,11 @@ function DefaultEditorAgg({
onToggleEnableAgg,
removeAgg,
setAggsState,
timeRange,
}: DefaultEditorAggProps) {
const [isEditorOpen, setIsEditorOpen] = useState((agg as any).brandNew);
const [validState, setValidState] = useState(true);
const [, setLocalTimeRange] = useState(timeRange);
const showDescription = !isEditorOpen && validState;
const showError = !isEditorOpen && !validState;
const aggName = agg.type?.name;
Expand Down Expand Up @@ -114,6 +120,13 @@ function DefaultEditorAgg({
}
}

// This useEffect is required to initiate rerender to keep labels up to date (Issue #57822).
useEffect(() => {
if (aggName === 'date_histogram') {
setLocalTimeRange(timeRange);
}
}, [aggName, timeRange]);
DianaDerevyankina marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
if (isLastBucketAgg && ['date_histogram', 'histogram'].includes(aggName)) {
setAggParamValue(
Expand Down Expand Up @@ -288,22 +301,24 @@ function DefaultEditorAgg({
setStateParamValue={setStateParamValue}
/>
)}
<DefaultEditorAggParams
agg={agg}
aggError={aggError}
aggIndex={aggIndex}
aggIsTooLow={aggIsTooLow}
disabledParams={disabledParams}
formIsTouched={formIsTouched}
groupName={groupName}
indexPattern={agg.getIndexPattern()}
metricAggs={metricAggs}
state={state}
setAggParamValue={setAggParamValue}
onAggTypeChange={onAggTypeChange}
setTouched={setTouched}
setValidity={setValidity}
/>
<DefaultEditorAggParamsContext.Provider value={timeRange}>
<DefaultEditorAggParams
agg={agg}
aggError={aggError}
aggIndex={aggIndex}
aggIsTooLow={aggIsTooLow}
disabledParams={disabledParams}
formIsTouched={formIsTouched}
groupName={groupName}
indexPattern={agg.getIndexPattern()}
metricAggs={metricAggs}
state={state}
setAggParamValue={setAggParamValue}
onAggTypeChange={onAggTypeChange}
setTouched={setTouched}
setValidity={setValidity}
/>
</DefaultEditorAggParamsContext.Provider>
</>
</EuiAccordion>
);
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/public';

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 @@ -18,13 +18,14 @@
*/

import { get, find } from 'lodash';
import React, { useEffect } from 'react';
import React, { useContext, useEffect } from 'react';
import { EuiFormRow, EuiIconTip, EuiComboBox, EuiComboBoxOptionProps } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { isValidInterval, AggParamOption } from '../../legacy_imports';
import { AggParamEditorProps } from '../agg_param_props';
import { DefaultEditorAggParamsContext } from '../agg';

interface ComboBoxOption extends EuiComboBoxOptionProps {
key: string;
Expand All @@ -40,6 +41,7 @@ function TimeIntervalParamEditor({
setTouched,
setValidity,
}: AggParamEditorProps<string>) {
const timeRange = useContext(DefaultEditorAggParamsContext);
const timeBase: string = get(editorConfig, 'interval.timeBase');
const options = timeBase
? []
Expand Down Expand Up @@ -118,6 +120,11 @@ function TimeIntervalParamEditor({
setValidity(isValid);
}, [isValid]);

// To update aggConfigs actual timeRange, value of timeRange is set from context.
useEffect(() => {
agg.aggConfigs.setTimeRange(timeRange);
}, [agg.aggConfigs, timeRange]);

DianaDerevyankina marked this conversation as resolved.
Show resolved Hide resolved
return (
<EuiFormRow
compressed
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