mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 17:01:13 +00:00
fix partitionkey value fetching (#1972)
* fix partitionkey value fetching * fix partitionkey value fetching * added unit test * Added some unit tests * move the constant
This commit is contained in:
@@ -95,6 +95,24 @@ export const queryPagesUntilContentPresent = async (
|
||||
return await doRequest(firstItemIndex);
|
||||
};
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export const getValueForPath = (content: any, pathSegments: string[]): any => {
|
||||
if (pathSegments.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let currentValue = content;
|
||||
|
||||
for (const segment of pathSegments) {
|
||||
if (!currentValue || currentValue[segment] === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
currentValue = currentValue[segment];
|
||||
}
|
||||
|
||||
return currentValue;
|
||||
};
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export const extractPartitionKeyValues = (
|
||||
documentContent: any,
|
||||
@@ -105,11 +123,15 @@ export const extractPartitionKeyValues = (
|
||||
}
|
||||
|
||||
const partitionKeyValues: PartitionKey[] = [];
|
||||
|
||||
partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => {
|
||||
const partitionKeyPathWithoutSlash: string = partitionKeyPath.substring(1);
|
||||
if (documentContent[partitionKeyPathWithoutSlash] !== undefined) {
|
||||
partitionKeyValues.push(documentContent[partitionKeyPathWithoutSlash]);
|
||||
const pathSegments: string[] = partitionKeyPath.substring(1).split("/");
|
||||
const value = getValueForPath(documentContent, pathSegments);
|
||||
|
||||
if (value !== undefined) {
|
||||
partitionKeyValues.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
return partitionKeyValues;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user