Add support for multi-partition key (#1252)

This commit is contained in:
victor-meng
2022-04-21 13:37:02 -07:00
committed by GitHub
parent 9e7bbcfab6
commit 22f7d588a1
21 changed files with 175 additions and 158 deletions

View File

@@ -65,8 +65,8 @@ export class SubSettingsComponent extends React.Component<SubSettingsComponentPr
constructor(props: SubSettingsComponentProps) {
super(props);
this.geospatialVisible = userContext.apiType === "SQL";
this.partitionKeyValue = "/" + this.props.collection.partitionKeyProperty;
this.partitionKeyName = userContext.apiType === "Mongo" ? "Shard key" : "Partition key";
this.partitionKeyValue = this.getPartitionKeyValue();
}
componentDidMount(): void {
@@ -291,6 +291,14 @@ export class SubSettingsComponent extends React.Component<SubSettingsComponentPr
);
};
private getPartitionKeyValue = (): string => {
if (userContext.apiType === "Mongo") {
return this.props.collection.partitionKeyProperties?.[0] || "";
}
return (this.props.collection.partitionKeyProperties || []).map((property) => "/" + property).join(", ");
};
private getPartitionKeyComponent = (): JSX.Element => (
<Stack {...titleAndInputStackProps}>
{this.getPartitionKeyVisible() && (
@@ -310,7 +318,8 @@ export class SubSettingsComponent extends React.Component<SubSettingsComponentPr
if (
userContext.apiType === "Cassandra" ||
userContext.apiType === "Tables" ||
!this.props.collection.partitionKeyProperty ||
!this.props.collection.partitionKeyProperties ||
this.props.collection.partitionKeyProperties.length === 0 ||
(userContext.apiType === "Mongo" && this.props.collection.partitionKey.systemKey)
) {
return false;

View File

@@ -39,7 +39,7 @@ export const collection = ({
kind: "hash",
version: 2,
},
partitionKeyProperty: "partitionKey",
partitionKeyProperties: ["partitionKey"],
readSettings: () => {
return;
},

View File

@@ -1669,7 +1669,9 @@ exports[`SettingsComponent renders 1`] = `
"paths": Array [],
"version": 2,
},
"partitionKeyProperty": "partitionKey",
"partitionKeyProperties": Array [
"partitionKey",
],
"readSettings": [Function],
"uniqueKeyPolicy": Object {},
"usageSizeInKB": [Function],
@@ -3348,7 +3350,9 @@ exports[`SettingsComponent renders 1`] = `
"paths": Array [],
"version": 2,
},
"partitionKeyProperty": "partitionKey",
"partitionKeyProperties": Array [
"partitionKey",
],
"readSettings": [Function],
"uniqueKeyPolicy": Object {},
"usageSizeInKB": [Function],