mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 09:26:17 -05:00
Displaying warning when no drive is mounted.
This commit is contained in:
parent
1951ca548d
commit
da340a00b3
12 changed files with 301 additions and 4 deletions
|
|
@ -38,7 +38,7 @@ import {DateSelectorButton} from "./components/DatesSelector";
|
|||
import {useCalculators} from "./components/Calculators";
|
||||
import {classifyAndEvaluate} from "./components/calculators/mathConfig";
|
||||
|
||||
function FlagsMessages() {
|
||||
export function FlagsMessages() {
|
||||
const {settings, fetchSettings} = React.useContext(SettingsContext);
|
||||
const {status} = useContext(StatusContext);
|
||||
|
||||
|
|
@ -88,9 +88,20 @@ function FlagsMessages() {
|
|||
</ErrorMessage>;
|
||||
}
|
||||
|
||||
let mediaUnmountedMessage;
|
||||
if (flags.media_mounted === false) {
|
||||
mediaUnmountedMessage = <ErrorMessage icon='hdd outline'>
|
||||
<Message.Header>No drive mounted</Message.Header>
|
||||
WROLPi has no media drive mounted for one or more storage locations.
|
||||
Downloads would write to the root filesystem and can fill it.
|
||||
{' '}<Link to='/admin/controller'>Open the Controller</Link> to mount a drive.
|
||||
</ErrorMessage>;
|
||||
}
|
||||
|
||||
return <>
|
||||
{refreshingMessage}
|
||||
{dbDownMessage || refreshRequiredMessage}
|
||||
{mediaUnmountedMessage}
|
||||
{settings && settings['ignore_outdated_zims'] === false && flags.outdated_zims ?
|
||||
<OutdatedZimsMessage onClick={fetchSettings}/> : null}
|
||||
{internetDownMessage}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import React from 'react';
|
||||
import {render, screen} from '@testing-library/react';
|
||||
import {MemoryRouter} from 'react-router';
|
||||
import {Getters} from './DashboardPage';
|
||||
import {StatusContext, ThemeContext} from './contexts/contexts';
|
||||
import {Getters, FlagsMessages} from './DashboardPage';
|
||||
import {SettingsContext, StatusContext, ThemeContext} from './contexts/contexts';
|
||||
|
||||
// Replace DownloadMenu with a stub that records its props. The deep-link
|
||||
// behavior under test is just "Getters reads URL params and forwards them
|
||||
|
|
@ -76,3 +76,35 @@ describe('DashboardPage Getters deep-link', () => {
|
|||
// newlines into the `download` prop's `urls` field) is exercised in the
|
||||
// browser via manual verification, not unit-tested here — reaching into the
|
||||
// per-form trees pulls in heavy fetch-driven components.
|
||||
|
||||
function renderFlagsMessages({flags = {}, settings = {}} = {}) {
|
||||
const status = {flags: {refresh_complete: true, db_up: true, have_internet: true, ...flags}};
|
||||
return render(
|
||||
<MemoryRouter>
|
||||
<SettingsContext.Provider value={{settings, fetchSettings: () => {}}}>
|
||||
<StatusContext.Provider value={{status}}>
|
||||
<FlagsMessages/>
|
||||
</StatusContext.Provider>
|
||||
</SettingsContext.Provider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
}
|
||||
|
||||
describe('DashboardPage no-drive-mounted banner', () => {
|
||||
it('shows the banner when media_mounted is false', () => {
|
||||
renderFlagsMessages({flags: {media_mounted: false}});
|
||||
expect(screen.getByText(/No drive mounted/i)).toBeInTheDocument();
|
||||
const link = screen.getByText(/Open the Controller/i);
|
||||
expect(link).toHaveAttribute('href', '/admin/controller');
|
||||
});
|
||||
|
||||
it('hides the banner when media_mounted is true', () => {
|
||||
renderFlagsMessages({flags: {media_mounted: true}});
|
||||
expect(screen.queryByText(/No drive mounted/i)).toBeNull();
|
||||
});
|
||||
|
||||
it('hides the banner when media_mounted is undefined (status not yet loaded)', () => {
|
||||
renderFlagsMessages();
|
||||
expect(screen.queryByText(/No drive mounted/i)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -332,6 +332,7 @@ export async function getSettings() {
|
|||
nav_color: content.nav_color,
|
||||
media_directory: content.media_directory,
|
||||
require_cookies_unlocked: content.require_cookies_unlocked,
|
||||
require_media_mounted: content.require_media_mounted,
|
||||
save_ffprobe_json: content.save_ffprobe_json,
|
||||
tags_directory: content.tags_directory,
|
||||
throttle_on_startup: content.throttle_on_startup,
|
||||
|
|
|
|||
|
|
@ -453,6 +453,7 @@ export function SettingsPage() {
|
|||
archive_destination: settings.archive_destination,
|
||||
download_on_startup: settings.download_on_startup,
|
||||
require_cookies_unlocked: settings.require_cookies_unlocked,
|
||||
require_media_mounted: settings.require_media_mounted,
|
||||
download_timeout: settings.download_timeout,
|
||||
download_wait: settings.download_wait,
|
||||
download_window_start: settings.download_window_start || '',
|
||||
|
|
@ -686,6 +687,19 @@ export function SettingsPage() {
|
|||
/>
|
||||
</div>
|
||||
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label={<>
|
||||
Pause downloads when no drive is mounted
|
||||
<InfoPopup
|
||||
content='When enabled, downloads will not start unless every storage destination (videos, archive, zims, map) is backed by a mounted drive. Prevents filling the SD card on a Raspberry Pi.'/>
|
||||
</>}
|
||||
disabled={disabled || state.require_media_mounted === null}
|
||||
checked={state.require_media_mounted === true}
|
||||
onChange={checked => handleInputChange(null, 'require_media_mounted', checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
label={<>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue