mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw-ui.git
synced 2025-10-30 02:12:33 +00:00
Prettier run
This commit is contained in:
@@ -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 (
|
||||
<AuthProvider token={storageToken ?? ''} apiEndpoints={apiEndpoints}>
|
||||
|
||||
@@ -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');
|
||||
})
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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(() => {});
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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');
|
||||
})
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 }) => {
|
||||
<CHeaderNav className="px-3">
|
||||
<CPopover content={t('common.logout')}>
|
||||
<CLink className="c-subheader-nav-link">
|
||||
<CIcon name="cilAccountLogout" content={cilAccountLogout} size="2xl" onClick={() => logout(currentToken, endpoints.ucentralsec)} />
|
||||
<CIcon
|
||||
name="cilAccountLogout"
|
||||
content={cilAccountLogout}
|
||||
size="2xl"
|
||||
onClick={() => logout(currentToken, endpoints.ucentralsec)}
|
||||
/>
|
||||
</CLink>
|
||||
</CPopover>
|
||||
</CHeaderNav>
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -12,7 +12,13 @@ const Routes = () => {
|
||||
<Route
|
||||
path="/"
|
||||
name="Devices"
|
||||
render={(props) => (currentToken !== '' && Object.keys(endpoints).length !== 0 ? <TheLayout {...props} /> : <Login {...props} />)}
|
||||
render={(props) =>
|
||||
currentToken !== '' && Object.keys(endpoints).length !== 0 ? (
|
||||
<TheLayout {...props} />
|
||||
) : (
|
||||
<Login {...props} />
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user