mirror of https://github.com/grafana/grafana
Merge pull request #15198 from CorpGlory/azure-monitor-refactor-#15087
Azure Monitor: refactor #15087pull/15383/head
commit
52fe6b0316
@ -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