Skip to content

Commit bf75681

Browse files
committed
OU-1264: use show-timeseries tool for vis
1 parent c285543 commit bf75681

6 files changed

Lines changed: 109 additions & 70 deletions

File tree

config/perses-dashboards.patch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@
126126
"value": {
127127
"type": "ols.tool-ui",
128128
"properties": {
129-
"id": "mcp-obs/execute-range-query",
129+
"id": "mcp-obs/show-timeseries",
130130
"component": {
131-
"$codeRef": "ols-tool-ui.ExecuteRangeQuery"
131+
"$codeRef": "ols-tool-ui.ShowTimeseries"
132132
}
133133
}
134134
}

web/src/components/ols-tool-ui/AddToDashboardButton.tsx

Lines changed: 0 additions & 56 deletions
This file was deleted.

web/src/components/ols-tool-ui/ExecuteRangeQuery.tsx renamed to web/src/components/ols-tool-ui/ShowTimeseries.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
23
import { DataQueriesProvider } from '@perses-dev/plugin-system';
34
import type { DurationString } from '@perses-dev/prometheus-plugin';
45
import { Panel } from '@perses-dev/dashboards';
56

6-
import { OlsToolUIPersesWrapper } from './OlsToolUIPersesWrapper';
7-
import { AddToDashboardButton } from './AddToDashboardButton';
7+
import { OlsToolUIPersesWrapper } from './helpers/OlsToolUIPersesWrapper';
8+
import { AddToDashboardButton } from './helpers/AddToDashboardButton';
89

910
type ExecuteRangeQueryTool = {
10-
name: 'execute_range_query';
1111
args: {
12+
title: string;
13+
description: string;
1214
query: string;
1315
};
1416
};
@@ -17,8 +19,10 @@ const persesTimeRange = {
1719
pastDuration: '1h' as DurationString,
1820
};
1921

20-
export const ExecuteRangeQuery: React.FC<{ tool: ExecuteRangeQueryTool }> = ({ tool }) => {
21-
const query = tool.args.query;
22+
export const ShowTimeseries: React.FC<{ tool: ExecuteRangeQueryTool }> = ({ tool }) => {
23+
const { t } = useTranslation(process.env.I18N_NAMESPACE);
24+
const { query, title, description } = tool.args;
25+
const queryDescription = t('Query: {{query}}', { query: query });
2226
const definitions = [
2327
{
2428
kind: 'PrometheusTimeSeriesQuery',
@@ -38,17 +42,20 @@ export const ExecuteRangeQuery: React.FC<{ tool: ExecuteRangeQueryTool }> = ({ t
3842
<Panel
3943
panelOptions={{
4044
hideHeader: false,
45+
extra: () => (
46+
<AddToDashboardButton query={query} name={title} description={description} />
47+
),
4148
}}
4249
definition={{
4350
kind: 'Panel',
4451
spec: {
4552
queries: [],
46-
display: { name: query },
53+
display: { name: title, description: `${description}\n\n${queryDescription}` },
4754
plugin: {
4855
kind: 'TimeSeriesChart',
4956
spec: {
50-
visual: {
51-
stack: 'all',
57+
legend: {
58+
position: 'bottom',
5259
},
5360
},
5461
},
@@ -57,9 +64,8 @@ export const ExecuteRangeQuery: React.FC<{ tool: ExecuteRangeQueryTool }> = ({ t
5764
/>
5865
</DataQueriesProvider>
5966
</OlsToolUIPersesWrapper>
60-
<AddToDashboardButton query={query} />
6167
</>
6268
);
6369
};
6470

65-
export default ExecuteRangeQuery;
71+
export default ShowTimeseries;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { useDispatch, useSelector } from 'react-redux';
4+
import { IconButton, IconButtonProps, styled } from '@mui/material';
5+
import { Theme } from '@mui/material/styles';
6+
import ViewGridPlusIcon from 'mdi-material-ui/ViewGridPlus';
7+
import { StyledComponent } from '@emotion/styled';
8+
9+
import type { PanelDefinition } from '@perses-dev/core';
10+
import { InfoTooltip } from '@perses-dev/components';
11+
12+
import { dashboardsAddPersesPanelExternally } from '../../../store/actions';
13+
14+
export const HeaderIconButton: StyledComponent<IconButtonProps & { theme?: Theme }> = styled(
15+
IconButton,
16+
)(({ theme }) => ({
17+
borderRadius: theme.shape.borderRadius,
18+
padding: '4px',
19+
}));
20+
21+
function createPanelDefinition(query: string, name: string, description: string): PanelDefinition {
22+
return {
23+
kind: 'Panel',
24+
spec: {
25+
display: {
26+
name: name,
27+
description: description,
28+
},
29+
plugin: {
30+
kind: 'TimeSeriesChart',
31+
spec: {},
32+
},
33+
queries: [
34+
{
35+
kind: 'TimeSeriesQuery',
36+
spec: {
37+
plugin: {
38+
kind: 'PrometheusTimeSeriesQuery',
39+
spec: {
40+
query: query,
41+
},
42+
},
43+
},
44+
},
45+
],
46+
},
47+
};
48+
}
49+
50+
type AddToDashboardButtonProps = {
51+
query: string;
52+
name?: string;
53+
description?: string;
54+
};
55+
56+
export const AddToDashboardButton: React.FC<AddToDashboardButtonProps> = ({
57+
query,
58+
name,
59+
description,
60+
}) => {
61+
const dispatch = useDispatch();
62+
const { t } = useTranslation(process.env.I18N_NAMESPACE);
63+
const isCustomDashboardOpen: boolean = useSelector(
64+
(s: any) => s.plugins?.mp?.dashboards?.isOpened,
65+
);
66+
const addToPersesDashboard = React.useCallback(() => {
67+
const panelDefinition = createPanelDefinition(query, name, description);
68+
dispatch(dashboardsAddPersesPanelExternally(panelDefinition));
69+
}, [query, name, description, dispatch]);
70+
71+
if (!isCustomDashboardOpen) {
72+
// No dashboard is opened - nothing to add to.
73+
return null;
74+
}
75+
76+
return (
77+
<InfoTooltip description={t('Add To Dashboard')}>
78+
<HeaderIconButton aria-label="panel description" size="small">
79+
<ViewGridPlusIcon
80+
aria-describedby="info-tooltip"
81+
aria-hidden={false}
82+
fontSize="inherit"
83+
sx={{ color: (theme) => theme.palette.text.secondary }}
84+
onClick={addToPersesDashboard}
85+
/>
86+
</HeaderIconButton>
87+
</InfoTooltip>
88+
);
89+
};

web/src/components/ols-tool-ui/OlsToolUIPersesWrapper.tsx renamed to web/src/components/ols-tool-ui/helpers/OlsToolUIPersesWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { DurationString } from '@perses-dev/prometheus-plugin';
77
import {
88
PersesWrapper,
99
PersesPrometheusDatasourceWrapper,
10-
} from '../dashboards/perses/PersesWrapper';
10+
} from '../../dashboards/perses/PersesWrapper';
1111

1212
const queryClient = new QueryClient({
1313
defaultOptions: {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { ExecuteRangeQuery } from './ExecuteRangeQuery';
1+
export { ShowTimeseries } from './ShowTimeseries';

0 commit comments

Comments
 (0)