Skip to content

Commit 9dc4c35

Browse files
authored
Merge pull request #2400 from visualize-admin/fix/user-chart-names
fix: Markdown in user profile chart titles
2 parents 98930db + 50be105 commit 9dc4c35

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ You can also check the
2727
filters section
2828
- Dataset browse view is now correctly displayed on mobile devices
2929
- Database-related actions are now hidden in preview mode (copy URL, share)
30+
- Chart titles in user profile are now correctly rendered
3031
- Security
3132
- Added additional protection against data source URL injection
3233
- Removed feature flag for custom GraphQL endpoint

app/components/markdown.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,39 @@ export const Markdown = (
6969
);
7070
};
7171

72+
export const InlineMarkdown = ({
73+
children,
74+
...rest
75+
}: Omit<ComponentProps<typeof ReactMarkdown>, "components">) => {
76+
const inlineMarkdown = children?.replace(/\r?\n|\r/g, " ");
77+
78+
return (
79+
<ReactMarkdown
80+
components={{
81+
p: ({ children }) => <>{children}</>,
82+
strong: ({ children }) => <strong>{children}</strong>,
83+
em: ({ children }) => <em>{children}</em>,
84+
a: ({ children, href }) => <a href={href}>{children}</a>,
85+
h1: () => null,
86+
h2: () => null,
87+
h3: () => null,
88+
h4: () => null,
89+
h5: () => null,
90+
h6: () => null,
91+
ul: () => null,
92+
li: () => null,
93+
blockquote: () => null,
94+
code: ({ children }) => <code>{children}</code>,
95+
br: () => <> </>,
96+
}}
97+
skipHtml
98+
{...rest}
99+
>
100+
{inlineMarkdown}
101+
</ReactMarkdown>
102+
);
103+
};
104+
72105
const componentsInheritFonts: ComponentProps<
73106
typeof ReactMarkdown
74107
>["components"] = {

app/login/components/profile-tables.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import sortBy from "lodash/sortBy";
2121
import NextLink from "next/link";
2222
import { ReactNode, useMemo, useState } from "react";
2323

24+
import { InlineMarkdown, Markdown } from "@/components/markdown";
2425
import { MenuActionProps } from "@/components/menu-action-item";
2526
import { OverflowTooltip } from "@/components/overflow-tooltip";
2627
import {
@@ -361,9 +362,13 @@ const ProfileVisualizationsRow = (props: {
361362
legacyBehavior
362363
>
363364
<Link>
364-
<OverflowTooltip arrow title={chartTitle} color="primary.main">
365-
<Typography variant="body3" noWrap>
366-
{chartTitle}
365+
<OverflowTooltip
366+
arrow
367+
title={<Markdown>{chartTitle}</Markdown>}
368+
color="primary.main"
369+
>
370+
<Typography variant="body3" component="p" noWrap>
371+
<InlineMarkdown>{chartTitle}</InlineMarkdown>
367372
</Typography>
368373
</OverflowTooltip>
369374
</Link>

0 commit comments

Comments
 (0)