Skip to content

Commit da4469b

Browse files
committed
fix: UX description at creation notification form
1 parent e694247 commit da4469b

9 files changed

Lines changed: 73 additions & 29 deletions

File tree

ui/dashboard/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"react-router": "^7.18.2",
8282
"react-select": "^5.9.0",
8383
"remark": "^15.0.1",
84+
"remark-gfm": "^4.0.1",
8485
"strip-markdown": "^6.0.0",
8586
"tailwind-merge": "^2.4.0",
8687
"timeago.js": "^4.0.2",

ui/dashboard/src/pages/notification-feed/drafts/draft-card.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IconTrash } from '@icons';
55
import Icon from 'components/icon';
66
import { markdownToText } from '../elements/markdown-content';
77
import NotificationCard from '../elements/notification-card';
8-
import TagChip from '../elements/tag-chip';
8+
import TagList from '../elements/tag-list';
99
import { NotificationDraft } from '../types';
1010

1111
interface DraftCardProps {
@@ -27,14 +27,14 @@ const DraftCard = ({ draft, active, onClick, onDelete }: DraftCardProps) => {
2727
<div className="flex w-full flex-col gap-1">
2828
<span
2929
className={cn(
30-
'typo-para-medium font-medium text-gray-900',
30+
'truncate typo-para-medium font-medium text-gray-900',
3131
onDelete && 'pr-8'
3232
)}
3333
>
3434
{draft.title}
3535
</span>
3636
{draft.content && (
37-
<p className="line-clamp-1 typo-para-small text-gray-500">
37+
<p className="line-clamp-2 typo-para-small text-gray-500">
3838
{markdownToText(draft.content)}
3939
</p>
4040
)}
@@ -51,9 +51,7 @@ const DraftCard = ({ draft, active, onClick, onDelete }: DraftCardProps) => {
5151
</div>
5252
}
5353
>
54-
{draft.tags.map(tag => (
55-
<TagChip key={tag.name} tag={tag} />
56-
))}
54+
<TagList tags={draft.tags} />
5755
</NotificationCard>
5856
{onDelete && (
5957
<button

ui/dashboard/src/pages/notification-feed/elements/markdown-content.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
.markdown-content .wmde-markdown,
2-
.markdown-content .wmde-markdown * {
1+
.wmde-markdown,
2+
.wmde-markdown * {
33
font-family: 'Sofia Pro', sans-serif;
44
}
55

66
/* Keep code/pre in a monospace font, as Markdown expects. */
7-
.markdown-content .wmde-markdown code,
8-
.markdown-content .wmde-markdown pre,
9-
.markdown-content .wmde-markdown kbd,
10-
.markdown-content .wmde-markdown samp {
7+
.wmde-markdown code,
8+
.wmde-markdown pre,
9+
.wmde-markdown kbd,
10+
.wmde-markdown samp {
1111
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
1212
}
1313

ui/dashboard/src/pages/notification-feed/elements/markdown-content.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import MDEditor from '@uiw/react-md-editor';
22
import { remark } from 'remark';
3+
import remarkGfm from 'remark-gfm';
34
import strip from 'strip-markdown';
45
import { visit } from 'unist-util-visit';
56
import { cn } from 'utils/style';
@@ -22,7 +23,7 @@ export const MarkdownContent = ({
2223
);
2324
};
2425

25-
const stripProcessor = remark().use(strip);
26+
const stripProcessor = remark().use(remarkGfm).use(strip);
2627

2728
export const markdownToText = (markdown: string): string =>
2829
String(stripProcessor.processSync(markdown)).replace(/\s+/g, ' ').trim();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { IconMoreHorizOutlined } from 'react-icons-material-design';
2+
import { cn } from 'utils/style';
3+
import { Tooltip } from 'components/tooltip';
4+
import { NotificationTag } from '../types';
5+
import TagChip from './tag-chip';
6+
7+
const MAX_VISIBLE_TAGS = 3;
8+
9+
const TagList = ({
10+
tags,
11+
className
12+
}: {
13+
tags: NotificationTag[];
14+
className?: string;
15+
}) => {
16+
const visibleTags = tags.slice(0, MAX_VISIBLE_TAGS);
17+
const hiddenTags = tags.slice(MAX_VISIBLE_TAGS);
18+
19+
if (!visibleTags.length) return null;
20+
21+
const hiddenTagsLabel = hiddenTags.map(tag => tag.name).join(', ');
22+
23+
return (
24+
<div className={cn('flex shrink-0 items-center gap-1.5', className)}>
25+
{visibleTags.map(tag => (
26+
<TagChip key={tag.name} tag={tag} />
27+
))}
28+
{hiddenTags.length > 0 && (
29+
<Tooltip
30+
content={hiddenTagsLabel}
31+
trigger={
32+
<span
33+
aria-label={hiddenTagsLabel}
34+
className="inline-flex items-center gap-0.5 rounded bg-gray-100 px-2 py-0.5 typo-para-tiny font-medium text-gray-700"
35+
>
36+
<IconMoreHorizOutlined style={{ fontSize: 14 }} />+
37+
{hiddenTags.length}
38+
</span>
39+
}
40+
/>
41+
)}
42+
</div>
43+
);
44+
};
45+
46+
export default TagList;

ui/dashboard/src/pages/notification-feed/feed/notification-row.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cn } from 'utils/style';
33
import Checkbox from 'components/checkbox';
44
import { markdownToText } from '../elements/markdown-content';
55
import NotificationCard from '../elements/notification-card';
6-
import TagChip from '../elements/tag-chip';
6+
import TagList from '../elements/tag-list';
77
import { FeedNotification } from '../types';
88

99
interface NotificationRowProps {
@@ -50,13 +50,7 @@ const NotificationRow = ({
5050
>
5151
{notification.title}
5252
</span>
53-
{notification.tags.length > 0 && (
54-
<div className="flex shrink-0 items-center gap-1.5">
55-
{notification.tags.map(tag => (
56-
<TagChip key={tag.name} tag={tag} />
57-
))}
58-
</div>
59-
)}
53+
<TagList tags={notification.tags} />
6054
<span className="ml-auto shrink-0 typo-para-tiny text-gray-500">
6155
{formatDateTime(notification.publishedAt)}
6256
</span>

ui/dashboard/src/pages/notification-feed/publisher/markdown-editor.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ import '../elements/markdown-content.css';
1010
import './markdown-editor.css';
1111

1212
interface MarkdownEditorProps {
13-
// stored as Markdown text
1413
value: string;
1514
onChange: (value: string) => void;
1615
placeholder?: string;
1716
}
1817

1918
type Mode = 'edit' | 'preview';
2019

21-
// Inserts an "@" at the cursor to start a mention, mirroring the previous
22-
// editor's behavior. There is no built-in mention command in the library.
2320
const createMention = (t: TFunction): ICommand => ({
2421
name: 'mention',
2522
keyCommand: 'mention',
@@ -96,6 +93,7 @@ const MarkdownEditor = ({
9693
visibleDragbar={false}
9794
extraCommands={[]}
9895
commands={createToolbar(t)}
96+
className="markdown-editor-preview text-sm"
9997
textareaProps={{
10098
placeholder: placeholder ?? t('form:description-placeholder')
10199
}}

ui/dashboard/src/pages/notification-feed/publisher/publish-form.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ const PublishForm = ({
108108
);
109109

110110
useEffect(() => {
111-
const locs = buildLocalizations(initialDraft);
112-
form.reset({ localizations: locs });
113-
setActiveLanguage(initialActiveLanguage(locs));
114-
}, [initialDraft]);
111+
if (initialDraft) {
112+
const locs = buildLocalizations(initialDraft);
113+
form.reset({ localizations: locs });
114+
setActiveLanguage(initialActiveLanguage(locs));
115+
return;
116+
}
117+
if (form.formState.isDirty) return;
118+
form.reset({ localizations: [emptyLocalization(defaultLanguage)] });
119+
setActiveLanguage(defaultLanguage);
120+
}, [initialDraft?.id, initialDraft?.updatedAt, defaultLanguage]);
115121

116122
const activeIndex = Math.max(
117123
0,

ui/dashboard/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5727,7 +5727,7 @@ rehype@~13.0.0:
57275727
rehype-stringify "^10.0.0"
57285728
unified "^11.0.0"
57295729

5730-
remark-gfm@~4.0.0:
5730+
remark-gfm@^4.0.1, remark-gfm@~4.0.0:
57315731
version "4.0.1"
57325732
resolved "https://registry.yarnpkg.com/remark-gfm/-/remark-gfm-4.0.1.tgz#33227b2a74397670d357bf05c098eaf8513f0d6b"
57335733
integrity sha512-1quofZ2RQ9EWdeN34S79+KExV1764+wCUGop5CPL1WGdD0ocPpu91lzPGbwWMECpEpd42kJGQwzRfyov9j4yNg==

0 commit comments

Comments
 (0)