Browse Source

Updates selected row on search init & navigation

main
Eric Amodio 2 years ago
parent
commit
7254dafbc0
4 changed files with 58 additions and 35 deletions
  1. +32
    -25
      src/plus/webviews/graph/graphWebview.ts
  2. +8
    -5
      src/plus/webviews/graph/protocol.ts
  3. +11
    -2
      src/webviews/apps/plus/graph/GraphWrapper.tsx
  4. +7
    -3
      src/webviews/apps/plus/graph/graph.tsx

+ 32
- 25
src/plus/webviews/graph/graphWebview.ts View File

@ -39,7 +39,7 @@ import {
DidEnsureCommitNotificationType,
DidSearchCommitsNotificationType,
DismissBannerCommandType,
EnsureHasCommitCommandType,
EnsureCommitCommandType,
GetMissingAvatarsCommandType,
GetMoreCommitsCommandType,
SearchCommitsCommandType,
@ -213,8 +213,8 @@ export class GraphWebview extends WebviewBase {
case UpdateSelectionCommandType.method:
onIpc(UpdateSelectionCommandType, e, params => this.onSelectionChanged(params.selection));
break;
case EnsureHasCommitCommandType.method:
onIpc(EnsureHasCommitCommandType, e, params => this.onEnsureCommit(params.id, e.id));
case EnsureCommitCommandType.method:
onIpc(EnsureCommitCommandType, e, params => this.onEnsureCommit(params.id, e.completionId));
break;
}
}
@ -349,6 +349,24 @@ export class GraphWebview extends WebviewBase {
void this.notifyDidChangeGraphConfiguration();
}
private async onEnsureCommit(id: string, completionId?: string) {
if (this._graph?.more == null) return;
if (!this._graph.ids.has(id)) {
const { defaultItemLimit, pageItemLimit } = configuration.get('graph');
const newGraph = await this._graph.more(pageItemLimit ?? defaultItemLimit, id);
if (newGraph != null) {
this.setGraph(newGraph);
} else {
debugger;
}
void this.notifyDidChangeCommits();
}
void this.notify(DidEnsureCommitNotificationType, { id: id }, completionId);
}
private async onGetMissingAvatars(emails: { [email: string]: string }) {
if (this._graph == null) return;
@ -407,14 +425,21 @@ export class GraphWebview extends WebviewBase {
ordering: configuration.get('graph.commitOrdering'),
});
if (search.results.length > 0) {
this.setSelectedRows(search.results[0]);
}
void this.notify(
DidSearchCommitsNotificationType,
{
ids: search.results,
paging: {
startingCursor: search.paging?.startingCursor,
more: search.paging?.more ?? false,
searchResults: {
ids: search.results,
paging: {
startingCursor: search.paging?.startingCursor,
more: search.paging?.more ?? false,
},
},
selectedRows: this._selectedRows,
},
completionId,
);
@ -678,24 +703,6 @@ export class GraphWebview extends WebviewBase {
this._selectedSha = sha;
this._selectedRows = sha != null ? { [sha]: true } : {};
}
private async onEnsureCommit(id: string, completionId: string) {
if (this._graph == null) return;
if (!this._graph.ids.has(id)) {
const { defaultItemLimit, pageItemLimit } = configuration.get('graph');
const newGraph = await this._graph.more!(pageItemLimit ?? defaultItemLimit, id);
if (newGraph != null) {
this.setGraph(newGraph);
} else {
debugger;
}
void this.notifyDidChangeCommits();
}
void this.notify(DidEnsureCommitNotificationType, { id: id }, completionId);
}
}
function formatRepositories(repositories: Repository[]): GraphRepository[] {

+ 8
- 5
src/plus/webviews/graph/protocol.ts View File

@ -25,7 +25,7 @@ export interface State {
// Props below are computed in the webview (not passed)
mixedColumnColors?: Record<string, string>;
searchResults?: DidSearchCommitsParams;
searchResults?: DidSearchCommitsParams['searchResults'];
}
export interface GraphPaging {
@ -112,10 +112,10 @@ export interface UpdateSelectionParams {
}
export const UpdateSelectionCommandType = new IpcCommandType<UpdateSelectionParams>('graph/update/selection');
export interface EnsureHasCommitParams {
export interface EnsureCommitParams {
id: string;
}
export const EnsureHasCommitCommandType = new IpcCommandType<EnsureHasCommitParams>('graph/update/ensureHasCommit');
export const EnsureCommitCommandType = new IpcCommandType<EnsureCommitParams>('graph/ensureCommit');
// Notifications
export interface DidChangeParams {
@ -163,8 +163,11 @@ export const DidChangeSelectionNotificationType = new IpcNotificationType
);
export interface DidSearchCommitsParams {
ids: string[];
paging?: GraphPaging;
searchResults: {
ids: string[];
paging?: GraphPaging;
};
selectedRows?: { [id: string]: true };
}
export const DidSearchCommitsNotificationType = new IpcNotificationType<DidSearchCommitsParams>(
'graph/commits/didSearch',

+ 11
- 2
src/webviews/apps/plus/graph/GraphWrapper.tsx View File

@ -294,13 +294,22 @@ export function GraphWrapper({
if (nextSha == null) return;
if (onEnsureCommit != null) {
setIsLoading(true);
let timeout: ReturnType<typeof setTimeout> | undefined = setTimeout(() => {
timeout = undefined;
setIsLoading(true);
}, 250);
onEnsureCommit(nextSha).finally(() => {
setIsLoading(false);
if (timeout == null) {
setIsLoading(false);
} else {
clearTimeout(timeout);
}
setSearchResultKey(nextSha);
setSelectedRows({ [nextSha!]: true });
});
} else {
setSearchResultKey(nextSha);
setSelectedRows({ [nextSha]: true });
}
};

+ 7
- 3
src/webviews/apps/plus/graph/graph.tsx View File

@ -21,7 +21,7 @@ import {
DidEnsureCommitNotificationType,
DidSearchCommitsNotificationType,
DismissBannerCommandType,
EnsureHasCommitCommandType,
EnsureCommitCommandType,
GetMissingAvatarsCommandType,
GetMoreCommitsCommandType,
SearchCommitsCommandType,
@ -192,7 +192,11 @@ export class GraphApp extends App {
case DidSearchCommitsNotificationType.method:
onIpc(DidSearchCommitsNotificationType, msg, params => {
this.setState({ ...this.state, searchResults: params });
this.setState({
...this.state,
searchResults: params.searchResults,
selectedRows: params.selectedRows,
});
this.refresh(this.state);
});
break;
@ -313,7 +317,7 @@ export class GraphApp extends App {
}
private onEnsureCommit(id: string) {
return this.sendCommandWithCompletion(EnsureHasCommitCommandType, { id: id }, DidEnsureCommitNotificationType);
return this.sendCommandWithCompletion(EnsureCommitCommandType, { id: id }, DidEnsureCommitNotificationType);
}
private onSelectionChanged(selection: { id: string; type: GitGraphRowType }[]) {

Loading…
Cancel
Save