Skip to content

Commit

Permalink
Updated breakdowns with updated UI of configuration panel (#1077)
Browse files Browse the repository at this point in the history
Signed-off-by: ruchika-narang <[email protected]>

Signed-off-by: ruchika-narang <[email protected]>
  • Loading branch information
ruchika-narang authored Oct 6, 2022
1 parent 1267ae9 commit 5cfca38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 59 deletions.
1 change: 1 addition & 0 deletions common/constants/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,4 @@ export enum ConfigChartOptionsEnum {
}

export const CUSTOM_LABEL = 'customLabel';
export const BREAKDOWNS = 'breakdowns';
3 changes: 2 additions & 1 deletion common/types/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
GROUPBY,
AGGREGATIONS,
CUSTOM_LABEL,
BREAKDOWNS,
} from '../constants/explorer';
import {
CoreStart,
Expand Down Expand Up @@ -301,7 +302,7 @@ export interface DimensionSpan {
export interface ConfigList {
[GROUPBY]?: ConfigListEntry[] | HistogramConfigList[];
[AGGREGATIONS]?: ConfigListEntry[];
breakdowns?: ConfigListEntry[] | HistogramConfigList[];
[BREAKDOWNS]?: ConfigListEntry[] | HistogramConfigList[];
span?: DimensionSpan;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { batch, useDispatch } from 'react-redux';
import {
AGGREGATIONS,
AGGREGATION_OPTIONS,
BREAKDOWNS,
CUSTOM_LABEL,
GROUPBY,
RAW_QUERY,
Expand All @@ -36,6 +37,7 @@ import {
ConfigListEntry,
DataConfigPanelFieldProps,
DataConfigPanelProps,
SelectedConfigItem,
} from '../../../../../../../../common/types/explorer';
import { TabContext } from '../../../../../hooks';
import { changeQuery } from '../../../../../redux/slices/query_slice';
Expand Down Expand Up @@ -128,10 +130,15 @@ export const DataConfigPanelItem = ({
setIsAddConfigClicked(true);
const list = {
...configList,
[name]: [
...configList[name],
name === AGGREGATIONS ? initialSeriesEntry : initialDimensionEntry,
],
[name]:
name !== `${BREAKDOWNS}`
? [
...configList[name],
name === AGGREGATIONS ? initialSeriesEntry : initialDimensionEntry,
]
: configList[name] !== undefined
? [...configList[name], initialDimensionEntry]
: [initialDimensionEntry],
};
setSelectedConfigItem({ index: list[name].length - 1, name });
setConfigList(list);
Expand Down Expand Up @@ -197,7 +204,7 @@ export const DataConfigPanelItem = ({
...userConfigs.dataConfig,
[GROUPBY]: updatedConfigList[GROUPBY],
[AGGREGATIONS]: updatedConfigList[AGGREGATIONS],
breakdowns: updatedConfigList.breakdowns,
[BREAKDOWNS]: updatedConfigList[BREAKDOWNS],
span: updatedConfigList.span,
},
},
Expand All @@ -220,13 +227,15 @@ export const DataConfigPanelItem = ({
: visualizations.vis.name === VIS_CHART_TYPES.Line ||
visualizations.vis.name === VIS_CHART_TYPES.Scatter
? unselectedFields.filter((i) => i.type === 'timestamp')
: sectionName === BREAKDOWNS
? configList[GROUPBY]
: unselectedFields;
};

const getCommonUI = (title: string) => {
const { index, name } = selectedConfigItem;
const selectedObj = configList[name][index];
const isDimensions = name === GROUPBY;
const isAggregations = name === AGGREGATIONS;
return (
<>
<div className="services">
Expand All @@ -238,7 +247,7 @@ export const DataConfigPanelItem = ({
/>
<EuiPanel color="subdued" style={{ padding: '0px' }}>
{/* Aggregation input for Series */}
{!isDimensions && (
{isAggregations && (
<EuiFormRow label="Aggregation">
<EuiComboBox
aria-label="aggregation input"
Expand All @@ -259,7 +268,7 @@ export const DataConfigPanelItem = ({
</EuiFormRow>
)}
{/* Show input fields for Series when aggregation is not empty */}
{!isDimensions && selectedObj.aggregation !== '' && (
{isAggregations && selectedObj.aggregation !== '' && (
<>
{getCommonDimensionsField(selectedObj, name)}
<EuiFormRow label="Custom label">
Expand All @@ -273,7 +282,7 @@ export const DataConfigPanelItem = ({
</>
)}
{/* Show input fields for dimensions */}
{isDimensions && getCommonDimensionsField(selectedObj, name)}
{!isAggregations && getCommonDimensionsField(selectedObj, name)}
{isPositionButtonVisible(name) && (
<EuiFormRow label="Side">
<ButtonGroupItem
Expand Down Expand Up @@ -334,43 +343,6 @@ export const DataConfigPanelItem = ({
</>
);

const getBreakDownFields = useCallback(
(configList: ConfigList) => {
return configList[GROUPBY];
},
[configList[GROUPBY]]
);

const Breakdowns = () => {
return (
<>
<div className="services">
<div className="first-division">
<EuiPanel color="subdued" style={{ padding: '0px' }}>
<EuiFormRow label="Fields">
<EuiComboBox
aria-label="Accessible screen reader label"
placeholder="Select fields"
singleSelection={false}
options={configList[GROUPBY]}
selectedOptions={configList.breakdowns ?? []}
onChange={(fields) => {
setConfigList((staleState) => {
return {
...staleState,
breakdowns: fields,
};
});
}}
/>
</EuiFormRow>
</EuiPanel>
</div>
</div>
</>
);
};

const DateHistogram = useMemo(() => {
return (
<>
Expand Down Expand Up @@ -455,7 +427,7 @@ export const DataConfigPanelItem = ({

const getRenderFieldsObj = (sectionName: string): DataConfigPanelFieldProps => {
return {
list: configList[sectionName],
list: configList[sectionName] ?? [],
sectionName,
visType: visualizations.vis.name,
addButtonText: 'Click to add',
Expand Down Expand Up @@ -485,12 +457,7 @@ export const DataConfigPanelItem = ({
<EuiSpacer size="s" />
{(visualizations.vis.name === VIS_CHART_TYPES.Bar ||
visualizations.vis.name === VIS_CHART_TYPES.HorizontalBar) && (
<>
<EuiTitle size="xxs">
<h3>Breakdowns</h3>
</EuiTitle>
{Breakdowns}
</>
<>{DataConfigPanelFields(getRenderFieldsObj(BREAKDOWNS))}</>
)}
</>
) : (
Expand Down
10 changes: 5 additions & 5 deletions public/components/visualizations/charts/bar/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { AvailabilityUnitType } from '../../../event_analytics/explorer/visualiz
import { ThresholdUnitType } from '../../../event_analytics/explorer/visualizations/config_panel/config_panes/config_controls/config_thresholds';
import { getPropName, hexToRgb } from '../../../event_analytics/utils/utils';
import { EmptyPlaceholder } from '../../../event_analytics/explorer/visualizations/shared_components/empty_placeholder';
import { AGGREGATIONS, GROUPBY } from '../../../../../common/constants/explorer';
import { AGGREGATIONS, BREAKDOWNS, GROUPBY } from '../../../../../common/constants/explorer';
import { IVisualizationContainerProps } from '../../../../../common/types/explorer';

export const Bar = ({ visualizations, layout, config }: any) => {
Expand All @@ -40,7 +40,7 @@ export const Bar = ({ visualizations, layout, config }: any) => {
isEmpty(queriedVizData) ||
!Array.isArray(dataConfig[GROUPBY]) ||
!Array.isArray(dataConfig[AGGREGATIONS]) ||
(dataConfig.breakdowns && !Array.isArray(dataConfig.breakdowns))
(dataConfig[BREAKDOWNS] && !Array.isArray(dataConfig[BREAKDOWNS]))
)
return <EmptyPlaceholder icon={visMetaData?.icontype} />;

Expand Down Expand Up @@ -79,11 +79,11 @@ export const Bar = ({ visualizations, layout, config }: any) => {
*/
const xaxes = useMemo(() => {
// breakdown selections
if (dataConfig.breakdowns) {
if (dataConfig[BREAKDOWNS]) {
return [
...dataConfig[GROUPBY].filter(
(dimension) =>
!some(dataConfig.breakdowns, (breakdown) => breakdown.label === dimension.label)
!some(dataConfig[BREAKDOWNS], (breakdown) => breakdown.label === dimension.label)
),
];
}
Expand All @@ -95,7 +95,7 @@ export const Bar = ({ visualizations, layout, config }: any) => {
}

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

/**
* determine y axis
Expand Down

0 comments on commit 5cfca38

Please sign in to comment.