Skip to content

Commit

Permalink
Rename molecule types (#1729)
Browse files Browse the repository at this point in the history
* chore: rename molecule types

* refactor: update dependencies
  • Loading branch information
wadjih-bencheikh18 authored Aug 26, 2022
1 parent 9f53d79 commit 5819b74
Show file tree
Hide file tree
Showing 18 changed files with 6,465 additions and 4,032 deletions.
10,395 changes: 6,413 additions & 3,982 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@playwright/test": "^1.25.0",
"@playwright/test": "^1.25.1",
"@simbathesailor/use-what-changed": "^2.0.0",
"@types/d3": "^7.4.0",
"@types/jest": "^28.1.7",
"@types/node": "^18.7.8",
"@types/jest": "^28.1.8",
"@types/node": "^18.7.13",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.0.1",
"@zakodium/eslint-config": "^6.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.22.0",
"jest": "^28.1.3",
"jest": "^29.0.1",
"modern-normalize": "^1.1.0",
"prettier": "^2.7.1",
"rc-menu": "^9.6.3",
Expand All @@ -124,7 +124,7 @@
"rimraf": "^3.0.2",
"rollup-plugin-analyzer": "^4.0.0",
"serve": "^14.0.1",
"typescript": "~4.7.4",
"typescript": "~4.8.2",
"vite": "^3.0.9"
}
}
4 changes: 2 additions & 2 deletions src/component/elements/MoleculeSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback, useEffect, useState } from 'react';
import MF from 'react-mf/lib/components/MF';
import { MolfileSvgRenderer } from 'react-ocl/full';

import { InternalMolecule } from '../../data/molecules/Molecule';
import { StateMoleculeExtended } from '../../data/molecules/Molecule';

import NextPrev from './NextPrev';

Expand Down Expand Up @@ -64,7 +64,7 @@ const moleculeContainerStyle = css`
`;

interface MoleculeSelectionProps {
molecules: Array<InternalMolecule>;
molecules: Array<StateMoleculeExtended>;
onChange: (element: number) => void;
index?: number;
}
Expand Down
10 changes: 6 additions & 4 deletions src/component/modal/MoleculeStructureEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useState, useEffect, useCallback } from 'react';
import { StructureEditor } from 'react-ocl/full';

import { InternalMolecule } from '../../data/molecules/Molecule';
import { StateMoleculeExtended } from '../../data/molecules/Molecule';
import { isMolFileEmpty } from '../../data/utilities/isMolFileEmpty';
import { useDispatch } from '../context/DispatchContext';
import ActionButtons from '../elements/ActionButtons';
Expand All @@ -14,7 +14,7 @@ import { ModalStyles } from './ModalStyle';

interface MoleculeStructureEditorModalProps {
onClose?: (element?: string) => void;
selectedMolecule?: InternalMolecule;
selectedMolecule?: StateMoleculeExtended;
}

function MoleculeStructureEditorModal(
Expand Down Expand Up @@ -81,10 +81,12 @@ function MoleculeStructureEditorModal(
);
}

