Skip to content

Commit 6e6ab96

Browse files
authored
Merge pull request #698 from gauravshinde1729/feat/add-4k-character-limit-to-justification-fields
feat: add 4K character limit to justification input fields
2 parents 03259e2 + e1333b7 commit 6e6ab96

5 files changed

Lines changed: 80 additions & 46 deletions

File tree

src/components/AcceptRiskDialog.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,19 @@ const AcceptRiskDialog: FunctionComponent<AcceptRiskDialogProps> = ({
8484
placeholder="Add your comment here..."
8585
value={justification}
8686
setValue={(value) => setJustification(value ?? "")}
87+
maxLength={4000}
8788
/>
8889
</div>
8990
<DialogFooter>
9091
<Button variant="secondary" onClick={() => onOpenChange(false)}>
9192
Cancel
9293
</Button>
93-
<AsyncButton onClick={handleSubmit}>Accept Risk</AsyncButton>
94+
<AsyncButton
95+
onClick={handleSubmit}
96+
disabled={justification.length > 4000}
97+
>
98+
Accept Risk
99+
</AsyncButton>
94100
</DialogFooter>
95101
</form>
96102
</DialogContent>

src/components/CommentDialog.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ const CommentDialog: FunctionComponent<CommentDialogProps> = ({
6363
placeholder="Add your comment here..."
6464
value={justification}
6565
setValue={(value) => setJustification(value ?? "")}
66+
maxLength={4000}
6667
/>
6768
</div>
6869
<DialogFooter>
6970
<Button variant="secondary" onClick={() => onOpenChange(false)}>
7071
Cancel
7172
</Button>
72-
<AsyncButton onClick={handleSubmit}>Add Comment</AsyncButton>
73+
<AsyncButton
74+
onClick={handleSubmit}
75+
disabled={justification.length > 4000}
76+
>
77+
Add Comment
78+
</AsyncButton>
7379
</DialogFooter>
7480
</form>
7581
</DialogContent>

src/components/FalsePositiveDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ const FalsePositiveDialog: FunctionComponent<FalsePositiveDialogProps> = ({
206206
placeholder="Add your comment here..."
207207
value={justification}
208208
setValue={(value) => setJustification(value ?? "")}
209+
maxLength={4000}
209210
/>
210211
</div>
211212
<DialogFooter>
@@ -218,6 +219,7 @@ const FalsePositiveDialog: FunctionComponent<FalsePositiveDialogProps> = ({
218219
onClick={handleSubmit}
219220
variant={"default"}
220221
className="mr-0 rounded-r-none pr-0 capitalize"
222+
disabled={justification.length > 4000}
221223
>
222224
{removeUnderscores(selectedOption)}
223225
</AsyncButton>

src/components/MitigateDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ const MitigateDialog: FunctionComponent<MitigateDialogProps> = ({
7474
placeholder="Add your justification for mitigating this vulnerability..."
7575
value={justification}
7676
setValue={(value) => setJustification(value ?? "")}
77+
maxLength={4000}
7778
/>
7879
</div>
7980
<DialogFooter>
8081
<Button variant="secondary" onClick={() => onOpenChange(false)}>
8182
Cancel
8283
</Button>
83-
<AsyncButton variant={"secondary"} onClick={handleSubmit}>
84+
<AsyncButton variant={"secondary"} onClick={handleSubmit} disabled={justification.length > 4000}>
8485
<div className="flex flex-row items-center">
8586
{integrationType === "gitlab" && (
8687
<>

src/components/common/MarkdownEditor.tsx

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,64 +29,83 @@ interface Props extends Partial<MDXEditorProps> {
2929
value: string;
3030
setValue: (value?: string) => void;
3131
placeholder?: string;
32+
maxLength?: number;
3233
}
3334

3435
const MarkdownEditor: FunctionComponent<Props> = ({
3536
value,
3637
setValue,
3738
placeholder,
39+
maxLength,
3840
...rest
3941
}) => {
4042
const markdownRef = useRef<MDXEditorMethods>(null);
4143

4244
useEffect(() => {
4345
markdownRef.current?.setMarkdown(value);
4446
}, [value]);
47+
48+
const charCount = value.length;
49+
const isOverLimit = maxLength !== undefined && charCount > maxLength;
50+
4551
return (
46-
<MDXEditor
47-
ref={markdownRef}
48-
className={classNames(
49-
"ring-primary focus:ring-2 focus-within:ring-2 rounded border",
50-
styles.mdxeditor,
51-
rest.className || "",
52-
)}
53-
onChange={(value) => setValue(value)}
54-
placeholder={placeholder}
55-
markdown={value}
56-
contentEditableClassName="mdx-editor-content"
57-
plugins={[
58-
// toolbarPlugin({ toolbarContents: () => <KitchenSinkToolbar /> }),
59-
toolbarPlugin({
60-
toolbarContents: () => (
61-
<>
62-
<BoldItalicUnderlineToggles />
63-
<CodeToggle />
64-
<ListsToggle />
65-
</>
66-
),
67-
}),
68-
listsPlugin(),
69-
quotePlugin(),
70-
headingsPlugin(),
71-
linkPlugin(),
72-
imagePlugin(),
73-
tablePlugin(),
74-
thematicBreakPlugin(),
75-
frontmatterPlugin(),
76-
codeBlockPlugin({ defaultCodeBlockLanguage: "go" }),
77-
codeMirrorPlugin({
78-
codeBlockLanguages: {
79-
js: "JavaScript",
80-
css: "CSS",
81-
txt: "text",
82-
tsx: "TypeScript",
83-
go: "Go",
84-
},
85-
}),
52+
<div>
53+
<MDXEditor
54+
ref={markdownRef}
55+
className={classNames(
56+
"ring-primary focus:ring-2 focus-within:ring-2 rounded border",
57+
isOverLimit ? "border-destructive" : "",
58+
styles.mdxeditor,
59+
rest.className || "",
60+
)}
61+
onChange={(value) => setValue(value)}
62+
placeholder={placeholder}
63+
markdown={value}
64+
contentEditableClassName="mdx-editor-content"
65+
plugins={[
66+
// toolbarPlugin({ toolbarContents: () => <KitchenSinkToolbar /> }),
67+
toolbarPlugin({
68+
toolbarContents: () => (
69+
<>
70+
<BoldItalicUnderlineToggles />
71+
<CodeToggle />
72+
<ListsToggle />
73+
</>
74+
),
75+
}),
76+
listsPlugin(),
77+
quotePlugin(),
78+
headingsPlugin(),
79+
linkPlugin(),
80+
imagePlugin(),
81+
tablePlugin(),
82+
thematicBreakPlugin(),
83+
frontmatterPlugin(),
84+
codeBlockPlugin({ defaultCodeBlockLanguage: "go" }),
85+
codeMirrorPlugin({
86+
codeBlockLanguages: {
87+
js: "JavaScript",
88+
css: "CSS",
89+
txt: "text",
90+
tsx: "TypeScript",
91+
go: "Go",
92+
},
93+
}),
8694

87-
markdownShortcutPlugin(),
88-
]}
89-
/>
95+
markdownShortcutPlugin(),
96+
]}
97+
/>
98+
{maxLength !== undefined && (
99+
<p
100+
className={classNames(
101+
"mt-1 text-right text-xs",
102+
isOverLimit ? "text-destructive" : "text-muted-foreground",
103+
)}
104+
>
105+
{charCount} / {maxLength}
106+
</p>
107+
)}
108+
</div>
90109
);
91110
};
92111

0 commit comments

Comments
 (0)