Skip to content

Commit 9375d71

Browse files
committed
requested shard key
1 parent 90051d2 commit 9375d71

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

packages/compass-global-writes/src/components/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const containerStyles = css({
2020
display: 'flex',
2121
width: '100%',
2222
height: '100%',
23+
maxWidth: '700px',
2324
});
2425

2526
const workspaceContentStyles = css({

packages/compass-global-writes/src/components/shard-key-markup.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ const codeBlockContainerStyles = css({
66
display: 'flex',
77
flexDirection: 'column',
88
gap: spacing[100],
9-
maxWidth: '700px',
109
});
1110

1211
interface ShardKeyMarkupProps {
1312
shardKey: ShardKey;
1413
namespace: string;
1514
showMetaData?: boolean;
15+
type?: 'requested' | 'existing';
1616
}
1717

1818
export function ShardKeyMarkup({
1919
namespace,
2020
shardKey,
2121
showMetaData,
22+
type = 'existing',
2223
}: ShardKeyMarkupProps) {
2324
let markup = shardKey.fields
2425
.map(
@@ -31,7 +32,14 @@ export function ShardKeyMarkup({
3132
return (
3233
<div className={codeBlockContainerStyles}>
3334
<Body data-testid="shardkey-description-title">
34-
<strong>{namespace}</strong> is configured with the following shard key:
35+
{type === 'existing' ? (
36+
<>
37+
<strong>{namespace}</strong> is configured with the following shard
38+
key:
39+
</>
40+
) : (
41+
<>You requested to use the shard key:</>
42+
)}
3543
</Body>
3644
<Code language="js" data-testid="shardkey-description-content">
3745
{markup}

packages/compass-global-writes/src/components/states/shard-key-mismatch.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type ShardKey,
1616
} from '../../store/reducer';
1717
import { connect } from 'react-redux';
18+
import type { ManagedNamespace } from '../../services/atlas-global-writes-service';
1819

1920
const containerStyles = css({
2021
display: 'flex',
@@ -27,15 +28,33 @@ const unmanageBtnStyles = css({
2728
marginTop: spacing[100],
2829
});
2930

31+
const getRequestedShardKey = (
32+
managedNamespace: ManagedNamespace
33+
): ShardKey => ({
34+
fields: [
35+
{
36+
name: 'location',
37+
type: 'RANGE',
38+
},
39+
{
40+
name: managedNamespace.customShardKey,
41+
type: managedNamespace.isCustomShardKeyHashed ? 'HASHED' : 'RANGE',
42+
},
43+
],
44+
isUnique: managedNamespace.isShardKeyUnique,
45+
});
46+
3047
interface ShardKeyMismatchProps {
3148
shardKey?: ShardKey;
49+
requestedShardKey?: ShardKey;
3250
namespace: string;
3351
isUnmanagingNamespace: boolean;
3452
onUnmanageNamespace: () => void;
3553
}
3654

3755
export function ShardKeyMismatch({
3856
shardKey,
57+
requestedShardKey,
3958
namespace,
4059
onUnmanageNamespace,
4160
isUnmanagingNamespace,
@@ -64,14 +83,20 @@ export function ShardKeyMismatch({
6483
Unmanage collection
6584
</Button>
6685
</div>
67-
{/* {this.state.error && <div className="bem-alert-error">{exceptionToMessage(this.state.error)}</div>} */}
6886
</Banner>
6987
<ShardKeyMarkup
7088
namespace={namespace}
7189
shardKey={shardKey}
7290
showMetaData={true}
7391
/>
74-
{/** TODO: Add the requested key */}
92+
{requestedShardKey && (
93+
<ShardKeyMarkup
94+
namespace={namespace}
95+
shardKey={requestedShardKey}
96+
showMetaData={true}
97+
type="requested"
98+
/>
99+
)}
75100
</div>
76101
);
77102
}
@@ -80,6 +105,8 @@ export default connect(
80105
(state: RootState) => ({
81106
namespace: state.namespace,
82107
shardKey: state.shardKey,
108+
requestedShardKey:
109+
state.managedNamespace && getRequestedShardKey(state.managedNamespace),
83110
isUnmanagingNamespace:
84111
state.status === ShardingStatuses.UNMANAGING_NAMESPACE_MISMATCH,
85112
}),

0 commit comments

Comments
 (0)