Skip to content

Commit

Permalink
Merge pull request #4643 from epam/4615-sorting-is-absent-for-rna-bui…
Browse files Browse the repository at this point in the history
…lder-components-sugar-base-phosphates

#4615 – Implemented sorting for RNA builder components
  • Loading branch information
svvald authored May 23, 2024
2 parents 242004a + 0d62f33 commit 513d3c5
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 14 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 36 additions & 14 deletions packages/ketcher-macromolecules/src/state/library/librarySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,50 @@ export const selectMonomers = (state: RootState) => {
};

export const selectMonomerGroups = (monomers: MonomerItemType[]) => {
const preparedData = monomers.reduce((result, monomerItem) => {
// separate monomers by NaturalAnalogCode
const code = monomerItem.props.MonomerNaturalAnalogCode;
if (!result[code]) {
result[code] = [];
}
result[code].push({
...monomerItem,
label: monomerItem.props.MonomerName,
});
return result;
}, {});
const preparedData: Record<string, MonomerItemType[]> = monomers.reduce(
(result, monomerItem) => {
// separate monomers by NaturalAnalogCode
const code = monomerItem.props.MonomerNaturalAnalogCode;
if (!result[code]) {
result[code] = [];
}
result[code].push({
...monomerItem,
label: monomerItem.props.MonomerName,
});
return result;
},
{},
);

const sortedPreparedData = Object.entries(preparedData).reduce(
(result, [code, monomers]) => {
const sortedMonomers = monomers.sort((a, b) =>
a.label.localeCompare(b.label),
);
const baseIndex = sortedMonomers.findIndex(
(monomer) => monomer.label === code,
);
if (baseIndex !== -1) {
const base = sortedMonomers.splice(baseIndex, 1);
sortedMonomers.unshift(base[0]);
}
result[code] = sortedMonomers;
return result;
},
{},
);

// generate list of monomer groups
const preparedGroups: Group[] = [];
return Object.keys(preparedData)
return Object.keys(sortedPreparedData)
.sort()
.reduce((result, code) => {
const group: Group = {
groupTitle: code,
groupItems: [],
};
preparedData[code].forEach((item: MonomerItemType) => {
sortedPreparedData[code].forEach((item: MonomerItemType) => {
group.groupItems.push({
...item,
props: { ...item.props },
Expand Down

0 comments on commit 513d3c5

Please sign in to comment.