From d9a8a02cd70c8fbad334f9f13b00702908e5b769 Mon Sep 17 00:00:00 2001 From: bourquecharles Date: Mon, 5 Jul 2021 08:53:48 -0400 Subject: [PATCH] Prettier run --- src/App.js | 4 ++- src/components/BlinkModal/index.js | 6 ++++- src/components/CommandHistory/index.js | 9 +++++-- src/components/ConfigureModal/index.js | 6 ++++- src/components/DeviceActionCard/index.js | 5 +++- src/components/DeviceConfiguration/index.js | 5 +++- src/components/DeviceHealth/index.js | 7 ++++- src/components/DeviceListTable/index.js | 11 +++++--- src/components/DeviceLogs/index.js | 7 ++++- src/components/DeviceStatusCard/index.js | 4 ++- src/components/FactoryResetModal/index.js | 6 ++++- .../UpgradeWaitingBody.js | 7 +++-- src/components/FirmwareUpgradeModal/index.js | 12 +++++++-- .../LatestStatisticsModal.js | 5 +++- .../StatisticsChartList.js | 5 +++- src/components/RebootModal/index.js | 6 ++++- .../TraceModal/WaitingForTraceBody.js | 7 +++-- src/components/TraceModal/index.js | 12 +++++++-- src/components/WifiScanModal/index.js | 6 ++++- src/contexts/AuthProvider/index.js | 6 ++--- src/layout/Header/index.js | 9 +++++-- src/pages/LoginPage/index.js | 16 +++++++----- src/router/index.js | 8 +++++- src/utils/authHelper.js | 26 +++++++++---------- 24 files changed, 143 insertions(+), 52 deletions(-) diff --git a/src/App.js b/src/App.js index 5bd0b1d..1912491 100644 --- a/src/App.js +++ b/src/App.js @@ -13,7 +13,9 @@ const loading = ( const App = () => { const storageToken = sessionStorage.getItem('access_token'); - const apiEndpoints = checkIfJson(sessionStorage.getItem('gateway_endpoints')) ? JSON.parse(sessionStorage.getItem('gateway_endpoints')) : {}; + const apiEndpoints = checkIfJson(sessionStorage.getItem('gateway_endpoints')) + ? JSON.parse(sessionStorage.getItem('gateway_endpoints')) + : {}; return ( diff --git a/src/components/BlinkModal/index.js b/src/components/BlinkModal/index.js index 6eae13d..2af506d 100644 --- a/src/components/BlinkModal/index.js +++ b/src/components/BlinkModal/index.js @@ -73,7 +73,11 @@ const BlinkModal = ({ show, toggleModal }) => { }; axiosInstance - .post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/leds`, parameters, { headers }) + .post( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/leds`, + parameters, + { headers }, + ) .then(() => { setResult('success'); }) diff --git a/src/components/CommandHistory/index.js b/src/components/CommandHistory/index.js index 664f2d2..82a91b3 100644 --- a/src/components/CommandHistory/index.js +++ b/src/components/CommandHistory/index.js @@ -110,7 +110,9 @@ const DeviceCommands = () => { axiosInstance .get( - `${endpoints.ucentralgw}/api/v1/commands?serialNumber=${encodeURIComponent(deviceSerialNumber)}${extraParams}`, + `${endpoints.ucentralgw}/api/v1/commands?serialNumber=${encodeURIComponent( + deviceSerialNumber, + )}${extraParams}`, options, ) .then((response) => { @@ -133,7 +135,10 @@ const DeviceCommands = () => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/file/${uuid}?serialNumber=${deviceSerialNumber}`, options) + .get( + `${endpoints.ucentralgw}/api/v1/file/${uuid}?serialNumber=${deviceSerialNumber}`, + options, + ) .then((response) => { const blob = new Blob([response.data], { type: 'application/octet-stream' }); const link = document.createElement('a'); diff --git a/src/components/ConfigureModal/index.js b/src/components/ConfigureModal/index.js index 456638a..f8b21b7 100644 --- a/src/components/ConfigureModal/index.js +++ b/src/components/ConfigureModal/index.js @@ -84,7 +84,11 @@ const ConfigureModal = ({ show, toggleModal }) => { }; axiosInstance - .post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/configure`, parameters, { headers }) + .post( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/configure`, + parameters, + { headers }, + ) .then(() => { setHadSuccess(true); }) diff --git a/src/components/DeviceActionCard/index.js b/src/components/DeviceActionCard/index.js index 3c2713c..98faae0 100644 --- a/src/components/DeviceActionCard/index.js +++ b/src/components/DeviceActionCard/index.js @@ -66,7 +66,10 @@ const DeviceActions = () => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/rtty`, options) + .get( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/rtty`, + options, + ) .then((response) => { const url = `https://${response.data.server}:${response.data.viewport}/connect/${response.data.connectionId}`; const newWindow = window.open(url, '_blank', 'noopener,noreferrer'); diff --git a/src/components/DeviceConfiguration/index.js b/src/components/DeviceConfiguration/index.js index 3644a3b..abf3018 100644 --- a/src/components/DeviceConfiguration/index.js +++ b/src/components/DeviceConfiguration/index.js @@ -49,7 +49,10 @@ const DeviceConfiguration = () => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}`, options) + .get( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}`, + options, + ) .then((response) => { setDevice(response.data); }) diff --git a/src/components/DeviceHealth/index.js b/src/components/DeviceHealth/index.js index ff4df40..3b33cb8 100644 --- a/src/components/DeviceHealth/index.js +++ b/src/components/DeviceHealth/index.js @@ -87,7 +87,12 @@ const DeviceHealth = () => { } axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/healthchecks${extraParams}`, options) + .get( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent( + deviceSerialNumber, + )}/healthchecks${extraParams}`, + options, + ) .then((response) => { setHealthChecks(response.data.values); }) diff --git a/src/components/DeviceListTable/index.js b/src/components/DeviceListTable/index.js index 127d3ec..36df38f 100644 --- a/src/components/DeviceListTable/index.js +++ b/src/components/DeviceListTable/index.js @@ -96,9 +96,14 @@ const DeviceList = () => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/devices?deviceWithStatus=true&select=${encodeURIComponent(serialNumber)}`, { - headers, - }) + .get( + `${endpoints.ucentralgw}/api/v1/devices?deviceWithStatus=true&select=${encodeURIComponent( + serialNumber, + )}`, + { + headers, + }, + ) .then((response) => { const device = response.data.devicesWithStatus[0]; const foundIndex = devices.findIndex((obj) => obj.serialNumber === serialNumber); diff --git a/src/components/DeviceLogs/index.js b/src/components/DeviceLogs/index.js index 3af663c..8f0d8f7 100644 --- a/src/components/DeviceLogs/index.js +++ b/src/components/DeviceLogs/index.js @@ -84,7 +84,12 @@ const DeviceLogs = () => { } axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/logs${extraParams}`, options) + .get( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent( + deviceSerialNumber, + )}/logs${extraParams}`, + options, + ) .then((response) => { setLogs(response.data.values); }) diff --git a/src/components/DeviceStatusCard/index.js b/src/components/DeviceStatusCard/index.js index fbaa90d..d42012f 100644 --- a/src/components/DeviceStatusCard/index.js +++ b/src/components/DeviceStatusCard/index.js @@ -47,7 +47,9 @@ const DeviceStatusCard = () => { }; const lastStatsRequest = axiosInstance.get( - `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/statistics?lastOnly=true`, + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent( + deviceSerialNumber, + )}/statistics?lastOnly=true`, options, ); const statusRequest = axiosInstance.get( diff --git a/src/components/FactoryResetModal/index.js b/src/components/FactoryResetModal/index.js index 03da2d1..01ba0d1 100644 --- a/src/components/FactoryResetModal/index.js +++ b/src/components/FactoryResetModal/index.js @@ -65,7 +65,11 @@ const ConfigureModal = ({ show, toggleModal }) => { }; axiosInstance - .post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/factory`, parameters, { headers }) + .post( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/factory`, + parameters, + { headers }, + ) .then(() => { setHadSuccess(true); }) diff --git a/src/components/FirmwareUpgradeModal/UpgradeWaitingBody.js b/src/components/FirmwareUpgradeModal/UpgradeWaitingBody.js index b7d3b4d..77d5f98 100644 --- a/src/components/FirmwareUpgradeModal/UpgradeWaitingBody.js +++ b/src/components/FirmwareUpgradeModal/UpgradeWaitingBody.js @@ -22,7 +22,10 @@ const UpgradeWaitingBody = ({ serialNumber }) => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(serialNumber)}/status`, options) + .get( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(serialNumber)}/status`, + options, + ) .then((response) => response.data.connected) .catch(() => {}); }; @@ -36,7 +39,7 @@ const UpgradeWaitingBody = ({ serialNumber }) => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(serialNumber)}`, options) + .get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(serialNumber)}`, options) .then((response) => response.data.firmware) .catch(() => {}); }; diff --git a/src/components/FirmwareUpgradeModal/index.js b/src/components/FirmwareUpgradeModal/index.js index 26ef6fb..35273e7 100644 --- a/src/components/FirmwareUpgradeModal/index.js +++ b/src/components/FirmwareUpgradeModal/index.js @@ -84,7 +84,11 @@ const FirmwareUpgradeModal = ({ show, toggleModal }) => { useEffect(() => { if (deviceSerialNumber !== null && show) { const asyncGet = async () => { - const isConnected = await getDeviceConnection(deviceSerialNumber, currentToken, endpoints.ucentralgw); + const isConnected = await getDeviceConnection( + deviceSerialNumber, + currentToken, + endpoints.ucentralgw, + ); setDisableWaiting(!isConnected); setDeviceConnected(isConnected); }; @@ -108,7 +112,11 @@ const FirmwareUpgradeModal = ({ show, toggleModal }) => { uri: firmware, }; axiosInstance - .post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/upgrade`, parameters, { headers }) + .post( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/upgrade`, + parameters, + { headers }, + ) .then(() => { if (waitForUpgrade) { setShowWaitingConsole(true); diff --git a/src/components/InterfaceStatistics/LatestStatisticsModal.js b/src/components/InterfaceStatistics/LatestStatisticsModal.js index 9ae2f1e..ed9bbdd 100644 --- a/src/components/InterfaceStatistics/LatestStatisticsModal.js +++ b/src/components/InterfaceStatistics/LatestStatisticsModal.js @@ -29,7 +29,10 @@ const LatestStatisticsModal = ({ show, toggle }) => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${deviceSerialNumber}/statistics?lastOnly=true`, options) + .get( + `${endpoints.ucentralgw}/api/v1/device/${deviceSerialNumber}/statistics?lastOnly=true`, + options, + ) .then((response) => { setLatestStats(response.data); }) diff --git a/src/components/InterfaceStatistics/StatisticsChartList.js b/src/components/InterfaceStatistics/StatisticsChartList.js index 52d5be1..e702706 100644 --- a/src/components/InterfaceStatistics/StatisticsChartList.js +++ b/src/components/InterfaceStatistics/StatisticsChartList.js @@ -128,7 +128,10 @@ const StatisticsChartList = () => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/device/${deviceSerialNumber}/statistics?newest=true&limit=50`, options) + .get( + `${endpoints.ucentralgw}/api/v1/device/${deviceSerialNumber}/statistics?newest=true&limit=50`, + options, + ) .then((response) => { transformIntoDataset(response.data.data); }) diff --git a/src/components/RebootModal/index.js b/src/components/RebootModal/index.js index a09299c..1d32c2b 100644 --- a/src/components/RebootModal/index.js +++ b/src/components/RebootModal/index.js @@ -66,7 +66,11 @@ const ActionModal = ({ show, toggleModal }) => { }; axiosInstance - .post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/reboot`, parameters, { headers }) + .post( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/reboot`, + parameters, + { headers }, + ) .then(() => { setResult('success'); }) diff --git a/src/components/TraceModal/WaitingForTraceBody.js b/src/components/TraceModal/WaitingForTraceBody.js index 557bdc4..61ca28f 100644 --- a/src/components/TraceModal/WaitingForTraceBody.js +++ b/src/components/TraceModal/WaitingForTraceBody.js @@ -22,7 +22,7 @@ const WaitingForTraceBody = ({ serialNumber, commandUuid, toggle }) => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/command/${encodeURIComponent(commandUuid)}`, options) + .get(`${endpoints.ucentralgw}/api/v1/command/${encodeURIComponent(commandUuid)}`, options) .then((response) => { if (response.data.waitingForFile === 0) { setWaitingForFile(false); @@ -41,7 +41,10 @@ const WaitingForTraceBody = ({ serialNumber, commandUuid, toggle }) => { }; axiosInstance - .get(`${endpoints.ucentralgw}/api/v1/file/${commandUuid}?serialNumber=${serialNumber}`, options) + .get( + `${endpoints.ucentralgw}/api/v1/file/${commandUuid}?serialNumber=${serialNumber}`, + options, + ) .then((response) => { const blob = new Blob([response.data], { type: 'application/octet-stream' }); const link = document.createElement('a'); diff --git a/src/components/TraceModal/index.js b/src/components/TraceModal/index.js index 54ea015..8dce46b 100644 --- a/src/components/TraceModal/index.js +++ b/src/components/TraceModal/index.js @@ -83,7 +83,11 @@ const TraceModal = ({ show, toggleModal }) => { }; axiosInstance - .post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/trace`, parameters, { headers }) + .post( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/trace`, + parameters, + { headers }, + ) .then((response) => { setHadSuccess(true); if (waitForTrace) { @@ -105,7 +109,11 @@ const TraceModal = ({ show, toggleModal }) => { useEffect(() => { if (deviceSerialNumber !== null && show) { const asyncGet = async () => { - const isConnected = await getDeviceConnection(deviceSerialNumber, currentToken, endpoints.ucentralgw); + const isConnected = await getDeviceConnection( + deviceSerialNumber, + currentToken, + endpoints.ucentralgw, + ); setIsDeviceConnected(isConnected); }; asyncGet(); diff --git a/src/components/WifiScanModal/index.js b/src/components/WifiScanModal/index.js index 9e4214a..4f26f71 100644 --- a/src/components/WifiScanModal/index.js +++ b/src/components/WifiScanModal/index.js @@ -100,7 +100,11 @@ const WifiScanModal = ({ show, toggleModal }) => { }; axiosInstance - .post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/wifiscan`, parameters, { headers }) + .post( + `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/wifiscan`, + parameters, + { headers }, + ) .then((response) => { const scanList = response?.data?.results?.status?.scan; diff --git a/src/contexts/AuthProvider/index.js b/src/contexts/AuthProvider/index.js index 5f294cf..b3b2999 100644 --- a/src/contexts/AuthProvider/index.js +++ b/src/contexts/AuthProvider/index.js @@ -17,11 +17,11 @@ export const AuthProvider = ({ token, apiEndpoints, children }) => { AuthProvider.propTypes = { token: PropTypes.string.isRequired, children: PropTypes.node.isRequired, - apiEndpoints: PropTypes.instanceOf(Object) + apiEndpoints: PropTypes.instanceOf(Object), }; AuthProvider.defaultProps = { - apiEndpoints: {} -} + apiEndpoints: {}, +}; export const useAuth = () => React.useContext(AuthContext); diff --git a/src/layout/Header/index.js b/src/layout/Header/index.js index a0857c4..f57ace4 100644 --- a/src/layout/Header/index.js +++ b/src/layout/Header/index.js @@ -20,7 +20,7 @@ import { useAuth } from 'contexts/AuthProvider'; const TheHeader = ({ showSidebar, setShowSidebar }) => { const { t, i18n } = useTranslation(); - const { currentToken, endpoints} = useAuth(); + const { currentToken, endpoints } = useAuth(); const [translatedRoutes, setTranslatedRoutes] = useState(routes); const toggleSidebar = () => { @@ -54,7 +54,12 @@ const TheHeader = ({ showSidebar, setShowSidebar }) => { - logout(currentToken, endpoints.ucentralsec)} /> + logout(currentToken, endpoints.ucentralsec)} + /> diff --git a/src/pages/LoginPage/index.js b/src/pages/LoginPage/index.js index 67aacb4..b67dd6a 100644 --- a/src/pages/LoginPage/index.js +++ b/src/pages/LoginPage/index.js @@ -89,16 +89,18 @@ const Login = () => { .then((response) => { sessionStorage.setItem('access_token', response.data.access_token); token = response.data.access_token; - return axiosInstance.get(`${finalUCentralSecUrl}/api/v1/systemEndpoints`, { headers: { - Accept: 'application/json', - Authorization: `Bearer ${response.data.access_token}`, - }}); + return axiosInstance.get(`${finalUCentralSecUrl}/api/v1/systemEndpoints`, { + headers: { + Accept: 'application/json', + Authorization: `Bearer ${response.data.access_token}`, + }, + }); }) - .then ((response) => { + .then((response) => { const endpoints = { - ucentralsec: finalUCentralSecUrl + ucentralsec: finalUCentralSecUrl, }; - for (const endpoint of response.data.endpoints){ + for (const endpoint of response.data.endpoints) { endpoints[endpoint.type] = endpoint.uri; } sessionStorage.setItem('gateway_endpoints', JSON.stringify(endpoints)); diff --git a/src/router/index.js b/src/router/index.js index 90746e8..aaebe82 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -12,7 +12,13 @@ const Routes = () => { (currentToken !== '' && Object.keys(endpoints).length !== 0 ? : )} + render={(props) => + currentToken !== '' && Object.keys(endpoints).length !== 0 ? ( + + ) : ( + + ) + } /> ); }; diff --git a/src/utils/authHelper.js b/src/utils/authHelper.js index 9fe7edb..eebae6b 100644 --- a/src/utils/authHelper.js +++ b/src/utils/authHelper.js @@ -1,19 +1,19 @@ -import axiosInstance from "./axiosInstance"; +import axiosInstance from './axiosInstance'; export const logout = (token, endpoint) => { axiosInstance - .delete(`${endpoint}/api/v1/oauth2/${token}`, { - headers: { - Accept: 'application/json', - Authorization: `Bearer ${token}`, - }, - }) - .then(() => {}) - .catch(() => {}) - .finally(() => { - sessionStorage.clear(); - window.location.replace('/'); - }) + .delete(`${endpoint}/api/v1/oauth2/${token}`, { + headers: { + Accept: 'application/json', + Authorization: `Bearer ${token}`, + }, + }) + .then(() => {}) + .catch(() => {}) + .finally(() => { + sessionStorage.clear(); + window.location.replace('/'); + }); }; export const getToken = () => {