Skip to content

Commit

Permalink
Show metrics in events homepage (#1232)
Browse files Browse the repository at this point in the history
* Add Metrics to events home page and fix jest test

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

* fix save_query_table jest test

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

* fix backend test

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

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>
  • Loading branch information
kavithacm authored Nov 3, 2022
1 parent ff0b28c commit f71c81e
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common/constants/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const TAB_CHART_ID_TXT_PFX = 'main-content-vis-';
export const TAB_EVENT_ID = 'main-content-events';
export const TAB_CHART_ID = 'main-content-vis';
export const HAS_SAVED_TIMESTAMP = 'hasSavedTimestamp';
export const FILTER_OPTIONS = ['Visualization', 'Query'];
export const FILTER_OPTIONS = ['Visualization', 'Query', 'Metric'];
export const SAVED_QUERY = 'savedQuery';
export const SAVED_VISUALIZATION = 'savedVisualization';
export const SAVED_OBJECT_ID = 'savedObjectId';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`Saved query table component Renders saved query table 1`] = `
<SavePanel
curVisId="line"
handleNameChange={[MockFunction]}
handleOptionChange={[MockFunction]}
savePanelName="Count by depature"
Expand Down Expand Up @@ -32,7 +33,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
},
]
}
setMetricLabel={[MockFunction]}
setMetricMeasure="hours (h)"
setSubType="metric"
showOptionList={true}
spanValue={false}
>
<EuiTitle
size="xxs"
Expand Down Expand Up @@ -701,5 +706,84 @@ exports[`Saved query table component Renders saved query table 1`] = `
</div>
</div>
</EuiFormRow>
<EuiFormRow
describedByIds={Array []}
display="columnCompressedSwitch"
fullWidth={false}
hasChildLabel={true}
hasEmptyLabelSpace={false}
labelType="label"
>
<div
className="euiFormRow euiFormRow--compressed euiFormRow--horizontal euiFormRow--hasSwitch"
id="random_html_id-row"
>
<div
className="euiFormRow__fieldWrapper"
>
<EuiToolTip
content="Only Time Series visualization and a query including stats/span can be saved as Metric"
delay="regular"
id="random_html_id"
onBlur={[Function]}
onFocus={[Function]}
position="top"
>
<span
className="euiToolTipAnchor"
onKeyUp={[Function]}
onMouseOut={[Function]}
onMouseOver={[Function]}
>
<EuiSwitch
checked={false}
compressed={true}
disabled={true}
label="Save as Metric"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
showLabel={true}
>
<div
className="euiSwitch euiSwitch--compressed"
>
<button
aria-checked={false}
aria-labelledby="random_html_id"
className="euiSwitch__button"
disabled={true}
id="random_html_id"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
role="switch"
type="button"
>
<span
className="euiSwitch__body"
>
<span
className="euiSwitch__thumb"
/>
<span
className="euiSwitch__track"
/>
</span>
</button>
<span
className="euiSwitch__label"
id="random_html_id"
onClick={[Function]}
>
Save as Metric
</span>
</div>
</EuiSwitch>
</span>
</EuiToolTip>
</div>
</div>
</EuiFormRow>
</SavePanel>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
EuiSpacer,
EuiFieldText,
EuiSwitch,
EuiIconTip,
EuiFlexItem,
EuiToolTip
} from '@elastic/eui';
import { useEffect } from 'react';
import { isEmpty, isEqual } from 'lodash';
Expand Down Expand Up @@ -130,17 +133,21 @@ export const SavePanel = ({
data-test-subj="eventExplorer__querySaveName"
/>
</EuiFormRow>
{showOptionList && (isEqual(curVisId, 'line')) && spanValue && (
{showOptionList && (
<>
<EuiFormRow display="columnCompressedSwitch">
<EuiToolTip
content="Only Time Series visualization and a query including stats/span can be saved as Metric" >
<EuiSwitch
showLabel={true}
label="Save as Metric"
checked={checked}
onChange={onToggleChange}
compressed
disabled = {!((isEqual(curVisId, 'line')) && spanValue)}
/>
</EuiFormRow>
</EuiToolTip>
</EuiFormRow>
{checked && (
<>
<EuiSpacer size="s" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
},
Expand Down Expand Up @@ -194,6 +199,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
},
Expand Down Expand Up @@ -337,6 +347,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
},
Expand Down Expand Up @@ -384,6 +399,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
}
Expand Down
11 changes: 10 additions & 1 deletion public/components/event_analytics/home/saved_objects_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React, { useState, useRef } from 'react';
import { EuiLink, EuiInMemoryTable, EuiIcon } from '@elastic/eui';
import { FILTER_OPTIONS } from '../../../../common/constants/explorer';
import { isEmpty } from 'lodash';

interface savedQueryTableProps {
savedHistories: Array<any>;
Expand Down Expand Up @@ -86,6 +87,14 @@ export function SavedQueryTable({
const isSavedVisualization = h.hasOwnProperty('savedVisualization');
const savedObject = isSavedVisualization ? h.savedVisualization : h.savedQuery;
const curType = isSavedVisualization ? 'savedVisualization' : 'savedQuery';
var subType = '';
if (isSavedVisualization) {
if (savedObject?.sub_type === 'metric') {
subType = 'Metric'
} else {
subType = savedObject?.sub_type;
}
}
const record = {
objectId: h.objectId,
objectType: curType,
Expand All @@ -100,7 +109,7 @@ export function SavedQueryTable({
id: h.objectId,
data: record,
name: savedObject.name,
type: isSavedVisualization ? 'Visualization' : 'Query',
type: isSavedVisualization ? (!isEmpty(subType)) ? subType: 'Visualization' : 'Query',
};
});

Expand Down

0 comments on commit f71c81e

Please sign in to comment.