mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #15198 from CorpGlory/azure-monitor-refactor-#15087
Azure Monitor: refactor #15087
This commit is contained in:
commit
52fe6b0316
@ -1,6 +1,6 @@
|
||||
import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
|
||||
import config from 'app/core/config';
|
||||
import { isVersionGtOrEq } from './version';
|
||||
import { isVersionGtOrEq } from 'app/core/utils/version';
|
||||
|
||||
export class AzureMonitorConfigCtrl {
|
||||
static templateUrl = 'public/app/plugins/datasource/grafana-azure-monitor-datasource/partials/config.html';
|
||||
|
@ -1,12 +1,8 @@
|
||||
import PluginPrism from './slate-plugins/prism';
|
||||
// import PluginPrism from 'slate-prism';
|
||||
// import Prism from 'prismjs';
|
||||
|
||||
import PluginPrism from 'app/features/explore/slate-plugins/prism';
|
||||
import BracesPlugin from 'app/features/explore/slate-plugins/braces';
|
||||
import ClearPlugin from 'app/features/explore/slate-plugins/clear';
|
||||
// Custom plugins (new line on Enter and run on Shift+Enter)
|
||||
import NewlinePlugin from './slate-plugins/newline';
|
||||
import RunnerPlugin from './slate-plugins/runner';
|
||||
import NewlinePlugin from 'app/features/explore/slate-plugins/newline';
|
||||
import RunnerPlugin from 'app/features/explore/slate-plugins/runner';
|
||||
|
||||
import Typeahead from './typeahead';
|
||||
import { getKeybindingSrv, KeybindingSrv } from 'app/core/services/keybindingSrv';
|
||||
|
@ -1,35 +0,0 @@
|
||||
function getIndent(text) {
|
||||
let offset = text.length - text.trimLeft().length;
|
||||
if (offset) {
|
||||
let indent = text[0];
|
||||
while (--offset) {
|
||||
indent += text[0];
|
||||
}
|
||||
return indent;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export default function NewlinePlugin() {
|
||||
return {
|
||||
onKeyDown(event, change) {
|
||||
const { value } = change;
|
||||
if (!value.isCollapsed) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
|
||||
const { startBlock } = value;
|
||||
const currentLineText = startBlock.text;
|
||||
const indent = getIndent(currentLineText);
|
||||
|
||||
return change
|
||||
.splitBlock()
|
||||
.insertText(indent)
|
||||
.focus();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
export default function RunnerPlugin({ handler }) {
|
||||
return {
|
||||
onKeyDown(event) {
|
||||
// Handle enter
|
||||
if (handler && event.key === 'Enter' && event.shiftKey) {
|
||||
// Submit on Enter
|
||||
event.preventDefault();
|
||||
handler(event);
|
||||
return true;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
import { SemVersion, isVersionGtOrEq } from './version';
|
||||
|
||||
describe('SemVersion', () => {
|
||||
let version = '1.0.0-alpha.1';
|
||||
|
||||
describe('parsing', () => {
|
||||
it('should parse version properly', () => {
|
||||
const semver = new SemVersion(version);
|
||||
expect(semver.major).toBe(1);
|
||||
expect(semver.minor).toBe(0);
|
||||
expect(semver.patch).toBe(0);
|
||||
expect(semver.meta).toBe('alpha.1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('comparing', () => {
|
||||
beforeEach(() => {
|
||||
version = '3.4.5';
|
||||
});
|
||||
|
||||
it('should detect greater version properly', () => {
|
||||
const semver = new SemVersion(version);
|
||||
const cases = [
|
||||
{ value: '3.4.5', expected: true },
|
||||
{ value: '3.4.4', expected: true },
|
||||
{ value: '3.4.6', expected: false },
|
||||
{ value: '4', expected: false },
|
||||
{ value: '3.5', expected: false },
|
||||
];
|
||||
cases.forEach(testCase => {
|
||||
expect(semver.isGtOrEq(testCase.value)).toBe(testCase.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isVersionGtOrEq', () => {
|
||||
it('should compare versions properly (a >= b)', () => {
|
||||
const cases = [
|
||||
{ values: ['3.4.5', '3.4.5'], expected: true },
|
||||
{ values: ['3.4.5', '3.4.4'], expected: true },
|
||||
{ values: ['3.4.5', '3.4.6'], expected: false },
|
||||
{ values: ['3.4', '3.4.0'], expected: true },
|
||||
{ values: ['3', '3.0.0'], expected: true },
|
||||
{ values: ['3.1.1-beta1', '3.1'], expected: true },
|
||||
{ values: ['3.4.5', '4'], expected: false },
|
||||
{ values: ['3.4.5', '3.5'], expected: false },
|
||||
];
|
||||
cases.forEach(testCase => {
|
||||
expect(isVersionGtOrEq(testCase.values[0], testCase.values[1])).toBe(testCase.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,34 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
const versionPattern = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;
|
||||
|
||||
export class SemVersion {
|
||||
major: number;
|
||||
minor: number;
|
||||
patch: number;
|
||||
meta: string;
|
||||
|
||||
constructor(version: string) {
|
||||
const match = versionPattern.exec(version);
|
||||
if (match) {
|
||||
this.major = Number(match[1]);
|
||||
this.minor = Number(match[2] || 0);
|
||||
this.patch = Number(match[3] || 0);
|
||||
this.meta = match[4];
|
||||
}
|
||||
}
|
||||
|
||||
isGtOrEq(version: string): boolean {
|
||||
const compared = new SemVersion(version);
|
||||
return !(this.major < compared.major || this.minor < compared.minor || this.patch < compared.patch);
|
||||
}
|
||||
|
||||
isValid(): boolean {
|
||||
return _.isNumber(this.major);
|
||||
}
|
||||
}
|
||||
|
||||
export function isVersionGtOrEq(a: string, b: string): boolean {
|
||||
const aSemver = new SemVersion(a);
|
||||
return aSemver.isGtOrEq(b);
|
||||
}
|
Loading…
Reference in New Issue
Block a user