From 877c00c8c6b69807f63e8536c3a1adeb6e1efa03 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Thu, 19 Sep 2024 12:39:32 +0930 Subject: [PATCH] feat: updating diff modal. - not finished yet --- .../src/components/settings/git/ChangeRow.jsx | 1 + .../settings/git/modal/DiffCommit.jsx | 51 +++++++++++++++ .../settings/git/modal/ViewDiff.jsx | 64 ++++++++++++------- 3 files changed, 94 insertions(+), 22 deletions(-) create mode 100644 frontend/src/components/settings/git/modal/DiffCommit.jsx diff --git a/frontend/src/components/settings/git/ChangeRow.jsx b/frontend/src/components/settings/git/ChangeRow.jsx index 543a312..2b73270 100644 --- a/frontend/src/components/settings/git/ChangeRow.jsx +++ b/frontend/src/components/settings/git/ChangeRow.jsx @@ -117,6 +117,7 @@ const ChangeRow = ({ name={change.name} commitMessage={change.commit_message} isDevMode={isDevMode} + isIncoming={isIncoming} /> ); diff --git a/frontend/src/components/settings/git/modal/DiffCommit.jsx b/frontend/src/components/settings/git/modal/DiffCommit.jsx new file mode 100644 index 0000000..50b4a69 --- /dev/null +++ b/frontend/src/components/settings/git/modal/DiffCommit.jsx @@ -0,0 +1,51 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import {GitCommit} from 'lucide-react'; + +const DiffCommit = ({commitMessage}) => { + if (!commitMessage) return null; + + const [firstLine, ...restLines] = commitMessage.split('\n'); + const [commitType, commitSummary] = firstLine.split(': '); + + return ( +
+
+ +
+

+ Commit Message +

+
+ + {commitType} + + + {commitSummary} + +
+ {restLines.length > 0 && ( +
    + {restLines.map((line, index) => ( +
  • + {line.trim()} +
  • + ))} +
+ )} +
+
+
+ ); +}; + +DiffCommit.propTypes = { + commitMessage: PropTypes.string +}; + +export default DiffCommit; diff --git a/frontend/src/components/settings/git/modal/ViewDiff.jsx b/frontend/src/components/settings/git/modal/ViewDiff.jsx index 5d2ffe2..3107189 100644 --- a/frontend/src/components/settings/git/modal/ViewDiff.jsx +++ b/frontend/src/components/settings/git/modal/ViewDiff.jsx @@ -1,6 +1,8 @@ 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 = ({ isOpen, @@ -9,11 +11,14 @@ const ViewDiff = ({ type, name, commitMessage, - title = 'View Diff' + isIncoming }) => { const formatDiffContent = content => { if (!content) return []; - return content.split('\n').map((line, index) => { + const lines = content.split('\n'); + // Remove the first 5 lines (git diff header) + const contentWithoutHeader = lines.slice(5); + return contentWithoutHeader.map((line, index) => { let lineClass = 'py-1 pl-4 border-l-2 '; if (line.startsWith('+')) { lineClass += 'bg-green-900/30 text-green-400 border-green-500'; @@ -35,29 +40,44 @@ const ViewDiff = ({ }); }; + const getTypeIcon = () => { + switch (type) { + case 'Regex Pattern': + return ; + case 'Custom Format': + return ; + case 'Quality Profile': + return ; + default: + return ; + } + }; + const formattedContent = formatDiffContent(diffContent); + const titleContent = ( +
+ {getTypeIcon()} + {`${type}: ${name}`} + + {isIncoming ? 'Incoming' : 'Outgoing'} + +
+ ); + return ( - +
-
-
- - Type: - - - {type} - -
-
- - Name: - - - {name === 'Deleted File' ? 'Deleted File' : name} - -
-
+
Diff Content @@ -84,7 +104,7 @@ ViewDiff.propTypes = { type: PropTypes.string.isRequired, name: PropTypes.string.isRequired, commitMessage: PropTypes.string, - title: PropTypes.string + isIncoming: PropTypes.bool.isRequired }; export default ViewDiff;