Skip to content

Commit

Permalink
[docs-infra] Split feedback channels per product (mui#42413)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Fauquette <[email protected]>
  • Loading branch information
alexfauquette authored May 28, 2024
1 parent f153423 commit 79bad36
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
10 changes: 6 additions & 4 deletions docs/src/modules/components/AppLayoutDocsFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function postFeedback(data) {
}

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

const sentData = {
callback_id: 'send_feedback',
Expand All @@ -106,6 +106,7 @@ async function postFeedbackOnSlack(data) {
commmentSectionURL: `${window.location.origin}${window.location.pathname}#${commentedSection.hash}`,
commmentSectionTitle: commentedSection.text,
githubRepo: process.env.SOURCE_CODE_REPO,
productId,
};
if (!comment || comment.length < 10) {
return 'ignored';
Expand Down Expand Up @@ -187,7 +188,7 @@ async function getUserFeedback(id) {
}
}

async function submitFeedback(page, rating, comment, language, commentedSection) {
async function submitFeedback(page, rating, comment, language, commentedSection, productId) {
const data = {
id: getCookie('feedbackId'),
page,
Expand All @@ -197,7 +198,7 @@ async function submitFeedback(page, rating, comment, language, commentedSection)
language,
};

const resultSlack = await postFeedbackOnSlack({ ...data, commentedSection });
const resultSlack = await postFeedbackOnSlack({ ...data, productId, commentedSection });
if (rating !== undefined) {
const resultVote = await postFeedback(data);
if (resultVote) {
Expand Down Expand Up @@ -259,7 +260,7 @@ export default function AppLayoutDocsFooter(props) {
const theme = useTheme();
const t = useTranslate();
const userLanguage = useUserLanguage();
const { activePage } = React.useContext(PageContext);
const { activePage, productId } = React.useContext(PageContext);
const [rating, setRating] = React.useState();
const [comment, setComment] = React.useState('');
const [snackbarOpen, setSnackbarOpen] = React.useState(false);
Expand Down Expand Up @@ -303,6 +304,7 @@ export default function AppLayoutDocsFooter(props) {
comment,
userLanguage,
commentedSection,
productId,
);
if (result) {
setSnackbarMessage(t('feedbackSubmitted'));
Expand Down
5 changes: 4 additions & 1 deletion docs/src/modules/utils/getProductInfoFromUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export type MuiProductId =
| 'docs'
| 'x-data-grid'
| 'x-date-pickers'
| 'x-charts';
| 'x-charts'
| 'x-tree-view'
| 'toolpad-studio'
| 'toolpad-core';

type MuiProductCategoryId = 'null' | 'core' | 'x';

Expand Down
64 changes: 56 additions & 8 deletions netlify/functions/feedback-management.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,72 @@ const X_FEEBACKS_CHANNEL_ID = 'C04U3R2V9UK';
const JOY_FEEBACKS_CHANNEL_ID = 'C050VE13HDL';
const TOOLPAD_FEEBACKS_CHANNEL_ID = 'C050MHU703Z';
const CORE_FEEBACKS_CHANNEL_ID = 'C041SDSF32L';

const BASE_UI_FEEBACKS_CHANNEL_ID = 'C075LJG1LMP';
const MATERIAL_UI_FEEBACKS_CHANNEL_ID = 'C0757QYLK7V';
// const PIGMENT_CSS_FEEBACKS_CHANNEL_ID = 'C074TBW0JKZ';
const X_GRID_FEEBACKS_CHANNEL_ID = 'C0757R0KW67';
const X_CHARTS_FEEBACKS_CHANNEL_ID = 'C0757UBND98';
const X_EXPLORE_FEEBACKS_CHANNEL_ID = 'C074TBYQK2T';
// const DESIGN_KITS_FEEBACKS_CHANNEL_ID = 'C075ADGN0UU';

// The design feedback alert was removed in https://github.com/mui/material-ui/pull/39691
// This dead code is here to simplify the creation of special feedback channel
const DESIGN_FEEDBACKS_CHANNEL_ID = 'C05HHSFH2QJ';

const getSlackChannelId = (url, specialCases) => {
export type MuiProductId =
| 'null'
| 'base-ui'
| 'material-ui'
| 'joy-ui'
| 'system'
| 'docs-infra'
| 'docs'
| 'x-data-grid'
| 'x-date-pickers'
| 'x-charts'
| 'x-tree-view'
| 'toolpad-studio'
| 'toolpad-core';

const getSlackChannelId = (
url: string,
productId: MuiProductId,
specialCases: { isDesignFeedback?: boolean },
) => {
const { isDesignFeedback } = specialCases;

if (isDesignFeedback) {
return DESIGN_FEEDBACKS_CHANNEL_ID;
}

switch (productId) {
case 'base-ui':
return BASE_UI_FEEBACKS_CHANNEL_ID;
case 'material-ui':
case 'system':
return MATERIAL_UI_FEEBACKS_CHANNEL_ID;
case 'joy-ui':
return JOY_FEEBACKS_CHANNEL_ID;
case 'x-data-grid':
return X_GRID_FEEBACKS_CHANNEL_ID;
case 'x-date-pickers':
case 'x-tree-view':
return X_EXPLORE_FEEBACKS_CHANNEL_ID;
case 'x-charts':
return X_CHARTS_FEEBACKS_CHANNEL_ID;
case 'toolpad-studio':
case 'toolpad-core':
return TOOLPAD_FEEBACKS_CHANNEL_ID;
default:
break;
}

// Fallback

if (url.includes('/x/')) {
return X_FEEBACKS_CHANNEL_ID;
}
if (url.includes('/joy-ui/')) {
return JOY_FEEBACKS_CHANNEL_ID;
}
if (url.includes('/toolpad/')) {
return TOOLPAD_FEEBACKS_CHANNEL_ID;
}
return CORE_FEEBACKS_CHANNEL_ID;
};

Expand Down Expand Up @@ -154,6 +201,7 @@ export const handler: Handler = async (event, context, callback) => {
commmentSectionURL: inCommmentSectionURL,
commmentSectionTitle,
githubRepo,
productId,
} = data;

// The design feedback alert was removed in https://github.com/mui/material-ui/pull/39691
Expand Down Expand Up @@ -181,7 +229,7 @@ from ${commmentSectionURL}
});

await app.client.chat.postMessage({
channel: getSlackChannelId(currentLocationURL, { isDesignFeedback }),
channel: getSlackChannelId(currentLocationURL, productId, { isDesignFeedback }),
text: simpleSlackMessage, // Fallback for notification
blocks: [
{
Expand Down

0 comments on commit 79bad36

Please sign in to comment.