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

IBX-9170: AI Assistant #1385

Open
wants to merge 11 commits into
base: 4.6
Choose a base branch
from
Open

IBX-9170: AI Assistant #1385

wants to merge 11 commits into from

Conversation

GrabowskiM
Copy link
Contributor

@GrabowskiM GrabowskiM commented Oct 30, 2024

🎫 Issue IBX-9170

Description:

This PR provides two reusable react components - draggable dialog (that will be used for AI assistant) and popup menu (based a little on dropdown component, using similar styles as popup menu from vanilla JS)

For QA:

Documentation:

@GrabowskiM GrabowskiM marked this pull request as draft October 30, 2024 14:15
@GrabowskiM GrabowskiM changed the title AI Assistant IBX-9170: AI Assistant Nov 7, 2024
@GrabowskiM GrabowskiM marked this pull request as ready for review November 7, 2024 16:37
@GrabowskiM GrabowskiM marked this pull request as draft November 13, 2024 08:08
@GrabowskiM GrabowskiM marked this pull request as ready for review November 19, 2024 16:05
onClose: () => {},
onItemClick: () => {},
positionOffset: () => ({ x: 0, y: 0 }),
scrollContainer: window.document.body,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&__item-content {
position: relative;
display: flex;
align-items: center;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated align-items

cursor: pointer;
padding: calculateRem(9px);
color: $ibexa-color-dark;
font-size: calculateRem(14px);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have variable for font-size

&:disabled,
&--disabled {
pointer-events: none;
cursor: not-allowed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointer-events: none and cursor: not-allowed, is it working together?


useEffect(() => {
if (isDragging) {
rootDOMElement.addEventListener('mousemove', handleDragging);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rootDOMElement.addEventListener('mousemove', handleDragging);
rootDOMElement.addEventListener('mousemove', handleDragging, false);

just for consistency

return null;
}

const groupClassName = createCssClassNames({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should use createCssClassNames because this it's only one class and it's not conditional

@@ -0,0 +1,24 @@
const createDynamicRoot = (contextDOMElement = window.document.body, id) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window.document.body you can get this object by function getRootDOMElement from https://github.com/ibexa/admin-ui/blob/main/src/bundle/Resources/public/js/scripts/helpers/context.helper.js. We will avoid possible problems in the future if this code is used outside DXP

onClose();
};

window.document.body.addEventListener('click', onInteractionOutside, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use getRootDOMElement

scrollContainer.addEventListener('scroll', calculateAndSetItemsListStyles, false);

return () => {
window.document.body.removeEventListener('click', onInteractionOutside);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use getRootDOMElement

import { getRootDOMElement } from './context.helper';

const createDynamicRoot = ({ contextDOMElement = getRootDOMElement(), id } = {}) => {
if (id && contextDOMElement.querySelector(`#${id}`) !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: getElementById seems to be simpler

Suggested change
if (id && contextDOMElement.querySelector(`#${id}`) !== null) {
if (id && contextDOMElement.getElementById(id) !== null) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getElementById exists only on document and here we have any possible element (currently - body), so I can't use it.

But at the same time, instead of contextDOMElement I can use just window.document, id has to be unique anyway...

const DraggableDialog = ({ children, referenceElement, positionOffset }) => {
const rootDOMElement = getRootDOMElement();
const containerRef = useRef();
const dragOffsetPosition = useRef({ x: 0, y: 0 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the react state too slow or were there other problems with it? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other problems - this variable is used in drag handlers - it's recalculated (and also used) on mousemove event, which keeps state from moment when drag started, so too old for its purpose.

rootDOMElement.removeEventListener('mousemove', handleDragging);
rootDOMElement.removeEventListener('mouseup', stopDragging);
};
}, [isDragging]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}, [isDragging]);
}, [isDragging, handleDragging, stopDragging]);

Comment on lines 91 to 99
if (isDragging) {
rootDOMElement.addEventListener('mousemove', handleDragging, false);
rootDOMElement.addEventListener('mouseup', stopDragging, false);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to return a callback which removes listeners if they have not been added.

Suggested change
if (isDragging) {
rootDOMElement.addEventListener('mousemove', handleDragging, false);
rootDOMElement.addEventListener('mouseup', stopDragging, false);
}
if (!isDragging) {
return;
}
rootDOMElement.addEventListener('mousemove', handleDragging, false);
rootDOMElement.addEventListener('mouseup', stopDragging, false);

x,
y,
});
}, [referenceElement]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing hook's dependencies.


setItemsListStyles({});
};
}, [onClose, scrollContainer]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dependencies.


setItemsListStyles(itemsStyles);
};
const renderSearch = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can split this component into smaller ones? WDYT?

Copy link

sonarcloud bot commented Dec 11, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants