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

#4615 – implement sorting for rna builder components #4643

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
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
Loading