Skip to content

Commit

Permalink
Improved maintanance of popups visibility (cvat-ai#2809)
Browse files Browse the repository at this point in the history
* Manual handling of popovers visibility

* Updated version & changelog, added minor comments

* Removed extra user hook
  • Loading branch information
Boris Sekachev authored and kenu committed Feb 23, 2021
1 parent 5fdcfb5 commit 01b95d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped nuclio version to 1.5.16 (<https://github.com/openvinotoolkit/cvat/pull/2578>)
- All methods for interative segmentation accept negative points as well
- Persistent queue added to logstash (<https://github.com/openvinotoolkit/cvat/pull/2744>)
- Improved maintanance of popups visibility (<https://github.com/openvinotoolkit/cvat/pull/2809>)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.14.2",
"version": "1.14.3",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export default function withVisibilityHandling(WrappedComponent: typeof Popover,
return (props: PopoverProps): JSX.Element => {
const [initialized, setInitialized] = useState<boolean>(false);
const [visible, setVisible] = useState<boolean>(false);
let { overlayClassName } = props;
if (typeof overlayClassName !== 'string') overlayClassName = '';
const { overlayClassName, ...rest } = props;
const overlayClassNames = typeof overlayClassName === 'string' ? overlayClassName.split(/\s+/) : [];

overlayClassName += ` cvat-${popoverType}-popover`;
const popoverClassName = `cvat-${popoverType}-popover`;
overlayClassNames.push(popoverClassName);
if (visible) {
overlayClassName += ` cvat-${popoverType}-popover-visible`;
const visiblePopoverClassName = `cvat-${popoverType}-popover-visible`;
overlayClassNames.push(visiblePopoverClassName);
}

const callback = (event: Event): void => {
Expand All @@ -25,10 +27,19 @@ export default function withVisibilityHandling(WrappedComponent: typeof Popover,

return (
<WrappedComponent
{...props}
overlayClassName={overlayClassName.trim()}
{...rest}
trigger={visible ? 'click' : 'hover'}
overlayClassName={overlayClassNames.join(' ').trim()}
onVisibleChange={(_visible: boolean) => {
if (!_visible) setVisible(false);
if (!_visible) {
setVisible(false);
} else {
// Hide other popovers
const element = window.document.getElementsByClassName(`${popoverClassName}`)[0];
if (element) {
element.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
}
}
if (!initialized) {
const self = window.document.getElementsByClassName(`cvat-${popoverType}-popover`)[0];
self?.addEventListener('animationend', callback);
Expand Down

0 comments on commit 01b95d3

Please sign in to comment.