-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1820 – adding salts and solvents tab
- Loading branch information
Showing
9 changed files
with
4,965 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/ketcher-core/src/domain/helpers/saltsAndSolventsProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/**************************************************************************** | ||
* Copyright 2021 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
***************************************************************************/ | ||
import { Struct } from '../entities' | ||
|
||
export class SaltsAndSolventsProvider { | ||
// eslint-disable-next-line no-use-before-define | ||
private static instance: SaltsAndSolventsProvider | ||
saltsAndSolventsList: Struct[] | ||
constructor() { | ||
this.saltsAndSolventsList = [] | ||
} | ||
|
||
public static getInstance(): SaltsAndSolventsProvider { | ||
if (!SaltsAndSolventsProvider.instance) { | ||
SaltsAndSolventsProvider.instance = new SaltsAndSolventsProvider() | ||
} | ||
return SaltsAndSolventsProvider.instance | ||
} | ||
|
||
public getSaltsAndSolventsList() { | ||
return this.saltsAndSolventsList | ||
} | ||
|
||
public setSaltsAndSolventsList(list: Struct[]): void { | ||
this.saltsAndSolventsList = list | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/ketcher-react/src/script/ui/state/saltsAndSolvents/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/**************************************************************************** | ||
* Copyright 2021 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
***************************************************************************/ | ||
|
||
import { AnyAction } from 'redux' | ||
import { appUpdate } from '../options' | ||
import { | ||
SaltsAndSolventsProvider, | ||
SdfItem, | ||
SdfSerializer, | ||
Struct | ||
} from 'ketcher-core' | ||
import { prefetchStatic } from '../templates/init-lib' | ||
|
||
interface SaltsAndSolventsState { | ||
lib: [] | ||
mode: string | ||
} | ||
|
||
const initialState: SaltsAndSolventsState = { | ||
lib: [], | ||
mode: 'saltsAndSolvents' | ||
} | ||
|
||
const saltsAndSolventsReducer = ( | ||
state = initialState, | ||
{ type, payload }: AnyAction | ||
) => { | ||
switch (type) { | ||
case 'SALTS_AND_SOLVENTS_INIT': | ||
return { ...state, ...payload } | ||
|
||
default: | ||
return state | ||
} | ||
} | ||
|
||
const initSaltsAndSolvents = (lib: SdfItem[]) => ({ type: 'SALTS_AND_SOLVENTS_INIT', payload: { lib } }) | ||
|
||
export function initSaltsAndSolventsTemplates(baseUrl: string) { | ||
return async (dispatch) => { | ||
const fileName = 'salts-and-solvents.sdf' | ||
const url = `${baseUrl}/templates/${fileName}` | ||
const provider = SaltsAndSolventsProvider.getInstance() | ||
const sdfSerializer = new SdfSerializer() | ||
const text = await prefetchStatic(url) | ||
const templates = sdfSerializer.deserialize(text) | ||
const saltsAndSolvents = templates.reduce( | ||
(acc: Struct[], { struct }) => [...acc, struct], | ||
[] | ||
) | ||
provider.setSaltsAndSolventsList(saltsAndSolvents) | ||
dispatch(initSaltsAndSolvents(templates)) | ||
dispatch(appUpdate({ saltsAndSolvents: true })) | ||
} | ||
} | ||
|
||
export default saltsAndSolventsReducer | ||
|
21 changes: 21 additions & 0 deletions
21
packages/ketcher-react/src/script/ui/state/saltsAndSolvents/selectors/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/**************************************************************************** | ||
* Copyright 2021 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
***************************************************************************/ | ||
|
||
export const saltsAndSolventsSelector = (state) => { | ||
console.log('selector called ', state); | ||
return state.saltsAndSolvents.lib | ||
} | ||
|