Skip to content

Commit 89d23fd

Browse files
authored
chore: modernize compass-serverstats COMPASS-5161 (#4929)
* update lint&prettier config of compass-serverstats * lint & typescript * package-lock * reformat * lint * depalign
1 parent 6351f72 commit 89d23fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+981
-1656
lines changed

package-lock.json

+83-1,041
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@babel/core": "7.16.0",
6262
"@babel/parser": "7.16.0",
6363
"@mongodb-js/monorepo-tools": "^1.1.1",
64-
"@mongodb-js/sbom-tools": "^0.5.2",
64+
"@mongodb-js/sbom-tools": "^0.5.3",
6565
"@testing-library/dom": "^8.11.1",
6666
"babel-loader": "^7.1.5",
6767
"husky": "^8.0.3",

packages/compass-explain-plan/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@mongodb-js/webpack-config-compass": "^1.2.0",
7575
"@testing-library/react": "^12.1.4",
7676
"@testing-library/user-event": "^13.5.0",
77-
"@types/d3": "3.5.x",
77+
"@types/d3": "^3.5.x",
7878
"@types/d3-flextree": "^2.1.0",
7979
"@types/d3-hierarchy": "^3.1.2",
8080
"chai": "^4.2.0",
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
ignores: [
2-
"mongodb-compass",
3-
# webpack always externalizes 'clipboard' for legacy reasons
4-
"clipboard",
5-
"react-dom"
6-
]
1+
ignores:
2+
- "@mongodb-js/prettier-config-compass"
3+
- "@mongodb-js/tsconfig-compass"
4+
- "mongodb-compass"
5+
# webpack always externalizes 'clipboard' for legacy reasons
6+
- "clipboard"
7+
- "react-dom"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.nyc-output
2+
dist

packages/compass-serverstats/.eslintrc

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@mongodb-js/eslint-config-compass'],
4+
parserOptions: {
5+
tsconfigRootDir: __dirname,
6+
project: ['./tsconfig-lint.json'],
7+
},
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.nyc_output
2+
coverage
3+
dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"@mongodb-js/prettier-config-compass"

packages/compass-serverstats/README.md

+24-48
Original file line numberDiff line numberDiff line change
@@ -20,61 +20,38 @@ const realTimeLineChart = require('compass-serverstats').d3.realTimeLineChart;
2020

2121
const el = document.getElementById('myChart');
2222
const data = {
23-
"dataSets" : [
23+
dataSets: [
2424
{
25-
"line" : "virtual",
26-
"count" : [
27-
2.48,
28-
2.48,
29-
2.49
30-
],
31-
"active" : true
25+
line: 'virtual',
26+
count: [2.48, 2.48, 2.49],
27+
active: true,
3228
},
3329
{
34-
"line" : "resident",
35-
"count" : [
36-
0.02,
37-
0.02,
38-
0.02
39-
],
40-
"active":true
30+
line: 'resident',
31+
count: [0.02, 0.02, 0.02],
32+
active: true,
4133
},
4234
{
43-
"line" : "mapped",
44-
"count" : [
45-
0,
46-
0,
47-
0
48-
],
49-
"active":true
50-
}
51-
],
52-
"localTime" : [
53-
"2016-10-30T07:12:05.077Z",
54-
"2016-10-30T07:12:06.069Z",
55-
"2016-10-30T07:12:07.153Z"
56-
],
57-
"skip" : [
58-
false,
59-
false,
60-
false
35+
line: 'mapped',
36+
count: [0, 0, 0],
37+
active: true,
38+
},
6139
],
62-
"yDomain" : [
63-
0,
64-
2.49
40+
localTime: [
41+
'2016-10-30T07:12:05.077Z',
42+
'2016-10-30T07:12:06.069Z',
43+
'2016-10-30T07:12:07.153Z',
6544
],
66-
"xLength" : 60,
67-
"labels" : {
68-
"title" : "memory",
69-
"keys" : [
70-
"vsize",
71-
"resident",
72-
"mapped"
73-
],
74-
"yAxis" : "GB"
45+
skip: [false, false, false],
46+
yDomain: [0, 2.49],
47+
xLength: 60,
48+
labels: {
49+
title: 'memory',
50+
keys: ['vsize', 'resident', 'mapped'],
51+
yAxis: 'GB',
7552
},
76-
"keyLength" : 6,
77-
"paused" : false
53+
keyLength: 6,
54+
paused: false,
7855
};
7956

8057
d3.select(el).datum(data).call(realTimeLineChart());
@@ -106,7 +83,6 @@ For completeness, below is a list of directories present in this module:
10683
- `src` components, actions and stores source code, as well as style files. This is the place to implement your own components. `npm run compile` will use `./src` as input and create `./lib`.
10784
- `test` implement your tests here, and name the files `*.test.js`.
10885

109-
11086
[npm_img]: https://img.shields.io/npm/v/mongodb-component-template.svg?style=flat-square
11187
[npm_url]: https://www.npmjs.org/package/mongodb-component-template
11288
[enzyme]: http://airbnb.io/enzyme/

packages/compass-serverstats/package.json

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
"webpack": "webpack-compass",
1919
"test": "mocha",
2020
"test-electron": "xvfb-maybe electron-mocha --no-sandbox",
21-
"check": "npm run lint && npm run depcheck",
22-
"lint": "eslint \"./{src,test}/**/*.{js,jsx}\"",
21+
"typecheck": "tsc -p tsconfig-lint.json --noEmit",
22+
"check": "npm run typecheck && npm run lint && npm run depcheck",
23+
"check-ci": "npm run check",
24+
"eslint": "eslint",
25+
"prettier": "prettier",
26+
"lint": "npm run eslint . && npm run prettier -- --check .",
2327
"depcheck": "compass-scripts check-peer-deps && depcheck",
2428
"test-ci": "npm run test",
2529
"test-ci-electron": "npm run test-electron",
2630
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
27-
"bootstrap": "npm run compile"
31+
"bootstrap": "npm run compile",
32+
"reformat": "npm run prettier -- --write . && npm run eslint . --fix"
2833
},
2934
"license": "SSPL",
3035
"peerDependencies": {
@@ -37,8 +42,13 @@
3742
"@mongodb-js/compass-logging": "^1.2.0"
3843
},
3944
"devDependencies": {
45+
"@mongodb-js/eslint-config-compass": "^1.0.9",
4046
"@mongodb-js/mocha-config-compass": "^1.3.1",
47+
"@mongodb-js/prettier-config-compass": "^1.0.1",
48+
"@mongodb-js/tsconfig-compass": "^1.0.3",
4149
"@mongodb-js/webpack-config-compass": "^1.2.0",
50+
"@types/d3": "^3.5.x",
51+
"@types/enzyme": "^3.10.14",
4252
"chai": "^4.1.2",
4353
"d3": "^3.5.17",
4454
"d3-timer": "^1.0.3",
@@ -47,8 +57,6 @@
4757
"electron-mocha": "^10.1.0",
4858
"enzyme": "^3.11.0",
4959
"eslint": "^7.25.0",
50-
"eslint-config-mongodb-js": "^2.1.0",
51-
"eslint-plugin-react": "^7.24.0",
5260
"hadron-app": "^5.11.0",
5361
"hadron-app-registry": "^9.0.10",
5462
"lodash": "^4.17.21",

packages/compass-serverstats/src/actions/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Actions = Reflux.createActions([
1414
'serverStats',
1515
'top',
1616
'killOp',
17-
{ mouseOver: { sync: true }}
17+
{ mouseOver: { sync: true } },
1818
]);
1919

2020
module.exports = Actions;

packages/compass-serverstats/src/components/chart-component.jsx

+17-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const LINE_COLORS = [
1414
palette.blue.base,
1515
palette.red.light1,
1616
palette.purple.base,
17-
palette.yellow.light2
17+
palette.yellow.light2,
1818
];
1919

2020
/**
@@ -78,8 +78,12 @@ class ChartComponent extends React.Component {
7878
if (!data.localTime || data.localTime.length === 0) {
7979
return;
8080
}
81-
const maxTime = data.localTime ? data.localTime[data.localTime.length - 1] : new Date();
82-
const minTime = data.xLength ? new Date(maxTime.getTime() - (data.xLength * 1000)) : maxTime;
81+
const maxTime = data.localTime
82+
? data.localTime[data.localTime.length - 1]
83+
: new Date();
84+
const minTime = data.xLength
85+
? new Date(maxTime.getTime() - data.xLength * 1000)
86+
: maxTime;
8387

8488
this.chart
8589
.width(this.props.width)
@@ -102,7 +106,9 @@ class ChartComponent extends React.Component {
102106

103107
.y2Domain(data.secondScale ? [0, data.secondScale.currentMax] : null)
104108
.y2Val((d) => d)
105-
.y2Values((selectionData) => selectionData.secondScale ? [selectionData.secondScale] : [])
109+
.y2Values((selectionData) =>
110+
selectionData.secondScale ? [selectionData.secondScale] : []
111+
)
106112
.y2Units(data.secondScale ? data.secondScale.units : '')
107113
.y2Data((y2Value) => y2Value.count)
108114
.y2Label((y2Value) => y2Value.line)
@@ -115,9 +121,7 @@ class ChartComponent extends React.Component {
115121
.on('mouseout', Actions.mouseOut)
116122
.eventDispatcher(this.props.dispatcher);
117123

118-
d3.select(this.containerRef)
119-
.datum(this.state.data)
120-
.call(this.chart);
124+
d3.select(this.containerRef).datum(this.state.data).call(this.chart);
121125
}
122126

123127
/**
@@ -128,9 +132,11 @@ class ChartComponent extends React.Component {
128132
render() {
129133
return (
130134
<div className="chart">
131-
<div ref={(container) => {
132-
this.containerRef = container;
133-
}} />
135+
<div
136+
ref={(container) => {
137+
this.containerRef = container;
138+
}}
139+
/>
134140
</div>
135141
);
136142
}
@@ -140,7 +146,7 @@ ChartComponent.propTypes = {
140146
width: PropTypes.number,
141147
height: PropTypes.number,
142148
store: PropTypes.any.isRequired,
143-
dispatcher: PropTypes.any.isRequired
149+
dispatcher: PropTypes.any.isRequired,
144150
};
145151

146152
ChartComponent.displayName = 'ChartComponent';

packages/compass-serverstats/src/components/current-op-component.jsx

+16-11
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ class CurrentOpComponent extends React.Component {
3131
*/
3232
componentDidMount() {
3333
this.unsubscribeRefresh = this.props.store.listen(this.refresh.bind(this));
34-
this.unsubscribeShowOperationDetails = Actions.showOperationDetails.listen(this.hide.bind(this));
35-
this.unsubscribeHideOperationDetails = Actions.hideOperationDetails.listen(this.show.bind(this));
34+
this.unsubscribeShowOperationDetails = Actions.showOperationDetails.listen(
35+
this.hide.bind(this)
36+
);
37+
this.unsubscribeHideOperationDetails = Actions.hideOperationDetails.listen(
38+
this.show.bind(this)
39+
);
3640

3741
if (!DBErrorStore.ops.currentOp) {
3842
this.unsubscribeError = DBErrorStore.listen(this.stop.bind(this));
@@ -125,9 +129,7 @@ class CurrentOpComponent extends React.Component {
125129
<header className="rt-lists__header">
126130
<h2 className="rt-lists__headerlabel">Slowest Operations</h2>
127131
</header>
128-
<div
129-
data-testid="no-slow-operations"
130-
className="rt-lists__empty-error">
132+
<div data-testid="no-slow-operations" className="rt-lists__empty-error">
131133
&#10004; No Slow Operations
132134
</div>
133135
</div>
@@ -141,9 +143,14 @@ class CurrentOpComponent extends React.Component {
141143
*/
142144
renderGraph() {
143145
const showOperationDetails = this.showOperationDetails;
144-
const rows = this.state.data.map(function(row, i) {
146+
const rows = this.state.data.map(function (row, i) {
145147
return (
146-
<li className="rt-lists__item rt-lists__item--slow" onClick={showOperationDetails.bind(null, row)} key={`list-item-${i}`}>
148+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
149+
<li
150+
className="rt-lists__item rt-lists__item--slow"
151+
onClick={showOperationDetails.bind(null, row)}
152+
key={`list-item-${i}`}
153+
>
147154
<div className="rt-lists__op">{row.op}</div>
148155
<div className="rt-lists__collection-slow">{row.ns}</div>
149156
<div className="rt-lists__time">{row.ms_running + ' ms'}</div>
@@ -156,9 +163,7 @@ class CurrentOpComponent extends React.Component {
156163
<h2 className="rt-lists__headerlabel">Slowest Operations</h2>
157164
</header>
158165
<div className="rt-lists__listdiv" id="div-scroll">
159-
<ul className="rt-lists__list">
160-
{rows}
161-
</ul>
166+
<ul className="rt-lists__list">{rows}</ul>
162167
</div>
163168
</div>
164169
);
@@ -182,7 +187,7 @@ class CurrentOpComponent extends React.Component {
182187

183188
CurrentOpComponent.propTypes = {
184189
store: PropTypes.any.isRequired,
185-
interval: PropTypes.number.isRequired
190+
interval: PropTypes.number.isRequired,
186191
};
187192

188193
CurrentOpComponent.displayName = 'CurrentOpComponent';

packages/compass-serverstats/src/components/dberror-component.tsx

+11-12
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,37 @@ import { ErrorSummary, css, spacing } from '@mongodb-js/compass-components';
44

55
const errorContainerStyles = css({
66
padding: spacing[2],
7-
position: 'relative'
7+
position: 'relative',
88
});
99

1010
/**
1111
* Represents the component that renders DB Errors.
1212
*/
13-
function DBErrorComponent({
14-
store
15-
}: {
16-
store: Store
17-
}) {
13+
function DBErrorComponent({ store }: { store: Store }) {
1814
const [data, setData] = useState([]);
1915

20-
const onRefresh = useCallback((data) => {
21-
setData(data);
22-
}, [setData]);
16+
const onRefresh = useCallback(
17+
(data) => {
18+
setData(data);
19+
},
20+
[setData]
21+
);
2322

2423
const errors = useMemo(() => {
2524
return !data || data.length < 1
2625
? []
27-
: data.map((row) => {
26+
: (data as any[]).map((row) => {
2827
return `Command "${row.ops}" returned error "${row.errorMsg}"`;
2928
});
3029
}, [data]);
3130

3231
useEffect(() => {
33-
const unsubscribeRefresh = store.listen(onRefresh);
32+
const unsubscribeRefresh = store.listen(onRefresh, store);
3433

3534
return () => {
3635
unsubscribeRefresh();
3736
};
38-
}, [onRefresh]);
37+
}, [store, onRefresh]);
3938

4039
if (!data || data.length < 1) {
4140
return null;

0 commit comments

Comments
 (0)