Skip to content

Commit 789e292

Browse files
committed
add logic to show suggestion when commit message reaches 50 characters
1 parent 1f0100e commit 789e292

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

ui/src/Components/DashBoard/Repository/GitComponents/GitOperation/CommitComponent.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default function CommitComponent(props) {
1111
const [commitDone, setCommitDone] = useState(false);
1212
const [commitError, setCommitError] = useState(false);
1313
const [loadingCommit, setLoadingCommit] = useState(false);
14+
const [commitMessageWarning, setCommitMessageWarning] = useState(false);
1415

1516
const commitRef = useRef();
1617

@@ -101,7 +102,8 @@ export default function CommitComponent(props) {
101102
{!commitDone ? (
102103
<div className="git-ops--commit--wrapper">
103104
<div className="git-ops--commit--header">
104-
{stagedCount} Changes to commit...
105+
{stagedCount} {stagedCount > 1 ? "Changes" : "Change"} to
106+
commit...
105107
</div>
106108
<div className="overflow-auto" style={{ height: "300px" }}>
107109
{stagedFilesState.map((stagedFile) => {
@@ -116,12 +118,36 @@ export default function CommitComponent(props) {
116118
})}
117119
</div>
118120
<div className="text-xl my-4">Commit Message</div>
121+
{commitMessageWarning ? (
122+
<div className="font-sans font-semibold italic p-2 border-b border-dotted border-orange-500 text-yellow-600">
123+
<span role="img" aria-label="suggestion">
124+
💡
125+
</span>
126+
<span className="mx-1">
127+
It is usually a good practice to limit the commit message to
128+
50 characters
129+
</span>
130+
<div className="my-1 font-sans text-sm font-semibold text-yellow-700">
131+
For additional content, include a line break and enter the
132+
messages
133+
</div>
134+
</div>
135+
) : null}
119136
<textarea
120137
className="git-ops--commit--message"
121138
placeholder="Enter commit message"
122139
cols="20"
123140
rows="5"
124141
ref={commitRef}
142+
onChange={(e) => {
143+
const content = e.currentTarget.value;
144+
const len = content.split("\n")[0].length;
145+
if (len > 50) {
146+
setCommitMessageWarning(true);
147+
} else {
148+
setCommitMessageWarning(false);
149+
}
150+
}}
125151
></textarea>
126152
{commitError ? (
127153
<div className="git-ops--commit--alert--failed">

0 commit comments

Comments
 (0)