This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 7132d5a86a chore(number-formatter): upgrade pretty-ms to 9.1.0 (#30599)
7132d5a86a is described below

commit 7132d5a86a54d31849d339ebe07b86bd8150addd
Author: Ville Brofeldt <[email protected]>
AuthorDate: Tue Oct 15 10:37:28 2024 -0700

    chore(number-formatter): upgrade pretty-ms to 9.1.0 (#30599)
---
 superset-frontend/jest.config.js                   |  2 +-
 superset-frontend/package-lock.json                | 65 +++++++++++----------
 .../packages/superset-ui-core/package.json         |  2 +-
 .../factories/createDurationFormatter.ts           |  7 ++-
 .../factories/createDurationFormatter.test.ts      | 67 +++++++++++-----------
 5 files changed, 74 insertions(+), 69 deletions(-)

diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js
index 9caf67f166..22e5db98b3 100644
--- a/superset-frontend/jest.config.js
+++ b/superset-frontend/jest.config.js
@@ -56,7 +56,7 @@ module.exports = {
   moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
   snapshotSerializers: ['@emotion/jest/enzyme-serializer'],
   transformIgnorePatterns: [
-    
'node_modules/(?!d3-(interpolate|color|time)|remark-gfm|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|@rjsf/*.|sinon|echarts|zrender|fetch-mock)',
+    
'node_modules/(?!d3-(interpolate|color|time)|remark-gfm|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|@rjsf/*.|sinon|echarts|zrender|fetch-mock|pretty-ms|parse-ms)',
   ],
   globals: {
     __DEV__: true,
diff --git a/superset-frontend/package-lock.json 
b/superset-frontend/package-lock.json
index 9c90f016f2..e08995b929 100644
--- a/superset-frontend/package-lock.json
+++ b/superset-frontend/package-lock.json
@@ -42976,13 +42976,6 @@
         "node": ">=4"
       }
     },
-    "node_modules/parse-ms": {
-      "version": "2.1.0",
-      "license": "MIT",
-      "engines": {
-        "node": ">=6"
-      }
-    },
     "node_modules/parse-node-version": {
       "version": "1.0.1",
       "dev": true,
@@ -44119,19 +44112,6 @@
         "node": ">= 0.8"
       }
     },
-    "node_modules/pretty-ms": {
-      "version": "7.0.1",
-      "license": "MIT",
-      "dependencies": {
-        "parse-ms": "^2.1.0"
-      },
-      "engines": {
-        "node": ">=10"
-      },
-      "funding": {
-        "url": "https://github.com/sponsors/sindresorhus";
-      }
-    },
     "node_modules/prismjs": {
       "version": "1.27.0",
       "license": "MIT",
@@ -55984,7 +55964,7 @@
         "jed": "^1.1.1",
         "lodash": "^4.17.21",
         "math-expression-evaluator": "^1.3.8",
-        "pretty-ms": "^7.0.0",
+        "pretty-ms": "^9.1.0",
         "react-error-boundary": "^1.2.5",
         "react-markdown": "^8.0.7",
         "rehype-raw": "^7.0.0",
@@ -56414,6 +56394,25 @@
         "url": "https://opencollective.com/unified";
       }
     },
+    "packages/superset-ui-core/node_modules/parse-ms": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz";,
+      "integrity": 
"sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==",
+      "engines": {
+        "node": ">=18"
+      }
+    },
+    "packages/superset-ui-core/node_modules/pretty-ms": {
+      "version": "9.1.0",
+      "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.1.0.tgz";,
+      "integrity": 
"sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==",
+      "dependencies": {
+        "parse-ms": "^4.0.0"
+      },
+      "engines": {
+        "node": ">=18"
+      }
+    },
     "packages/superset-ui-core/node_modules/remark-gfm": {
       "version": "3.0.1",
       "license": "MIT",
@@ -66353,7 +66352,7 @@
         "jest-mock-console": "^2.0.0",
         "lodash": "^4.17.21",
         "math-expression-evaluator": "^1.3.8",
-        "pretty-ms": "^7.0.0",
+        "pretty-ms": "^9.1.0",
         "react-error-boundary": "^1.2.5",
         "react-markdown": "^8.0.7",
         "rehype-raw": "^7.0.0",
@@ -66629,6 +66628,19 @@
             "uvu": "^0.5.0"
           }
         },
