Skip to content

Commit

Permalink
feat(frontend): Display better error messages during model comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
freshavocado7 authored and Wuestengecko committed Oct 1, 2024
1 parent 1cc496d commit cbca3b0
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 196 deletions.
11 changes: 8 additions & 3 deletions capella_model_explorer/backend/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ async def post_compare(commit_range: CommitRange):
self.model, commit_range.head, commit_range.prev
)
self.diff["lookup"] = create_diff_lookup(self.diff["objects"])
return {"success": True}
if self.diff["lookup"]:
return {"success": True}
return {"success": False, "error": "No model changes to show"}
except Exception as e:
LOGGER.exception("Failed to compare versions")
return {"success": False, "error": str(e)}
Expand All @@ -301,8 +303,11 @@ async def post_object_diff(object_id: ObjectDiffID):

@self.router.get("/api/commits")
async def get_commits():
result = model_diff.populate_commits(self.model)
return result
try:
result = model_diff.populate_commits(self.model)
return result
except Exception as e:
return {"error": str(e)}

@self.router.get("/api/diff")
async def get_diff():
Expand Down
2 changes: 1 addition & 1 deletion capella_model_explorer/backend/model_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _get_revision_info(
.strip()
.split("\x00")
)
subject = description.splitlines()[0]
subject = description.splitlines()[0] if description.splitlines() else ""
try:
tag = subprocess.check_output(
["git", "tag", "--points-at", revision],
Expand Down
46 changes: 46 additions & 0 deletions frontend/src/components/CommitInformation.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

const CommitInformation = ({
commitDetails,
isExpanded,
toggleExpand,
section
}) => {
return (
<div className="text-left">
<p>
<span className="font-semibold">Hash:</span> {commitDetails.hash}
</p>
{commitDetails.tag && (
<p>
<span className="font-semibold">Tag:</span> {commitDetails.tag}
</p>
)}
<p>
<span className="font-semibold">Author:</span> {commitDetails.author}
</p>
<p style={{ whiteSpace: 'pre-wrap' }}>
<span className="font-semibold">Description:</span>{' '}
{isExpanded
? commitDetails.description
: `${commitDetails.description.split('\n')[0]}${
commitDetails.description.includes('\n') ? '' : ''
}`}
</p>
{commitDetails.description.includes('\n') && (
<button
className="mb-4 mt-2 font-normal text-custom-blue
hover:text-custom-blue-hover"
onClick={() => toggleExpand(section)}>
{isExpanded ? 'Show Less' : 'Show Full Description'}
</button>
)}
<p>
<span className="font-semibold">Date:</span> {commitDetails.date}
</p>
</div>
);
};

export default CommitInformation;
Loading

0 comments on commit cbca3b0

Please sign in to comment.