mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 01:11:25 +00:00
Enable column selection and sorting in DocumentsTab (with persistence) with improvements (#1963)
* Reapply "Enable column selection and sorting in DocumentsTab (with persistence) (#1881)" (#1960)
This reverts commit fe9730206e.
* Fix logic bug: always include defaultQueryFields in query.
* Show resize column option outside of feature flag
* Improve prevention of no selected columns
* Add more unit tests
* Fix styling on table
* Update test snapshots
* Remove "sortable" property on table which makes the header cell focusable (user sorts by selecting menu item, not by clicking on cell)
This commit is contained in:
@@ -4,7 +4,7 @@ import * as sinon from "sinon";
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import * as QueryUtils from "./QueryUtils";
|
||||
import { extractPartitionKeyValues } from "./QueryUtils";
|
||||
import { defaultQueryFields, extractPartitionKeyValues } from "./QueryUtils";
|
||||
|
||||
describe("Query Utils", () => {
|
||||
const generatePartitionKeyForPath = (path: string): DataModels.PartitionKey => {
|
||||
@@ -54,6 +54,20 @@ describe("Query Utils", () => {
|
||||
|
||||
expect(partitionProjection).toContain('c["\\\\\\"a\\\\\\""]');
|
||||
});
|
||||
|
||||
it("should always include the default fields", () => {
|
||||
const query: string = QueryUtils.buildDocumentsQuery("", [], generatePartitionKeyForPath("/a"), []);
|
||||
|
||||
defaultQueryFields.forEach((field) => {
|
||||
expect(query).toContain(`c.${field}`);
|
||||
});
|
||||
});
|
||||
|
||||
it("should always include the default fields even if they are themselves partition key fields", () => {
|
||||
const query: string = QueryUtils.buildDocumentsQuery("", ["id"], generatePartitionKeyForPath("/id"), ["id"]);
|
||||
|
||||
expect(query).toContain("c.id");
|
||||
});
|
||||
});
|
||||
|
||||
describe("queryPagesUntilContentPresent()", () => {
|
||||
|
||||
@@ -2,18 +2,29 @@ import { PartitionKey, PartitionKeyDefinition } from "@azure/cosmos";
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
|
||||
export const defaultQueryFields = ["id", "_self", "_rid", "_ts"];
|
||||
|
||||
export function buildDocumentsQuery(
|
||||
filter: string,
|
||||
partitionKeyProperties: string[],
|
||||
partitionKey: DataModels.PartitionKey,
|
||||
additionalField: string[] = [],
|
||||
): string {
|
||||
const fieldSet = new Set<string>(defaultQueryFields);
|
||||
additionalField.forEach((prop) => {
|
||||
if (!partitionKeyProperties.includes(prop)) {
|
||||
fieldSet.add(prop);
|
||||
}
|
||||
});
|
||||
|
||||
const objectListSpec = [...fieldSet].map((prop) => `c.${prop}`).join(",");
|
||||
let query =
|
||||
partitionKeyProperties && partitionKeyProperties.length > 0
|
||||
? `select c.id, c._self, c._rid, c._ts, [${buildDocumentsQueryPartitionProjections(
|
||||
? `select ${objectListSpec}, [${buildDocumentsQueryPartitionProjections(
|
||||
"c",
|
||||
partitionKey,
|
||||
)}] as _partitionKeyValue from c`
|
||||
: `select c.id, c._self, c._rid, c._ts from c`;
|
||||
: `select ${objectListSpec} from c`;
|
||||
|
||||
if (filter) {
|
||||
query += " " + filter;
|
||||
|
||||
Reference in New Issue
Block a user