Skip to content

Commit

Permalink
Typechecking, linting and cleanup
Browse files Browse the repository at this point in the history
* Revert removal of compressed cell colour features
* Dependency updates
* Use ts-loader instead of babel for typescript (ts-loader does type checking)
* Use pako for zlib compression
* Replace some uses of Lodash with Ramda
* Upgrade from Webpack 4 to Webpack 5
  • Loading branch information
MaybeJustJames committed Dec 7, 2020
1 parent 1282a53 commit e47de8f
Show file tree
Hide file tree
Showing 12 changed files with 909 additions and 898 deletions.
3 changes: 1 addition & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
}
}
],
'@babel/preset-react',
'@babel/preset-typescript'
'@babel/preset-react'
]
};
4 changes: 2 additions & 2 deletions opt/scopeserver/dataserver/modules/gserver/GServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def getCellColorByFeatures(self, request, context):
logger.debug("{0:.5f} seconds elapsed getting colours ---".format(time.time() - start_time))
return s_pb2.CellColorByFeaturesReply(
color=None,
compressedColor=cell_color_by_features.get_hex_vec(),
hasAddCompressionLayer=False,
compressedColor=cell_color_by_features.get_compressed_hex_vec(),
hasAddCompressionLayer=True,
vmax=cell_color_by_features.get_v_max(),
maxVmax=cell_color_by_features.get_max_v_max(),
cellIndices=cell_color_by_features.get_cell_indices(),
Expand Down
1,593 changes: 758 additions & 835 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 26 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@
"grpc-bus-websocket-client": "^0.3.1",
"grpc-bus-websocket-server": "file:opt/scopeserver/bindserver",
"grpc-caller": "^0.13.0",
"grpc-tools": "^1.9.0",
"immer": "^7.0.14",
"grpc-tools": "^1.10.0",
"immer": "^8.0.0",
"js-file-download": "^0.4.12",
"json-schema": "^0.2.3",
"json2csv": "^4.0.1",
"pako": "^1.0.6",
"pako": "^2.0.2",
"pixi.js": "^5.3.3",
"protobufjs": "^6.9.0",
"protobufjs": "^6.10.2",
"public-ip": "^2.4.0",
"ramda": "^0.27.0",
"rc-slider": "^8.6.0",
"react": "^16.14.0",
"react-addons-css-transition-group": "^15.6.2",
"react-cookie": "^4.0.3",
"react-cookie-consent": "^6.1.0",
"react-cookie-consent": "^6.2.0",
"react-csv-reader": "^3.1.1",
"react-dnd": "^2.5.4",
"react-dnd-html5-backend": "^2.5.4",
Expand All @@ -81,48 +81,46 @@
"url-loader": "^4.1.1"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/cli": "^7.12.8",
"@babel/core": "^7.12.9",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"@babel/preset-typescript": "^7.12.1",
"@babel/preset-env": "^7.12.7",
"@babel/preset-react": "^7.12.7",
"@babel/runtime": "^7.12.5",
"@redux-saga/testing-utils": "^1.1.3",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.1.2",
"@types/jest": "^26.0.15",
"@types/react": "^16.9.56",
"@types/react-dom": "^16.9.9",
"@testing-library/react": "^11.2.2",
"@types/jest": "^26.0.16",
"@types/react": "^16.14.2",
"@types/react-dom": "^16.9.10",
"@types/react-router-dom": "^5.1.6",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.1",
"babel-plugin-redux-saga": "^1.1.2",
"cross-env": "^7.0.2",
"babel-loader": "^8.2.2",
"cross-env": "^7.0.3",
"css-loader": "^5.0.1",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-react": "^7.21.5",
"fork-ts-checker-webpack-plugin": "^6.0.1",
"google-protobuf": "^3.13.0",
"google-protobuf": "^3.14.0",
"grpc": "^1.24.4",
"grpc-loader": "^2.0.1",
"jest": "^26.6.3",
"jest-css-modules-transform": "4.0.1",
"prettier": "^2.1.2",
"prettier": "^2.2.1",
"redux-devtools-extension": "^2.13.8",
"script-loader": "^0.7.2",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.0.3",
"ts-jest": "^26.4.4",
"typescript": "^4.0.5",
"webpack": "^5.4.0",
"webpack-bundle-analyzer": "^4.1.0",
"ts-loader": "^8.0.11",
"typescript": "^4.1.2",
"webpack": "^5.10.0",
"webpack-bundle-analyzer": "^4.2.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
},
Expand Down
3 changes: 1 addition & 2 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import { withRouter, Route, Link } from 'react-router-dom';
import { withCookies, Cookies } from 'react-cookie';
import CookieConsent from 'react-cookie-consent';

import pako from 'pako';
import Favicon from 'react-favicon';

