Skip to content

Commit

Permalink
#3580 - Macro: fix issue with not re-rendering svg
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariia_Khrustaleva(EPAM) authored and Mariia_Khrustaleva(EPAM) committed Nov 30, 2023
1 parent 0e46abc commit 8f77d3b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const StyledStructRender = styled(StructRender)(({ theme }) => ({
'& svg': {
maxWidth: 'fit-content',
margin: 'auto',
padding: '4px',
},
}));

Expand Down Expand Up @@ -87,6 +88,7 @@ const MonomerConnection = ({
useState<string | null>(getDefaultAttachmentPoint(firstMonomer));
const [secondSelectedAttachmentPoint, setSecondSelectedAttachmentPoint] =
useState<string | null>(getDefaultAttachmentPoint(secondMonomer));
const [modalExpanded, setModalExpanded] = useState(false);

const cancelBondCreationAndClose = () => {
editor.events.cancelBondCreationViaModal.dispatch(secondMonomer);
Expand Down Expand Up @@ -114,6 +116,9 @@ const MonomerConnection = ({
isOpen={isModalOpen}
onClose={cancelBondCreationAndClose}
showExpandButton
modalWidth="350px"
expanded={modalExpanded}
setExpanded={setModalExpanded}
>
<Modal.Content>
<ModalContent>
Expand All @@ -123,6 +128,7 @@ const MonomerConnection = ({
monomer={firstMonomer}
selectedAttachmentPoint={firstSelectedAttachmentPoint}
onSelectAttachmentPoint={setFirstSelectedAttachmentPoint}
expanded={modalExpanded}
/>
<span />
<ConnectionSymbol />
Expand All @@ -133,6 +139,7 @@ const MonomerConnection = ({
monomer={secondMonomer}
selectedAttachmentPoint={secondSelectedAttachmentPoint}
onSelectAttachmentPoint={setSecondSelectedAttachmentPoint}
expanded={modalExpanded}
/>
</AttachmentPointsRow>
</ModalContent>
Expand Down Expand Up @@ -160,12 +167,14 @@ interface AttachmentPointSelectionPanelProps {
monomer: BaseMonomer;
selectedAttachmentPoint: string | null;
onSelectAttachmentPoint: (attachmentPoint: string) => void;
expanded?: boolean;
}

function AttachmentPointSelectionPanel({
monomer,
selectedAttachmentPoint,
onSelectAttachmentPoint,
expanded = false,
}: AttachmentPointSelectionPanelProps): React.ReactElement {
const bonds = monomer.attachmentPointsToBonds;

Expand All @@ -192,7 +201,9 @@ function AttachmentPointSelectionPanel({
currentlySelectedMonomerAttachmentPoint:
selectedAttachmentPoint ?? undefined,
labelInMonomerConnectionsModal: true,
needCache: false,
}}
update={expanded}
/>
<AttachmentPointList>
{monomer.listOfAttachmentPoints.map((attachmentPoint, i) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const MonomerName = styled.div(({ theme }) => ({
font: theme.ketcher.font.family.inter,
fontSize: theme.ketcher.font.size.regular,
fontWeight: theme.ketcher.font.weight.regular,
width: '150px',
flexBasis: '200px',
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Icon } from 'ketcher-react';
import { scrollbarThin } from 'theming/mixins';
import { EmptyFunction } from 'helpers/emptyFunction';

interface ModalProps {
children: JSX.Element | Array<JSX.Element>;
Expand All @@ -20,6 +21,8 @@ interface ModalProps {
onClose: VoidFunction;
className?: string;
modalWidth?: string;
expanded?: boolean;
setExpanded?: (boolean) => void;
}
const StyledDialog = styled(Dialog)`
.MuiPaper-root {
Expand Down Expand Up @@ -86,9 +89,10 @@ export const Modal = ({
onClose,
className,
modalWidth,
expanded = false,
setExpanded = EmptyFunction,
}: ModalProps) => {
const theme = useTheme();
const [expanded, setExpanded] = React.useState(false);

const paperProps = useMemo(
() => ({
Expand All @@ -97,6 +101,7 @@ export const Modal = ({
borderRadius: '8px',
color: theme.ketcher.color.text.primary,
...(showExpandButton && {
margin: 'auto',
width: expanded ? '100%' : modalWidth,
height: expanded ? '100%' : undefined,
maxWidth: 'calc(min(1280px, 100%))',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const normalizeStruct = (molV2000StringOrStruct: string | Struct) => {
}
};

const StructRender = ({ struct, options, className }: IStructRenderProps) => {
const StructRender = ({
struct,
options,
className,
update,
}: IStructRenderProps) => {
const renderRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const container = renderRef.current;
Expand All @@ -47,7 +52,7 @@ const StructRender = ({ struct, options, className }: IStructRenderProps) => {
const normalizedStruct = normalizeStruct(struct);
RenderStruct.render(container, normalizedStruct, options);
}
}, [struct, options]);
}, [struct, options, update]);

return <Container ref={renderRef} className={className}></Container>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface IStructRenderProps {
struct: Struct;
options?: RenderOptions & { cachePrefix?: string; needCache?: boolean };
className?: string;
update?: boolean;
}

0 comments on commit 8f77d3b

Please sign in to comment.