Skip to content

Commit 3156bcb

Browse files
authored
Merge branch 'main' into cloudp-278538-remove-moment-lg-tools-tr46
2 parents a42f4ea + 8101f31 commit 3156bcb

22 files changed

+794
-201
lines changed

.github/workflows/check-pr-title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ jobs:
1919
# Skip the JIRA ticket check for PRs opened by bots
2020
if: ${{ !contains(github.event.pull_request.user.login, '[bot]') }}
2121
with:
22-
regex: '[A-Z]{4,10}-[0-9]{1,5}$'
22+
regex: '[A-Z]{4,10}-[0-9]{1,10}$'
2323
error-hint: 'Invalid PR title. Make sure it ends with a JIRA ticket - i.e. COMPASS-1234 or add the no-title-validation label'
2424
ignore-labels: 'no-title-validation'

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **Mongodb Compass**.
2-
This document was automatically generated on Tue Nov 05 2024.
2+
This document was automatically generated on Wed Nov 06 2024.
33

44
## List of dependencies
55

docs/tracking-plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Compass Tracking Plan
33

4-
Generated on Tue, Nov 5, 2024 at 08:14 AM
4+
Generated on Wed, Nov 6, 2024 at 12:38 PM
55

66
## Table of Contents
77

packages/compass-crud/src/components/json-editor.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ const editorDarkModeStyles = css({
4545
});
4646

4747
const actionsGroupStyles = css({
48-
paddingTop: spacing[2],
49-
paddingRight: spacing[2],
48+
padding: spacing[200],
5049
});
5150

