Skip to content

Commit

Permalink
[BUG]: If all Series and Dimensions are removed from a query and Refr…
Browse files Browse the repository at this point in the history
…esh button is hit, the app breaks. (opensearch-project#1110)

* fix for blank stats query breaking the app

Signed-off-by: Dipra Aich <[email protected]>

* Eliminated isRefresh from fetchData

Signed-off-by: Dipra Aich <[email protected]>

* fixed blank stats issue for gauge

Signed-off-by: Dipra Aich <[email protected]>

* Removed span initialization for config

Signed-off-by: Dipra Aich <[email protected]>

Signed-off-by: Dipra Aich <[email protected]>
  • Loading branch information
DipraAich authored Oct 12, 2022
1 parent e8f22a3 commit 0f808ed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
15 changes: 11 additions & 4 deletions public/components/event_analytics/explorer/explorer.tsx
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
21 changes: 11 additions & 10 deletions public/components/visualizations/charts/bar/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,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 @@ -103,7 +95,7 @@ export const Bar = ({ visualizations, layout, config }: any) => {
return [timestampField, ...dataConfig[GROUPBY]];
}

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

/**
Expand All @@ -117,7 +109,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 @@ -147,6 +139,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

0 comments on commit 0f808ed

Please sign in to comment.