8000 feat: support markdown in update messages by aslilac · Pull Request #12273 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: support markdown in update messages #12273

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

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: support markdown in update messages
  • Loading branch information
aslilac committed Feb 22, 2024
commit 8a9c40dbeab57b97a1924045e9109fdd6a56919d
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ type Story = StoryObj<typeof TemplateVersionPageView>;

export const Default: Story = {};

export const LongVersionMessage: Story = {
args: {
currentVersion: {
...MockTemplateVersion,
message: `
# Abiding Grace
## Enchantment
At the beginning of your end step, choose one —

- You gain 1 life.

- Return target creature card with mana value 1 from your graveyard to the battlefield.
`,
},
},
};

export const Error: Story = {
args: {
...defaultArgs,
Expand Down
41 changes: 36 additions & 5 deletions site/src/pages/TemplateVersionPage/TemplateVersionPageView.tsx
10000
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Button from "@mui/material/Button";
import AddIcon from "@mui/icons-material/Add";
import EditIcon from "@mui/icons-material/Edit";
import { type Interpolation, type Theme } from "@emotion/react";
import { type FC } from "react";
import { Link as RouterLink } from "react-router-dom";
import { Loader } from "components/Loader/Loader";
Expand All @@ -18,6 +19,7 @@ import type { TemplateVersion } from "api/typesGenerated";
import { createDayString } from "utils/createDayString";
import { TemplateVersionFiles } from "utils/templateVersion";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { MemoizedMarkdown } from "components/Markdown/Markdown";

export interface TemplateVersionPageViewProps {
versionName: string;
Expand Down Expand Up @@ -65,17 +67,17 @@ export const TemplateVersionPageView: FC<TemplateVersionPageViewProps> = ({
>
<PageHeaderCaption>Version</PageHeaderCaption>
<PageHeaderTitle>{versionName}</PageHeaderTitle>
{currentVersion &&
currentVersion.message &&
currentVersion.message !== "" && (
<PageHeaderSubtitle>{currentVersion.message}</PageHeaderSubtitle>
)}
</PageHeader>

{!currentFiles && !error && <Loader />}

<Stack spacing={4}>
{Boolean(error) && <ErrorAlert error={error} />}
{currentVersion?.message && (
<MemoizedMarkdown css={styles.versionMessage}>
{currentVersion.message}
</MemoizedMarkdown>
)}
{currentVersion && currentFiles && (
<>
<Stats>
Expand Down Expand Up @@ -110,4 +112,33 @@ export const TemplateVersionPageView: FC<TemplateVersionPageViewProps> = ({
);
};

const styles = {
versionMessage: {
fontSize: "0.9em",
lineHeight: 1.2,

"& h1, & h2, & h3, & h4, & h5, & h6": {
margin: "0 0 0.75em",
},
"& h1": {
fontSize: "1.2em",
},
"& h2": {
fontSize: "1.15em",
},
"& h3": {
fontSize: "1.1em",
},
"& h4": {
fontSize: "1.05em",
},
"& h5": {
fontSize: "1em",
},
"& h6": {
fontSize: "0.95em",
},
},
} satisfies Record<string, Interpolation<Theme>>;

export default TemplateVersionPageView;
5 changes: 4 additions & 1 deletion site/src/pages/WorkspacePage/ChangeVersionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Alert, AlertDetail } from "components/Alert/Alert";
import type { DialogProps } from "components/Dialogs/Dialog";
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog";
import { FormFields } from "components/Form/Form";
import { MemoizedMarkdown } from "components/Markdown/Markdown";
import { Stack } from "components/Stack/Stack";
import { Loader } from "components/Loader/Loader";
import { AvatarData } from "components/AvatarData/AvatarData";
Expand Down Expand Up @@ -143,7 +144,9 @@ export const ChangeVersionDialog: FC<ChangeVersionDialogProps> = ({
Published by {version.created_by.username}
</AlertTitle>
{version.message && (
<AlertDetail>{version.message}</AlertDetail>
<AlertDetail>
<MemoizedMarkdown>{version.message}</MemoizedMarkdown>
</AlertDetail>
)}
</Alert>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = ({
notifications.push({
title: "An update is available for your workspace",
severity: "info",
detail: latestVersion.message,
detail: (
8000 <MemoizedInlineMarkdown allowedElements={["ol", "ul", "li"]}>
{latestVersion.message}
</MemoizedInlineMarkdown>
),
actions,
});
}
Expand Down
6 changes: 4 additions & 2 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
4EAC
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
toggleFavorite,
cancelBuild,
} from "api/queries/workspaces";
import { Alert } from "components/Alert/Alert";
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown";
import { Stack } from "components/Stack/Stack";
import {
ConfirmDialog,
Expand Down Expand Up @@ -324,7 +324,9 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
<strong>delete non-persistent data</strong>.
</p>
{latestVersion?.message && (
<Alert severity="info">{latestVersion.message}</Alert>
<MemoizedInlineMarkdown allowedElements={["ol", "ul", "li"]}>
{latestVersion.message}
</MemoizedInlineMarkdown>
)}
</Stack>
}
Expand Down
0