Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update react-science #2795

Merged
merged 10 commits into from
Dec 12, 2023
2,903 changes: 1,614 additions & 1,289 deletions package-lock.json

Large diffs are not rendered by default.

63 changes: 32 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"react-dom": ">=18.0.0"
},
"dependencies": {
"@blueprintjs/core": "^5.6.0",
"@blueprintjs/core": "^5.7.1",
"@blueprintjs/icons": "^5.4.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@lukeed/uuid": "^2.0.1",
Expand All @@ -80,71 +81,71 @@
"ml-baseline-correction-regression": "^1.0.2",
"ml-conrec": "^5.0.2",
"ml-gsd": "^12.1.3",
"ml-matrix": "^6.10.8",
"ml-matrix": "^6.11.0",
"ml-spectra-processing": "^12.8.0",
"ml-stat": "^1.3.3",
"multiplet-analysis": "^2.1.2",
"nmr-correlation": "^2.3.3",
"nmr-load-save": "^0.23.9",
"nmr-processing": "^11.6.1",
"nmredata": "^0.9.7",
"nmredata": "^0.9.9",
"numeral": "^2.0.6",
"openchemlib": "^8.7.1",
"openchemlib-utils": "^5.6.1",
"openchemlib": "^8.7.2",
"openchemlib-utils": "^5.6.0",
"papaparse": "^5.4.1",
"re-resizable": "6.9.11",
"react-d3-utils": "^1.0.0",
"react-dropzone": "^14.2.3",
"react-error-boundary": "^4.0.11",
"react-icons": "^4.11.0",
"react-icons": "^4.12.0",
"react-inspector": "^6.0.2",
"react-mf": "^2.0.2",
"react-ocl": "^6.1.0",
"react-ocl-nmr": "^3.0.1",
"react-plot": "^1.4.2",
"react-rnd": "^10.4.1",
"react-science": "^0.27.0",
"react-science": "0.30.2-pre.1702391005",
"react-slider": "^2.0.6",
"react-table": "^7.8.0",
"react-transition-group": "^4.4.5",
"react-use": "^17.4.0",
"react-use": "^17.4.2",
"smart-array-filter": "^4.0.2",
"yup": "^1.3.2"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.2",
"@playwright/test": "^1.39.0",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@playwright/test": "^1.40.1",
"@simbathesailor/use-what-changed": "^2.0.0",
"@types/d3": "^7.4.2",
"@types/lodash": "^4.14.200",
"@types/node": "^20.8.10",
"@types/papaparse": "^5.3.10",
"@types/react": "^18.2.36",
"@types/react-dom": "^18.2.14",
"@types/react-table": "^7.7.17",
"@vitejs/plugin-react-swc": "^3.4.1",
"@vitest/coverage-v8": "^0.34.6",
"@types/d3": "^7.4.3",
"@types/lodash": "^4.14.202",
"@types/node": "^20.10.4",
"@types/papaparse": "^5.3.14",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"@types/react-table": "^7.7.18",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitest/coverage-v8": "^1.0.1",
"cross-env": "^7.0.3",
"cspell": "^7.3.8",
"eslint": "^8.53.0",
"eslint-config-cheminfo-react": "^10.0.0",
"eslint-config-cheminfo-typescript": "^12.0.4",
"cspell": "^8.1.3",
"eslint": "^8.55.0",
"eslint-config-cheminfo-react": "^10.1.0",
"eslint-config-cheminfo-typescript": "^12.1.0",
"modern-normalize": "^2.0.0",
"postcss-styled-syntax": "^0.5.0",
"prettier": "^3.0.3",
"rc-menu": "^9.12.2",
"prettier": "^3.1.0",
"rc-menu": "^9.12.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.18.0",
"react-router-dom": "^6.20.1",
"rimraf": "^5.0.5",
"rollup-plugin-analyzer": "^4.0.0",
"serve": "^14.2.1",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^34.0.0",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vitest": "^0.34.6"
"typescript": "^5.3.3",
"vite": "^5.0.6",
"vitest": "^1.0.1"
}
}
8 changes: 4 additions & 4 deletions src/component/1d-2d/tools/BrushXY.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@
dimensionBorder.endX && endX > dimensionBorder.endX
? dimensionBorder.endX
: dimensionBorder.startX && endX < dimensionBorder.startX
? dimensionBorder.startX
: endX;
? dimensionBorder.startX
: endX;

