Merge pull request #529 from jcreedcmu/jcreed/fix-527
Fix sorting of raw results
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
|||||||
RAW_RESULTS_PAGE_SIZE,
|
RAW_RESULTS_PAGE_SIZE,
|
||||||
INTERPRETED_RESULTS_PAGE_SIZE,
|
INTERPRETED_RESULTS_PAGE_SIZE,
|
||||||
ALERTS_TABLE_NAME,
|
ALERTS_TABLE_NAME,
|
||||||
|
RawResultsSortState,
|
||||||
} from './interface-types';
|
} from './interface-types';
|
||||||
import { Logger } from './logging';
|
import { Logger } from './logging';
|
||||||
import * as messages from './messages';
|
import * as messages from './messages';
|
||||||
@@ -190,8 +191,8 @@ export class InterfaceManager extends DisposableObject {
|
|||||||
return this._panel;
|
return this._panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async changeSortState(
|
private async changeInterpretedSortState(
|
||||||
update: (query: CompletedQuery) => Promise<void>
|
sortState: InterpretedResultsSortState | undefined
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (this._displayedQuery === undefined) {
|
if (this._displayedQuery === undefined) {
|
||||||
showAndLogErrorMessage(
|
showAndLogErrorMessage(
|
||||||
@@ -201,10 +202,34 @@ export class InterfaceManager extends DisposableObject {
|
|||||||
}
|
}
|
||||||
// Notify the webview that it should expect new results.
|
// Notify the webview that it should expect new results.
|
||||||
await this.postMessage({ t: 'resultsUpdating' });
|
await this.postMessage({ t: 'resultsUpdating' });
|
||||||
await update(this._displayedQuery);
|
this._displayedQuery.updateInterpretedSortState(sortState);
|
||||||
await this.showResults(this._displayedQuery, WebviewReveal.NotForced, true);
|
await this.showResults(this._displayedQuery, WebviewReveal.NotForced, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async changeRawSortState(
|
||||||
|
resultSetName: string,
|
||||||
|
sortState: RawResultsSortState | undefined
|
||||||
|
): Promise<void> {
|
||||||
|
if (this._displayedQuery === undefined) {
|
||||||
|
showAndLogErrorMessage(
|
||||||
|
'Failed to sort results since evaluation info was unknown.'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Notify the webview that it should expect new results.
|
||||||
|
await this.postMessage({ t: 'resultsUpdating' });
|
||||||
|
await this._displayedQuery.updateSortState(
|
||||||
|
this.cliServer,
|
||||||
|
resultSetName,
|
||||||
|
sortState
|
||||||
|
);
|
||||||
|
// Sorting resets to first page, as there is arguably no particular
|
||||||
|
// correlation between the results on the nth page that the user
|
||||||
|
// was previously viewing and the contents of the nth page in a
|
||||||
|
// new sorted order.
|
||||||
|
await this.showPageOfRawResults(resultSetName, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
private async handleMsgFromView(msg: FromResultsViewMsg): Promise<void> {
|
private async handleMsgFromView(msg: FromResultsViewMsg): Promise<void> {
|
||||||
switch (msg.t) {
|
switch (msg.t) {
|
||||||
case 'viewSourceFile': {
|
case 'viewSourceFile': {
|
||||||
@@ -235,18 +260,10 @@ export class InterfaceManager extends DisposableObject {
|
|||||||
this._panelLoadedCallBacks = [];
|
this._panelLoadedCallBacks = [];
|
||||||
break;
|
break;
|
||||||
case 'changeSort':
|
case 'changeSort':
|
||||||
await this.changeSortState(query =>
|
await this.changeRawSortState(msg.resultSetName, msg.sortState);
|
||||||
query.updateSortState(
|
|
||||||
this.cliServer,
|
|
||||||
msg.resultSetName,
|
|
||||||
msg.sortState
|
|
||||||
)
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case 'changeInterpretedSort':
|
case 'changeInterpretedSort':
|
||||||
await this.changeSortState(query =>
|
await this.changeInterpretedSortState(msg.sortState);
|
||||||
query.updateInterpretedSortState(this.cliServer, msg.sortState)
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case 'changePage':
|
case 'changePage':
|
||||||
if (msg.selectedTable === ALERTS_TABLE_NAME) {
|
if (msg.selectedTable === ALERTS_TABLE_NAME) {
|
||||||
@@ -423,7 +440,8 @@ export class InterfaceManager extends DisposableObject {
|
|||||||
*/
|
*/
|
||||||
public async showPageOfRawResults(
|
public async showPageOfRawResults(
|
||||||
selectedTable: string,
|
selectedTable: string,
|
||||||
pageNumber: number
|
pageNumber: number,
|
||||||
|
sorted = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const results = this._displayedQuery;
|
const results = this._displayedQuery;
|
||||||
if (results === undefined) {
|
if (results === undefined) {
|
||||||
@@ -445,8 +463,21 @@ export class InterfaceManager extends DisposableObject {
|
|||||||
if (schema === undefined)
|
if (schema === undefined)
|
||||||
throw new Error(`Query result set '${selectedTable}' not found.`);
|
throw new Error(`Query result set '${selectedTable}' not found.`);
|
||||||
|
|
||||||
|
const getResultsPath = () => {
|
||||||
|
if (sorted) {
|
||||||
|
const resultsPath = results.sortedResultsInfo.get(selectedTable)?.resultsPath;
|
||||||
|
if (resultsPath === undefined) {
|
||||||
|
throw new Error(`Can't find sorted results for table ${selectedTable}`);
|
||||||
|
}
|
||||||
|
return resultsPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return results.query.resultsPaths.resultsPath;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const chunk = await this.cliServer.bqrsDecode(
|
const chunk = await this.cliServer.bqrsDecode(
|
||||||
results.query.resultsPaths.resultsPath,
|
getResultsPath(),
|
||||||
schema.name,
|
schema.name,
|
||||||
{
|
{
|
||||||
offset: schema.pagination?.offsets[pageNumber],
|
offset: schema.pagination?.offsets[pageNumber],
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ export class CompletedQuery implements QueryWithResults {
|
|||||||
this.sortedResultsInfo.set(resultSetName, sortedResultSetInfo);
|
this.sortedResultsInfo.set(resultSetName, sortedResultSetInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateInterpretedSortState(_server: cli.CodeQLCliServer, sortState: InterpretedResultsSortState | undefined): Promise<void> {
|
async updateInterpretedSortState(sortState: InterpretedResultsSortState | undefined): Promise<void> {
|
||||||
this.interpretedResultsSortState = sortState;
|
this.interpretedResultsSortState = sortState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user