Skip to content

Commit 6925231

Browse files
authored
Add divider from grafana 10 (#70)
1 parent e79603f commit 6925231

File tree

4 files changed

+817
-604
lines changed

4 files changed

+817
-604
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"@grafana/experimental": "1.7.0"
3232
},
3333
"devDependencies": {
34-
"@grafana/data": "9.4.14",
34+
"@grafana/data": "10.2.0",
3535
"@grafana/eslint-config": "^6.0.1",
36-
"@grafana/runtime": "9.4.14",
37-
"@grafana/ui": "9.4.14",
36+
"@grafana/runtime": "10.2.0",
37+
"@grafana/ui": "10.2.0",
3838
"@rollup/plugin-node-resolve": "^15.0.1",
3939
"@swc/core": "^1.3.93",
4040
"@swc/jest": "^0.2.29",

src/components/Divider.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// copied from Azure Data Explorer plugin since there is not Divider component in G<10.1
22
import React from 'react';
3-
import { useTheme2 } from '@grafana/ui';
3+
import { Divider as GrafanaDivider, useTheme2 } from '@grafana/ui';
4+
import { config } from '@grafana/runtime';
5+
import { isVersionGtOrEq } from './utils/version';
46

57
export function Divider() {
68
const theme = useTheme2();
9+
if (isVersionGtOrEq(config.buildInfo.version, '10.1.0')) {
10+
return <GrafanaDivider />;
11+
}
712
return (
813
<div
914
style={{ borderTop: `1px solid ${theme.colors.border.weak}`, margin: theme.spacing(2, 0), width: '100%' }}

src/components/utils/version.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// copied from Azure Data Explorer plugin
2+
import { isNumber } from 'lodash';
3+
4+
const versionPattern = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;
5+
6+
export class SemVersion {
7+
major: number;
8+
minor: number;
9+
patch: number;
10+
meta: string;
11+
12+
constructor(version: string) {
13+
this.major = 0;
14+
this.minor = 0;
15+
this.patch = 0;
16+
this.meta = '';
17+
18+
const match = versionPattern.exec(version);
19+
if (match) {
20+
this.major = Number(match[1]);
21+
this.minor = Number(match[2] || 0);
22+
this.patch = Number(match[3] || 0);
23+
this.meta = match[4];
24+
}
25+
}
26+
27+
isGtOrEq(version: string): boolean {
28+
const compared = new SemVersion(version);
29+
30+
for (let i = 0; i < this.comparable.length; ++i) {
31+
if (this.comparable[i] > compared.comparable[i]) {
32+
return true;
33+
}
34+
if (this.comparable[i] < compared.comparable[i]) {
35+
return false;
36+
}
37+
}
38+
return true;
39+
}
40+
41+
isValid(): boolean {
42+
return isNumber(this.major);
43+
}
44+
45+
get comparable() {
46+
return [this.major, this.minor, this.patch];
47+
}
48+
}
49+
50+
export function isVersionGtOrEq(a: string, b: string): boolean {
51+
const aSemver = new SemVersion(a);
52+
return aSemver.isGtOrEq(b);
53+
}

0 commit comments

Comments
 (0)