Skip to content

Commit afe25d3

Browse files
authored
feat(explain-plan, query-history): use leafygreen code in explain and query history, remove global code styles COMPASS-5873 (#3159)
1 parent bd3d44b commit afe25d3

File tree

16 files changed

+48
-185
lines changed

16 files changed

+48
-185
lines changed

.depalignrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"^4.5.0"
7474
],
7575
"electron-mocha": ["^8.2.0", "^8.1.2", "^6.0.1", "^8.2.2"],
76-
"highlight.js": ["^9.8.0", "^9.12.0", "^8.9.1"],
7776
"chai-enzyme": [
7877
"1.0.0-beta.0",
7978
"1.0.0-beta.1",

package-lock.json

Lines changed: 5 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@leafygreen-ui/banner": "^3.0.9",
3636
"@leafygreen-ui/button": "^12.0.5",
3737
"@leafygreen-ui/card": "^5.1.4",
38+
"@leafygreen-ui/code": "^9.4.0",
3839
"@leafygreen-ui/checkbox": "^6.0.6",
3940
"@leafygreen-ui/confirmation-modal": "^2.2.3",
4041
"@leafygreen-ui/emotion": "^4.0.0",

packages/compass-components/src/components/leafygreen.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { default as Banner } from '@leafygreen-ui/banner';
1111
import { default as LeafyGreenButton } from '@leafygreen-ui/button';
1212
import { default as LeafyGreenCheckbox } from '@leafygreen-ui/checkbox';
1313
import { default as LeafyGreenCard } from '@leafygreen-ui/card';
14+
import { default as LeafyGreenCode } from '@leafygreen-ui/code';
1415
import { default as LeafyGreenConfirmationModal } from '@leafygreen-ui/confirmation-modal';
1516
import { default as Icon } from '@leafygreen-ui/icon';
1617
import { default as LeafyGreenIconButton } from '@leafygreen-ui/icon-button';
@@ -81,6 +82,11 @@ const Checkbox = withTheme(
8182
React.ComponentProps<typeof LeafyGreenCheckbox>
8283
>
8384
) as typeof LeafyGreenCheckbox;
85+
const Code = withTheme(
86+
LeafyGreenCode as React.ComponentType<
87+
React.ComponentProps<typeof LeafyGreenCode>
88+
>
89+
) as typeof LeafyGreenCode;
8490
const ConfirmationModal: typeof LeafyGreenConfirmationModal = withTheme(
8591
LeafyGreenConfirmationModal as React.ComponentType<
8692
React.ComponentProps<typeof LeafyGreenConfirmationModal>
@@ -143,6 +149,7 @@ export {
143149
Button,
144150
Card,
145151
Checkbox,
152+
Code,
146153
ConfirmationModal,
147154
Icon,
148155
IconButton,

packages/compass-explain-plan/src/components/explain-stage/explain-stage.jsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import { map, isBoolean, camelCase } from 'lodash';
55
import d3 from 'd3';
66
import { Button } from 'react-bootstrap';
7+
import { Code } from '@mongodb-js/compass-components';
78

89
import styles from './explain-stage.module.less';
910

@@ -81,27 +82,6 @@ class ExplainStage extends Component {
8182
return zIndexCounter++;
8283
}
8384

84-
/**
85-
* Gets details.
86-
*
87-
* @returns {React.Component}
88-
*/
89-
getDetails() {
90-
if (!this.state.detailsOpen) {
91-
return null;
92-
}
93-
94-
const detailsJSON = JSON.stringify(this.props.details, null, ' ') || '{}';
95-
96-
return (
97-
<div className={classnames(styles['details-output'])}>
98-
<pre>
99-
<code>{detailsJSON}</code>
100-
</pre>
101-
</div>
102-
);
103-
}
104-
10585
/**
10686
* Gets highlight sections.
10787
*
@@ -291,7 +271,7 @@ class ExplainStage extends Component {
291271
<ul className={classnames(styles.highlighted)}>
292272
{this.getHighlightSections()}
293273
</ul>
294-
<div className={classnames(styles.details)}>
274+
<div className={styles.details}>
295275
<Button
296276
bsSize="xsmall"
297277
bsStyle="default"
@@ -300,7 +280,15 @@ class ExplainStage extends Component {
300280
>
301281
Details
302282
</Button>
303-
{this.getDetails()}
283+
{this.state.detailsOpen && (
284+
<Code
285+
className={styles['details-output']}
286+
copyable={false}
287+
language="json"
288+
>
289+
{JSON.stringify(this.props.details, null, ' ') || '{}'}
290+
</Code>
291+
)}
304292
</div>
305293
</div>
306294
);

packages/compass-explain-plan/src/components/explain-stage/explain-stage.module.less

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
margin: 0 auto;
99
position: absolute;
1010
border-radius: 3px;
11-
padding: 18px 12px 12px;
11+
padding: 18px 12px 6px 12px;
1212
box-shadow: 0px 2px 0px rgba(0, 0, 0, 0.06);
1313

1414
&:hover {
@@ -131,27 +131,12 @@
131131
button {
132132
pointer-events: all;
133133
margin: 0;
134+
margin-bottom: 6px;
134135
}
135136
}
136137

137138
.details-output {
138139
pointer-events: all;
139-
padding: 6px;
140-
margin-top: 6px;
141-
background: @gray8;
142-
border-radius: 3px;
143-
}
144-
145-
.details-output pre {
146-
background: none;
147-
word-break: break-word;
148-
border: none;
149-
margin: 0;
150-
font-size: 11px;
151-
}
152-
153-
.details-output pre code {
154-
background: none;
155-
margin: 0;
140+
max-height: 40vh;
156141
}
157142
}

packages/compass-query-history/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
"dependencies": {
4646
"@mongodb-js/compass-logging": "^0.12.0",
4747
"bson": "^4.4.1",
48-
"highlight.js": "^9.12.0",
4948
"lodash": "^4.17.15",
5049
"mongodb-data-service": "^21.21.0"
5150
},
5251
"peerDependencies": {
52+
"@mongodb-js/compass-components": "^0.15.0",
5353
"bson": "^4.4.1",
5454
"debug": "*",
5555
"hadron-react-components": "^5.15.0",
@@ -71,6 +71,7 @@
7171
"@babel/preset-env": "^7.14.2",
7272
"@babel/preset-react": "^7.13.13",
7373
"@babel/register": "^7.13.16",
74+
"@mongodb-js/compass-components": "^0.15.0",
7475
"ampersand-model": "^8.0.1",
7576
"ampersand-rest-collection": "^6.0.0",
7677
"autoprefixer": "^9.4.6",

packages/compass-query-history/src/components/code/code.jsx

Lines changed: 0 additions & 48 deletions
This file was deleted.

packages/compass-query-history/src/components/code/code.module.less

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/compass-query-history/src/components/code/code.spec.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)