Skip to content

Commit

Permalink
[Events] Save panel (#1185)
Browse files Browse the repository at this point in the history
* Save panel

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* remove comments

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* remove milliseconds from constants

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>
  • Loading branch information
kavithacm authored Oct 31, 2022
1 parent 00c07d1 commit f20c75d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
10 changes: 10 additions & 0 deletions common/constants/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,13 @@ export enum ConfigChartOptionsEnum {

export const CUSTOM_LABEL = 'customLabel';
export const BREAKDOWNS = 'breakdowns';

// Metrics constants
export const UNITS_OF_MEASURE = [
'seconds (s)',
'hours (h)',
'celsius (C)',
'farenheit (F)',
'meters (m)',
'kilometers (k)',
]
4 changes: 4 additions & 0 deletions public/components/common/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export const Search = (props: any) => {
setIsLiveTailPopoverOpen,
liveTailName,
searchError = null,
curVisId,
spanValue,
} = props;

const appLogEvents = tabId.match(APP_ANALYTICS_TAB_ID_REGEX);
Expand Down Expand Up @@ -215,6 +217,8 @@ export const Search = (props: any) => {
showSavePanelOptionsList &&
searchBarConfigs[selectedSubTabId]?.showSavePanelOptionsList
}
curVisId={curVisId}
spanValue={spanValue}
/>
<EuiPopoverFooter>
<EuiFlexGroup justifyContent="flexEnd">
Expand Down
9 changes: 9 additions & 0 deletions public/components/event_analytics/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const Explorer = ({
const [isValidDataConfigOptionSelected, setIsValidDataConfigOptionSelected] = useState<boolean>(
false
);
const [spanValue, setSpanValue] = useState(false);
const queryRef = useRef();
const appBasedRef = useRef('');
appBasedRef.current = appBaseQuery;
Expand Down Expand Up @@ -1279,6 +1280,12 @@ export const Explorer = ({
[tempQuery]
);

useEffect(() => {
const statsTokens = queryManager.queryParser().parse(tempQuery).getStats();
const updatedDataConfig = getUpdatedDataConfig(statsTokens);
setSpanValue(!isEqual(typeof updatedDataConfig.span, 'undefined'));
}, [tempQuery, query, selectedContentTabId]);

return (
<TabContext.Provider
value={{
Expand Down Expand Up @@ -1333,6 +1340,8 @@ export const Explorer = ({
setIsLiveTailPopoverOpen={setIsLiveTailPopoverOpen}
liveTailName={liveTailNameRef.current}
searchError={explorerVisualizations}
curVisId={curVisId}
spanValue={spanValue}
/>
<EuiTabbedContent
className="mainContentTabs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@

import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { EuiTitle, EuiComboBox, EuiFormRow, EuiSpacer, EuiFieldText } from '@elastic/eui';
import {
EuiTitle,
EuiComboBox,
EuiFormRow,
EuiSpacer,
EuiFieldText,
EuiSwitch,
} from '@elastic/eui';
import { useEffect } from 'react';
import { isEmpty } from 'lodash';
import { isEmpty, isEqual } from 'lodash';
import SavedObjects from '../../../../services/saved_objects/event_analytics/saved_objects';
import { UNITS_OF_MEASURE } from '../../../../../common/constants/explorer';

interface ISavedPanelProps {
selectedOptions: any;
Expand All @@ -17,6 +25,8 @@ interface ISavedPanelProps {
savedObjects: SavedObjects;
savePanelName: string;
showOptionList: boolean;
curVisId: string;
spanValue: boolean;
}

interface CustomPanelOptions {
Expand All @@ -33,8 +43,13 @@ export const SavePanel = ({
savedObjects,
savePanelName,
showOptionList,
curVisId,
spanValue,
}: ISavedPanelProps) => {
const [options, setOptions] = useState([]);
const [checked, setChecked] = useState(false);
const [measure, setMeasure] = useState([]);
const [label, setLabel] = useState([]);

const getCustomPabnelList = async (savedObjects: SavedObjects) => {
const optionRes = await savedObjects
Expand All @@ -50,6 +65,18 @@ export const SavePanel = ({
getCustomPabnelList(savedObjects);
}, []);

const onToggleChange = (e: { target: { checked: React.SetStateAction<boolean> } }) => {
setChecked(e.target.checked);
};

const onMeasureChange = (selectedMeasures: React.SetStateAction<never[]>) => {
setMeasure(selectedMeasures);
};

const onLabelChange = (selectedLabels: React.SetStateAction<never[]>) => {
setLabel(selectedLabels);
};

return (
<>
{showOptionList && (
Expand Down Expand Up @@ -90,6 +117,60 @@ export const SavePanel = ({
data-test-subj="eventExplorer__querySaveName"
/>
</EuiFormRow>
{showOptionList && (isEqual(curVisId, 'line')) && spanValue && (
<>
<EuiFormRow display="columnCompressedSwitch">
<EuiSwitch
showLabel={true}
label="Save as Metric"
checked={checked}
onChange={onToggleChange}
compressed
/>
</EuiFormRow>
{checked && (
<>
<EuiSpacer size="s" />
<EuiTitle size="xxs">
<h3>{'Units of Measure'}</h3>
</EuiTitle>
<EuiFormRow>
<EuiComboBox
placeholder="Select measure"
singleSelection={{ asPlainText: true }}
onChange={onMeasureChange}
selectedOptions={measure}
options={UNITS_OF_MEASURE.map((i) => {
return {
label: i,
};
})}
isClearable={false}
data-test-subj="eventExplorer__metricMeasureSaveComboBox"
/>
</EuiFormRow>
<EuiSpacer size="s" />
<EuiTitle size="xxs">
<h3>{'Labels'}</h3>
</EuiTitle>
<EuiFormRow>
<EuiComboBox
placeholder="Select labels"
onChange={onLabelChange}
selectedOptions={label}
options={UNITS_OF_MEASURE.map((i) => {
return {
label: i,
};
})}
isClearable={true}
data-test-subj="eventExplorer__metricLabelSaveComboBox"
/>
</EuiFormRow>
</>
)}
</>
)}
</>
);
};

0 comments on commit f20c75d

Please sign in to comment.