5251
export type JSONEditorProps = {
@@ -258,6 +257,14 @@ const JSONEditor: React.FunctionComponent<JSONEditorProps> = ({
258257
onDeletionFinished,
259258
]);
260259

260+
const toggleExpandCollapse = useCallback(() => {
261+
if (doc.expanded) {
262+
doc.collapse();
263+
} else {
264+
doc.expand();
265+
}
266+
}, [doc]);
267+
261268
// Trying to change CodeMirror editor state when an update "effect" is in
262269
// progress results in an error which is why we timeout the code mirror update
263270
// itself.
@@ -297,6 +304,8 @@ const JSONEditor: React.FunctionComponent<JSONEditorProps> = ({
297304
className={cx(editorStyles, darkMode && editorDarkModeStyles)}
298305
actionsClassName={actionsGroupStyles}
299306
completer={completer}
307+
onExpand={editing ? undefined : toggleExpandCollapse}
308+
expanded={expanded}
300309
/>
301310
<DocumentList.DocumentEditActionsFooter
302311
doc={doc}

packages/compass-editor/src/action-button.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export type Action = {
1212

1313
const actionButtonStyle = css({
1414
flex: 'none',
15+
pointerEvents: 'all',
16+
});
17+
18+
const actionCompactButtonStyle = css({
19+
'& > div:has(svg)': {
20+
paddingLeft: 3,
21+
paddingRight: 3,
22+
},
1523
});
1624

1725
const actionButtonContentStyle = css({
@@ -52,7 +60,8 @@ export const ActionButton: React.FunctionComponent<{
5260
...args: Parameters<React.MouseEventHandler<HTMLButtonElement>>
5361
) => boolean | void;
5462
'data-testid'?: string;
55-
}> = ({ label, icon, onClick, ...props }) => {
63+
compact?: boolean;
64+
}> = ({ label, icon, onClick, compact, ...props }) => {
5665
const [clickResult, setClickResult] = useState<'success' | 'error'>(
5766
'success'
5867
);
@@ -89,7 +98,7 @@ export const ActionButton: React.FunctionComponent<{
8998
aria-label={label}
9099
title={label}
91100
onClick={onButtonClick}
92-
className={actionButtonStyle}
101+
className={cx(actionButtonStyle, { [actionCompactButtonStyle]: compact })}
93102
data-testid={props['data-testid'] ?? `editor-action-${label}`}
94103
>
95104
<div className={actionButtonContentStyle}>

packages/compass-editor/src/actions-container.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ type ActionsContainerProps = {
1010
customActions?: Action[];
1111
className?: string;
1212
editorRef: RefObject<EditorRef>;
13+
onExpand?: () => void;
14+
expanded?: boolean;
1315
};
1416

1517
const actionsContainerStyle = css({
1618
position: 'absolute',
17-
top: spacing[1],
18-
right: spacing[2],
19+
top: spacing[100],
20+
right: spacing[100],
21+
left: spacing[100],
1922
display: 'none',
20-
gap: spacing[2],
23+
gap: spacing[200],
24+
pointerEvents: 'none',
25+
});
26+
27+
const expandContainerStyle = css({
28+
position: 'relative',
29+
top: -spacing[100],
30+
left: -spacing[100],
31+
});
32+
33+
const actionsGroupItemSeparator = css({
34+
flex: '1 0 auto',
35+
pointerEvents: 'none',
2136
});
2237

2338
export const ActionsContainer = ({
@@ -26,6 +41,8 @@ export const ActionsContainer = ({
2641
customActions,
2742
className,
2843
editorRef,
44+
onExpand,
45+
expanded,
2946
}: ActionsContainerProps) => {
3047
return (
3148
<div
@@ -35,6 +52,17 @@ export const ActionsContainer = ({
3552
className
3653
)}
3754
>
55+
{onExpand && (
56+
<div className={expandContainerStyle}>
57+
<ActionButton
58+
label={expanded ? 'Collapse all' : 'Expand all'}
59+
icon={expanded ? 'CaretDown' : 'CaretRight'}
60+
onClick={onExpand}
61+
compact
62+
/>
63+
</div>
64+
)}
65+
<span className={actionsGroupItemSeparator}></span>
3866
{copyable && (
3967
<ActionButton
4068
label="Copy"

packages/compass-editor/src/editor.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,13 @@ const multilineEditorContainerWithActionsStyle = css({
13891389
minHeight: spacing[5] - 2,
13901390
});
13911391

1392+
const multilineEditorContainerWithExpandStyle = css({
1393+
['& .cm-gutters']: {
1394+
// Offset to prevent the "expand" button from overlapping with fold / unfold icons
1395+
paddingLeft: spacing[500],
1396+
},
1397+
});
1398+
13921399
const multilineEditorContainerDarkModeStyle = css({
13931400
backgroundColor: editorPalette.dark.backgroundColor,
13941401
});
@@ -1399,6 +1406,8 @@ type MultilineEditorProps = EditorProps & {
13991406
formattable?: boolean;
14001407
editorClassName?: string;
14011408
actionsClassName?: string;
1409+
onExpand?: () => void;
1410+
expanded?: boolean;
14021411
};
14031412

14041413
const MultilineEditor = React.forwardRef<EditorRef, MultilineEditorProps>(
@@ -1411,8 +1420,10 @@ const MultilineEditor = React.forwardRef<EditorRef, MultilineEditorProps>(
14111420
editorClassName,
14121421
actionsClassName,
14131422
darkMode: _darkMode,
1423+
onExpand,
1424+
expanded,
14141425
...props
1415-
},
1426+
}: MultilineEditorProps,
14161427
ref
14171428
) {
14181429
const darkMode = useDarkMode(_darkMode);
@@ -1469,6 +1480,7 @@ const MultilineEditor = React.forwardRef<EditorRef, MultilineEditorProps>(
14691480
multilineEditorContainerStyle,
14701481
darkMode && multilineEditorContainerDarkModeStyle,
14711482
hasActions && multilineEditorContainerWithActionsStyle,
1483+
onExpand && multilineEditorContainerWithExpandStyle,
14721484
className
14731485
)}
14741486
// We want folks to be able to click into the container element
@@ -1492,6 +1504,8 @@ const MultilineEditor = React.forwardRef<EditorRef, MultilineEditorProps>(
14921504
></BaseEditor>
14931505
{hasActions && (
14941506
<ActionsContainer
1507+
onExpand={onExpand}
1508+
expanded={expanded}
14951509
copyable={copyable}
14961510
formattable={formattable}
14971511
editorRef={editorRef}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import { renderWithStore } from '../../tests/create-store';
3+
import { expect } from 'chai';
4+
import { screen } from '@mongodb-js/testing-library-compass';
5+
import ExampleCommandsMarkup, {
6+
type ExampleCommandsMarkupProps,
7+
} from './example-commands-markup';
8+
import { type ShardKey } from '../store/reducer';
9+
10+
describe('ExampleCommandsMarkup', function () {
11+
const db = 'db1';
12+
const coll = 'coll1';
13+
const namespace = `${db}.${coll}`;
14+
const shardKey: ShardKey = {
15+
fields: [
16+
{ type: 'RANGE', name: 'location' },
17+
{ type: 'HASHED', name: 'secondary' },
18+
],
19+
isUnique: false,
20+
};
21+
22+
function renderWithProps(props?: Partial<ExampleCommandsMarkupProps>) {
23+
return renderWithStore(
24+
<ExampleCommandsMarkup
25+
namespace={namespace}
26+
shardKey={shardKey}
27+
{...props}
28+
/>
29+
);
30+
}
31+
32+
it('Contains sample codes', async function () {
33+
await renderWithProps();
34+
35+
const findingDocumentsSample = await screen.findByTestId(
36+
'sample-finding-documents'
37+
);
38+
expect(findingDocumentsSample).to.be.visible;
39+
expect(findingDocumentsSample.textContent).to.contain(
40+
`use db1db["coll1"].find({"location": "US-NY", "secondary": "<id_value>"})`
41+
);
42+
43+
const insertingDocumentsSample = await screen.findByTestId(
44+
'sample-inserting-documents'
45+
);
46+
expect(insertingDocumentsSample).to.be.visible;
47+
expect(insertingDocumentsSample.textContent).to.contain(
48+
`use db1db["coll1"].insertOne({"location": "US-NY", "secondary": "<id_value>",...<other fields>})`
49+
);
50+
});
51+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import {
2+
Body,
3+
Code,
4+
css,
5+
Label,
6+
Link,
7+
spacing,
8+
Subtitle,
9+
} from '@mongodb-js/compass-components';
10+
import React, { useMemo } from 'react';
11+
import type { ShardKey } from '../store/reducer';
12+
import toNS from 'mongodb-ns';
13+
14+
const codeBlockContainerStyles = css({
15+
display: 'flex',
16+
flexDirection: 'column',
17+
gap: spacing[100],
18+
});
19+
20+
export interface ExampleCommandsMarkupProps {
21+
shardKey: ShardKey;
22+
namespace: string;
23+
showMetaData?: boolean;
24+
type?: 'requested' | 'existing';
25+
}
26+
27+
const paragraphStyles = css({
28+
display: 'flex',
29+
flexDirection: 'column',
30+
gap: spacing[100],
31+
});
32+
33+
export function ExampleCommandsMarkup({
34+
namespace,
35+
shardKey,
36+
}: ExampleCommandsMarkupProps) {
37+
const customShardKeyField = useMemo(() => {
38+
return shardKey.fields[1].name;
39+
}, [shardKey]);
40+
41+
const sampleCodes = useMemo(() => {
42+
const { collection, database } = toNS(namespace);
43+
return {
44+
findingDocuments: `use ${database}\ndb[${JSON.stringify(
45+
collection
46+
)}].find({"location": "US-NY", "${customShardKeyField}": "<id_value>"})`,
47+
insertingDocuments: `use ${database}\ndb[${JSON.stringify(
48+
collection
49+
)}].insertOne({"location": "US-NY", "${customShardKeyField}": "<id_value>",...<other fields>})`,
50+
};
51+
}, [namespace, customShardKeyField]);
52+
53+
return (
54+
<>
55+
<Subtitle>Example commands</Subtitle>
56+
<div className={paragraphStyles}>
57+
<Body>
58+
Start querying your database with some of the most{' '}
59+
<Link
60+
href="https://www.mongodb.com/docs/atlas/global-clusters"
61+
hideExternalIcon
62+
>
63+
common commands
64+
</Link>{' '}
65+
for Global Writes.
66+
</Body>
67+
<Body>
68+
Replace the text to perform operations on different documents. US-NY
69+
is an ISO 3166 location code referring to New York, United States. You
70+
can look up other ISO 3166 location codes below.
71+
</Body>
72+
</div>
73+
74+
<div className={codeBlockContainerStyles}>
75+
<Label htmlFor="finding-documents">Finding documents</Label>
76+
<Code
77+
language="js"
78+
data-testid="sample-finding-documents"
79+
id="finding-documents"
80+
>
81+
{sampleCodes.findingDocuments}
82+
</Code>
83+
</div>
84+
85+
<div className={codeBlockContainerStyles}>
86+
<Label htmlFor="inserting-documents">Inserting documents</Label>
87+
<Code
88+
language="js"
89+
data-testid="sample-inserting-documents"
90+
id="inserting-documents"
91+
>
92+
{sampleCodes.insertingDocuments}
93+
</Code>
94+
</div>
95+
</>
96+
);
97+
}
98+
99+
export default ExampleCommandsMarkup;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import ShardKeyCorrect from './states/shard-key-correct';
1515
import ShardKeyInvalid from './states/shard-key-invalid';
1616
import ShardKeyMismatch from './states/shard-key-mismatch';
1717
import ShardingError from './states/sharding-error';
18+
import IncompleteShardingSetup from './states/incomplete-sharding-setup';
1819

1920
const containerStyles = css({
2021
paddingLeft: spacing[400],
@@ -93,6 +94,13 @@ function ShardingStateView({
9394
return <ShardKeyMismatch />;
9495
}
9596

97+
if (
98+
shardingStatus === ShardingStatuses.INCOMPLETE_SHARDING_SETUP ||
99+
shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE
100+
) {
101+
return <IncompleteShardingSetup />;
102+
}
103+
96104
return null;
97105
}
98106

0 commit comments

Comments
 (0)