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

[BUG]: If all Series and Dimensions are removed from a query and Refresh button is hit, the app breaks. #1110

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -316,7 +316,7 @@ export const Explorer = ({
indexPattern: string
): Promise<IDefaultTimestampState> => await timestampUtils.getTimestamp(indexPattern);

const fetchData = async (isRefresh?: boolean, startingTime?: string, endingTime?: string) => {
const fetchData = async (startingTime?: string, endingTime?: string) => {
const curQuery = queryRef.current;
const rawQueryStr = buildQuery(appBasedRef.current, curQuery![RAW_QUERY]);
const curIndex = getIndexPatternFromRawQuery(rawQueryStr);
Expand Down Expand Up @@ -375,7 +375,7 @@ export const Explorer = ({
changeVisualizationConfig({
tabId,
vizId: visId,
data: isRefresh ? { dataConfig: {} } : { ...userVizConfigs[visId] },
data: { ...userVizConfigs[visId] },
})
);
}
Expand Down Expand Up @@ -857,6 +857,13 @@ export const Explorer = ({
};

const getUpdatedDataConfig = (statsToken: statsChunk) => {
if (statsToken === null) {
return {
[GROUPBY]: [],
[AGGREGATIONS]: [],
};
}

const groupByToken = statsToken.groupby;
const seriesToken = statsToken.aggregations && statsToken.aggregations[0];
const span = getSpanValue(groupByToken);
Expand Down Expand Up @@ -954,7 +961,7 @@ export const Explorer = ({
if (availability !== true) {
await updateQueryInStore(tempQuery);
}
await fetchData(true);
await fetchData();

if (selectedContentTabId === TAB_CHART_ID) {
// parse stats section on every search
Expand Down Expand Up @@ -1267,7 +1274,7 @@ export const Explorer = ({
const handleLiveTailSearch = useCallback(
async (startingTime: string, endingTime: string) => {
await updateQueryInStore(tempQuery);
fetchData(false, startingTime, endingTime);
fetchData(startingTime, endingTime);
},
[tempQuery]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ export const ConfigPanelOptionGauge = ({
handleConfigChange,
}: any) => {
const {
data: {
rawVizData: {
metadata: { fields },
},
userConfigs,
},
data: { rawVizData: { metadata: { fields = [] } = {} } = {}, userConfigs },
}: IVisualizationContainerProps = visualizations;

const { dataConfig = {} } = userConfigs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ export const Bar = ({ visualizations, layout, config }: any) => {
const lastIndex = fields.length - 1;
const { dataConfig = {}, layoutConfig = {}, availabilityConfig = {} } = userConfigs;

if (
isEmpty(queriedVizData) ||
!Array.isArray(dataConfig[GROUPBY]) ||
!Array.isArray(dataConfig[AGGREGATIONS]) ||
(dataConfig[BREAKDOWNS] && !Array.isArray(dataConfig[BREAKDOWNS]))
)
return <EmptyPlaceholder icon={visMetaData?.icontype} />;

/**
* determine stylings
*/
Expand Down Expand Up @@ -94,7 +86,7 @@ export const Bar = ({ visualizations, layout, config }: any) => {
return [timestampField, ...dataConfig[GROUPBY]];
}

return [...dataConfig[GROUPBY]];
return dataConfig[GROUPBY];
}, [dataConfig[GROUPBY], dataConfig[BREAKDOWNS]]);

/**
Expand All @@ -108,7 +100,7 @@ export const Bar = ({ visualizations, layout, config }: any) => {
* prepare data for visualization, map x-xais to y-xais
*/
const chartAxis = useMemo(() => {
return Array.isArray(queriedVizData[getPropName(yaxes[0])])
return yaxes.length > 0 && Array.isArray(queriedVizData[getPropName(yaxes[0])])
? queriedVizData[getPropName(yaxes[0])].map((_, idx) => {
// let combineXaxis = '';
const xaxisName = xaxes.map((xaxis) => {
Expand Down Expand Up @@ -138,6 +130,15 @@ export const Bar = ({ visualizations, layout, config }: any) => {
};
});

if (
isEmpty(queriedVizData) ||
!Array.isArray(dataConfig[GROUPBY]) ||
!Array.isArray(dataConfig[AGGREGATIONS]) ||
(dataConfig[BREAKDOWNS] && !Array.isArray(dataConfig[BREAKDOWNS])) ||
yaxes.length === 0
)
return <EmptyPlaceholder icon={visMetaData?.icontype} />;

// If chart has length of result buckets < 16
// then use the LONG_CHART_COLOR for all the bars in the chart
const plotlyColorway =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { isEmpty, take } from 'lodash';
import React, { useMemo } from 'react';
import { take, isEmpty, last } from 'lodash';
import { Plt } from '../../plotly/plot';
import { GROUPBY } from '../../../../../common/constants/explorer';
import {
DEFAULT_CHART_STYLES,
PLOTLY_COLOR,
FILLOPACITY_DIV_FACTOR,
PLOTLY_COLOR,
VIS_CHART_TYPES,
} from '../../../../../common/constants/shared';
import { IVisualizationContainerProps } from '../../../../../common/types/explorer';
import { hexToRgb } from '../../../../components/event_analytics/utils/utils';
import { GROUPBY } from '../../../../../common/constants/explorer';
import { Plt } from '../../plotly/plot';

export const Histogram = ({ visualizations, layout, config }: any) => {
const { LineWidth, FillOpacity, LegendPosition, ShowLegend } = DEFAULT_CHART_STYLES;
Expand All @@ -32,6 +32,7 @@ export const Histogram = ({ visualizations, layout, config }: any) => {
vis: visMetaData,
}: IVisualizationContainerProps = visualizations;
const { dataConfig = {}, layoutConfig = {} } = userConfigs;

const lastIndex = fields.length - 1;
const lineWidth = dataConfig?.chartStyles?.lineWidth || LineWidth;
const showLegend =
Expand Down