Skip to content

Commit

Permalink
ui: upgrade package versions
Browse files Browse the repository at this point in the history
Summary:
Upgrade packages.  Fix minor typescript errors.  Run prettier.
fixed deprecated flow scripts to use check-types

Test Plan: build/test/start/lint

Reviewers: ecarrel, arinehouse, nsawas, O13 UI Common, O12 LIMS UI

Reviewed By: ecarrel, nsawas, O13 UI Common, O12 LIMS UI

Subscribers: lkong, #lab_testing

Tags: #software-only_change_control, #platform-wide

Differential Revision: https://phabricator.grailbio.com/D43785

fbshipit-source-id: e7ff116
  • Loading branch information
Jack Zhao committed Mar 25, 2020
1 parent 7aaa4d2 commit ac41e89
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 127 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start:client": "NODE_ENV=development tsdx watch",
"cover": "open coverage/lcov-report/index.html",
"check-types": "tsc",
"lint": "yarn flow && tsdx lint src",
"lint": "yarn check-types && tsdx lint src",
"lint-fix": "yarn lint --fix",
"format": "prettier --write \"*.js\" && yarn lint-fix",
"preinstall": "node -e 'if(!/yarn\\.js$/.test(process.env.npm_execpath))throw new Error(\"Use yarn install\")'",
Expand All @@ -27,32 +27,32 @@
"dependencies": {
"@types/history": "^4.7.5",
"@types/lodash": "^4.14.149",
"csv-string": "^3.1.7",
"date-fns": "^2.9.0",
"csv-string": "^3.2.0",
"date-fns": "^2.11.0",
"fuzzy": "^0.1.3",
"googleapis": "^47.0.0",
"googleapis": "^48.0.0",
"http-status-codes": "^1.4.0",
"lodash": "^4.17.15",
"lodash-es": "^4.17.15",
"minimist": "^1.2.0",
"minimist": "^1.2.5",
"node-fetch": "^2.6.0",
"passport": "^0.4.1",
"passport-strategy": "^1.0.0",
"qs": "^6.9.1",
"uuid": "^3.4.0"
"qs": "^6.9.2",
"uuid": "^7.0.2"
},
"devDependencies": {
"@grailbio/eslint-config-grail": "1.0.3",
"@types/jest": "24.9.0",
"@types/react": "16.9.21",
"@types/jest": "25.1.4",
"@types/react": "16.9.25",
"eslint-plugin-tsc": "1.2.0",
"fs-extra": "8.1.0",
"fs-extra": "9.0.0",
"husky": "4.2.3",
"jest-mock-console": "1.0.0",
"lint-staged": "7.3.0",
"mock-socket": "9.0.3",
"prettier": "1.19.1",
"tsdx": "0.12.3"
"prettier": "2.0.2",
"tsdx": "0.13.0"
},
"lint-staged": {
"*.+(ts|tsx)": [
Expand Down
4 changes: 2 additions & 2 deletions src/api/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as apis from "./api";
import { sentenceCase } from "../utils/string-utils";

["error", "warning"].forEach(issueType => {
["error", "warning"].forEach((issueType) => {
const functionName = `extract${sentenceCase(issueType)}Messages`;
const parameterName = `${issueType}s`;
describe(functionName, () => {
Expand All @@ -13,7 +13,7 @@ import { sentenceCase } from "../utils/string-utils";
).toEqual([]);
});

[1, 3, 42].forEach(length => {
[1, 3, 42].forEach((length) => {
it(`should handle ${length} ${issueType} messages`, () => {
const messages = Array.from({ length }, (_, key) => ({
message: `Error ${key + 1}`,
Expand Down
36 changes: 19 additions & 17 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import HttpStatus from "http-status-codes";
import uuid from "uuid";
import {
ApiDispatchers,
ApiObjectProcessors,
Expand All @@ -8,6 +7,7 @@ import {
UnprocessedJsonResult,
} from "../types/api";
import { has, isObject, isString, merge, partialRight } from "lodash";
import { v4 } from "uuid";

const SEMICOLON_SEPARATOR = "; ";

Expand All @@ -26,10 +26,10 @@ const extractIssueMessages = (
return [errors];
}
if (Array.isArray(errors)) {
if (errors.every(error => isString(error))) {
if (errors.every((error) => isString(error))) {
return errors;
}
return errors.map(error => error.message);
return errors.map((error) => error.message);
}
return [];
};
Expand All @@ -49,10 +49,12 @@ export const extractIssueCodes = (
return [];
}
if (Array.isArray(errors)) {
if (errors.every(error => isString(error))) {
if (errors.every((error) => isString(error))) {
return [];
}
return errors.map(error => error.errorCode).filter(errorCode => errorCode);
return errors
.map((error) => error.errorCode)
.filter((errorCode) => errorCode);
}
return [];
};
Expand Down Expand Up @@ -98,7 +100,7 @@ const checkForServerError = (response: Response): Promise<Response> =>

// Check for API server version mismatch. If mismatched, throw an error and reload the UI.
const checkForServerVersionMismatch = (response: Response): Promise<Response> =>
new Promise(resolve => {
new Promise((resolve) => {
const { status } = response;
if (status === HttpStatus.PRECONDITION_FAILED) {
// If the server rejects the request with PRECONDITION_FAILED, most likely it is due
Expand Down Expand Up @@ -152,7 +154,7 @@ export class Api {
getCommonHeaders = (): Record<string, any> => {
const commonHeaders = {
accept: `application/json, ${this.getAcceptVersionHeader()}`,
"x-request-id": uuid.v4(),
"x-request-id": v4(),
};
return { headers: { ...commonHeaders } };
};
Expand Down Expand Up @@ -185,7 +187,7 @@ export class Api {
.then(checkForServerVersionMismatch)
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore: type JsonResult is not assignable.
.then(response => {
.then((response) => {
const { status, ok } = response;
if (ok) {
let filename = "";
Expand All @@ -202,7 +204,7 @@ export class Api {
if (!filename) {
filename = new Date().toISOString();
}
return response.blob().then(blob => ({
return response.blob().then((blob) => ({
blob,
filename,
status,
Expand All @@ -215,7 +217,7 @@ export class Api {
);
})
.catch(this.processCatch.bind(null, urlSuffix, options))
.then(response => {
.then((response) => {
apiDispatchers && apiDispatchers.dispatchIsLoading(false);
return response;
})
Expand All @@ -239,11 +241,11 @@ export class Api {
return fetch(`${this.apiUrl}${urlSuffix}`, fetchOptions)
.then(checkForServerError)
.then(checkForServerVersionMismatch)
.then(resp =>
.then((resp) =>
this.processJsonResponse(resp, merge({}, apiDispatchers, options)),
)
.catch(this.processCatch.bind(null, urlSuffix, options))
.then(response => {
.then((response) => {
apiDispatchers && apiDispatchers.dispatchIsSaving(false);
return response;
});
Expand All @@ -259,11 +261,11 @@ export class Api {
return fetch(`${this.apiUrl}${urlSuffix}`, this.getCommonHeaders())
.then(checkForServerError)
.then(checkForServerVersionMismatch)
.then(resp =>
.then((resp) =>
this.processJsonResponse(resp, merge({}, apiDispatchers, options)),
)
.catch(this.processCatch.bind(null, urlSuffix, options))
.then(response => {
.then((response) => {
apiDispatchers && apiDispatchers.dispatchIsLoading(false);
return response;
});
Expand Down Expand Up @@ -291,11 +293,11 @@ export class Api {
return fetch(`${this.apiUrl}${urlSuffix}`, fetchOptions)
.then(checkForServerError)
.then(checkForServerVersionMismatch)
.then(response =>
.then((response) =>
this.processJsonResponse(response, merge({}, apiDispatchers, options)),
)
.catch(this.processCatch.bind(null, urlSuffix, options))
.then(response => {
.then((response) => {
apiDispatchers && apiDispatchers.dispatchIsSaving(false);
return response;
});
Expand Down Expand Up @@ -334,7 +336,7 @@ export class Api {
options: ApiOptions = defaultOptions,
): JsonResult<any> => {
const { status, statusText, ok } = response;
return response.json().then(object => {
return response.json().then((object) => {
const hasResultInResponse = options.hasResultInResponse !== false;

if (this.apiObjectProcessors) {
Expand Down
4 changes: 2 additions & 2 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type OmniQueryOptions = {
searchOptions: SearchOption[];
};

// TODO(jzhao): simplify all these types!
// TODO(nsawas): simplify all these types!
export type ApiQueryOptions = {
searchOptions: SearchOption[];
sortOptions: SortOption[];
Expand All @@ -61,7 +61,7 @@ export type OmniSearchDef = {
aliases?: string[];
description?: string;
localStorageKeySuffix?: string;
// TODO(jzhao): support validation in the future?
// TODO(nsawas): support validation in the future?
} & SearchDef;

export type OmniSearchValues = Map<number, string>;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/api-utils/api-util-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe("isValueValid", () => {
false,
"A sentence",
" ",
].forEach(value => {
].forEach((value) => {
it(`should validate '${String(value)}'`, () =>
expect(isValueValid(value)).toBe(true));
});
["", null, undefined].forEach(value => {
["", null, undefined].forEach((value) => {
it(`should invalidate '${String(value)}'`, () =>
expect(isValueValid(value)).toBe(false));
});
Expand Down
36 changes: 19 additions & 17 deletions src/utils/api-utils/api-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const resolveSearchOptions = async (
transformId: (x: string) => string = identity,
): Promise<SearchOption[]> =>
Promise.all(
searchOptions.map(async searchOption => {
searchOptions.map(async (searchOption) => {
const { type, mapValues } = searchOption;
let { values } = searchOption;
const isDateSearchType = DATE_SEARCH_TYPES.includes(type);
Expand All @@ -95,7 +95,7 @@ const resolveSearchOptions = async (
values = getEscapedSearchValues(
{ ...searchOption, values },
transformId,
).map(value => {
).map((value) => {
if (isDateSearchType) {
return value;
}
Expand All @@ -112,15 +112,16 @@ export const buildCustomURIQueryParams = async (
): Promise<void> => {
const resolvedSearchOptions = await resolveSearchOptions(
searchOptions.filter(
searchOption => searchOption && searchOption.queryType === URI_QUERY_TYPE,
(searchOption) =>
searchOption && searchOption.queryType === URI_QUERY_TYPE,
),
transformId,
);
resolvedSearchOptions
.filter(searchOption => searchOption.values && searchOption.values.length)
.filter((searchOption) => searchOption.values && searchOption.values.length)
.forEach(({ searchFields, values }) => {
if (searchFields) {
values.forEach(value => {
values.forEach((value) => {
params.append(searchFields[0], value);
});
}
Expand All @@ -138,7 +139,7 @@ export const buildSearchQuery = async (
): Promise<string> => {
const resolvedSearchOptions = await resolveSearchOptions(
searchOptions.filter(
searchOption => searchOption && !searchOption.queryType,
(searchOption) => searchOption && !searchOption.queryType,
),
transformId,
);
Expand Down Expand Up @@ -182,8 +183,9 @@ export const buildSearchQuery = async (
},
"",
);
return `${multiValueSearchMemo}${multiValueSearchMemo &&
"||"}${multiFieldSearch}`;
return `${multiValueSearchMemo}${
multiValueSearchMemo && "||"
}${multiFieldSearch}`;
}, initialSubQuery);
if (!multiValueSearch) {
return null;
Expand All @@ -196,7 +198,7 @@ export const buildSearchQuery = async (
switch (type) {
case LIKE_TEXT_SEARCH_TYPE:
case OMNI_TEXT_SEARCH_TYPE:
return multiValueSearchBuilder(value => {
return multiValueSearchBuilder((value) => {
let searchValue = value.trim();
const quotedValue = extractQuotedString(searchValue);
if (quotedValue != null) {
Expand All @@ -218,18 +220,18 @@ export const buildSearchQuery = async (
case NUMERIC_SEARCH_TYPE:
// fallthrough to next case
case BOOLEAN_SEARCH_TYPE:
return multiValueSearchBuilder(value => `${value}`);
return multiValueSearchBuilder((value) => `${value}`);
case FULL_TEXT_SEARCH_TYPE:
// fallthrough to next case
case ENUM_SEARCH_TYPE:
return multiValueSearchBuilder(value => `"${value.trim()}"`);
return multiValueSearchBuilder((value) => `"${value.trim()}"`);
case FULL_ID_SEARCH_TYPE:
return multiValueSearchBuilder(value => `"${value}"`);
return multiValueSearchBuilder((value) => `"${value}"`);
case LIKE_ID_SEARCH_TYPE:
return multiValueSearchBuilder(value => `"${value}%"`);
return multiValueSearchBuilder((value) => `"${value}%"`);
case DATE_SEARCH_TYPE:
case DATETIME_SEARCH_TYPE: {
return multiValueSearchBuilder(dateRangeString => {
return multiValueSearchBuilder((dateRangeString) => {
// Note: startDate or endDate could be null, undefined or "". Consider all as `unset`
let { startDate, endDate = "" } = extractDateRange(
dateRangeString || "",
Expand Down Expand Up @@ -320,7 +322,7 @@ export const filterResults = (
): Array<any> => {
const { count, offset, sortOptions = [], searchOptions = [] } = options;

const filteredResults = items.filter(item =>
const filteredResults = items.filter((item) =>
searchOptions.reduce((result: boolean, searchOption) => {
if (!result || !searchOption) {
return false;
Expand Down Expand Up @@ -359,7 +361,7 @@ export const filterResults = (
);
}

const validValues = searchValues.filter(value => isValueValid(value));
const validValues = searchValues.filter((value) => isValueValid(value));
if (validValues.length === 0) {
return true;
}
Expand Down Expand Up @@ -405,7 +407,7 @@ export const filterResults = (
const filterKey = tokens.join(".");

if (filterKey && itemKey != null && Array.isArray(item[itemKey])) {
return item[itemKey].some(e => {
return item[itemKey].some((e) => {
const resultValue = get(e, filterKey);
if (includeNulls && resultValue == null) {
return true;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/array-utils/array-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("generateFilledArray functional", () => {
});

describe("serializePromises", () => {
it("shall serially call array functions", done => {
it("shall serially call array functions", (done) => {
const count = 10;
let start = 0;
// eslint-disable-next-line no-plusplus
Expand All @@ -50,16 +50,16 @@ describe("serializePromises", () => {
let resolutionIndex = 0;
const promise = serializePromises(
values,
value =>
new Promise(resolve => {
(value) =>
new Promise((resolve) => {
setTimeout(() => {
resolutionValues[resolutionIndex] = value;
resolutionIndex += 1;
resolve(value);
}, Math.random() * 10);
}),
);
promise.then(results => {
promise.then((results) => {
expect(resolutionValues).toEqual(values);
expect(results).toEqual(values);
done();
Expand Down
4 changes: 1 addition & 3 deletions src/utils/array-utils/array-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export const generateFilledArray = (
valueOrGenerator: any = 0,
): Array<any> => {
if (typeof valueOrGenerator === "function") {
return Array(count)
.fill(null)
.map(valueOrGenerator);
return Array(count).fill(null).map(valueOrGenerator);
}
return Array(count).fill(valueOrGenerator);
};
Expand Down
Loading

0 comments on commit ac41e89

Please sign in to comment.