Skip to content

Commit

Permalink
Make Settings UI's StartScreen only fully reload configs when clickin…
Browse files Browse the repository at this point in the history
…g Reload
  • Loading branch information
SchoofsKelvin committed Mar 25, 2023
1 parent 574d466 commit 5900185
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
- Add a new `extend` config option that allows a config to extend one or more other configs (#268)
- The extension will automatically detect and report missing or cyclic dependencies, skipping them
- Note that if a config tries to extend a non-existing config, it will be skipped and an error will also be shown
- Start screen of Settings UI will use the cached list of configs instead of reloading them
- This should make navigating to the start screen (especially when navigating back and forth between configs) faster
- The Refresh button is now renamed to Reload and will still reload the configs (from disk, remote workspaces, ...)

### Development changes

Expand Down
1 change: 1 addition & 0 deletions common/src/webviewMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ConfigLocation, FileSystemConfig } from './fileSystemConfig';

export interface RequestDataMessage {
type: 'requestData';
reload?: boolean;
}
export interface ResponseDataMessage {
type: 'responseData';
Expand Down
6 changes: 3 additions & 3 deletions src/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { Message, Navigation } from 'common/webviewMessages';
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { deleteConfig, loadConfigs, updateConfig } from './config';
import { DEBUG, Logging as _Logging, LOGGING_NO_STACKTRACE } from './logging';
import { deleteConfig, getConfigs, loadConfigs, updateConfig } from './config';
import { DEBUG, LOGGING_NO_STACKTRACE, Logging as _Logging } from './logging';
import { toPromise } from './utils';

const Logging = _Logging.scope('WebView');
Expand Down Expand Up @@ -89,7 +89,7 @@ async function handleMessage(message: Message): Promise<any> {
}
switch (message.type) {
case 'requestData': {
const configs = await loadConfigs();
const configs = await (message.reload ? loadConfigs : getConfigs)();
const locations = getLocations(configs);
return postMessage({
configs, locations,
Expand Down
11 changes: 6 additions & 5 deletions webview/src/Startscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface StateProps {
groupBy: string;
}
interface DispatchProps {
refresh(): void;
refresh(reload?: boolean): void;
changeGroupBy(current: string): void;
add(): void;
}
Expand All @@ -26,7 +26,7 @@ class Startscreen extends React.Component<StateProps & DispatchProps> {
const nextGroupBy = this.props.groupBy === 'group' ? 'location' : 'group';
return <div className="Homescreen">
<h2>Configurations</h2>
<button onClick={this.props.refresh}>Refresh</button>
<button onClick={this.reload}>Reload</button>
<button onClick={this.props.add}>Add</button>
<button onClick={this.changeGroupBy}>Sort by {nextGroupBy}</button>
{grouped.map(([loc, configs]) => this.createGroup(loc, configs))}
Expand All @@ -39,7 +39,8 @@ class Startscreen extends React.Component<StateProps & DispatchProps> {
<ConfigList configs={configs} />
</div>;
}
public changeGroupBy = () => this.props.changeGroupBy(this.props.groupBy);
protected reload = () => this.props.refresh(true);
protected changeGroupBy = () => this.props.changeGroupBy(this.props.groupBy);
}

export default connect(Startscreen)<StateProps, DispatchProps>(
Expand All @@ -50,9 +51,9 @@ export default connect(Startscreen)<StateProps, DispatchProps>(
dispatch => ({
add: () => dispatch(openNewConfig()),
changeGroupBy: (current: string) => dispatch(openStartScreen(current === 'group' ? 'location' : 'group')),
refresh: () => {
refresh: (reload?: boolean) => {
dispatch(receivedData([], []));
API.postMessage({ type: 'requestData' });
API.postMessage({ type: 'requestData', reload });
},
}),
);

0 comments on commit 5900185

Please sign in to comment.