Check warning on line 106 in src/component/1d-2d/tools/BrushXY.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/1d-2d/tools/BrushXY.tsx#L105-L106

Added lines #L105 - L106 were not covered by tests
endY =
dimensionBorder.endY && endY > dimensionBorder.endY
? dimensionBorder.endY
: dimensionBorder.startY && endY < dimensionBorder.startY
? dimensionBorder.startY
: endY;
? dimensionBorder.startY
: endY;

Check warning on line 112 in src/component/1d-2d/tools/BrushXY.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/1d-2d/tools/BrushXY.tsx#L111-L112

Added lines #L111 - L112 were not covered by tests

const scaleX =
brushType === BRUSH_TYPE.X || brushType === BRUSH_TYPE.XY
Expand Down
67 changes: 67 additions & 0 deletions src/component/elements/ContextMenuBluePrint.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
ContextMenuProps as BluePrintContextMenuProps,
Menu,
MenuItem,
MenuItemProps,
showContextMenu,
} from '@blueprintjs/core';
import React, { ComponentProps, ElementType, ReactNode } from 'react';

export interface ContextMenuItem extends MenuItemProps {
data?: object;
}

type ElementProps<E = 'div'> = E extends ElementType
? ComponentProps<E>
: never;

export interface BaseContextMenuProps {
options: ContextMenuItem[];
onSelect: (data?: object) => void;
}

export interface ContextMenuProps<E>
extends BaseContextMenuProps,
Omit<BluePrintContextMenuProps, 'onSelect' | 'content' | 'children'> {
as?: E;
children: ReactNode;
}

export function ContextMenu<E extends ElementType = 'div'>(
props: ContextMenuProps<E> & ElementProps<E>,
) {
const { options, onSelect, children, as: Wrapper = 'div', ...other } = props;

function handleContextMenu(event: React.MouseEvent<HTMLElement>) {
if (!Array.isArray(options) || options.length === 0) {
return;
}

const content = (
<Menu>
{options.map((option) => (
<MenuItem
key={JSON.stringify(option)}
{...option}
onClick={() => onSelect(option?.data)}
/>
))}
</Menu>
);

event.preventDefault();
showContextMenu({
content,
targetOffset: {
left: event.clientX,
top: event.clientY,
},
});
}

return (
<Wrapper {...other} onContextMenu={handleContextMenu}>
{children}
</Wrapper>
);
}

Check warning on line 67 in src/component/elements/ContextMenuBluePrint.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ContextMenuBluePrint.tsx#L2-L67

Added lines #L2 - L67 were not covered by tests
39 changes: 39 additions & 0 deletions src/component/elements/DropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Menu,
MenuItem,
MenuItemProps,
Popover,
PopoverProps,
} from '@blueprintjs/core';

export interface DropdownMenuItem extends MenuItemProps {
data?: object;
}

export interface DropdownMenuProps
extends Omit<PopoverProps, 'onSelect' | 'content'> {
options: DropdownMenuItem[];
onSelect: (data?: object) => void;
}

export function DropdownMenu(props: DropdownMenuProps) {
const { options, onSelect, children, ...other } = props;

const content = (
<Menu>
{options.map((option) => (
<MenuItem
key={JSON.stringify(option)}
{...option}
onClick={() => onSelect(option?.data)}
/>
))}
</Menu>
);

return (
<Popover {...other} content={content}>
{children}
</Popover>
);
}

Check warning on line 39 in src/component/elements/DropdownMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/DropdownMenu.tsx#L2-L39

Added lines #L2 - L39 were not covered by tests
18 changes: 9 additions & 9 deletions src/component/elements/ReactTable/Elements/ReactTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/** @jsxImportSource @emotion/react */

import { css, CSSObject } from '@emotion/react';
import { css, CSSObject, SerializedStyles } from '@emotion/react';

Check warning on line 3 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L3

Added line #L3 was not covered by tests
import { useMemo, useEffect, useCallback } from 'react';
import { DropdownMenu } from 'react-science/ui';

import { HighlightEventSource, useHighlight } from '../../../highlight/index';
import { BaseRowStyle, ContextMenuProps } from '../ReactTable';
import { ContextMenu } from '../../ContextMenuBluePrint';
import { BaseRowStyle, TableContextMenuProps } from '../ReactTable';

