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

[docs] Improve feedback precision #34641

Merged
merged 59 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
63319ac
first try
alexfauquette Oct 6, 2022
acd727e
customize a bit
alexfauquette Oct 10, 2022
f000559
remove context, only rely on event dispatch
alexfauquette Oct 11, 2022
8bd78cd
Only display buttons when feedback footer is available
alexfauquette Oct 11, 2022
3141e6d
add the hash to the slack message
alexfauquette Oct 11, 2022
56dfe02
manage undefined up/down vote
alexfauquette Oct 11, 2022
d787afc
Merge remote-tracking branch 'upstream/master' into improve-feedbacks
alexfauquette Oct 14, 2022
317907d
remove early thanks
alexfauquette Nov 2, 2022
3fff812
remove section selector
alexfauquette Nov 2, 2022
9915504
make the submit more visible
alexfauquette Nov 2, 2022
27fc469
fix accessibility
alexfauquette Nov 2, 2022
ef60d25
inline CSS
alexfauquette Nov 2, 2022
fa2da76
prettier
alexfauquette Nov 2, 2022
2534cda
Merge remote-tracking branch 'upstream/master' into improve-feedbacks
alexfauquette Nov 2, 2022
6940285
add a link to github issue
alexfauquette Nov 2, 2022
929eb2c
Apply suggestions from code review
alexfauquette Nov 2, 2022
11f33ad
wordings
alexfauquette Nov 9, 2022
36fd434
button alignments
alexfauquette Nov 9, 2022
f79b446
Merge remote-tracking branch 'upstream/master' into improve-feedbacks
alexfauquette Nov 15, 2022
0ea5e20
vertically align
alexfauquette Nov 15, 2022
bf5c0c1
feedbacks
alexfauquette Nov 15, 2022
40beb69
inver call to action and form actions
alexfauquette Nov 15, 2022
26de531
tweak layout
oliviertassinari Nov 20, 2022
a0bc9be
GitHub
oliviertassinari Nov 20, 2022
308595e
avoid style duplication and fix dark mode
oliviertassinari Nov 20, 2022
ec013b4
allow to reset to the whole page
oliviertassinari Nov 20, 2022
8e6a1d7
Merge branch 'master' into improve-feedbacks
oliviertassinari Nov 20, 2022
573facf
Alex's feedback, revert change
oliviertassinari Nov 21, 2022
02c4d0c
[website] Exclude experiment pages in production (#35180)
siriwatknp Nov 21, 2022
3f2e780
[website] Fix theme mode toggle state (#35216)
siriwatknp Nov 21, 2022
edfad73
Bump Font awesome SVG icons to ^6.2.1 (#35207)
renovate[bot] Nov 21, 2022
b9e220f
Bump @types/react-dom to ^18.0.9 (#35206)
renovate[bot] Nov 21, 2022
0d9dc7a
Bump @types/lodash to ^4.14.189 (#35205)
renovate[bot] Nov 21, 2022
1d0c387
Bump @chakra-ui/system to ^2.3.3 (#35204)
renovate[bot] Nov 21, 2022
4f373b9
Bump webpack to ^5.75.0 (#35128)
renovate[bot] Nov 21, 2022
5ff07ba
Bump typescript-eslint to ^5.43.0 (#35127)
renovate[bot] Nov 21, 2022
91a5f74
Bump marked to ^4.2.3 (#35126)
renovate[bot] Nov 21, 2022
85a40ba
Bump danger to ^11.2.0 (#35124)
renovate[bot] Nov 21, 2022
1a4156a
Bump cimg/node Docker tag to v14.21 (#35123)
renovate[bot] Nov 21, 2022
c7f70a8
Bump aws-sdk to ^2.1258.0 (#35121)
renovate[bot] Nov 21, 2022
d921f78
Bump postcss to ^8.4.19 (#35119)
renovate[bot] Nov 21, 2022
b3067cf
Bump loader-utils from 2.0.3 to 2.0.4 (#35186)
dependabot[bot] Nov 21, 2022
4767ba7
[website] Add Security questionnaire in pricing (#35172)
oliviertassinari Nov 21, 2022
5d79e10
Bump babel-loader to ^8.3.0 (#35122)
renovate[bot] Nov 21, 2022
a1e5c37
Bump theme-ui to ^0.15.4 (#35120)
renovate[bot] Nov 21, 2022
cca882e
[docs] Fix confusion in TOCs when reaching scroll bottom (#35214)
oliviertassinari Nov 21, 2022
f9a8b86
[Joy] Uplift introduction demos & make consistent with Base (#34316)
danilo-leal Nov 21, 2022
9a2d5d4
[icons] Update the Material Design icons (#35194)
michaldudak Nov 21, 2022
f409f94
[l10n] Add Urdu (ur-PK) locale (#35154)
MBilalShafi Nov 21, 2022
12d631a
[Material You] Add theme structure & Button component (#34650)
mnajdova Nov 21, 2022
447d0a9
[docs] Change MUI -> Material UI in icons-material's readme (#35220)
michaldudak Nov 21, 2022
4a1af80
Convert icons scripts to ESM (#35101)
Janpot Nov 21, 2022
52a26f2
[Autocomplete] Fix keyboard navigation when using custom popover (#35…
sai6855 Nov 21, 2022
14304e3
[docs] Fix a couple documentation errors (#35217)
danilo-leal Nov 22, 2022
ff98e23
5.10.15 (#35221)
siriwatknp Nov 22, 2022
3e21bc0
typo fix
alexfauquette Nov 22, 2022
e8e009b
Olivier feedbacks
alexfauquette Nov 22, 2022
bd63ff8
Merge remote-tracking branch 'upstream/master' into improve-feedbacks
alexfauquette Nov 23, 2022
fe883b2
make template customizable
alexfauquette Nov 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ function createRender(context) {
`<a aria-labelledby="${hash}" class="anchor-link-style" href="#${hash}" tabindex="-1">`,
'<svg><use xlink:href="#anchor-link-icon" /></svg>',
'</a>',
`<button class="comment-link-style" data-feedback-hash="${hash}">`,
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
'<svg><use xlink:href="#comment-link-icon" /></svg>',
`</button>`,
`</h${level}>`,
].join('');
};
Expand Down Expand Up @@ -458,6 +461,11 @@ ${headers.components
<symbol id="anchor-link-icon" viewBox="0 0 16 16">
<path d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z" />
</symbol>
</svg>`);
rendered.unshift(`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
<symbol id="comment-link-icon" viewBox="0 0 24 24">
<path d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 14v-2.47l6.88-6.88c.2-.2.51-.2.71 0l1.77 1.77c.2.2.2.51 0 .71L8.47 14H6zm12 0h-7.5l2-2H18v2z" />
</symbol>
</svg>`);

docs[userLanguage] = {
Expand Down
9 changes: 8 additions & 1 deletion docs/src/modules/components/AppLayoutDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const Main = styled('main', {
[theme.breakpoints.up('lg')]: {
width: 'calc(100% - var(--MuiDocs-navDrawer-width))',
},
'& .markdown-body': {
'& h1, & h2, & h3, & h4': {
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
'& .comment-link-style': {
display: 'inline-block',
},
},
},
}));

const StyledAppContainer = styled(AppContainer, {
Expand Down Expand Up @@ -130,7 +137,7 @@ function AppLayoutDocs(props) {
<ActionsDiv>{location && <EditPage markdownLocation={location} />}</ActionsDiv>
{children}
<NoSsr>
<AppLayoutDocsFooter />
<AppLayoutDocsFooter tableOfContents={toc} />
</NoSsr>
</StyledAppContainer>
</Main>
Expand Down
117 changes: 98 additions & 19 deletions docs/src/modules/components/AppLayoutDocsFooter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-restricted-globals */
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import DialogActions from '@mui/material/DialogActions';
import TextField from '@mui/material/TextField';
Expand All @@ -10,6 +11,7 @@ import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import Tooltip from '@mui/material/Tooltip';
import IconButton from '@mui/material/IconButton';
import MenuItem from '@mui/material/MenuItem';
import ThumbUpIcon from '@mui/icons-material/ThumbUpAlt';
import ThumbDownIcon from '@mui/icons-material/ThumbDownAlt';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
Expand Down Expand Up @@ -109,10 +111,10 @@ async function postFeedback(data) {
}

async function postFeedbackOnSlack(data) {
const { rating, comment } = data;
const { rating, comment, commentedSection } = data;

if (!comment || comment.length < 10) {
return;
return 'ignored';
}

/**
Expand Down Expand Up @@ -158,9 +160,11 @@ async function postFeedbackOnSlack(data) {
*/

const simpleSlackMessage = [
`New comment ${rating > 0 ? '👍' : '👎'}`,
`New comment ${rating === 1 ? '👍' : ''}${rating === 0 ? '👎' : ''}`,
`>${comment.split('\n').join('\n>')}`,
`sent from ${window.location.href}`,
`sent from ${window.location.href}${commentedSection.hash ? `#${commentedSection.hash}` : ''}${
commentedSection.text ? ` (section ${commentedSection.text})` : ''
}`,
].join('\n\n');

try {
Expand All @@ -169,8 +173,10 @@ async function postFeedbackOnSlack(data) {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body: JSON.stringify({ text: simpleSlackMessage }),
});
return 'sent';
} catch (error) {
console.error(error);
return null;
}
}

Expand All @@ -191,7 +197,7 @@ async function getUserFeedback(id) {
}
}

async function submitFeedback(page, rating, comment, language) {
async function submitFeedback(page, rating, comment, language, commentedSection) {
const data = {
id: getCookie('feedbackId'),
page,
Expand All @@ -201,18 +207,22 @@ async function submitFeedback(page, rating, comment, language) {
language,
};

await postFeedbackOnSlack(data);
const result = await postFeedback(data);
if (result) {
document.cookie = `feedbackId=${result.id};path=/;max-age=31536000`;
setTimeout(async () => {
const userFeedback = await getUserFeedback(result.id);
if (userFeedback) {
document.cookie = `feedback=${JSON.stringify(userFeedback)};path=/;max-age=31536000`;
}
});
const resultSlack = await postFeedbackOnSlack({ ...data, commentedSection });
if (rating !== undefined) {
const resultVote = await postFeedback(data);
if (resultVote) {
document.cookie = `feedbackId=${resultVote.id};path=/;max-age=31536000`;
setTimeout(async () => {
const userFeedback = await getUserFeedback(resultVote.id);
if (userFeedback) {
document.cookie = `feedback=${JSON.stringify(userFeedback)};path=/;max-age=31536000`;
}
});
}
return resultSlack && resultVote;
}
return result;

return resultSlack;
}

function getCurrentRating(pathname) {
Expand Down Expand Up @@ -242,19 +252,36 @@ function usePageNeighbours() {
return { prevPage, nextPage };
}

export default function AppLayoutDocsFooter() {
const EMPTY_SECTION = { hash: '', text: '' };

export default function AppLayoutDocsFooter(props) {
const { tableOfContents = [] } = props;

const t = useTranslate();
const userLanguage = useUserLanguage();
const { activePage } = React.useContext(PageContext);
const [rating, setRating] = React.useState();
const [comment, setComment] = React.useState('');
const [commentOpen, setCommentOpen] = React.useState(false);
const [snackbarOpen, setSnackbarOpen] = React.useState(false);
const [snackbarMessage, setSnackbarMessage] = React.useState(false);
const inputRef = React.useRef();
const [commentOpen, setCommentOpen] = React.useState(false);
const [commentedSection, setCommentedSection] = React.useState(EMPTY_SECTION);

const { nextPage, prevPage } = usePageNeighbours();

const sectionOptions = React.useMemo(
() =>
tableOfContents.flatMap((section) => [
{
hash: section.hash,
text: section.text,
},
...section.children.map(({ hash, text }) => ({ hash, text })),
]),
[tableOfContents],
);

const setCurrentRatingFromCookie = React.useCallback(() => {
if (activePage !== null) {
setRating(getCurrentRating(activePage.pathname));
Expand All @@ -270,7 +297,13 @@ export default function AppLayoutDocsFooter() {
setSnackbarMessage(t('feedbackFailed'));
}

const result = await submitFeedback(activePage.pathname, rating, comment, userLanguage);
const result = await submitFeedback(
activePage.pathname,
rating,
comment,
userLanguage,
commentedSection,
);
if (result) {
setSnackbarMessage(t('feedbackSubmitted'));
} else {
Expand All @@ -291,6 +324,12 @@ export default function AppLayoutDocsFooter() {
setComment(event.target.value);
};

const handleChangeSection = (event) => {
const section =
sectionOptions.find((item) => item.hash === event.target.value) || EMPTY_SECTION;
setCommentedSection(section);
};

const handleSubmitComment = (event) => {
event.preventDefault();
setCommentOpen(false);
Expand All @@ -310,6 +349,24 @@ export default function AppLayoutDocsFooter() {
setSnackbarOpen(false);
};

React.useEffect(() => {
const eventListener = (event) => {
const feedbackHash = event.target.getAttribute('data-feedback-hash');
if (feedbackHash) {
const section = sectionOptions.find((item) => item.hash === feedbackHash) || EMPTY_SECTION;
setCommentOpen(true);
setCommentedSection(section);
if (inputRef.current) {
inputRef.current.focus();
}
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
}
};
document.addEventListener('click', eventListener);
return () => {
document.removeEventListener('click', eventListener);
};
}, [sectionOptions]);

const hidePagePagination = activePage === null || activePage.ordered === false;

return (
Expand Down Expand Up @@ -389,6 +446,24 @@ export default function AppLayoutDocsFooter() {
<Typography id="feedback-description" color="text.secondary" gutterBottom>
{rating === 1 ? t('feedbackMessageUp') : t('feedbackMessageDown')}
</Typography>
<TextField
select
size="small"
margin="dense"
name="commentedSection"
fullWidth
value={commentedSection?.hash || ''}
onChange={handleChangeSection}
inputProps={{
'aria-label': t('feedbackSectionLabel'),
}}
placeholder={t('feedbackSectionPlaceholder')}
>
<MenuItem value="">{t('feedbackNoSectionSelected')}</MenuItem>
{sectionOptions.map((section) => (
<MenuItem value={section.hash}>{section.text}</MenuItem>
))}
</TextField>
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
<TextField
multiline
margin="dense"
Expand Down Expand Up @@ -420,3 +495,7 @@ export default function AppLayoutDocsFooter() {
</React.Fragment>
);
}

AppLayoutDocsFooter.propTypes = {
tableOfContents: PropTypes.array,
};
27 changes: 27 additions & 0 deletions docs/src/modules/components/MarkdownElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ const Root = styled('div')(({ theme }) => ({
fill: 'currentColor',
},
},
'& .comment-link-style': {
display: 'none',
verticalAlign: 'middle',
textAlign: 'center',
lineHeight: '21.5px',
marginLeft: 10,
height: '26px',
width: '26px',
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
background: theme.palette.mode === 'dark' ? alpha(blue[800], 0.3) : theme.palette.primary[50],
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? blueDark[500] : theme.palette.grey[200],
borderRadius: 8,
color: theme.palette.text.secondary,
float: 'right',
marginRight: '16px',
cursor: 'pointer',
'&:hover': {
color: theme.palette.text.primary,
},
'& svg': {
verticalAlign: 'middle',
width: '0.875rem',
height: '0.875rem',
fill: 'currentColor',
pointerEvents: 'none',
},
},
},
'& h1 code': {
fontWeight: theme.typography.fontWeightSemiBold,
Expand Down
3 changes: 3 additions & 0 deletions docs/translations/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
"emoojiWarning": "Warning",
"expandAll": "Expand all",
"feedbackCommentLabel": "Comment",
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
"feedbackSectionLabel": "Section concerned by the comment",
"feedbackSectionPlaceholder": "Comment about the section ...",
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
"feedbackNoSectionSelected": "The all page",
"feedbackFailed": "Couldn't submit feedback. Please try again later.",
"feedbackMessage": "Was this page helpful?",
"feedbackMessageDown": "Please let us know what we could do to improve this page.",
Expand Down