Skip to content

Commit

Permalink
- fixed types
Browse files Browse the repository at this point in the history
  • Loading branch information
rrodionov91 committed Sep 1, 2024
1 parent 38b7e0a commit 29ff826
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 74 deletions.
17 changes: 10 additions & 7 deletions packages/ketcher-macromolecules/src/EditorEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
***************************************************************************/
import { useCallback, useEffect } from 'react';
import {
AmbiguousMonomerPreviewState,
BondPreviewState,
MonomerPreviewState,
PresetPosition,
PresetPreviewState,
selectEditor,
selectEditorActiveTool,
selectTool,
Expand All @@ -37,6 +32,7 @@ import {
BaseMonomer,
Nucleoside,
Nucleotide,
PolymerBond,
} from 'ketcher-core';
import {
calculateAmbiguousMonomerPreviewLeft,
Expand All @@ -46,8 +42,15 @@ import {
calculateNucleoElementPreviewTop,
} from 'helpers';
import { selectAllPresets } from 'state/rna-builder';
import { PolymerBond } from 'ketcher-core/dist/domain/entities/PolymerBond';
import { PreviewStyle, PreviewType } from 'state/types';
import {
AmbiguousMonomerPreviewState,
BondPreviewState,
MonomerPreviewState,
PresetPosition,
PresetPreviewState,
PreviewStyle,
PreviewType,
} from 'state/types';

const noPreviewTools = ['bond-single'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ import {
GroupContainerRow,
ItemsContainer,
} from 'components/monomerLibrary/monomerLibraryGroup/styles';
import {
AmbiguousMonomerPreviewState,
PresetPosition,
PresetPreviewState,
selectEditor,
selectShowPreview,
showPreview,
} from 'state/common';
import { selectEditor, selectShowPreview, showPreview } from 'state/common';
import { RNAContextMenu } from 'components/contextMenu/RNAContextMenu';
import { CONTEXT_MENU_ID } from 'components/contextMenu/types';
import { useContextMenu } from 'react-contexify';
import { IRnaPreset } from '../RnaBuilder/types';
import { PreviewType } from 'state';
import {
AmbiguousMonomerPreviewState,
PresetPosition,
PresetPreviewState,
PreviewType,
} from 'state';

export const RnaPresetGroup = ({ presets, duplicatePreset, editPreset }) => {
const activePreset = useAppSelector(selectActivePreset);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AmbiguousMonomerPreviewState } from '../../../../state/common';
import { useMemo } from 'react';
import styled from '@emotion/styled';
import {
Expand All @@ -8,6 +7,10 @@ import {
Header,
RatioBar,
} from './AmbiguousMonomerPreview.styles';
// Usage of aliases instead of relative import path causes error in the following import
// because this component used directly from ketcher-react package and there are no such aliases in that package.
// It needs to create shared components library and use it in both packages.
import { AmbiguousMonomerPreviewState } from '../../../../state/types';

interface Props {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import styled from '@emotion/styled';
import { useMemo } from 'react';
import { useAppSelector } from 'hooks';
import { BondPreviewState, selectShowPreview } from 'state/common';
import { selectShowPreview } from 'state/common';
import ConnectionOverview from 'components/shared/ConnectionOverview/ConnectionOverview';
import MonomerOverview from 'components/shared/ConnectionOverview/components/MonomerOverview/MonomerOverview';
import { useAttachmentPoints } from '../../hooks/useAttachmentPoints';
import { Container } from './BondPreview.styles';
import BondAttachmentPoints from 'components/preview/components/BondAttachmentPoints/BondAttachmentPoints';
import { preview } from '../../../../constants';
import { UsageInMacromolecule } from 'ketcher-core';
import { BondPreviewState } from 'state';

interface Props {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
StyledStructRender,
} from './MonomerPreview.styles';
import styled from '@emotion/styled';
import { MonomerPreviewState, selectShowPreview } from 'state/common';
import { selectShowPreview } from 'state/common';
import { useAppSelector } from 'hooks';
import { useAttachmentPoints } from '../../hooks/useAttachmentPoints';
import useIDTAliasesTextForMonomer from '../../hooks/useIDTAliasesTextForMonomer';
Expand All @@ -31,6 +31,7 @@ import AttachmentPoints from '../AttachmentPoints/AttachmentPoints';
import IDTAliases from '../IDTAliases/IDTAliases';
import { preview } from '../../../../constants';
import { UsageInMacromolecule } from 'ketcher-core';
import { MonomerPreviewState } from 'state';

interface Props {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import {
} from './PresetPreview.styles';
import { preview } from '../../../../constants';
import styled from '@emotion/styled';
import { PresetPreviewState, selectShowPreview } from 'state/common';
import { selectShowPreview } from 'state/common';
import { IconName } from 'ketcher-react';
import useIDTAliasesTextForPreset from '../../hooks/useIDTAliasesTextForPreset';
import { useAppSelector } from 'hooks';
import IDTAliases from '../IDTAliases/IDTAliases';
import { PresetPreviewState } from 'state';

const icons: Extract<IconName, 'sugar' | 'base' | 'phosphate'>[] = [
'sugar',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IKetIdtAliases } from 'ketcher-core';
import { useMemo } from 'react';
import { PresetPosition } from 'state/common';

import { PresetPosition } from 'state';

type Props = {
presetName: string | undefined;
Expand Down
56 changes: 3 additions & 53 deletions packages/ketcher-macromolecules/src/state/common/editorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,12 @@
***************************************************************************/

import { createSlice, PayloadAction, Slice } from '@reduxjs/toolkit';
import {
AmbiguousMonomerType,
AttachmentPointsToBonds,
CoreEditor,
IKetIdtAliases,
MonomerItemType,
PolymerBond,
} from 'ketcher-core';
import { RootState } from 'state';
import { PreviewStyle, PreviewType } from 'state/types';
import { CoreEditor } from 'ketcher-core';
import { EditorStatePreview, RootState } from 'state';
import { PreviewType } from 'state/types';
import { ThemeType } from 'theming/defaultTheme';
import { DeepPartial } from '../../types';

interface BasePreviewState {
readonly type: PreviewType;
readonly style?: PreviewStyle;
}

export interface MonomerPreviewState extends BasePreviewState {
readonly type: PreviewType.Monomer;
readonly monomer: MonomerItemType | undefined;
readonly attachmentPointsToBonds?: AttachmentPointsToBonds;
}

export enum PresetPosition {
Library = 'library',
ChainStart = 'chainStart',
ChainMiddle = 'chainMiddle',
ChainEnd = 'chainEnd',
}

export interface PresetPreviewState extends BasePreviewState {
readonly type: PreviewType.Preset;
readonly monomers: ReadonlyArray<MonomerItemType | undefined>;
readonly position: PresetPosition;
readonly name?: string;
readonly idtAliases?: IKetIdtAliases;
}

export interface BondPreviewState extends BasePreviewState {
readonly type: PreviewType.Bond;
readonly polymerBond: PolymerBond;
}

export interface AmbiguousMonomerPreviewState extends BasePreviewState {
readonly type: PreviewType.AmbiguousMonomer;
readonly monomer: AmbiguousMonomerType;
readonly presetMonomers?: ReadonlyArray<MonomerItemType | undefined>;
}

export type EditorStatePreview =
| MonomerPreviewState
| PresetPreviewState
| BondPreviewState
| AmbiguousMonomerPreviewState;

// TODO: Looks like we do not use `isReady`. Delete?
interface EditorState {
isReady: boolean | null;
Expand Down
51 changes: 51 additions & 0 deletions packages/ketcher-macromolecules/src/state/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
AmbiguousMonomerType,
AttachmentPointsToBonds,
IKetIdtAliases,
MonomerItemType,
PolymerBond,
} from 'ketcher-core';

export enum PreviewType {
Monomer = 'monomer',
Preset = 'preset',
Expand All @@ -11,3 +19,46 @@ export interface PreviewStyle {
readonly right?: string;
readonly transform?: string;
}

interface BasePreviewState {
readonly type: PreviewType;
readonly style?: PreviewStyle;
}

export interface MonomerPreviewState extends BasePreviewState {
readonly type: PreviewType.Monomer;
readonly monomer: MonomerItemType | undefined;
readonly attachmentPointsToBonds?: AttachmentPointsToBonds;
}

export enum PresetPosition {
Library = 'library',
ChainStart = 'chainStart',
ChainMiddle = 'chainMiddle',
ChainEnd = 'chainEnd',
}

export interface PresetPreviewState extends BasePreviewState {
readonly type: PreviewType.Preset;
readonly monomers: ReadonlyArray<MonomerItemType | undefined>;
readonly position: PresetPosition;
readonly name?: string;
readonly idtAliases?: IKetIdtAliases;
}

export interface BondPreviewState extends BasePreviewState {
readonly type: PreviewType.Bond;
readonly polymerBond: PolymerBond;
}

export interface AmbiguousMonomerPreviewState extends BasePreviewState {
readonly type: PreviewType.AmbiguousMonomer;
readonly monomer: AmbiguousMonomerType;
readonly presetMonomers?: ReadonlyArray<MonomerItemType | undefined>;
}

export type EditorStatePreview =
| MonomerPreviewState
| PresetPreviewState
| BondPreviewState
| AmbiguousMonomerPreviewState;

0 comments on commit 29ff826

Please sign in to comment.