Explore button: fix item name building

This commit is contained in:
Alexander Zobnin
2020-05-20 11:21:59 +03:00
parent cf578b7249
commit 3aaf58b05a
3 changed files with 5 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import { GrafanaTheme, GrafanaThemeType } from '@grafana/data';
import { getLocationSrv } from '@grafana/runtime'; import { getLocationSrv } from '@grafana/runtime';
import { MODE_METRICS, MODE_ITEMID } from '../../datasource-zabbix/constants'; import { MODE_METRICS, MODE_ITEMID } from '../../datasource-zabbix/constants';
import { renderUrl } from '../../panel-triggers/utils'; import { renderUrl } from '../../panel-triggers/utils';
import { expandItemName } from '../../datasource-zabbix/utils';
import { FAIcon } from '../FAIcon/FAIcon'; import { FAIcon } from '../FAIcon/FAIcon';
import { ProblemDTO } from '../../datasource-zabbix/types'; import { ProblemDTO } from '../../datasource-zabbix/types';
@@ -26,18 +27,18 @@ export const ExploreButton: FC<Props> = ({ problem, panelId }) => {
}; };
const openInExplore = (problem: ProblemDTO, panelId: number) => { const openInExplore = (problem: ProblemDTO, panelId: number) => {
console.log(problem, panelId);
let query: any = {}; let query: any = {};
if (problem.items?.length === 1 && problem.hosts?.length === 1) { if (problem.items?.length === 1 && problem.hosts?.length === 1) {
const item = problem.items[0]; const item = problem.items[0];
const host = problem.hosts[0]; const host = problem.hosts[0];
const itemName = expandItemName(item.name, item.key_);
query = { query = {
queryType: MODE_METRICS, queryType: MODE_METRICS,
group: { filter: '/.*/' }, group: { filter: '/.*/' },
application: { filter: '' }, application: { filter: '' },
host: { filter: host.name }, host: { filter: host.name },
item: { filter: item.name }, item: { filter: itemName },
}; };
} else { } else {
const itemids = problem.items?.map(p => p.itemid).join(','); const itemids = problem.items?.map(p => p.itemid).join(',');
@@ -56,7 +57,6 @@ const openInExplore = (problem: ProblemDTO, panelId: number) => {
const exploreState = JSON.stringify(state); const exploreState = JSON.stringify(state);
const url = renderUrl('/explore', { left: exploreState }); const url = renderUrl('/explore', { left: exploreState });
console.log(url);
getLocationSrv().update({ path: url, query: {} }); getLocationSrv().update({ path: url, query: {} });
}; };

View File

@@ -19,7 +19,7 @@ export const variableRegex = /\$(\w+)|\[\[([\s\S]+?)(?::(\w+))?\]\]|\${(\w+)(?:\
* @param {string} key item key, ie system.cpu.util[,system,avg1] * @param {string} key item key, ie system.cpu.util[,system,avg1]
* @return {string} expanded name, ie "CPU system time" * @return {string} expanded name, ie "CPU system time"
*/ */
export function expandItemName(name, key) { export function expandItemName(name: string, key: string): string {
// extract params from key: // extract params from key:
// "system.cpu.util[,system,avg1]" --> ["", "system", "avg1"] // "system.cpu.util[,system,avg1]" --> ["", "system", "avg1"]

View File

@@ -44,7 +44,7 @@ export function renderUrl(path: string, query: UrlQueryMap | undefined): string
function encodeURIComponentAsAngularJS(val: string, pctEncodeSpaces?: boolean) { function encodeURIComponentAsAngularJS(val: string, pctEncodeSpaces?: boolean) {
return encodeURIComponent(val) return encodeURIComponent(val)
.replace(/%25/gi, '%2525') .replace(/%25/gi, '%2525') // Double-encode % symbol to make it properly decoded in Explore
.replace(/%40/gi, '@') .replace(/%40/gi, '@')
.replace(/%3A/gi, ':') .replace(/%3A/gi, ':')
.replace(/%24/g, '$') .replace(/%24/g, '$')