export function useMoleculeEditor(): (molecule?: InternalMolecule) => void {
export function useMoleculeEditor(): (
molecule?: StateMoleculeExtended,
) => void {
const modal = useModal();
return useCallback(
(molecule?: InternalMolecule) => {
(molecule?: StateMoleculeExtended) => {
modal.show(<MoleculeStructureEditorModal selectedMolecule={molecule} />, {
position: positions.TOP_CENTER,
width: 700,
Expand Down
6 changes: 3 additions & 3 deletions src/component/panels/MoleculesPanel/MoleculeHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, CSSProperties } from 'react';
import { MF } from 'react-mf';

import { InternalMolecule } from '../../../data/molecules/Molecule';
import { StateMoleculeExtended } from '../../../data/molecules/Molecule';
import {
extractLabelsNumbers,
extractNumber,
Expand All @@ -12,8 +12,8 @@ import { InputKeyboardEvent } from '../../elements/Input';
import { CHANGE_MOLECULE_LABEL } from '../../reducer/types/Types';

interface MoleculeHeaderProps {
currentMolecule: InternalMolecule;
molecules: InternalMolecule[];
currentMolecule: StateMoleculeExtended;
molecules: StateMoleculeExtended[];
}

const styles: Record<'toolbar' | 'labelInput', CSSProperties> = {
Expand Down
10 changes: 5 additions & 5 deletions src/component/panels/MoleculesPanel/MoleculePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import OCLnmr from 'react-ocl-nmr';

import {
FloatingMolecules,
InternalMolecule,
StateMoleculeExtended,
} from '../../../data/molecules/Molecule';
import { Datum1D, Ranges } from '../../../data/types/data1d';
import { Datum2D, Zones } from '../../../data/types/data2d';
Expand Down Expand Up @@ -68,7 +68,7 @@ const styles: Record<
interface MoleculePanelInnerProps extends MoleculePanelProps {
zones: Zones;
ranges: Ranges;
molecules: Array<InternalMolecule>;
molecules: Array<StateMoleculeExtended>;
floatingMolecules: Array<FloatingMolecules>;
activeTab: string;
displayerMode: DISPLAYER_MODE;
Expand All @@ -87,7 +87,7 @@ function MoleculePanelInner({
emptyTextStyle,
}: MoleculePanelInnerProps) {
const [currentIndex, setCurrentIndex] = useState(0);
const [molecules, setMolecules] = useState<Array<InternalMolecule>>([]);
const [molecules, setMolecules] = useState<Array<StateMoleculeExtended>>([]);

const dispatch = useDispatch();
const openMoleculeEditor = useMoleculeEditor();
Expand Down Expand Up @@ -149,7 +149,7 @@ function MoleculePanelInner({
defaultIndex={currentIndex}
>
{molecules && molecules.length > 0 ? (
molecules.map((mol: InternalMolecule, index) => (
molecules.map((mol: StateMoleculeExtended, index) => (
<div key={mol.id} css={styles.items}>
<MoleculeHeader
currentMolecule={mol}
Expand Down Expand Up @@ -216,7 +216,7 @@ const MemoizedMoleculePanel = memo(MoleculePanelInner);
const emptyData = { ranges: {}, zones: {} };

interface MoleculePanelProps {
onMoleculeChange?: (molecule: InternalMolecule) => void;
onMoleculeChange?: (molecule: StateMoleculeExtended) => void;
children?: ReactElement;
actionsOptions?: MoleculeHeaderActionsOptions;
emptyTextStyle?: CSSProperties;
Expand Down
4 changes: 2 additions & 2 deletions src/component/panels/MoleculesPanel/MoleculePanelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IoOpenOutline } from 'react-icons/io5';

import {
FloatingMolecules,
InternalMolecule,
StateMoleculeExtended,
} from '../../../data/molecules/Molecule';
import { useAssignmentData } from '../../assignment/AssignmentsContext';
import { useDispatch } from '../../context/DispatchContext';
Expand Down Expand Up @@ -90,7 +90,7 @@ export interface MoleculeHeaderActionsOptions {
}
interface MoleculePanelHeaderProps {
currentIndex: number;
molecules: Array<InternalMolecule>;
molecules: Array<StateMoleculeExtended>;
floatingMolecules: Array<FloatingMolecules>;
onMoleculeIndexChange: (index: number) => void;
onOpenMoleculeEditor: () => void;
Expand Down
4 changes: 2 additions & 2 deletions src/component/panels/RangesPanel/RangesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { css } from '@emotion/react';
import { xGetFromToIndex } from 'ml-spectra-processing';
import { useCallback, useMemo, memo, useState, useRef } from 'react';

import { InternalMolecule } from '../../../data/molecules/Molecule';
import { StateMoleculeExtended } from '../../../data/molecules/Molecule';
import { Data1D, Datum1D, Info1D, Ranges } from '../../../data/types/data1d';
import { useAssignmentData } from '../../assignment/AssignmentsContext';
import { useChartData } from '../../context/ChartContext';
Expand All @@ -28,7 +28,7 @@ interface RangesTablePanelInnerProps {
info: Info1D;
xDomain: Array<number>;
activeTab: string;
molecules: Array<InternalMolecule>;
molecules: Array<StateMoleculeExtended>;
showMultiplicityTrees: boolean;
showJGraph: boolean;
showRangesIntegrals: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/component/panels/predictionPanel/PredictionPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAccordionContext } from 'analysis-ui-components';
import { useState, useCallback } from 'react';

import { InternalMolecule } from '../../../data/molecules/Molecule';
import { StateMoleculeExtended } from '../../../data/molecules/Molecule';
import { useChartData } from '../../context/ChartContext';
import { useDispatch } from '../../context/DispatchContext';
import { useAlert } from '../../elements/popup/Alert';
Expand All @@ -11,7 +11,7 @@ import MoleculePanel from '../MoleculesPanel/MoleculePanel';
import PredictionPreferences from './PredictionOptions';

export default function PredictionPane() {
const [molecule, setMolecule] = useState<InternalMolecule | null>();
const [molecule, setMolecule] = useState<StateMoleculeExtended | null>();
const { molecules } = useChartData();
const {
item: spectraPanelState,
Expand Down
4 changes: 2 additions & 2 deletions src/component/reducer/Reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApodizationOptions } from '../../data/data1d/filter1d/apodization';
import { migrate } from '../../data/migration/MigrationManager';
import {
FloatingMolecules,
InternalMolecule,
StateMoleculeExtended,
} from '../../data/molecules/Molecule';
import { Contours } from '../../data/types/data2d/Contours';
import { UsedColors } from '../../types/UsedColors';
Expand Down Expand Up @@ -239,7 +239,7 @@ export interface State {
* molecules
* @default []
*/
molecules: Array<InternalMolecule>;
molecules: Array<StateMoleculeExtended>;
/**
* View related information
* @default { floatingMolecules: [] };
Expand Down
4 changes: 2 additions & 2 deletions src/component/reducer/actions/LoadActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Draft } from 'immer';
import { buildCorrelationData, CorrelationData } from 'nmr-correlation';

import { addJcamps, addJDFs } from '../../../data/SpectraManager';
import { InternalMolecule } from '../../../data/molecules/Molecule';
import { StateMoleculeExtended } from '../../../data/molecules/Molecule';
import * as MoleculeManager from '../../../data/molecules/MoleculeManager';
import { UsedColors } from '../../../types/UsedColors';
import { NMRiumPreferences, Spectra } from '../../NMRium';
Expand All @@ -26,7 +26,7 @@ function setData(
draft: Draft<State>,
data: {
spectra: Spectra;
molecules: InternalMolecule[];
molecules: StateMoleculeExtended[];
preferences: NMRiumPreferences;
correlations: CorrelationData;
usedColors: UsedColors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import OCL from 'openchemlib/full';
import { useCallback } from 'react';
import OCLnmr from 'react-ocl-nmr';

import { InternalMolecule } from '../../../data/molecules/Molecule';
import { StateMoleculeExtended } from '../../../data/molecules/Molecule';
import { Ranges } from '../../../data/types/data1d';
import { Zones } from '../../../data/types/data2d';
import { useDispatch } from '../../context/DispatchContext';
Expand All @@ -23,7 +23,7 @@ import ActionsButton from './ActionsButton';
interface DraggableStructureProps {
zones: Zones;
ranges: Ranges;
molecule: InternalMolecule;
molecule: StateMoleculeExtended;
activeTab: string;
displayerMode: DISPLAYER_MODE;
index?: number;
Expand Down
6 changes: 3 additions & 3 deletions src/component/tool/FloatMoleculeStructures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { memo } from 'react';

import {
FloatingMolecules,
InternalMolecule,
StateMoleculeExtended,
} from '../../../data/molecules/Molecule';
import { Datum1D, Ranges } from '../../../data/types/data1d';
import { Datum2D, Zones } from '../../../data/types/data2d';
Expand All @@ -15,7 +15,7 @@ import { DraggableStructure } from './DraggableStructure';
interface FloatMoleculeStructuresProps {
zones: Zones;
ranges: Ranges;
molecules: Array<InternalMolecule>;
molecules: Array<StateMoleculeExtended>;
floatingMolecules: Array<FloatingMolecules>;
activeTab: string;
displayerMode: DISPLAYER_MODE;
Expand Down Expand Up @@ -49,7 +49,7 @@ export function FloatMoleculeStructuresInner(
displayerMode,
molecule: molecules.find(
(m) => m.id === molecule.id,
) as InternalMolecule,
) as StateMoleculeExtended,
}}
/>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/data/SpectraManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export function toJSON(
});

const preferences = getPreferences(state);
const molecules = mols.map((mol: Molecule.InternalMolecule) =>
const molecules = mols.map((mol: Molecule.StateMoleculeExtended) =>
Molecule.toJSON(mol),
);

Expand Down
6 changes: 3 additions & 3 deletions src/data/data1d/Spectrum1D/SumManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Draft } from 'immer';

import { State } from '../../../component/reducer/Reducer';
import { InternalMolecule } from '../../molecules/Molecule';
import { StateMoleculeExtended } from '../../molecules/Molecule';
import { Datum1D, Integrals, Ranges } from '../../types/data1d';
import { SumOptions } from '../../types/data1d/SumOptions';
import getAtom from '../../utilities/getAtom';
Expand All @@ -14,7 +14,7 @@ import {

export interface SumParams {
nucleus: string;
molecules: InternalMolecule[];
molecules: StateMoleculeExtended[];
}

export type SetSumOptions = Omit<SumOptions, 'isSumConstant'>;
Expand Down Expand Up @@ -92,7 +92,7 @@ export function getAtoms(mf: string): Record<string, number> {
export function changeSpectraRelativeSum(
draft: Draft<State>,
molId: string,
molecule: InternalMolecule,
molecule: StateMoleculeExtended,
) {
const keys: (keyof Datum1D)[] = ['ranges', 'integrals'];

Expand Down
10 changes: 5 additions & 5 deletions src/data/molecules/Molecule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Molecule as OCLMolecule } from 'openchemlib/full';

import getAtomsFromMF from '../utilities/getAtomsFromMF';

export interface Molecule {
export interface StateMolecule {
id: string;
molfile: string;
label: string;
}
export interface InternalMolecule extends Molecule {
export interface StateMoleculeExtended extends StateMolecule {
mf: string;
em: number;
mw: number;
Expand All @@ -26,8 +26,8 @@ export interface FloatingMolecules {
visible: boolean;
}
export function initMolecule(
options: Partial<Molecule> = {},
): InternalMolecule {
options: Partial<StateMolecule> = {},
): StateMoleculeExtended {
const id = options.id || v4();
const label = options.label || 'p#';
const molfile = options.molfile || '';
Expand All @@ -47,7 +47,7 @@ export function initMolecule(
};
}

export function toJSON(molecule: InternalMolecule): Molecule {
export function toJSON(molecule: StateMoleculeExtended): StateMolecule {
const { molfile, label, id } = molecule;
return {
molfile,
Expand Down
10 changes: 5 additions & 5 deletions src/data/molecules/MoleculeManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Molecule as OCLMolecule } from 'openchemlib/full';

import { initMolecule, InternalMolecule } from './Molecule';
import { initMolecule, StateMoleculeExtended } from './Molecule';

export function fromJSON(mols: InternalMolecule[] = []) {
export function fromJSON(mols: StateMoleculeExtended[] = []) {
const reservedNumbers = extractLabelsNumbers(mols);

const molecules: InternalMolecule[] = [];
const molecules: StateMoleculeExtended[] = [];
for (const mol of mols) {
const molecule = OCLMolecule.fromMolfile(mol.molfile);
const fragments = molecule.getFragments();
Expand Down Expand Up @@ -43,7 +43,7 @@ export function addMolfile(molecules, molfile) {

export function setMolfile(
molecules,
currentMolecule: Pick<InternalMolecule, 'id' | 'molfile' | 'label'>,
currentMolecule: Pick<StateMoleculeExtended, 'id' | 'molfile' | 'label'>,
) {
const { molfile, id, label } = currentMolecule;
const reservedNumbers = extractLabelsNumbers(molecules);
Expand Down Expand Up @@ -82,7 +82,7 @@ export function extractNumber(value: string) {
return /(?<number>\d+)/.exec(value)?.groups?.number || null;
}

export function extractLabelsNumbers(molecules: InternalMolecule[]) {
export function extractLabelsNumbers(molecules: StateMoleculeExtended[]) {
const values: number[] = [];
for (const molecule of molecules) {
const value = extractNumber(molecule.label);
Expand Down
Loading

0 comments on commit 5819b74

Please sign in to comment.