Skip to content

Commit

Permalink
[Events] Save panel (opensearch-project#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 and ps48 committed Nov 3, 2022
1 parent 96350c6 commit 2fc0d25
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
10 changes: 10 additions & 0 deletions dashboards-observability/common/constants/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,13 @@ export const DATA_CONFIG_HINTS_INFO = {
[BREAKDOWNS]:
"Defines how each series is broken down. Breakdowns are 'by' clauses that subdivide the existing series.",
};

// Metrics constants
export const UNITS_OF_MEASURE = [
'seconds (s)',
'hours (h)',
'celsius (C)',
'farenheit (F)',
'meters (m)',
'kilometers (k)',
]
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export const Explorer = ({
const [liveTimestamp, setLiveTimestamp] = useState(DATE_PICKER_FORMAT);
const [triggerAvailability, setTriggerAvailability] = useState(false);
const [viewLogPatterns, setViewLogPatterns] = useState(false);
const [isValidDataConfigOptionSelected, setIsValidDataConfigOptionSelected] = useState<boolean>(
false
);
const [spanValue, setSpanValue] = useState(false);
const queryRef = useRef();
const appBasedRef = useRef('');
appBasedRef.current = appBaseQuery;
Expand Down Expand Up @@ -1408,6 +1412,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 @@ -1462,6 +1472,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 2fc0d25

Please sign in to comment.