From a8c773be7a0bb9e26a564144cf2c5782c4120941 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Thu, 19 Sep 2024 13:45:54 +0930 Subject: [PATCH] refactor: improve and move type / scope tags to diff modal --- backend/app/git/status/utils.py | 2 +- .../settings/git/modal/DiffCommit.jsx | 43 ++++++----- .../settings/git/modal/ViewDiff.jsx | 72 ++++++++++++++----- 3 files changed, 74 insertions(+), 43 deletions(-) diff --git a/backend/app/git/status/utils.py b/backend/app/git/status/utils.py index 00d9784..18e7951 100644 --- a/backend/app/git/status/utils.py +++ b/backend/app/git/status/utils.py @@ -67,7 +67,7 @@ def parse_commit_message(commit_message): 'scope': 'Unknown Scope', 'subject': 'No subject provided', 'body': 'No body provided', - 'footer': 'No footer provided' + 'footer': '' } # Mapping of commit types and scopes to canonical forms diff --git a/frontend/src/components/settings/git/modal/DiffCommit.jsx b/frontend/src/components/settings/git/modal/DiffCommit.jsx index 6fafc75..ff9e848 100644 --- a/frontend/src/components/settings/git/modal/DiffCommit.jsx +++ b/frontend/src/components/settings/git/modal/DiffCommit.jsx @@ -1,42 +1,39 @@ import React from 'react'; import PropTypes from 'prop-types'; -import {GitCommit} from 'lucide-react'; const DiffCommit = ({commitMessage}) => { if (!commitMessage) return null; - const {type, scope, subject, body, footer} = commitMessage; + const {subject, body, footer} = commitMessage; return ( -
+
-
-

- Commit Message -

- - {type} - - - {`${scope ? `(${scope})` : ''} ${subject}`} + + {subject}
+ + {/* Render the body without double hyphens */} {body && (
    - {body.split('\n').map((line, index) => ( -
  • - {line.trim()} -
  • - ))} + {body + .split('\n') + .filter(line => line.trim().startsWith('-')) // Ensure we only take lines starting with "-" + .map((line, index) => ( +
  • + {line.trim().replace(/^-\s*/, '')}{' '} + {/* Remove leading hyphen */} +
  • + ))}
)} + + {/* Render the footer if it exists */} {footer && (
{footer} @@ -50,7 +47,7 @@ const DiffCommit = ({commitMessage}) => { DiffCommit.propTypes = { commitMessage: PropTypes.shape({ - type: PropTypes.string.isRequired, + type: PropTypes.string, scope: PropTypes.string, subject: PropTypes.string.isRequired, body: PropTypes.string, diff --git a/frontend/src/components/settings/git/modal/ViewDiff.jsx b/frontend/src/components/settings/git/modal/ViewDiff.jsx index 175099d..57872c0 100644 --- a/frontend/src/components/settings/git/modal/ViewDiff.jsx +++ b/frontend/src/components/settings/git/modal/ViewDiff.jsx @@ -1,7 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import Modal from '../../../ui/Modal'; -import {Code, FileText, Settings, File} from 'lucide-react'; import DiffCommit from './DiffCommit'; const ViewDiff = ({ @@ -40,25 +39,45 @@ const ViewDiff = ({ }); }; - const getTypeIcon = () => { - switch (type) { - case 'Regex Pattern': - return ; - case 'Custom Format': - return ; - case 'Quality Profile': - return ; - default: - return ; - } + // Tag background colors based on the type and scope + const typeColors = { + 'New Feature': + 'bg-green-100 text-white-800 dark:bg-green-900 dark:text-white-200', + 'Bug Fix': + 'bg-red-100 text-white-800 dark:bg-red-900 dark:text-white-200', + Documentation: + 'bg-yellow-100 text-white-800 dark:bg-yellow-900 dark:text-white-200', + 'Style Change': + 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200', + Refactoring: + 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200', + 'Performance Improvement': + 'bg-teal-100 text-teal-800 dark:bg-teal-900 dark:text-teal-200', + 'Test Addition/Modification': + 'bg-pink-100 text-pink-800 dark:bg-pink-900 dark:text-pink-200', + 'Chore/Maintenance': + 'bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200' }; - const formattedContent = formatDiffContent(diffContent); + const scopeColors = { + 'Regex Pattern': + 'bg-blue-100 text-white-800 dark:bg-blue-900 dark:text-white-200', + 'Custom Format': + 'bg-green-100 text-white-800 dark:bg-green-900 dark:text-white-200', + 'Quality Profile': + 'bg-yellow-100 text-white-800 dark:bg-yellow-900 dark:text-white-200' + }; + + const renderTag = (label, colorClass) => ( + + {label} + + ); const titleContent = ( -
- {getTypeIcon()} - {`${type}: ${name}`} +
+ {name} {isIncoming ? 'Incoming' : 'Outgoing'} + {commitMessage && + commitMessage.type && + renderTag( + commitMessage.type, + typeColors[commitMessage.type] || + 'bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200' + )} + {commitMessage && + commitMessage.scope && + renderTag( + commitMessage.scope, + scopeColors[commitMessage.scope] || + 'bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200' + )}
); + const formattedContent = formatDiffContent(diffContent); + return ( + width='3xl'>
- {' '} - {/* Passing the commitMessage object */} +
Diff Content