mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-29 22:26:32 +00:00
patch: hide selftest if api is not available
This commit is contained in:
parent
cbbf99259d
commit
c1cb9e5ec8
@ -64,6 +64,7 @@ const InfoBox = (props: any) => (
|
|||||||
|
|
||||||
export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
||||||
const [settingsList, setCurrentSettingsList] = React.useState<Setting[]>([]);
|
const [settingsList, setCurrentSettingsList] = React.useState<Setting[]>([]);
|
||||||
|
const [diagApiIsUp, setDiagApiIsUp] = React.useState<boolean>(false);
|
||||||
const [showDiagScreen, setShowDiagScreen] = React.useState<boolean>(false);
|
const [showDiagScreen, setShowDiagScreen] = React.useState<boolean>(false);
|
||||||
const [currentSettings, setCurrentSettings] = React.useState<
|
const [currentSettings, setCurrentSettings] = React.useState<
|
||||||
_.Dictionary<boolean>
|
_.Dictionary<boolean>
|
||||||
@ -85,6 +86,23 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
|||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`http://localhost:3000/api/ping`);
|
||||||
|
if (res.status < 400 && res.status > 199) {
|
||||||
|
setDiagApiIsUp(true);
|
||||||
|
} else {
|
||||||
|
console.log('Diagnostics api not reachable.');
|
||||||
|
setDiagApiIsUp(false);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Diagnostics api not reachable.', err);
|
||||||
|
setDiagApiIsUp(false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const toggleSetting = async (setting: string) => {
|
const toggleSetting = async (setting: string) => {
|
||||||
const value = currentSettings[setting];
|
const value = currentSettings[setting];
|
||||||
analytics.logEvent('Toggle setting', { setting, value });
|
analytics.logEvent('Toggle setting', { setting, value });
|
||||||
@ -154,6 +172,7 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
|||||||
/>
|
/>
|
||||||
<Txt style={{ borderBottom: '1px solid #00aeef' }}>{version}</Txt>
|
<Txt style={{ borderBottom: '1px solid #00aeef' }}>{version}</Txt>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
{diagApiIsUp ? (
|
||||||
<Flex
|
<Flex
|
||||||
mt={18}
|
mt={18}
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
@ -171,8 +190,13 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
|||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
style={{ marginRight: 8 }}
|
style={{ marginRight: 8 }}
|
||||||
/>
|
/>
|
||||||
<Txt style={{ borderBottom: '1px solid #00aeef' }}>Run self-test</Txt>
|
<Txt style={{ borderBottom: '1px solid #00aeef' }}>
|
||||||
|
Run self-test
|
||||||
|
</Txt>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{showDiagScreen ? (
|
{showDiagScreen ? (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user