Skip to content

Commit

Permalink
update filtering and squash any bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lokesh-couchbase committed May 23, 2024
1 parent 1aeca6b commit 2e9b835
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 57 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,12 @@
},
{
"command": "vscode-couchbase.queryTypeDocumentFilter",
"title": "Add Query Based Document Filter",
"title": "Add Query Type Document Filter",
"category": "Couchbase"
},
{
"command": "vscode-couchbase.kvTypeDocumentFilter",
"title": "Add KV Range Based Document Filter",
"title": "Add KV Range Type Document Filter",
"category": "Couchbase"
},
{
Expand Down Expand Up @@ -917,17 +917,17 @@
},
{
"command": "vscode-couchbase.createDocument",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter || viewItem == collection_filter)",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter_kv || viewItem == default_collection_filter_query || viewItem == collection_filter_kv || viewItem == collection_filter_query)",
"group": "primary"
},
{
"command": "vscode-couchbase.searchDocument",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter || viewItem == collection_filter)",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter_kv || viewItem == default_collection_filter_query || viewItem == collection_filter_kv || viewItem == collection_filter_query)",
"group": "primary"
},
{
"submenu": "vscode-couchbase.filterDocumentsMenu",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter || viewItem == collection_filter)",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter_kv || viewItem == default_collection_filter_query || viewItem == collection_filter_kv || viewItem == collection_filter_query)",
"group": "secondary"
},
{
Expand All @@ -940,7 +940,7 @@
},
{
"command": "vscode-couchbase.refreshCollection",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter || viewItem == collection_filter)",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == default_collection_filter_kv || viewItem == default_collection_filter_query || viewItem == collection_filter_kv || viewItem == collection_filter_query)",
"group": "tertiary"
},
{
Expand Down Expand Up @@ -968,7 +968,7 @@
},
{
"command": "vscode-couchbase.removeCollection",
"when": "view == couchbase && (viewItem == collection || viewItem == collection_filter)",
"when": "view == couchbase && (viewItem == collection || viewItem == collection_filter_kv || viewItem == collection_filter_query)",
"group": "tertiary"
},
{
Expand Down Expand Up @@ -1047,26 +1047,26 @@
{
"command": "vscode-couchbase.queryTypeDocumentFilter",
"group": "navigation",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == collection_filter || viewItem == default_collection_filter)"
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == collection_filter_kv || viewItem == default_collection_filter_kv) && !isKVCluster"
},
{
"command": "vscode-couchbase.kvTypeDocumentFilter",
"group": "navigation",
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == collection_filter || viewItem == default_collection_filter)"
"when": "view == couchbase && (viewItem == collection || viewItem == default_collection || viewItem == collection_filter_query || viewItem == default_collection_filter_query)"
},
{
"command": "vscode-couchbase.editQueryTypeDocumentFilter",
"when": "view == couchbase && (viewItem == collection_filter || viewItem == default_collection_filter)",
"when": "view == couchbase && (viewItem == collection_filter_query || viewItem == default_collection_filter_query) && !isKVCluster",
"group": "secondary"
},
{
"command": "vscode-couchbase.editKvTypeDocumentFilter",
"when": "view == couchbase && (viewItem == collection_filter || viewItem == default_collection_filter)",
"when": "view == couchbase && (viewItem == collection_filter_kv || viewItem == default_collection_filter_kv)",
"group": "secondary"
},
{
"command": "vscode-couchbase.clearDocumentFilter",
"when": "view == couchbase && (viewItem == collection_filter || viewItem == default_collection_filter)",
"when": "view == couchbase && (viewItem == collection_filter_kv || viewItem == default_collection_filter_kv || viewItem == collection_filter_query || viewItem == default_collection_filter_query)",
"group": "tertiary"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ import CollectionNode from "../../../model/CollectionNode";
import { getActiveConnection } from "../../../util/connections";
import { Memory } from "../../../util/util";

export const clearDocumentFilter = async (node: CollectionNode) => {
export const clearDocumentFilter = (node: CollectionNode) => {
const connection = getActiveConnection();
if(!connection){
return;
}

commands.executeCommand(
"setContext",
"vscode-couchbase.documentFilterType",
""
);

Memory.state.update(
`filterDocumentsType-${connection.connectionIdentifier}-${node.bucketName}-${node.scopeName}-${node.collectionName}`,
``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CollectionNode from "../../../model/CollectionNode";
import { getActiveConnection } from "../../../util/connections";
import * as vscode from "vscode";
import { Memory } from "../../../util/util";
import { clearDocumentFilter } from "./clearDocumentFilter";

export const kvTypeFilterDocuments = async (node: CollectionNode) => {
const connection = getActiveConnection();
Expand Down Expand Up @@ -41,11 +42,7 @@ export const kvTypeFilterDocuments = async (node: CollectionNode) => {
return;
}

vscode.commands.executeCommand(
"setContext",
"vscode-couchbase.documentFilterType",
"kv"
);
clearDocumentFilter(node);

Memory.state.update(
`filterDocumentsType-${connection.connectionIdentifier}-${node.bucketName}-${node.scopeName}-${node.collectionName}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Memory } from "../../../util/util";
import { logger } from "../../../logger/logger";
import { ParsingFailureError, PlanningFailureError } from "couchbase";
import { getActiveConnection } from "../../../util/connections";
import { clearDocumentFilter } from "./clearDocumentFilter";

export const queryTypeFilterDocuments = async (node: CollectionNode) => {
const connection = getActiveConnection();
Expand Down Expand Up @@ -35,7 +36,7 @@ export const queryTypeFilterDocuments = async (node: CollectionNode) => {
title: `Apply filter for collection \`${collectionName}\``,
placeHolder: `airline="AI" OR country="United States"`,
value: filterStmt,
prompt: `SELECT meta.id() FROM \`${collectionName}\` WHERE [Your Filter] | `,
prompt: `SELECT meta.id() FROM \`${collectionName}\` WHERE [Your Filter] | This may reset other document filters | `,
validateInput: (input) => {
const tokens = input.split(" ");
for (const token of tokens) {
Expand Down Expand Up @@ -73,11 +74,8 @@ export const queryTypeFilterDocuments = async (node: CollectionNode) => {
return;
}

vscode.commands.executeCommand(
"setContext",
"vscode-couchbase.documentFilterType",
"query"
);
// Reset any existing document filter
clearDocumentFilter(node);

Memory.state.update(
`filterDocumentsType-${connection.connectionIdentifier}-${node.bucketName}-${node.scopeName}-${node.collectionName}`,
Expand Down
60 changes: 37 additions & 23 deletions src/model/CollectionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default class CollectionNode implements INode {
public readonly documentCount: number,
public readonly bucketName: string,
public readonly collectionName: string,
public readonly filter: boolean,
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
public cacheService: CacheService,
public limit: number = 10,
Expand All @@ -56,28 +55,33 @@ export default class CollectionNode implements INode {
if (!connection) {
return null;
}
const idxs = await connection.cluster?.queryIndexes().getAllIndexes(this.bucketName, { scopeName: this.scopeName, collectionName: this.collectionName });
let filter: string | null = null;
if (!idxs) {
return null;
}
try {
const idxs = await connection.cluster?.queryIndexes().getAllIndexes(this.bucketName, { scopeName: this.scopeName, collectionName: this.collectionName });
let filter: string | null = null;
if (!idxs) {
return null;
}

for (const idx of idxs) {
if (idx.isPrimary) {
return "meta().id";
} else {
const result = this.getValidIndexKey(idx.indexKey);
if (result) {
if (!idx.condition && result[1]) {
return result[0];
} else {
filter = result[0];
for (const idx of idxs) {
if (idx.isPrimary) {
return "meta().id";
} else {
const result = this.getValidIndexKey(idx.indexKey);
if (result) {
if (!idx.condition && result[1]) {
return result[0];
} else {
filter = result[0];
}
}
}
}
}

return filter;
return filter;
} catch (e) {
logger.error("error getting indexed fields: " + e);
return null;
}
}

private getValidIndexKey(array: any[]): [string, boolean] | null {
Expand All @@ -96,27 +100,38 @@ export default class CollectionNode implements INode {
}

public async getTreeItem(): Promise<vscode.TreeItem> {
const connection = getActiveConnection();
if (!connection) {
return new vscode.TreeItem(this.collectionName, vscode.TreeItemCollapsibleState.None);
}
const filterDocumentsType = Memory.state.get<string>(
`filterDocumentsType-${connection.connectionIdentifier}-${this.bucketName}-${this.scopeName}-${this.collectionName}`
) ?? "";


return {
label: `${this.collectionName} (${abbreviateCount(this.documentCount)})`,
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
contextValue:
(this.collectionName === "_default"
? "default_collection"
: "collection") + (this.filter ? "_filter" : ""),
: "collection") + (filterDocumentsType !== "" ? "_filter" : "")
+ (filterDocumentsType === "kv" ? "_kv" : "")
+ (filterDocumentsType === "query" ? "_query" : ""),
iconPath: {
light: path.join(
__filename,
"..",
"..",
"images/light",
this.filter ? "filter.svg" : "documents-icon.svg"
filterDocumentsType !== "" ? "filter.svg" : "documents-icon.svg"
),
dark: path.join(
__filename,
"..",
"..",
"images/dark",
this.filter ? "filter.svg" : "documents-icon.svg"
filterDocumentsType !== "" ? "filter.svg" : "documents-icon.svg"
),
},
};
Expand Down Expand Up @@ -170,14 +185,13 @@ export default class CollectionNode implements INode {

const couchbaseRestAPI = new CouchbaseRestAPI(connection);
if (!hasQueryService(connection?.services!) || isKVFilterEnabled) { // KV Based Fetching Documents
console.log("inside");
let [startingDocId, endingDocId]: [string | undefined, string | undefined] = [undefined, undefined];
if (isKVFilterEnabled) {
[startingDocId, endingDocId] = Memory.state.get<string>(
`kvTypeFilterDocuments-${connection.connectionIdentifier}-${this.bucketName}-${this.scopeName}-${this.collectionName}`
)?.split('|') ?? ["", ""];
}
console.log("docIds", startingDocId, endingDocId);

result = await couchbaseRestAPI.getKVDocuments(this.bucketName, this.scopeName, this.collectionName, 0, this.limit, startingDocId, endingDocId);
result.rows = result.rows.map((item: any) => item.id);
}
Expand Down
1 change: 0 additions & 1 deletion src/model/ScopeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class ScopeNode implements INode {
rowCount,
this.bucketName,
collection.name,
filterDocumentsType !== "",
vscode.TreeItemCollapsibleState.None,
this.cacheService
);
Expand Down
1 change: 0 additions & 1 deletion src/pages/FavoriteQueries/FavoriteQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface IFavoriteQueriesWebviewState {
}

export const fetchFavoriteQueries = (context: vscode.ExtensionContext) => {
console.log("context is", context);
const favoriteQueryWebviewDetails = Memory.state.get<IFavoriteQueriesWebviewState>(Constants.FAVORITE_QUERIES_WEBVIEW);
if (favoriteQueryWebviewDetails) {
// Favorite Queries Webview already exists, Closing existing and creating new
Expand Down
2 changes: 0 additions & 2 deletions src/util/apis/CouchbaseRestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export class CouchbaseRestAPI {
url += `&endkey=%22${endDocId}%22`;
}

console.log(url);
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
try {
let content = await axios.get(url, {
Expand All @@ -120,7 +119,6 @@ export class CouchbaseRestAPI {
rejectUnauthorized: false,
})
});
console.log(content.data)
return content.data;
}
catch (error) {
Expand Down

0 comments on commit 2e9b835

Please sign in to comment.