+        "parse-ms": {
+          "version": "4.0.0",
+          "resolved": 
"https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz";,
+          "integrity": 
"sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw=="
+        },
+        "pretty-ms": {
+          "version": "9.1.0",
+          "resolved": 
"https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.1.0.tgz";,
+          "integrity": 
"sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==",
+          "requires": {
+            "parse-ms": "^4.0.0"
+          }
+        },
         "remark-gfm": {
           "version": "3.0.1",
           "requires": {
@@ -88446,9 +88458,6 @@
         "json-parse-better-errors": "^1.0.1"
       }
     },
-    "parse-ms": {
-      "version": "2.1.0"
-    },
     "parse-node-version": {
       "version": "1.0.1",
       "dev": true
@@ -89110,12 +89119,6 @@
     "pretty-hrtime": {
       "version": "1.0.3"
     },
-    "pretty-ms": {
-      "version": "7.0.1",
-      "requires": {
-        "parse-ms": "^2.1.0"
-      }
-    },
     "prismjs": {
       "version": "1.27.0"
     },
diff --git a/superset-frontend/packages/superset-ui-core/package.json 
b/superset-frontend/packages/superset-ui-core/package.json
index e532c0e87a..b67dc92422 100644
--- a/superset-frontend/packages/superset-ui-core/package.json
+++ b/superset-frontend/packages/superset-ui-core/package.json
@@ -37,7 +37,7 @@
     "jed": "^1.1.1",
     "lodash": "^4.17.21",
     "math-expression-evaluator": "^1.3.8",
-    "pretty-ms": "^7.0.0",
+    "pretty-ms": "^9.1.0",
     "react-error-boundary": "^1.2.5",
     "react-markdown": "^8.0.7",
     "rehype-raw": "^7.0.0",
diff --git 
a/superset-frontend/packages/superset-ui-core/src/number-format/factories/createDurationFormatter.ts
 
b/superset-frontend/packages/superset-ui-core/src/number-format/factories/createDurationFormatter.ts
index 440e0b17c8..958136d90c 100644
--- 
a/superset-frontend/packages/superset-ui-core/src/number-format/factories/createDurationFormatter.ts
+++ 
b/superset-frontend/packages/superset-ui-core/src/number-format/factories/createDurationFormatter.ts
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-import prettyMsFormatter from 'pretty-ms';
+import prettyMilliseconds, { Options } from 'pretty-ms';
 import NumberFormatter from '../NumberFormatter';
 
 export default function createDurationFormatter(
@@ -26,13 +26,14 @@ export default function createDurationFormatter(
     id?: string;
     label?: string;
     multiplier?: number;
-  } & prettyMsFormatter.Options = {},
+  } & Options = {},
 ) {
   const { description, id, label, multiplier = 1, ...prettyMsOptions } = 
config;
 
   return new NumberFormatter({
     description,
-    formatFunc: value => prettyMsFormatter(value * multiplier, 
prettyMsOptions),
+    formatFunc: value =>
+      prettyMilliseconds(value * multiplier, prettyMsOptions),
     id: id ?? 'duration_format',
     label: label ?? `Duration formatter`,
   });
diff --git 
a/superset-frontend/packages/superset-ui-core/test/number-format/factories/createDurationFormatter.test.ts
 
b/superset-frontend/packages/superset-ui-core/test/number-format/factories/createDurationFormatter.test.ts
index fa24948163..0e7c6fff7f 100644
--- 
a/superset-frontend/packages/superset-ui-core/test/number-format/factories/createDurationFormatter.test.ts
+++ 
b/superset-frontend/packages/superset-ui-core/test/number-format/factories/createDurationFormatter.test.ts
@@ -19,40 +19,41 @@
 
 import { NumberFormatter, createDurationFormatter } from '@superset-ui/core';
 
-describe('createDurationFormatter()', () => {
-  it('creates an instance of NumberFormatter', () => {
-    const formatter = createDurationFormatter();
-    expect(formatter).toBeInstanceOf(NumberFormatter);
-  });
-  it('format milliseconds in human readable format with default options', () 
=> {
-    const formatter = createDurationFormatter();
-    expect(formatter(0)).toBe('0ms');
-    expect(formatter(1000)).toBe('1s');
-    expect(formatter(1337)).toBe('1.3s');
-    expect(formatter(10500)).toBe('10.5s');
-    expect(formatter(60 * 1000)).toBe('1m');
-    expect(formatter(90 * 1000)).toBe('1m 30s');
+test('creates an instance of NumberFormatter', () => {
+  const formatter = createDurationFormatter();
+  expect(formatter).toBeInstanceOf(NumberFormatter);
+});
+test('format milliseconds in human readable format with default options', () 
=> {
+  const formatter = createDurationFormatter();
+  expect(formatter(-1000)).toBe('-1s');
+  expect(formatter(0)).toBe('0ms');
+  expect(formatter(1000)).toBe('1s');
+  expect(formatter(1337)).toBe('1.3s');
+  expect(formatter(10500)).toBe('10.5s');
+  expect(formatter(60 * 1000)).toBe('1m');
+  expect(formatter(90 * 1000)).toBe('1m 30s');
+});
+test('format seconds in human readable format with default options', () => {
+  const formatter = createDurationFormatter({ multiplier: 1000 });
+  expect(formatter(-0.5)).toBe('-500ms');
+  expect(formatter(0.5)).toBe('500ms');
+  expect(formatter(1)).toBe('1s');
+  expect(formatter(30)).toBe('30s');
+  expect(formatter(60)).toBe('1m');
+  expect(formatter(90)).toBe('1m 30s');
+});
+test('format milliseconds in human readable format with additional pretty-ms 
options', () => {
+  const colonNotationFormatter = createDurationFormatter({
+    colonNotation: true,
   });
-  it('format seconds in human readable format with default options', () => {
-    const formatter = createDurationFormatter({ multiplier: 1000 });
-    expect(formatter(0.5)).toBe('500ms');
-    expect(formatter(1)).toBe('1s');
-    expect(formatter(30)).toBe('30s');
-    expect(formatter(60)).toBe('1m');
-    expect(formatter(90)).toBe('1m 30s');
+  expect(colonNotationFormatter(-10500)).toBe('-0:10.5');
+  expect(colonNotationFormatter(10500)).toBe('0:10.5');
+  const zeroDecimalFormatter = createDurationFormatter({
+    secondsDecimalDigits: 0,
   });
-  it('format milliseconds in human readable format with additional pretty-ms 
options', () => {
-    const colonNotationFormatter = createDurationFormatter({
-      colonNotation: true,
-    });
-    expect(colonNotationFormatter(10500)).toBe('0:10.5');
-    const zeroDecimalFormatter = createDurationFormatter({
-      secondsDecimalDigits: 0,
-    });
-    expect(zeroDecimalFormatter(10500)).toBe('10s');
-    const subMillisecondFormatter = createDurationFormatter({
-      formatSubMilliseconds: true,
-    });
-    expect(subMillisecondFormatter(100.40008)).toBe('100ms 400µs 80ns');
+  expect(zeroDecimalFormatter(10500)).toBe('10s');
+  const subMillisecondFormatter = createDurationFormatter({
+    formatSubMilliseconds: true,
   });
+  expect(subMillisecondFormatter(100.40008)).toBe('100ms 400µs 80ns');
 });

Reply via email to