Check warning on line 8 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L7-L8

Added lines #L7 - L8 were not covered by tests

function getRowStyle(
isActive: boolean,
rowStyle: BaseRowStyle = {},
disableDefaultRowStyle?: boolean,
) {
): SerializedStyles {

Check warning on line 14 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L14

Added line #L14 was not covered by tests
const { hover = {}, active = {}, base = {}, activated = {} } = rowStyle;

const hoverStyle = disableDefaultRowStyle
Expand All @@ -21,7 +21,7 @@
? (active as CSSObject)
: { backgroundColor: '#ff6f0070', ...active };
const baseStyle = disableDefaultRowStyle
? (base as CSSObject)
? (base as object)

Check warning on line 24 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L24

Added line #L24 was not covered by tests
: { backgroundColor: 'white', ...base };

return css([
Expand All @@ -36,7 +36,7 @@
export interface ClickEvent {
onClick?: (event: Event, data: unknown) => void;
}
interface ReactTableRowProps extends ClickEvent, ContextMenuProps {
interface ReactTableRowProps extends ClickEvent, TableContextMenuProps {

Check warning on line 39 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L39

Added line #L39 was not covered by tests
row: any;
highlightedSource?: HighlightEventSource;
isRowActive: boolean;
Expand Down Expand Up @@ -89,11 +89,11 @@
[onClick, row],
);
return (
<DropdownMenu
trigger="contextMenu"
<ContextMenu

Check warning on line 92 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L92

Added line #L92 was not covered by tests
options={contextMenu}
onSelect={(selected) => onContextMenuSelect?.(selected, row.original)}
as="tr"
style={{ position: 'static' }}

Check warning on line 96 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L96

Added line #L96 was not covered by tests
key={row.getRowProps().key}
css={getRowStyle(
highlight.isActive || isRowActive,
Expand Down Expand Up @@ -127,7 +127,7 @@
);
}
})}
</DropdownMenu>
</ContextMenu>

Check warning on line 130 in src/component/elements/ReactTable/Elements/ReactTableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/Elements/ReactTableRow.tsx#L130

Added line #L130 was not covered by tests
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/component/elements/ReactTable/ReactTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
useEffect,
useMemo,
} from 'react';
import { DropdownMenuProps } from 'react-science/ui';
import {
useTable,
useSortBy,
Expand All @@ -28,6 +27,7 @@
import { useMeasure } from 'react-use';

import { HighlightEventSource } from '../../highlight';
import { BaseContextMenuProps } from '../ContextMenuBluePrint';

Check warning on line 30 in src/component/elements/ReactTable/ReactTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/ReactTable.tsx#L30

Added line #L30 was not covered by tests

import { EmptyDataRow } from './Elements/EmptyDataRow';
import ReactTableHeader from './Elements/ReactTableHeader';
Expand Down Expand Up @@ -69,14 +69,14 @@
base?: CSSProperties;
}

export interface ContextMenuProps {
export interface TableContextMenuProps {

Check warning on line 72 in src/component/elements/ReactTable/ReactTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/ReactTable.tsx#L72

Added line #L72 was not covered by tests
onContextMenuSelect?: (
selected: Parameters<DropdownMenuProps<any, any>['onSelect']>[0],
selected: Parameters<BaseContextMenuProps['onSelect']>[0],

Check warning on line 74 in src/component/elements/ReactTable/ReactTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/ReactTable.tsx#L74

Added line #L74 was not covered by tests
data: any,
) => void;
contextMenu?: DropdownMenuProps<any, any>['options'];
contextMenu?: BaseContextMenuProps['options'];

Check warning on line 77 in src/component/elements/ReactTable/ReactTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/ReactTable.tsx#L77

Added line #L77 was not covered by tests
}
interface ReactTableProps extends ContextMenuProps, ClickEvent, SortEvent {
interface ReactTableProps extends TableContextMenuProps, ClickEvent, SortEvent {

Check warning on line 79 in src/component/elements/ReactTable/ReactTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/component/elements/ReactTable/ReactTable.tsx#L79

Added line #L79 was not covered by tests
data: any;
columns: any;
highlightedSource?: HighlightEventSource;
Expand Down
Loading
Loading