Skip to content

Commit 0c8fe31

Browse files
committed
feat: added diff to Comparator
1 parent 3e138c9 commit 0c8fe31

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/components/ProjectCompartor.tsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { scoreChecker } from "../utils/comparator/scoreChecker";
77
import CommonError from "./CommonError";
88
import Collapsible from "./Collapsable";
99
import Loading from "./Loading";
10-
10+
import { ComparatorDiff } from "./ComparatorDiff";
1111
import { ScoreElement } from "../types";
1212

1313
import "../styles/ProjectDetails.css";
@@ -22,7 +22,7 @@ function ProjectComparator() {
2222
queryKey: ["prevCommit"],
2323
queryFn: async () => {
2424
const response = await fetch(
25-
getScorecardUrl({ platform, org, repo, commitHash: prevCommitHash })
25+
getScorecardUrl({ platform, org, repo, commitHash: prevCommitHash }),
2626
);
2727
if (response.status >= 500) {
2828
throw new Error("An error ocurred. Invalid response from server");
@@ -35,7 +35,7 @@ function ProjectComparator() {
3535
queryKey: ["currentCommit"],
3636
queryFn: async () => {
3737
const response = await fetch(
38-
getScorecardUrl({ platform, org, repo, commitHash: currentCommitHash })
38+
getScorecardUrl({ platform, org, repo, commitHash: currentCommitHash }),
3939
);
4040
if (response.status >= 500) {
4141
throw new Error("An error ocurred. Invalid response from server");
@@ -85,7 +85,7 @@ function ProjectComparator() {
8585
url: e1.documentation.url,
8686
};
8787
}
88-
}
88+
},
8989
);
9090
setState(consolidatedData);
9191
};
@@ -157,23 +157,27 @@ function ProjectComparator() {
157157
See documentation
158158
</a>
159159
</p>
160-
<p>
161-
Reasoning: <span>{element?.reason.toLocaleLowerCase()}</span>
162-
</p>
163-
{Array.isArray(element.details) && (
164-
<Collapsible details={element.details} />
165-
)}
166160
{(element.prevDetails || element.prevReason) && (
167-
<>
168-
<h4>Additional details / variations</h4>
169-
<p>
170-
Previous revision reasoning:{" "}
171-
<span>{element.prevReason.toLocaleLowerCase()}</span>
172-
</p>
173-
{element.prevDetails && (
174-
<Collapsible details={element.prevDetails} />
175-
)}
176-
</>
161+
<h4>Additional details / variations</h4>
162+
)}
163+
{element.prevReason && element.reason ? (
164+
<p>
165+
Reasoning:{" "}
166+
<ComparatorDiff
167+
previous={element.prevReason.toLocaleLowerCase()}
168+
current={element.reason.toLocaleLowerCase()}
169+
/>
170+
</p>
171+
) : (
172+
<p>
173+
Reasoning: <span>{element?.reason.toLocaleLowerCase()}</span>
174+
</p>
175+
)}
176+
{Array.isArray(element.details) && (
177+
<Collapsible
178+
details={element.details}
179+
prevDetails={element.prevDetails}
180+
/>
177181
)}
178182
</div>
179183
<hr />

0 commit comments

Comments
 (0)