From 5c6cbac9b41a0b0e5e5b1cc9dd3591a9d5d517f4 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Sat, 11 Jan 2025 04:57:21 +1030 Subject: [PATCH] refactor: simplify commit message handling by removing custom type and scope inputs --- .../settings/git/status/CommitMessage.jsx | 98 +------------------ frontend/src/constants/commits.js | 40 ++++++++ 2 files changed, 45 insertions(+), 93 deletions(-) create mode 100644 frontend/src/constants/commits.js diff --git a/frontend/src/components/settings/git/status/CommitMessage.jsx b/frontend/src/components/settings/git/status/CommitMessage.jsx index 83a15a1..b4b9a6a 100644 --- a/frontend/src/components/settings/git/status/CommitMessage.jsx +++ b/frontend/src/components/settings/git/status/CommitMessage.jsx @@ -1,55 +1,5 @@ import React, {useState, useEffect} from 'react'; - -const COMMIT_TYPES = [ - {value: 'feat', label: 'Feature', description: 'A new feature'}, - {value: 'fix', label: 'Bug Fix', description: 'A bug fix'}, - { - value: 'docs', - label: 'Documentation', - description: 'Documentation only changes' - }, - { - value: 'style', - label: 'Style', - description: 'Changes that do not affect code meaning' - }, - { - value: 'refactor', - label: 'Refactor', - description: 'Code change that neither fixes a bug nor adds a feature' - }, - { - value: 'perf', - label: 'Performance', - description: 'A code change that improves performance' - }, - {value: 'test', label: 'Test', description: 'Adding or correcting tests'}, - { - value: 'chore', - label: 'Chore', - description: "Other changes that don't modify src or test files" - }, - {value: 'custom', label: 'Custom', description: 'Custom type'} -]; - -const SCOPES = [ - { - value: 'regex', - label: 'Regex', - description: 'Changes related to regex patterns' - }, - { - value: 'format', - label: 'Format', - description: 'Changes related to custom formats' - }, - { - value: 'profile', - label: 'Profile', - description: 'Changes related to quality profiles' - }, - {value: 'custom', label: 'Custom', description: 'Custom scope'} -]; +import {COMMIT_TYPES, COMMIT_SCOPES} from '@constants/commits'; const formatBodyLines = text => { if (!text) return ''; @@ -69,21 +19,14 @@ const formatBodyLines = text => { const CommitSection = ({commitMessage, setCommitMessage}) => { const [type, setType] = useState(''); - const [customType, setCustomType] = useState(''); const [scope, setScope] = useState(''); - const [customScope, setCustomScope] = useState(''); const [subject, setSubject] = useState(''); const [body, setBody] = useState(''); const [footer, setFooter] = useState(''); useEffect(() => { - const effectiveType = type === 'custom' ? customType : type; - const effectiveScope = scope === 'custom' ? customScope : scope; - - if (effectiveType && subject) { - let message = `${effectiveType}${ - effectiveScope ? `(${effectiveScope})` : '' - }: ${subject}`; + if (type && subject) { + let message = `${type}${scope ? `(${scope})` : ''}: ${subject}`; if (body) { message += `\n\n${formatBodyLines(body)}`; @@ -97,16 +40,7 @@ const CommitSection = ({commitMessage, setCommitMessage}) => { } else { setCommitMessage(''); } - }, [ - type, - customType, - scope, - customScope, - subject, - body, - footer, - setCommitMessage - ]); + }, [type, scope, subject, body, footer, setCommitMessage]); const selectStyles = 'bg-gray-900 text-sm text-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500'; @@ -145,17 +79,6 @@ const CommitSection = ({commitMessage, setCommitMessage}) => { - {type === 'custom' && ( - - setCustomType(e.target.value) - } - placeholder='Enter custom type' - className={`w-full px-3 py-2 mt-2 rounded-md ${inputStyles}`} - /> - )}
- {scope === 'custom' && ( - - setCustomScope(e.target.value) - } - placeholder='Enter custom scope' - className={`w-full px-3 py-2 mt-2 rounded-md ${inputStyles}`} - /> - )} diff --git a/frontend/src/constants/commits.js b/frontend/src/constants/commits.js new file mode 100644 index 0000000..a049c93 --- /dev/null +++ b/frontend/src/constants/commits.js @@ -0,0 +1,40 @@ +export const COMMIT_TYPES = [ + { + value: 'create', + label: 'Create', + description: 'Building entirely new components or systems' + }, + { + value: 'add', + label: 'Add', + description: 'Adding entries to existing systems' + }, + { + value: 'tweak', + label: 'Tweak', + description: 'Fine-tuning and adjustments to existing components' + }, + { + value: 'fix', + label: 'Fix', + description: 'Corrections and bug fixes' + } +]; + +export const COMMIT_SCOPES = [ + { + value: 'regex', + label: 'Regex Pattern', + description: 'Changes related to regex patterns' + }, + { + value: 'format', + label: 'Custom Format', + description: 'Changes related to custom formats' + }, + { + value: 'profile', + label: 'Quality Profile', + description: 'Changes related to quality profiles' + } +];