mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-26 12:21:23 +00:00
Compare commits
2 Commits
missing_pk
...
users/aisa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10b93b6cf3 | ||
|
|
c43132d5c0 |
@@ -55,6 +55,7 @@ import DeleteDocumentIcon from "../../../../images/DeleteDocument.svg";
|
||||
import NewDocumentIcon from "../../../../images/NewDocument.svg";
|
||||
import UploadIcon from "../../../../images/Upload_16x16.svg";
|
||||
import DiscardIcon from "../../../../images/discard.svg";
|
||||
import RefreshIcon from "../../../../images/refresh-cosmos.svg";
|
||||
import SaveIcon from "../../../../images/save-cosmos.svg";
|
||||
import * as Constants from "../../../Common/Constants";
|
||||
import * as HeadersUtility from "../../../Common/HeadersUtility";
|
||||
@@ -131,6 +132,14 @@ export const useDocumentsTabStyles = makeStyles({
|
||||
backgroundColor: "white",
|
||||
zIndex: 1,
|
||||
},
|
||||
refreshBtn: {
|
||||
position: "absolute",
|
||||
top: "3px",
|
||||
right: "4px",
|
||||
float: "right",
|
||||
zIndex: 1,
|
||||
backgroundColor: "transparent",
|
||||
},
|
||||
deleteProgressContent: {
|
||||
paddingTop: tokens.spacingVerticalL,
|
||||
},
|
||||
@@ -1028,7 +1037,6 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||
);
|
||||
|
||||
const selectedDocumentId = documentIds[clickedRowIndex as number];
|
||||
const originalPartitionKeyValue = selectedDocumentId.partitionKeyValue;
|
||||
selectedDocumentId.partitionKeyValue = partitionKeyValueArray;
|
||||
|
||||
onExecutionErrorChange(false);
|
||||
@@ -1064,14 +1072,9 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||
setColumnDefinitionsFromDocument(documentContent);
|
||||
},
|
||||
(error) => {
|
||||
// in case of any kind of failures of accidently changing partition key, restore the original
|
||||
// so that when user navigates away from current document and comes back,
|
||||
// it doesnt fail to load due to using the invalid partition keys
|
||||
selectedDocumentId.partitionKeyValue = originalPartitionKeyValue;
|
||||
onExecutionErrorChange(true);
|
||||
const errorMessage = getErrorMessage(error);
|
||||
useDialog.getState().showOkModalDialog("Update document failed", errorMessage);
|
||||
|
||||
TelemetryProcessor.traceFailure(
|
||||
Action.UpdateDocument,
|
||||
{
|
||||
@@ -2150,6 +2153,19 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||
isColumnSelectionDisabled={isPreferredApiMongoDB}
|
||||
/>
|
||||
</div>
|
||||
{!isPreferredApiMongoDB &&
|
||||
tableContainerSizePx?.width >= calculateOffset(selectedColumnIds.length) + 200 && (
|
||||
<div
|
||||
title="Refresh"
|
||||
className={styles.refreshBtn}
|
||||
role="button"
|
||||
onClick={() => refreshDocumentsGrid(false)}
|
||||
aria-label="Refresh"
|
||||
tabIndex={0}
|
||||
>
|
||||
<img src={RefreshIcon} alt="Refresh" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{tableItems.length > 0 && (
|
||||
<a
|
||||
|
||||
@@ -28,6 +28,11 @@ const loadTranslationFile = async (className: string): Promise<void> => {
|
||||
} catch (e) {
|
||||
translations = await import(/* webpackChunkName: "Localization-en-[request]" */ `../Localization/en/${fileName}`);
|
||||
}
|
||||
|
||||
if (className == "MaterializedViewsBuilder") {
|
||||
className = "p";
|
||||
}
|
||||
|
||||
i18n.addResourceBundle(language, className, translations.default, true);
|
||||
};
|
||||
|
||||
|
||||
@@ -35,13 +35,6 @@ describe("Query Utils", () => {
|
||||
version: 2,
|
||||
};
|
||||
};
|
||||
const generatePartitionKeysForPaths = (paths: string[]): DataModels.PartitionKey => {
|
||||
return {
|
||||
paths: paths,
|
||||
kind: "Hash",
|
||||
version: 2,
|
||||
};
|
||||
};
|
||||
|
||||
describe("buildDocumentsQueryPartitionProjections()", () => {
|
||||
it("should return empty string if partition key is undefined", () => {
|
||||
@@ -96,18 +89,6 @@ describe("Query Utils", () => {
|
||||
|
||||
expect(query).toContain("c.id");
|
||||
});
|
||||
|
||||
it("should always include {} for any missing partition keys", () => {
|
||||
const query = QueryUtils.buildDocumentsQuery(
|
||||
"",
|
||||
["a", "b", "c"],
|
||||
generatePartitionKeysForPaths(["/a", "/b", "/c"]),
|
||||
[],
|
||||
);
|
||||
expect(query).toContain('IIF(IS_DEFINED(c["a"]), c["a"], {})');
|
||||
expect(query).toContain('IIF(IS_DEFINED(c["b"]), c["b"], {})');
|
||||
expect(query).toContain('IIF(IS_DEFINED(c["c"]), c["c"], {})');
|
||||
});
|
||||
});
|
||||
|
||||
describe("queryPagesUntilContentPresent()", () => {
|
||||
@@ -220,6 +201,18 @@ describe("Query Utils", () => {
|
||||
expect(expectedPartitionKeyValues).toContain(documentContent["Category"]);
|
||||
});
|
||||
|
||||
it("should extract no partition key values in the case nested partition key", () => {
|
||||
const singlePartitionKeyDefinition: PartitionKeyDefinition = {
|
||||
kind: PartitionKeyKind.Hash,
|
||||
paths: ["/Location.type"],
|
||||
};
|
||||
const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues(
|
||||
documentContent,
|
||||
singlePartitionKeyDefinition,
|
||||
);
|
||||
expect(partitionKeyValues.length).toBe(0);
|
||||
});
|
||||
|
||||
it("should extract all partition key values for hierarchical and nested partition keys", () => {
|
||||
const mixedPartitionKeyDefinition: PartitionKeyDefinition = {
|
||||
kind: PartitionKeyKind.MultiHash,
|
||||
@@ -232,52 +225,5 @@ describe("Query Utils", () => {
|
||||
expect(partitionKeyValues.length).toBe(2);
|
||||
expect(partitionKeyValues).toEqual(["United States", "Point"]);
|
||||
});
|
||||
|
||||
it("if any partition key is null or empty string, the partitionKeyValues shall match", () => {
|
||||
const newDocumentContent = {
|
||||
...documentContent,
|
||||
...{
|
||||
Country: null,
|
||||
Location: {
|
||||
type: "",
|
||||
coordinates: [-121.49, 46.206],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mixedPartitionKeyDefinition: PartitionKeyDefinition = {
|
||||
kind: PartitionKeyKind.MultiHash,
|
||||
paths: ["/Country", "/Location/type"],
|
||||
};
|
||||
const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues(
|
||||
newDocumentContent,
|
||||
mixedPartitionKeyDefinition,
|
||||
);
|
||||
expect(partitionKeyValues.length).toBe(2);
|
||||
expect(partitionKeyValues).toEqual([null, ""]);
|
||||
});
|
||||
|
||||
it("if any partition key doesn't exist, it should still set partitionkey value as {}", () => {
|
||||
const newDocumentContent = {
|
||||
...documentContent,
|
||||
...{
|
||||
Country: null,
|
||||
Location: {
|
||||
coordinates: [-121.49, 46.206],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mixedPartitionKeyDefinition: PartitionKeyDefinition = {
|
||||
kind: PartitionKeyKind.MultiHash,
|
||||
paths: ["/Country", "/Location/type"],
|
||||
};
|
||||
const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues(
|
||||
newDocumentContent,
|
||||
mixedPartitionKeyDefinition,
|
||||
);
|
||||
expect(partitionKeyValues.length).toBe(2);
|
||||
expect(partitionKeyValues).toEqual([null, {}]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -61,9 +61,8 @@ export function buildDocumentsQueryPartitionProjections(
|
||||
projectedProperty += `[${projection}]`;
|
||||
}
|
||||
});
|
||||
const fullAccess = `${collectionAlias}${projectedProperty}`;
|
||||
const wrappedProjection = `IIF(IS_DEFINED(${fullAccess}), ${fullAccess}, {})`;
|
||||
projections.push(wrappedProjection);
|
||||
|
||||
projections.push(`${collectionAlias}${projectedProperty}`);
|
||||
}
|
||||
|
||||
return projections.join(",");
|
||||
@@ -131,8 +130,6 @@ export const extractPartitionKeyValues = (
|
||||
|
||||
if (value !== undefined) {
|
||||
partitionKeyValues.push(value);
|
||||
} else {
|
||||
partitionKeyValues.push({});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user