Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Remove popper when reset, change layout or component unmount #146

Merged
merged 2 commits into from
Jun 29, 2022
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
10 changes: 9 additions & 1 deletion src/apps/explorer/components/TransanctionBatchGraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ const updateLayout = (cy: Cytoscape.Core, layoutName: string, noAnimation = fals
cy.fit()
}

const removePopper = (popperInstance: React.MutableRefObject<PopperInstance | null>): void =>
popperInstance.current?.destroy()

function TransanctionBatchGraph({
txBatchData: { error, isLoading, txSettlement },
networkId,
Expand Down Expand Up @@ -308,6 +311,7 @@ function TransanctionBatchGraph({
if (resetZoom) {
updateLayout(cy, layout.name)
}
removePopper(cyPopperRef)
setResetZoom(null)
}, [error, isLoading, txSettlement, networkId, heightSize, resetZoom, layout.name])

Expand All @@ -329,7 +333,10 @@ function TransanctionBatchGraph({
})
cy.nodes().noOverlap({ padding: 5 })

return (): void => cy.removeAllListeners()
return (): void => {
cy.removeAllListeners()
removePopper(cyPopperRef)
}
}, [cytoscapeRef, elements.length])

if (isLoading)
Expand Down Expand Up @@ -366,6 +373,7 @@ function TransanctionBatchGraph({
dropdownButtonContentOpened={
<DropdownButtonContent icon={iconDice[currentLayoutIndex]} layout={LayoutNames[layout.name]} open />
}
callback={(): void => removePopper(cyPopperRef)}
items={Object.values(LayoutNames).map((layoutName) => (
<DropdownOption key={layoutName} onClick={(): void => setLayout(layouts[layoutName.toLowerCase()])}>
{layoutName}
Expand Down
7 changes: 5 additions & 2 deletions src/apps/explorer/components/common/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface DropdownProps extends DOMAttributes<HTMLDivElement> {
dropdownButtonContentOpened?: React.ReactNode | string
dropdownDirection?: DropdownDirection | undefined
dropdownPosition?: DropdownPosition | undefined
callback?: () => void
}

type CssString = FlattenSimpleInterpolation | string
Expand Down Expand Up @@ -107,18 +108,20 @@ export const Dropdown: React.FC<DropdownProps> = (props) => {
dropdownDirection,
dropdownPosition,
items,
callback,
} = props
const [isOpen, setIsOpen] = useState<boolean>(false)
const dropdownContainerRef = createRef<HTMLDivElement>()
useOnClickOutside(dropdownContainerRef, () => setIsOpen(false))

const onButtonClick = useCallback(
(e) => {
(e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation()
if (disabled) return
setIsOpen(!isOpen)
callback && callback()
},
[disabled, isOpen],
[callback, disabled, isOpen],
)

return (
Expand Down