import { SCOPE_COOKIE, ONE_MINUTE } from './constants';
Expand All @@ -24,7 +24,6 @@ import {
import { FullPageNotify } from './pages';
import { millisecondsToDays } from './utils';

const pako = require('pako');
const publicIp = require('public-ip');
const timer = 60 * 1000;

Expand Down
2 changes: 1 addition & 1 deletion src/components/AppHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { BackendAPI } from './common/API';
import PropTypes from 'prop-types';
import { withCookies, Cookies } from 'react-cookie';
import Bitly from 'bitly4api';
import pako from 'pako';

const pako = require('pako');
let bitly = new Bitly(BITLY.token);

import { toggleSidebar, consentToCookies } from '../redux/actions';
Expand Down
33 changes: 28 additions & 5 deletions src/components/common/Viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import * as d3 from 'd3';
import * as R from 'ramda';
import { BackendAPI } from './API';
import { Dimmer, Loader } from 'semantic-ui-react';
import pako from 'pako';
import Alert from 'react-popup';
import { debounce } from 'lodash';

import { zipLists } from '../../util';

const MIN_SCALING_FACTOR = 1;
const DEFAULT_POINT_COLOR = 'A6A6A6';

Expand Down Expand Up @@ -434,7 +437,7 @@ export default class Viewer extends Component {

translatePointsInLasso(indices) {
let ptsInLasso = [];
let idxInLasso = _.intersection(indices, this.state.coord.idx);
let idxInLasso = R.intersection(indices, this.state.coord.idx);
ptsInLasso = idxInLasso.map((idx) => {
return this.state.coord.idx.indexOf(idx);
});
Expand Down Expand Up @@ -1067,9 +1070,29 @@ export default class Viewer extends Component {
response
);
}
// Convert object to ArrayBuffer
let responseBuffered =
response.compressedColor.toArrayBuffer();

// Uncompress
if (response.hasAddCompressionLayer) {
// Uncompress
console.error('Zlib compression is not supported');
pako.inflate(
responseBuffered,
(err, uncompressedMessage) => {
if (err) {
console.log(err);
} else {
this.endBenchmark(
'getFeatureColors'
);
let colors = this.chunkString(
uncompressedMessage.toString(),
6
);
this.updateColors(response, colors);
}
}
);
} else {
this.endBenchmark('getFeatureColors');
this.updateColors(response, response.color);
Expand Down Expand Up @@ -1156,7 +1179,7 @@ export default class Viewer extends Component {
});
let settings = BackendAPI.getSettings();
if (settings.sortCells) {
let pts = _.zip(
let pts = zipLists(
this.state.coord.idx,
this.state.coord.x,
this.state.coord.y,
Expand All @@ -1173,7 +1196,7 @@ export default class Viewer extends Component {
});
this.endBenchmark('sort');
this.startBenchmark('map');
pts.map((p, i) => {
pts.forEach((p, i) => {
let point = this.getTexturedColorPoint(p[1], p[2], p[3]);
point._originalData.idx = p[0];
this.mainLayer.addChildAt(point, i);
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/ViewerSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ViewerSidebar extends Component {
getButtonText = (text) => {
switch (this.state.status) {
case 'ready':
switch (button) {
switch (text) {
case 'submit':
return (
<React.Fragment>
Expand Down Expand Up @@ -1374,7 +1374,7 @@ const viewerSidebar = withCookies(withRouter(ViewerSidebar));

const mapStateToProps = (rootState) => {
return {
sessionIsRW: rootState.main.sessionMode === 'rw'
sessionIsRW: rootState.main.sessionMode === 'rw',
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Compare.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class Compare extends Component {
}
this.setState({ crossAnnotations: cross });
} else {
console.log('Annotation cannot be found', viewer, name, remove);
console.log('Annotation cannot be found', viewer, name);
}
this.getCellMetadata();
}
Expand Down
42 changes: 42 additions & 0 deletions src/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'jest';

import { zipLists } from './util';

describe('zip arbitrary lists', () => {
it('zips the empty list', () => {
expect(zipLists([])).toEqual([]);
});

it('zips singleton lists', () => {
expect(zipLists([[1], [2], [3]])).toEqual([[1, 2, 3]]);

expect(zipLists([[1]])).toEqual([[1]]);

expect(zipLists([[1, 2, 3]])).toEqual([[1, 2, 3]]);
});

it('zips a pair of lists', () => {
expect(
zipLists([
[1, 2],
[3, 4],
])
).toEqual([
[1, 3],
[2, 4],
]);
});

it('zips 3 lists', () => {
expect(
zipLists([
[1, 2],
[3, 4],
[5, 6],
])
).toEqual([
[1, 3, 5],
[2, 4, 6],
]);
});
});
26 changes: 26 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Utility functions */

import * as R from 'ramda';

/**
* zip() but for an arbitrary number of lists.
* Normally you should use R.zip, but sometimes you may want to "zip"
* more than 2 arrays.
*
* Examples:
* zipLists([]) => []
* zipLists([[1], [2], [3]]) => [[1, 2, 3]]
* zipLists([[1, 2], ['a', 'b']]) => [[1, 'a'], [2, 'b']]
*/
export const zipLists = <T>(l: Array<Array<T>>): Array<Array<T>> => {
const acc: Array<T> | undefined = R.head(l);
const data: Array<Array<T>> | undefined = R.tail(l);

if (acc !== undefined && data !== undefined) {
const zipped: Readonly<any[]> = R.isEmpty(data)
? l
: R.reduce(R.zip, acc, data);
return R.map(R.flatten, zipped);
}
return [];
};
Loading

0 comments on commit e47de8f

Please sign in to comment.