Skip to content

Commit

Permalink
Allow specifying whether local or all snapshots are shown by default …
Browse files Browse the repository at this point in the history
…in the UI
  • Loading branch information
PhracturedBlue committed Sep 11, 2023
1 parent d78d5eb commit 1439dc8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/PreferencesView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <>
<form>
<div className='form-group'>
Expand All @@ -26,6 +26,15 @@ export class PreferencesView extends Component {
<small hmtlfor='bytesBaseInput' id='bytesHelp' className='form-text text-muted'>Specifies the representation of bytes</small>
</div>
<br />
<div className='form-group'>
<label className='label-description'>Default snapshot view</label>
<select className="form-select form-select-sm" title='Select default snapshot view' id='defaultSnapshotViewInput' value={defaultSnapshotViewAll} onChange={e => setDefaultSnapshotView(e.target.value)}>
<option value="true">All Snapshots</option>
<option value="false">Local Snapshots</option>
</select>
<small hmtlfor='defaultSnapshotViewInput' id='dsvHelp' className='form-text text-muted'>Specifies the default view on the Snapshots page</small>
</div>
<br />
<div className='form-group'>
<label className='label-description'>Page size</label>
<input className='form-control form-control-sm' id='pageSizeInput'
Expand Down
13 changes: 8 additions & 5 deletions src/SourcesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SourcesTable extends Component {

localSourceName: "",
multiUser: false,
selectedOwner: localSnapshots,
selectedOwner: null,
selectedDirectory: "",
};

Expand Down Expand Up @@ -210,15 +210,18 @@ export class SourcesTable extends Component {
}

render() {
let { sources, isLoading, error } = this.state;
const { bytesStringBase2 } = this.context
let { sources, isLoading, selectedOwner, error } = this.state;
const { bytesStringBase2, defaultSnapshotViewAll } = this.context
if (error) {
return <p>{error.message}</p>;
}
if (isLoading) {
return <Spinner animation="border" variant="primary" />;
}

if (selectedOwner == null) {
this.state.selectedOwner = defaultSnapshotViewAll ? allSnapshots : localSnapshots;
}
console.log(selectedOwner);
let uniqueOwners = sources.reduce((a, d) => {
const owner = ownerName(d.source);

Expand Down Expand Up @@ -324,4 +327,4 @@ export class SourcesTable extends Component {
</>;
}
}
SourcesTable.contextType = UIPreferencesContext
SourcesTable.contextType = UIPreferencesContext
11 changes: 9 additions & 2 deletions src/contexts/UIPreferencesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios from 'axios';
export const PAGE_SIZES = [10, 20, 30, 40, 50, 100];
export const UIPreferencesContext = React.createContext<UIPreferences>({} 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";
Expand All @@ -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 {
Expand Down Expand Up @@ -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 <UIPreferencesContext.Provider value={providedValue}>
{props.children}
Expand Down

0 comments on commit 1439dc8

Please sign in to comment.