-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/navigation-phase-3
- Loading branch information
Showing
14 changed files
with
143 additions
and
66 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@rocket.chat/meteor': patch | ||
--- | ||
|
||
Fixes an issue where the retention policy warning keep displaying even if the retention is disabled inside the room |
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,5 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
--- | ||
|
||
Prevented uiInteraction to subscribe multiple times |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import { AnchorPortal } from '@rocket.chat/ui-client'; | ||
import type { ReactNode } from 'react'; | ||
import React, { memo, useEffect, useState } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
import React, { memo } from 'react'; | ||
|
||
import { createAnchor } from '../lib/utils/createAnchor'; | ||
import { deleteAnchor } from '../lib/utils/deleteAnchor'; | ||
const tooltipAnchorId = 'tooltip-root'; | ||
|
||
type TooltipPortalProps = { | ||
children?: ReactNode; | ||
}; | ||
|
||
const TooltipPortal = ({ children }: TooltipPortalProps) => { | ||
const [tooltipRoot] = useState(() => createAnchor('tooltip-root')); | ||
useEffect(() => (): void => deleteAnchor(tooltipRoot), [tooltipRoot]); | ||
return <>{createPortal(children, tooltipRoot)}</>; | ||
return <AnchorPortal id={tooltipAnchorId}>{children}</AnchorPortal>; | ||
}; | ||
|
||
export default memo(TooltipPortal); |
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 |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import { AnchorPortal } from '@rocket.chat/ui-client'; | ||
import type { ReactElement, ReactNode } from 'react'; | ||
import React, { memo, useEffect, useState } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
import React, { memo } from 'react'; | ||
|
||
import { createAnchor } from '../lib/utils/createAnchor'; | ||
import { deleteAnchor } from '../lib/utils/deleteAnchor'; | ||
const videoConfAnchorId = 'video-conf-root'; | ||
|
||
type VideoConfPortalProps = { | ||
children?: ReactNode; | ||
}; | ||
|
||
const VideoConfPortal = ({ children }: VideoConfPortalProps): ReactElement => { | ||
const [videoConfRoot] = useState(() => createAnchor('video-conf-root')); | ||
useEffect(() => (): void => deleteAnchor(videoConfRoot), [videoConfRoot]); | ||
return <>{createPortal(children, videoConfRoot)}</>; | ||
return <AnchorPortal id={videoConfAnchorId}>{children}</AnchorPortal>; | ||
}; | ||
|
||
export default memo(VideoConfPortal); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import AnchorPortal from './AnchorPortal'; | ||
|
||
it('should render children', () => { | ||
render(<AnchorPortal id='test-anchor' children={<div role='presentation' aria-label='example' />} />, { legacyRoot: true }); | ||
|
||
expect(screen.getByRole('presentation', { name: 'example' })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not recreate the anchor element', () => { | ||
render(<AnchorPortal id='test-anchor' children={<div role='presentation' aria-label='example A' />} />, { legacyRoot: true }); | ||
const anchorA = document.getElementById('test-anchor'); | ||
|
||
render(<AnchorPortal id='test-anchor' children={<div role='presentation' aria-label='example B' />} />, { legacyRoot: true }); | ||
const anchorB = document.getElementById('test-anchor'); | ||
|
||
expect(anchorA).toBe(anchorB); | ||
expect(screen.getByRole('presentation', { name: 'example A' })).toBeInTheDocument(); | ||
expect(screen.getByRole('presentation', { name: 'example B' })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should remove the anchor element when unmounted', () => { | ||
const { unmount } = render(<AnchorPortal id='test-anchor' children={<div role='presentation' aria-label='example' />} />, { | ||
legacyRoot: true, | ||
}); | ||
expect(document.getElementById('test-anchor')).toBeInTheDocument(); | ||
|
||
unmount(); | ||
expect(document.getElementById('test-anchor')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should not remove the anchor element after unmounting if there are other portals with the same id', () => { | ||
const { unmount } = render(<AnchorPortal id='test-anchor' children={<div role='presentation' aria-label='example' />} />, { | ||
legacyRoot: true, | ||
}); | ||
expect(document.getElementById('test-anchor')).toBeInTheDocument(); | ||
|
||
render(<AnchorPortal id='test-anchor' children={<div role='presentation' aria-label='example' />} />, { | ||
legacyRoot: true, | ||
}); | ||
unmount(); | ||
|
||
expect(document.getElementById('test-anchor')).toBeInTheDocument(); | ||
}); |
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,25 @@ | ||
import { ReactNode, useLayoutEffect } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
import { ensureAnchorElement, refAnchorElement, unrefAnchorElement } from '../helpers/anchors'; | ||
|
||
export type AnchorPortalProps = { | ||
id: string; | ||
children: ReactNode; | ||
}; | ||
|
||
const AnchorPortal = ({ id, children }: AnchorPortalProps) => { | ||
const anchorElement = ensureAnchorElement(id); | ||
|
||
useLayoutEffect(() => { | ||
refAnchorElement(anchorElement); | ||
|
||
return () => { | ||
unrefAnchorElement(anchorElement); | ||
}; | ||
}, [anchorElement]); | ||
|
||
return <>{createPortal(children, anchorElement)}</>; | ||
}; | ||
|
||
export default AnchorPortal; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export const ensureAnchorElement = (id: string): HTMLElement => { | ||
const existingAnchor = document.getElementById(id); | ||
if (existingAnchor) return existingAnchor; | ||
|
||
const newAnchor = document.createElement('div'); | ||
newAnchor.id = id; | ||
document.body.appendChild(newAnchor); | ||
return newAnchor; | ||
}; | ||
|
||
const getAnchorRefCount = (anchorElement: HTMLElement): number => { | ||
const { refCount } = anchorElement.dataset; | ||
if (refCount) return parseInt(refCount, 10); | ||
return 0; | ||
}; | ||
|
||
const setAnchorRefCount = (anchorElement: HTMLElement, refCount: number): void => { | ||
anchorElement.dataset.refCount = String(refCount); | ||
}; | ||
|
||
export const refAnchorElement = (anchorElement: HTMLElement): void => { | ||
setAnchorRefCount(anchorElement, getAnchorRefCount(anchorElement) + 1); | ||
}; | ||
|
||
export const unrefAnchorElement = (anchorElement: HTMLElement): void => { | ||
const refCount = getAnchorRefCount(anchorElement) - 1; | ||
setAnchorRefCount(anchorElement, refCount); | ||
|
||
if (refCount <= 0) { | ||
document.body.removeChild(anchorElement); | ||
} | ||
}; |