Skip to content

Commit

Permalink
🐛 DOP-4363 fixes bug for submitting a feedback with a screenshot (#1043)
Browse files Browse the repository at this point in the history
Co-authored-by: Caesar Bell <[email protected]>
  • Loading branch information
caesarbell and Caesar Bell authored Mar 20, 2024
1 parent 8456123 commit b623b6f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
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);

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;
},
};

0 comments on commit b623b6f

Please sign in to comment.