Files
Dominik Prokop d2a13c4715 FieldOverride: Support data links via field overrides (#23590)
* Move xss and sanitize packages to grafana-data

* Move text, url and location utils to grafana-data

* Move grafana config types to grafana-data

* Move field display value proxy to grafana-data

* Fix

* Move data links built in vars to grafana-data

* Attach links supplier to when applying field overrides

* Prep tests

* Use links suppliers attached via field overrides

* locationUtil dependencies type

* Move sanitize-url declaration to grafana-data

* Revert "Move sanitize-url declaration to grafana-data"

This reverts commit 11db9f5e55423065264de230db643cd0bd03b9bd.

* Fix typo

* fix ts vol1

* Remove import from runtime in data.... Make TS happy at the same time ;)

* Lovely TS, please shut up

* Lovely TS, please shut up vol2

* fix tests

* Fixes

* minor refactor

* Attach get links to FieldDisplayValue for seamless usage

* Update packages/grafana-data/src/field/fieldOverrides.ts

* Make storybook build
2020-04-20 07:37:38 +02:00

53 lines
1.3 KiB
TypeScript

import { AdHocVariableFilter } from 'app/features/templating/types';
import { UrlQueryValue } from '@grafana/data';
import { isArray, isString } from 'lodash';
export const toUrl = (filters: AdHocVariableFilter[]): string[] => {
return filters.map(filter =>
toArray(filter)
.map(escapeDelimiter)
.join('|')
);
};
export const toFilters = (value: UrlQueryValue): AdHocVariableFilter[] => {
if (isArray(value)) {
const values = value as any[];
return values.map(toFilter).filter(isFilter);
}
const filter = toFilter(value);
return filter === null ? [] : [filter];
};
function escapeDelimiter(value: string) {
return value.replace(/\|/g, '__gfp__');
}
function unescapeDelimiter(value: string) {
return value.replace(/__gfp__/g, '|');
}
function toArray(filter: AdHocVariableFilter): string[] {
return [filter.key, filter.operator, filter.value];
}
function toFilter(value: string | number | boolean | undefined | null): AdHocVariableFilter | null {
if (!isString(value) || value.length === 0) {
return null;
}
const parts = value.split('|').map(unescapeDelimiter);
return {
key: parts[0],
operator: parts[1],
value: parts[2],
condition: '',
};
}
function isFilter(filter: AdHocVariableFilter | null): filter is AdHocVariableFilter {
return filter !== null && isString(filter.value);
}