From ee6caee9b0c7377b967785bcb8bed2d18eb9a14c Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Thu, 16 Nov 2023 15:09:07 -0800 Subject: [PATCH] Fix for timezone matcher - 1.6.4 --- .config/.cprc.json | 3 +++ .config/jest-setup.js | 2 +- .gitignore | 1 + package.json | 2 +- src/SimplePanel.tsx | 11 +++++++---- yarn.lock | 6 +++--- 6 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 .config/.cprc.json diff --git a/.config/.cprc.json b/.config/.cprc.json new file mode 100644 index 0000000..93cec15 --- /dev/null +++ b/.config/.cprc.json @@ -0,0 +1,3 @@ +{ + "version": "2.6.0" +} diff --git a/.config/jest-setup.js b/.config/jest-setup.js index d045711..1b9fc2f 100644 --- a/.config/jest-setup.js +++ b/.config/jest-setup.js @@ -22,4 +22,4 @@ Object.defineProperty(global, 'matchMedia', { })), }); -HTMLCanvasElement.prototype.getContext = () => { }; +HTMLCanvasElement.prototype.getContext = () => {}; diff --git a/.gitignore b/.gitignore index 88d2022..a082e5f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ nline-plotlyjs-panel-*.zip.md5 dist/ .trunk/ keys.env +.eslintcache diff --git a/package.json b/package.json index 9cfb980..4af3994 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nline-plotlyjs-panel", - "version": "1.6.3", + "version": "1.6.4", "description": "Grafana Plotly Plugin", "scripts": { "build": "webpack -c ./.config/webpack/webpack.config.ts --env production", diff --git a/src/SimplePanel.tsx b/src/SimplePanel.tsx index 450dc8f..e71bff6 100644 --- a/src/SimplePanel.tsx +++ b/src/SimplePanel.tsx @@ -64,11 +64,14 @@ export const SimplePanel = React.memo( // Add convenience function for matching UTC data to timezone const local = dayjs.tz.guess(); - const matchTimezone = (timeStamps: Int32Array, correct = true) => { + const matchTimezone = (timeStamps: Int32Array) => { const tz = timeZone === 'browser' ? local : timeZone; - const baseOffset = correct ? 0 : dayjs().tz(local).utcOffset(); - const offset = (dayjs().tz(tz).utcOffset() - baseOffset) * 60 * 1000; + const localOffset = dayjs().tz(local).utcOffset(); + const dashOffset = dayjs().tz(tz).utcOffset(); + // We need to reverse the offset that Plotly assigns + // And then consider the dashboard timezone offset + const offset = (localOffset - dashOffset) * 60 * 1000; return timeStamps.map((ts) => ts - offset); }; @@ -86,7 +89,7 @@ export const SimplePanel = React.memo( // Convert time column if selected let prcData = props.data; - const timeColExists = prcData.series[0].fields.some((f) => f.name === options.timeCol); + const timeColExists = prcData.series?.[0]?.fields?.some((f) => f.name === options.timeCol) || false; if (timeColExists) { prcData = correctTimeCol(props.data); } diff --git a/yarn.lock b/yarn.lock index b8de187..cfac7a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2667,9 +2667,9 @@ integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== "@types/node@*", "@types/node@^20.8.7": - version "20.9.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.0.tgz#bfcdc230583aeb891cf51e73cfdaacdd8deae298" - integrity sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw== + version "20.9.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.1.tgz#9d578c610ce1e984adda087f685ace940954fe19" + integrity sha512-HhmzZh5LSJNS5O8jQKpJ/3ZcrrlG6L70hpGqMIAoM9YVD0YBRNWYsfwcXq8VnSjlNpCpgLzMXdiPo+dxcvSmiA== dependencies: undici-types "~5.26.4"