Files
grafana/public/app/plugins/datasource/cloudwatch/dynamic-labels/language.ts
Erik Sundell 467e375fe6 Cloudwatch: Dynamic labels autocomplete (#49794)
* add completeable interface

* add basic labels language

* render monaco editor for label field

* align styling in math expression field

* add unit tests

* fix broken test

* remove unused import

* use theme

* remove comment

* pr feedback

* fix broken imports

* improve test

* make it possible to override code editor styles

* use input styles and align border styles
2022-06-02 10:54:51 +02:00

53 lines
1.4 KiB
TypeScript

import type * as monacoType from 'monaco-editor/esm/vs/editor/editor.api';
// Dynamic labels: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html
export const DYNAMIC_LABEL_PATTERNS = [
'${DATAPOINT_COUNT}',
'${FIRST}',
'${FIRST_LAST_RANGE}',
'${FIRST_LAST_TIME_RANGE}',
'${FIRST_TIME}',
'${FIRST_TIME_RELATIVE}',
'${LABEL}',
'${LAST}',
'${LAST_TIME}',
'${LAST_TIME_RELATIVE}',
'${MAX}',
'${MAX_TIME}',
'${MAX_TIME_RELATIVE}',
'${MIN}',
'${MIN_MAX_RANGE}',
'${MIN_MAX_TIME_RANGE}',
'${MIN_TIME}',
'${MIN_TIME_RELATIVE}',
"${PROP('AccountId')}",
"${PROP('MetricName')}",
"${PROP('Namespace')}",
"${PROP('Period')}",
"${PROP('Region')}",
"${PROP('Stat')}",
'${SUM}',
];
export const language: monacoType.languages.IMonarchLanguage = {
id: 'dynamicLabels',
ignoreCase: false,
tokenizer: {
root: [
{ include: '@whitespace' },
{ include: '@builtInFunctions' },
{ include: '@string' },
[/\$\{PROP\('Dim.[a-zA-Z0-9-_]?.*'\)\}+/, 'predefined'], //custom handling for dimension patterns
],
builtInFunctions: [[DYNAMIC_LABEL_PATTERNS.map(escapeRegExp).join('|'), 'predefined']],
whitespace: [[/\s+/, 'white']],
string: [],
},
};
export const conf: monacoType.languages.LanguageConfiguration = {};
function escapeRegExp(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}