diff --git a/src/PreferencesView.jsx b/src/PreferencesView.jsx index ea13d2a..ffbb556 100644 --- a/src/PreferencesView.jsx +++ b/src/PreferencesView.jsx @@ -3,7 +3,7 @@ import { UIPreferencesContext } from './contexts/UIPreferencesContext'; export class PreferencesView extends Component { render() { - const { pageSize, theme, bytesStringBase2, setByteStringBase, setTheme } = this.context; + const { pageSize, theme, bytesStringBase2, defaultSnapshotViewAll, setByteStringBase, setTheme, setDefaultSnapshotView } = this.context; return <>
@@ -26,6 +26,15 @@ export class PreferencesView extends Component { Specifies the representation of bytes

+
+ + + Specifies the default view on the Snapshots page +
+
{error.message}

; } if (isLoading) { return ; } - + if (selectedOwner == null) { + this.state.selectedOwner = defaultSnapshotViewAll ? allSnapshots : localSnapshots; + } + console.log(selectedOwner); let uniqueOwners = sources.reduce((a, d) => { const owner = ownerName(d.source); @@ -324,4 +327,4 @@ export class SourcesTable extends Component { ; } } -SourcesTable.contextType = UIPreferencesContext \ No newline at end of file +SourcesTable.contextType = UIPreferencesContext diff --git a/src/contexts/UIPreferencesContext.tsx b/src/contexts/UIPreferencesContext.tsx index 94cf1f4..f0840b0 100644 --- a/src/contexts/UIPreferencesContext.tsx +++ b/src/contexts/UIPreferencesContext.tsx @@ -4,7 +4,7 @@ import axios from 'axios'; export const PAGE_SIZES = [10, 20, 30, 40, 50, 100]; export const UIPreferencesContext = React.createContext({} as UIPreferences); -const DEFAULT_PREFERENCES = { pageSize: PAGE_SIZES[0], bytesStringBase2: false, theme: getDefaultTheme() } as SerializedUIPreferences; +const DEFAULT_PREFERENCES = { pageSize: PAGE_SIZES[0], bytesStringBase2: false, defaultSnapshotViewAll: false, theme: getDefaultTheme() } as SerializedUIPreferences; const PREFERENCES_URL = '/api/v1/ui-preferences'; export type Theme = "light" | "dark" | "pastel" | "ocean"; @@ -14,9 +14,11 @@ export interface UIPreferences { get pageSize(): PageSize get theme(): Theme get bytesStringBase2(): boolean + get defaultSnapshotViewAll(): boolean setTheme: (theme: Theme) => void setPageSize: (pageSize: number) => void setByteStringBase: (bytesStringBase2: String) => void + setDefaultSnapshotView: (defaultSnapshotView: String) => void } interface SerializedUIPreferences { @@ -114,7 +116,12 @@ export function UIPreferenceProvider(props: UIPreferenceProviderProps) { return { ...oldPreferences, bytesStringBase2 }; }); - const providedValue = { ...preferences, setTheme, setPageSize, setByteStringBase} as UIPreferences; + const setDefaultSnapshotView = (input: String) => setPreferences(oldPreferences => { + var defaultSnapshotViewAll = input === "true"; + return { ...oldPreferences, defaultSnapshotViewAll }; + }); + + const providedValue = { ...preferences, setTheme, setPageSize, setByteStringBase, setDefaultSnapshotView} as UIPreferences; return {props.children}