Skip to content

Commit

Permalink
#1820 – removed modifiedStruct from templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Dec 5, 2022
1 parent e168b62 commit f9a4b36
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
41 changes: 25 additions & 16 deletions packages/ketcher-react/src/script/ui/component/structrender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,36 @@
import { Component, ComponentType, createRef } from 'react'
import { MolSerializer, Render, Struct } from 'ketcher-core'

/**
* for S-Groups we want to show expanded structure
* without brackets
*/
function prepareStruct(struct: Struct) {
if (struct.sgroups.size > 0) {
const newStruct = struct.clone()
newStruct.sgroups.delete(0)
return newStruct
}
return struct
}

function renderStruct(
el: HTMLElement | null,
struct: Struct | null,
options = {}
) {
if (el) {
if (struct) {
console.info('render!', el.clientWidth, el.clientWidth)
struct.initHalfBonds()
struct.initNeighbors()
struct.setImplicitHydrogen()
struct.markFragments()
const rnd = new Render(el, {
autoScale: true,
...options
})
rnd.setMolecule(struct)
rnd.update()
// console.info('render!');//, el.innerHTML);
// struct.prerender = el.innerHTML;
}
if (el && struct) {
const preparedStruct = prepareStruct(struct)
preparedStruct.initHalfBonds()
preparedStruct.initNeighbors()
preparedStruct.setImplicitHydrogen()
preparedStruct.markFragments()
const rnd = new Render(el, {
autoScale: true,
...options
})
rnd.setMolecule(preparedStruct)
rnd.update()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ interface TemplateLibProps {
selected: Template
mode: string
initialTab: number
saltsAndSolvents: (Template & { modifiedStruct: Struct })[]
saltsAndSolvents: Template[]
}

interface TemplateLibCallProps {
Expand All @@ -86,7 +86,7 @@ interface TemplateLibCallProps {
onFilter: (filter: string) => void
onOk: (res: any) => void
onSelect: (res: any) => void
functionalGroups: (Template & { modifiedStruct: Struct })[]
functionalGroups: Template[]
}

type Props = TemplateLibProps & TemplateLibCallProps
Expand Down Expand Up @@ -357,23 +357,12 @@ const TemplateDialog: FC<Props> = (props) => {
)
}

/*
Think, this is a kind of workaround for some logic.
Without it only names of structures are rendered in dialog
instead of chemical structure.
*/
const removeSgroup = (template) => {
const struct = template.struct.clone()
struct.sgroups.delete(0)
return { ...template, modifiedStruct: struct }
}

export default connect(
(store) => ({
...omit(['attach'], (store as any).templates),
initialTab: (store as any).modal?.prop?.tab,
functionalGroups: functionalGroupsSelector(store).map(removeSgroup),
saltsAndSolvents: saltsAndSolventsSelector(store).map(removeSgroup)
functionalGroups: functionalGroupsSelector(store),
saltsAndSolvents: saltsAndSolventsSelector(store)
}),
(dispatch: Dispatch<any>, props) => ({
onFilter: (filter) => dispatch(changeFilter(filter)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Icon from 'src/script/ui/component/view/icon'

export interface Template {
struct: Struct
modifiedStruct?: Struct // TODO: Do something with that, in future it shouldn't be here
props: {
atomid: number
bondid: number
Expand Down Expand Up @@ -70,7 +69,7 @@ const RenderTmpl: FC<{
}> = ({ tmpl, options, ...props }) => {
return (
<StructRender
struct={tmpl.modifiedStruct || tmpl.struct}
struct={tmpl.struct}
options={{ ...options, autoScaleMargin: 15 }}
{...props}
/>
Expand Down

0 comments on commit f9a4b36

Please sign in to comment.