Allow remote query items to have their labels edited

The labels for remote query items are interpolated using the same
strategy as local queries with two caveats:

1. There is no easy way to get the result count without reading files,
   so, this value is kept empty.
2. There is no database name for remote queries. Instead, use the
   nwo of the controller repo.

Also, adds tests for the history item label provider.
This commit is contained in:
Andrew Eisenberg
2022-04-04 10:20:07 -07:00
parent eec506a209
commit f1c4fef8ba
4 changed files with 26 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import { env } from 'vscode';
import { QueryHistoryConfig } from './config';
import { LocalQueryInfo, QueryHistoryInfo } from './query-results';
import { RemoteQueryHistoryItem } from './remote-queries/remote-query-history-item';
interface InterpolateReplacements {
t: string; // Start time
@@ -18,11 +19,12 @@ export class HistoryItemLabelProvider {
}
getLabel(item: QueryHistoryInfo) {
if (item.t === 'remote') {
return item.remoteQuery.queryName;
}
const replacements = this.getLocalInterpolateReplacements(item);
const replacements = item.t === 'local'
? this.getLocalInterpolateReplacements(item)
: this.getRemoteInterpolateReplacements(item);
const rawLabel = item.userSpecifiedLabel ?? (this.config.format || '%q');
return this.interpolate(rawLabel, replacements);
}
@@ -60,4 +62,20 @@ export class HistoryItemLabelProvider {
'%': '%',
};
}
private getRemoteInterpolateReplacements(item: RemoteQueryHistoryItem): InterpolateReplacements {
return {
t: new Date(item.remoteQuery.executionStartTime).toLocaleString(env.language),
q: item.remoteQuery.queryName,
// There is no database name for remote queries. Instead use the controller repository name.
d: `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`,
// There is no synchronous way to get the results count.
r: '',
s: item.status,
f: item.remoteQuery.queryFilePath,
'%': '%'
};
}
}

View File

@@ -653,7 +653,7 @@ export class QueryHistoryManager extends DisposableObject {
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
// TODO will support remote queries
if (!this.assertSingleQuery(finalMultiSelect) || finalSingleItem?.t !== 'local') {
if (!this.assertSingleQuery(finalMultiSelect)) {
return;
}

View File

@@ -10,6 +10,6 @@ export interface RemoteQueryHistoryItem {
status: QueryStatus;
completed: boolean;
readonly queryId: string,
label: string; // TODO, the query label should have interpolation like local queries
remoteQuery: RemoteQuery;
userSpecifiedLabel?: string;
}

View File

@@ -16,6 +16,7 @@ import { DisposableBucket } from '../../disposable-bucket';
import { testDisposeHandler } from '../../test-dispose-handler';
import { walkDirectory } from '../../../helpers';
import { getErrorMessage } from '../../../pure/helpers-pure';
import { HistoryItemLabelProvider } from '../../../history-item-label-provider';
/**
* Tests for remote queries and how they interact with the query history manager.
@@ -71,6 +72,7 @@ describe('Remote queries and query history manager', function() {
{
onDidChangeConfiguration: () => new DisposableBucket(),
} as unknown as QueryHistoryConfig,
new HistoryItemLabelProvider({} as QueryHistoryConfig),
asyncNoop
);
disposables.push(qhm);