-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathopenCollectionView.ts
More file actions
97 lines (85 loc) · 3.78 KB
/
Copy pathopenCollectionView.ts
File metadata and controls
97 lines (85 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type IActionContext } from '@microsoft/vscode-azext-utils';
import * as l10n from '@vscode/l10n';
import * as vscode from 'vscode';
import { ClusterSession } from '../../documentdb/ClusterSession';
import { inferViewIdFromTreeId } from '../../documentdb/Views';
import { type CollectionItem } from '../../tree/documentdb/CollectionItem';
import { trackJourneyCorrelationId } from '../../utils/commandTelemetry';
import { openCollectionWebview } from '../../webviews/documentdb/collectionView/collectionViewController';
export async function openCollectionView(context: IActionContext, node: CollectionItem) {
// added manually here as this function can by called bypassing our general command registration
trackJourneyCorrelationId(context, node);
if (!node) {
throw new Error(l10n.t('No node selected.'));
}
context.telemetry.properties.experience = node?.experience.api;
// Extract viewId from the cluster model, or infer from treeId prefix
// The viewId tells us which branch data provider owns this node
const viewId = node.cluster.viewId ?? inferViewIdFromTreeId(node.cluster.treeId);
return openCollectionViewInternal(context, {
clusterId: node.cluster.clusterId,
clusterDisplayName: node.cluster.name,
viewId: viewId,
databaseName: node.databaseInfo.name,
collectionName: node.collectionInfo.name,
});
}
export async function openCollectionViewInternal(
_context: IActionContext,
props: {
clusterId: string;
clusterDisplayName: string;
viewId: string;
databaseName: string;
collectionName: string;
initialQuery?: {
filter?: string;
project?: string;
sort?: string;
skip?: number;
limit?: number;
};
/**
* Optional tab to land on when the view opens. When invoked from the
* "Indexes" tree node we pass `'tab_indexes'` so the user lands
* directly on the Index Management tab instead of Documents.
*/
initialTab?: 'tab_result' | 'tab_indexes' | 'tab_queryInsights';
},
): Promise<void> {
/**
* We're starting a new "session" using the existing connection.
* A session can cache data, handle paging, and convert data.
*/
const sessionId = await ClusterSession.initNewSession(props.clusterId);
// Enable feedback signals only when telemetry level is set to "all"
// See: https://code.visualstudio.com/docs/setup/enterprise#_configure-telemetry-level
let feedbackSignalsEnabled = false;
try {
const telemetryLevel = vscode.workspace.getConfiguration('telemetry').get<string>('telemetryLevel');
feedbackSignalsEnabled = telemetryLevel === 'all';
} catch {
// If we fail to read telemetry settings, default to false
feedbackSignalsEnabled = false;
}
const view = openCollectionWebview({
sessionId: sessionId,
clusterId: props.clusterId,
clusterDisplayName: props.clusterDisplayName,
viewId: props.viewId,
databaseName: props.databaseName,
collectionName: props.collectionName,
feedbackSignalsEnabled: feedbackSignalsEnabled,
initialQuery: props.initialQuery,
initialTab: props.initialTab,
});
// Clean up the ClusterSession when the tab is closed
view.onDisposed(() => {
ClusterSession.closeSession(sessionId);
});
view.revealToForeground();
}