Commit 52fe6b03 by Daniel Lee Committed by GitHub

Merge pull request #15198 from CorpGlory/azure-monitor-refactor-#15087

Azure Monitor: refactor #15087
parents 8769b7aa 0cc9cbcb
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';
......
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';
......
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();
}
},
};
}
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;
},
};
}
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);
});
});
});
});
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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment