From 2481bab369fffd7661731a5dcd36aa6bfa0a5133 Mon Sep 17 00:00:00 2001 From: Razvan Stoenescu Date: Tue, 17 Sep 2024 14:27:31 +0300 Subject: [PATCH] feat+refactor(ui/Platform): explicitly specify all boolean props (they were previously undefined if "false") #17482 --- ui/src/plugins/platform/Platform.js | 31 +++--- ui/src/plugins/platform/Platform.json | 121 ++++++++++------------- ui/src/plugins/platform/Platform.test.js | 31 +++--- 3 files changed, 88 insertions(+), 95 deletions(-) diff --git a/ui/src/plugins/platform/Platform.js b/ui/src/plugins/platform/Platform.js index c51e952dc37..7d45cf7bcf3 100644 --- a/ui/src/plugins/platform/Platform.js +++ b/ui/src/plugins/platform/Platform.js @@ -70,35 +70,40 @@ function getPlatform (UA) { const matched = getMatch(userAgent, platformMatch) const browser = { mobile: false, + desktop: false, + cordova: false, capacitor: false, nativeMobile: false, // nativeMobileWrapper: void 0, electron: false, - desktop: false, bex: false, - android: false, - blackberry: false, - cros: false, - ios: false, - ipad: false, - iphone: false, - ipod: false, - kindle: false, + linux: false, mac: false, win: false, - winphone: false, - playbook: false, - silk: false, + cros: false, + chrome: false, firefox: false, opera: false, safari: false, vivaldi: false, edge: false, + edgeChromium: false, ie: false, - webkit: false + webkit: false, + + android: false, + ios: false, + ipad: false, + iphone: false, + ipod: false, + kindle: false, + winphone: false, + blackberry: false, + playbook: false, + silk: false } if (matched.browser) { diff --git a/ui/src/plugins/platform/Platform.json b/ui/src/plugins/platform/Platform.json index 089847c489a..32c566f974a 100644 --- a/ui/src/plugins/platform/Platform.json +++ b/ui/src/plugins/platform/Platform.json @@ -38,39 +38,25 @@ "desc": "Major browser version as a number" }, - "desktop": { - "type": "Boolean", - "required": false, - "desc": "Whether the platform is desktop" - }, "mobile": { "type": "Boolean", - "required": false, "desc": "Whether the platform is mobile" }, - "electron": { + "desktop": { "type": "Boolean", - "required": false, - "desc": "Whether the platform is Electron" + "desc": "Whether the platform is desktop" }, - "bex": { + + "cordova": { "type": "Boolean", - "required": false, - "desc": "Whether the platform is BEX(Browser Extension)" + "desc": "Whether the platform is Cordova" }, "capacitor": { "type": "Boolean", - "required": false, "desc": "Whether the platform is Capacitor" }, - "cordova": { - "type": "Boolean", - "required": false, - "desc": "Whether the platform is Cordova" - }, "nativeMobile": { "type": "Boolean", - "required": false, "desc": "Whether the platform is a native mobile wrapper" }, "nativeMobileWrapper": { @@ -79,110 +65,107 @@ "values": [ "'cordova'", "'capacitor'" ], "desc": "Type of the native mobile wrapper" }, - - "webkit": { + "electron": { "type": "Boolean", - "required": false, - "desc": "Whether the browser is a Webkit one" + "desc": "Whether the platform is Electron" + }, + "bex": { + "type": "Boolean", + "desc": "Whether the platform is BEX(Browser Extension)" }, - "chrome": { + "linux": { "type": "Boolean", - "required": false, - "desc": "Whether the browser is Google Chrome" + "desc": "Whether the operating system is Linux" }, - "firefox": { + "mac": { "type": "Boolean", - "required": false, - "desc": "Whether the browser is Firefox" + "desc": "Whether the operating system is Mac OS" }, - "safari": { + "win": { "type": "Boolean", - "required": false, - "desc": "Whether the browser is Safari" + "desc": "Whether the operating system is Windows" }, - "edgeChromium": { + "cros": { "type": "Boolean", - "required": false, - "desc": "Whether the browser is Microsoft Edge (Chromium)" + "desc": "Whether the operating system is Chrome OS" }, - "edge": { + + "chrome": { "type": "Boolean", - "required": false, - "desc": "Whether the browser is Microsoft Edge Legacy" + "desc": "Whether the browser is Google Chrome" + }, + "firefox": { + "type": "Boolean", + "desc": "Whether the browser is Firefox" }, "opera": { "type": "Boolean", - "required": false, "desc": "Whether the browser is Opera" }, + "safari": { + "type": "Boolean", + "desc": "Whether the browser is Safari" + }, "vivaldi": { "type": "Boolean", - "required": false, "desc": "Whether the browser is Vivaldi" }, - - "win": { + "edge": { "type": "Boolean", - "required": false, - "desc": "Whether the operating system is Windows" + "desc": "Whether the browser is Microsoft Edge Legacy" }, - "linux": { + "edgeChromium": { "type": "Boolean", - "required": false, - "desc": "Whether the operating system is Linux" + "desc": "Whether the browser is Microsoft Edge (Chromium)" }, - "mac": { + "ie": { "type": "Boolean", - "required": false, - "desc": "Whether the operating system is Mac OS" + "desc": "Whether the browser is Internet Explorer" }, - "cros": { + "webkit": { "type": "Boolean", - "required": false, - "desc": "Whether the operating system is Chrome OS" + "desc": "Whether the browser is a Webkit or Webkit-based one" }, "android": { "type": "Boolean", - "required": false, "desc": "Whether the operating system is Android" }, "ios": { "type": "Boolean", - "required": false, "desc": "Whether the operating system is iOS" }, - "winphone": { + "ipad": { "type": "Boolean", - "required": false, - "desc": "Whether the operating system is Windows Phone" + "desc": "Whether the device is an iPad" }, - "iphone": { "type": "Boolean", - "required": false, "desc": "Whether the device is an iPhone" }, - "ipad": { - "type": "Boolean", - "required": false, - "desc": "Whether the device is an iPad" - }, "ipod": { "type": "Boolean", - "required": false, "desc": "Whether the device is an iPod" }, - "kindle": { "type": "Boolean", - "required": false, "desc": "Whether the device is a Kindle" }, + "winphone": { + "type": "Boolean", + "desc": "Whether the operating system is Windows Phone" + }, + "blackberry": { + "type": "Boolean", + "desc": "Whether the device is a Blackberry" + }, + "playbook": { + "type": "Boolean", + "desc": "Whether the device is a Blackberry Playbook" + }, "silk": { "type": "Boolean", - "required": false, "desc": "Whether the browser is Amazon Silk" } }, diff --git a/ui/src/plugins/platform/Platform.test.js b/ui/src/plugins/platform/Platform.test.js index 2070b2e85ff..482c84f4b8b 100644 --- a/ui/src/plugins/platform/Platform.test.js +++ b/ui/src/plugins/platform/Platform.test.js @@ -37,6 +37,8 @@ describe('[Platform API]', () => { versionNumber: expect.any(Number), mobile: expect.any(Boolean), + desktop: expect.any(Boolean), + cordova: expect.any(Boolean), capacitor: expect.any(Boolean), nativeMobile: expect.any(Boolean), @@ -45,30 +47,33 @@ describe('[Platform API]', () => { 'capacitor' ]), electron: expect.any(Boolean), - desktop: expect.any(Boolean), bex: expect.any(Boolean), - android: expect.any(Boolean), - blackberry: expect.any(Boolean), - cros: expect.any(Boolean), - ios: expect.any(Boolean), - ipad: expect.any(Boolean), - iphone: expect.any(Boolean), - ipod: expect.any(Boolean), - kindle: expect.any(Boolean), + linux: expect.any(Boolean), mac: expect.any(Boolean), win: expect.any(Boolean), - winphone: expect.any(Boolean), - playbook: expect.any(Boolean), - silk: expect.any(Boolean), + cros: expect.any(Boolean), + chrome: expect.any(Boolean), firefox: expect.any(Boolean), opera: expect.any(Boolean), safari: expect.any(Boolean), vivaldi: expect.any(Boolean), edge: expect.any(Boolean), + edgeChromium: expect.any(Boolean), ie: expect.any(Boolean), - webkit: expect.any(Boolean) + webkit: expect.any(Boolean), + + android: expect.any(Boolean), + ios: expect.any(Boolean), + ipad: expect.any(Boolean), + iphone: expect.any(Boolean), + ipod: expect.any(Boolean), + kindle: expect.any(Boolean), + winphone: expect.any(Boolean), + blackberry: expect.any(Boolean), + playbook: expect.any(Boolean), + silk: expect.any(Boolean) } const actualKeys = Object.keys(Platform.is)