From 19da963a194b039766478b8ba6090d5c3e3ee1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 25 Dec 2018 08:55:44 +0100 Subject: [PATCH] Typings issues --- package.json | 10 +++++++++- packages/grafana-ui/package.json | 5 +++-- packages/grafana-ui/src/components/Graph/Graph.tsx | 10 +++++++--- packages/grafana-ui/src/types/jquery.d.ts | 3 +++ tsconfig.json | 1 + yarn.lock | 5 +++++ 6 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 packages/grafana-ui/src/types/jquery.d.ts diff --git a/package.json b/package.json index 0f0f7fefa83..bb384197b8e 100644 --- a/package.json +++ b/package.json @@ -181,5 +181,13 @@ "caniuse-db": "1.0.30000772", "**/@types/react": "16.7.6" }, - "workspaces": ["packages/grafana-ui"] + "workspaces": { + "packages": [ + "packages/*" + ], + "nohoist": [ + "**/@types/*", + "**/@types/*/**" + ] + } } diff --git a/packages/grafana-ui/package.json b/packages/grafana-ui/package.json index d4bf80f5dec..fcba8f5f87d 100644 --- a/packages/grafana-ui/package.json +++ b/packages/grafana-ui/package.json @@ -11,18 +11,19 @@ "license": "ISC", "dependencies": { "@torkelo/react-select": "2.1.1", + "@types/jquery": "^1.10.35", + "lodash": "^4.17.10", "moment": "^2.22.2", "react": "^16.6.3", "react-dom": "^16.6.3", "react-highlight-words": "0.11.0", "react-popper": "^1.3.0", "react-transition-group": "^2.2.1", - "lodash": "^4.17.10", "react-virtualized": "^9.21.0" }, "devDependencies": { "@types/jest": "^23.3.2", - "@types/lodash": "^4.17.10", + "@types/lodash": "^4.14.119", "@types/react": "^16.7.6", "typescript": "^3.2.2" } diff --git a/packages/grafana-ui/src/components/Graph/Graph.tsx b/packages/grafana-ui/src/components/Graph/Graph.tsx index 07edd3f11f0..51afb33802d 100644 --- a/packages/grafana-ui/src/components/Graph/Graph.tsx +++ b/packages/grafana-ui/src/components/Graph/Graph.tsx @@ -22,7 +22,7 @@ export class Graph extends PureComponent { showBars: false, }; - element: HTMLElement; + element: HTMLElement | null; componentDidUpdate() { this.draw(); @@ -33,6 +33,10 @@ export class Graph extends PureComponent { } draw() { + if (this.element === null) { + return; + } + const { width, timeSeries, timeRange, showLines, showBars, showPoints } = this.props; if (!width) { @@ -74,7 +78,7 @@ export class Graph extends PureComponent { max: max, label: 'Datetime', ticks: ticks, - timeformat: time_format(ticks, min, max), + timeformat: timeFormat(ticks, min, max), }, grid: { minBorderMargin: 0, @@ -107,7 +111,7 @@ export class Graph extends PureComponent { } // Copied from graph.ts -function time_format(ticks, min, max) { +function timeFormat(ticks: number, min: number, max: number): string { if (min && max && ticks) { const range = max - min; const secPerTick = range / ticks / 1000; diff --git a/packages/grafana-ui/src/types/jquery.d.ts b/packages/grafana-ui/src/types/jquery.d.ts new file mode 100644 index 00000000000..e6e1be50edc --- /dev/null +++ b/packages/grafana-ui/src/types/jquery.d.ts @@ -0,0 +1,3 @@ +interface JQueryStatic { + plot: (element: HTMLElement, data: any[], options: any) => void; +} diff --git a/tsconfig.json b/tsconfig.json index 58b29ba428e..3c8c41f34e2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,6 +26,7 @@ "noUnusedLocals": true, "baseUrl": "public", "pretty": true, + "typeRoots": ["node_modules/@types", "types"], "paths": { "app": ["app"] } diff --git a/yarn.lock b/yarn.lock index c732e576022..3d267ed3e1d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1029,6 +1029,11 @@ resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.4.tgz#cc43ae176a91dcb1504839b0b9d6659386cf0af5" integrity sha512-46jSw0QMerCRkhJZbOwPA0Eb9T1p74HtECsfa0GXdgjkenSGhgvK96w+e2PEPu4GF0/brUK5WQKq/rUQQFyAxA== +"@types/jquery@^1.10.35": + version "1.10.35" + resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-1.10.35.tgz#4e5c2b1e5b3bf0b863efb8c5e70081f52e6c9518" + integrity sha512-SVtqEcudm7yjkTwoRA1gC6CNMhGDdMx4Pg8BPdiqI7bXXdCn1BPmtxgeWYQOgDxrq53/5YTlhq5ULxBEAlWIBg== + "@types/lodash@^4.14.119": version "4.14.119" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.119.tgz#be847e5f4bc3e35e46d041c394ead8b603ad8b39"