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

🐛 DOP-4363 fixes bug for submitting a feedback with a screenshot #1043

Merged
merged 5 commits into from
Mar 20, 2024
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
9 changes: 8 additions & 1 deletion src/components/Widgets/FeedbackWidget/FeedbackCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { theme } from '../../../../src/theme/docsTheme';
import useScreenSize from '../../../hooks/useScreenSize';
import useStickyTopValues from '../../../hooks/useStickyTopValues';
import { InstruqtContext } from '../../Instruqt/instruqt-context';
import { elementZIndex } from '../../../utils/dynamically-set-z-index';
import ProgressBar from './components/PageIndicators';
import CloseButton from './components/CloseButton';
import { useFeedbackContext } from './context';
Expand Down Expand Up @@ -52,11 +53,17 @@ const FeedbackCard = ({ isOpen, children }) => {
const { topSmall } = useStickyTopValues();
useNoScroll(isMobile);

const onClose = () => {
abandon();
// reset the z-index set by the screenshot button in ScreenshotButton.js
elementZIndex.resetZIndex('.widgets');
};

return (
isOpen && (
<FloatingContainer top={topSmall} id={feedbackId} hasOpenLabDrawer={isLabOpen}>
<Card top={topSmall}>
<CloseButton onClick={() => abandon()} />
<CloseButton onClick={onClose} />
<ProgressBar />
<div>{children}</div>
</Card>
Expand Down
2 changes: 0 additions & 2 deletions src/components/Widgets/FeedbackWidget/FeedbackForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { css, cx } from '@leafygreen-ui/emotion';
import Loadable from '@loadable/component';
import { createPortal } from 'react-dom';
import useScreenSize from '../../../hooks/useScreenSize';
import { theme } from '../../../theme/docsTheme';
import { useFeedbackContext } from './context';
import FeedbackCard from './FeedbackCard';
import RatingView from './views/RatingView';
Expand All @@ -21,7 +20,6 @@ export const FeedbackContent = ({ view }) => {

const formStyle = css`
position: relative;
z-index: ${theme.zIndexes.widgets};
`;

const FeedbackForm = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isBrowser } from '../../../../utils/is-browser';
import useNoScroll from '../hooks/useNoScroll';
import { theme } from '../../../../theme/docsTheme';
import { SCREENSHOT_BUTTON_TEXT, SCREENSHOT_OVERLAY_ALT_TEXT } from '../constants';
import { elementZIndex } from '../../../../utils/dynamically-set-z-index';

const HIGHLIGHT_BORDER_SIZE = 5;

Expand Down Expand Up @@ -182,6 +183,7 @@ const ScreenshotButton = ({ size = 'default', ...props }) => {
setIsScreenshotButtonClicked(true);
domElementClickedRef.current = 'dashed';
setSelectedElementBorderStyle('dashed');
elementZIndex.resetZIndex('.widgets');
}, []);

// close out the instructions panel
Expand All @@ -197,11 +199,15 @@ const ScreenshotButton = ({ size = 'default', ...props }) => {
setIsScreenshotButtonClicked(false);
setCurrElemState(null);
setScreenshotTaken(false);
elementZIndex.resetZIndex('.widgets');
};

const handleDOMElementClick = (e) => {
e.preventDefault();

//conditionally set the z-index on the widget card when the screenshot is clicked
elementZIndex.setZIndex('.widgets', 14);
rayangler marked this conversation as resolved.
Show resolved Hide resolved

domElementClickedRef.current = 'solid';
setSelectedElementBorderStyle(domElementClickedRef.current);
setScreenshotTaken(true);
Expand Down
3 changes: 3 additions & 0 deletions src/components/Widgets/FeedbackWidget/views/CommentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EMAIL_PLACEHOLDER_TEXT,
FEEDBACK_SUBMIT_BUTTON_TEXT,
} from '../constants';
import { elementZIndex } from '../../../../utils/dynamically-set-z-index';
const ScreenshotButton = Loadable(() => import('../components/ScreenshotButton'));

const SubmitButton = styled(Button)`
Expand Down Expand Up @@ -106,6 +107,8 @@ const CommentView = () => {
const { isMobile } = useScreenSize();

const handleSubmit = async () => {
elementZIndex.resetZIndex('.widgets');

if (isValidEmail) {
if (screenshotTaken) {
const dataUri = await retrieveDataUri();
Expand Down
27 changes: 27 additions & 0 deletions src/utils/dynamically-set-z-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const elementZIndex = {
setZIndex: (selector, zIndex) => {
const ele = document.querySelector(selector);

if (!ele) {
console.error('selector not found');
return;
}

if (typeof zIndex !== 'number') {
console.error('z-index value has to be a number');
return;
}

document.querySelector(selector).style.zIndex = zIndex;
},
resetZIndex: (selector) => {
const ele = document.querySelector(selector);

if (!ele) {
console.error('selector not found');
return;
}

ele.style.zIndex = 0;
},
};
Loading