Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion src/components/AcceptRiskDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ const AcceptRiskDialog: FunctionComponent<AcceptRiskDialogProps> = ({
placeholder="Add your comment here..."
value={justification}
setValue={(value) => setJustification(value ?? "")}
maxLength={4000}
/>
</div>
<DialogFooter>
<Button variant="secondary" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<AsyncButton onClick={handleSubmit}>Accept Risk</AsyncButton>
<AsyncButton
onClick={handleSubmit}
disabled={justification.length > 4000}
>
Accept Risk
</AsyncButton>
</DialogFooter>
</form>
</DialogContent>
Expand Down
8 changes: 7 additions & 1 deletion src/components/CommentDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ const CommentDialog: FunctionComponent<CommentDialogProps> = ({
placeholder="Add your comment here..."
value={justification}
setValue={(value) => setJustification(value ?? "")}
maxLength={4000}
/>
</div>
<DialogFooter>
<Button variant="secondary" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<AsyncButton onClick={handleSubmit}>Add Comment</AsyncButton>
<AsyncButton
onClick={handleSubmit}
disabled={justification.length > 4000}
>
Add Comment
</AsyncButton>
</DialogFooter>
</form>
</DialogContent>
Expand Down
2 changes: 2 additions & 0 deletions src/components/FalsePositiveDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const FalsePositiveDialog: FunctionComponent<FalsePositiveDialogProps> = ({
placeholder="Add your comment here..."
value={justification}
setValue={(value) => setJustification(value ?? "")}
maxLength={4000}
/>
</div>
<DialogFooter>
Expand All @@ -217,6 +218,7 @@ const FalsePositiveDialog: FunctionComponent<FalsePositiveDialogProps> = ({
onClick={handleSubmit}
variant={"default"}
className="mr-0 rounded-r-none pr-0 capitalize"
disabled={justification.length > 4000}
>
{removeUnderscores(selectedOption)}
</AsyncButton>
Expand Down
3 changes: 2 additions & 1 deletion src/components/MitigateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ const MitigateDialog: FunctionComponent<MitigateDialogProps> = ({
placeholder="Add your justification for mitigating this vulnerability..."
value={justification}
setValue={(value) => setJustification(value ?? "")}
maxLength={4000}
/>
</div>
<DialogFooter>
<Button variant="secondary" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<AsyncButton variant={"secondary"} onClick={handleSubmit}>
<AsyncButton variant={"secondary"} onClick={handleSubmit} disabled={justification.length > 4000}>
<div className="flex flex-row items-center">
{integrationType === "gitlab" && (
<>
Expand Down
105 changes: 62 additions & 43 deletions src/components/common/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,64 +28,83 @@ interface Props extends Partial<MDXEditorProps> {
value: string;
setValue: (value?: string) => void;
placeholder?: string;
maxLength?: number;
}

const MarkdownEditor: FunctionComponent<Props> = ({
value,
setValue,
placeholder,
maxLength,
...rest
}) => {
const markdownRef = useRef<MDXEditorMethods>(null);

useEffect(() => {
markdownRef.current?.setMarkdown(value);
}, [value]);

const charCount = value.length;
const isOverLimit = maxLength !== undefined && charCount > maxLength;

return (
<MDXEditor
ref={markdownRef}
className={classNames(
"ring-primary focus:ring-2 focus-within:ring-2 rounded border",
styles.mdxeditor,
rest.className || "",
)}
onChange={(value) => setValue(value)}
placeholder={placeholder}
markdown={value}
contentEditableClassName="mdx-editor-content"
plugins={[
// toolbarPlugin({ toolbarContents: () => <KitchenSinkToolbar /> }),
toolbarPlugin({
toolbarContents: () => (
<>
<BoldItalicUnderlineToggles />
<CodeToggle />
<ListsToggle />
</>
),
}),
listsPlugin(),
quotePlugin(),
headingsPlugin(),
linkPlugin(),
imagePlugin(),
tablePlugin(),
thematicBreakPlugin(),
frontmatterPlugin(),
codeBlockPlugin({ defaultCodeBlockLanguage: "go" }),
codeMirrorPlugin({
codeBlockLanguages: {
js: "JavaScript",
css: "CSS",
txt: "text",
tsx: "TypeScript",
go: "Go",
},
}),
<div>
<MDXEditor
ref={markdownRef}
className={classNames(
"ring-primary focus:ring-2 focus-within:ring-2 rounded border",
isOverLimit ? "border-destructive" : "",
styles.mdxeditor,
rest.className || "",
)}
onChange={(value) => setValue(value)}
placeholder={placeholder}
markdown={value}
contentEditableClassName="mdx-editor-content"
plugins={[
// toolbarPlugin({ toolbarContents: () => <KitchenSinkToolbar /> }),
toolbarPlugin({
toolbarContents: () => (
<>
<BoldItalicUnderlineToggles />
<CodeToggle />
<ListsToggle />
</>
),
}),
listsPlugin(),
quotePlugin(),
headingsPlugin(),
linkPlugin(),
imagePlugin(),
tablePlugin(),
thematicBreakPlugin(),
frontmatterPlugin(),
codeBlockPlugin({ defaultCodeBlockLanguage: "go" }),
codeMirrorPlugin({
codeBlockLanguages: {
js: "JavaScript",
css: "CSS",
txt: "text",
tsx: "TypeScript",
go: "Go",
},
}),

markdownShortcutPlugin(),
]}
/>
markdownShortcutPlugin(),
]}
/>
{maxLength !== undefined && (
<p
className={classNames(
"mt-1 text-right text-xs",
isOverLimit ? "text-destructive" : "text-muted-foreground",
)}
>
{charCount} / {maxLength}
</p>
)}
</div>
);
};

Expand Down
Loading