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

#1276 Template with simple objects are incorrect after refresh #1287

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export class KetSerializer implements Serializer<Struct> {
if (!validate(ket)) {
throw new Error('Cannot deserialize input JSON.')
}
resultingStruct.name = ket.header ? ket.header.moleculeName : null
const nodes = ket.root.nodes
Object.keys(nodes).forEach((i) => {
if (nodes[i].type) parseNode(nodes[i], resultingStruct)
else if (nodes[i].$ref) parseNode(ket[nodes[i].$ref], resultingStruct)
})
resultingStruct.name = ket.header ? ket.header.moleculeName : null

return resultingStruct
}
Expand Down
11 changes: 11 additions & 0 deletions packages/ketcher-core/src/domain/serializers/ket/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@
},
"^mol\\d+": {
"$ref": "#/definitions/molecule"
},
"^header$": {
"$ref": "#/definitions/header"
}
},
"additionalProperties": false,
"definitions": {
"header": {
"type": "object",
"properties": {
"moleculeName": {
"type": "string"
}
}
},
"rsite": {
"type": "object",
"required": ["type", "location"],
Expand Down
6 changes: 3 additions & 3 deletions packages/ketcher-react/src/script/ui/state/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import initTmplLib, { initLib } from './init-lib'

import { MolSerializer } from 'ketcher-core'
import { KetSerializer } from 'ketcher-core'
import { omit } from 'lodash/fp'
import { openDialog } from '../modal'
import { storage } from '../../storage-ext'
Expand Down Expand Up @@ -130,11 +130,11 @@ export function saveUserTmpl(struct) {
}

function updateLocalStore(lib) {
const molSerializer = new MolSerializer()
const ketSerializer = new KetSerializer()
const userLib = lib
.filter((item) => item.props.group === 'User Templates')
.map((item) => ({
struct: molSerializer.serialize(item.struct),
struct: ketSerializer.serialize(item.struct),
props: Object.assign({}, omit(['group'], item.props))
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
***************************************************************************/

import { MolSerializer, SdfSerializer } from 'ketcher-core'
import { KetSerializer, SdfSerializer } from 'ketcher-core'

import { appUpdate } from '../options'
import { storage } from '../../storage-ext'
Expand Down Expand Up @@ -57,15 +57,15 @@ const deserializeSdfTemplates = (baseUrl, cacheEl, fileName) => {
function userTmpls() {
const userLib = storage.getItem('ketcher-tmpls')
if (!Array.isArray(userLib) || userLib.length === 0) return []
const molSerializer = new MolSerializer()
const ketSerializer = new KetSerializer()
return userLib
.map((tmpl) => {
try {
if (tmpl.props === '') tmpl.props = {}
tmpl.props.group = 'User Templates'

return {
struct: molSerializer.deserialize(tmpl.struct),
struct: ketSerializer.deserialize(tmpl.struct),
props: tmpl.props
}
} catch (ex) {
Expand Down