Skip to content

Commit

Permalink
added code for when no persuasion techniques returned
Browse files Browse the repository at this point in the history
  • Loading branch information
rosannamilner committed Aug 7, 2024
1 parent e1934cb commit 86febec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion public/locales/en/components/NavItems/tools/Assistant.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"subjectivity": "Subjectivity",
"subjectivity_tooltip": "Identify the subjective sentences of the extracted text.",
"subjective_sentences_detected": "Subjective sentences detected",
"no_subjective_sentences_detected": "No subjective sentences detected",
"none_detected": "None detected",
"previous_fact_checks": "Previous Fact-Checks",
"previous_fact_checks_tooltip": "The Fact Check Semantic Search tool identifies whether the extracted text has previously been detected in a fact check database. It displays the most recent matches, up to a maximum of 5. This tool is currently only accessible to beta users.",
"more_details": "For more details see",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@ const calculateSubjectivity = (sentences) => {
}
}

return [
return (
" (",
scoresSUBJ.length,
[" (", scoresSUBJ.length, "/", sentences.length, ")"]
.toString()
.replaceAll(",", ""),
];
"/",
sentences.length,
")".toString().replaceAll(",", "")
);
};

const getExpandIcon = (loading, fail, done = null, role = null) => {
if (loading || fail || done || (role && !role.includes("BETA_TESTER"))) {
// "done" is for when subjectivityDone = true and subjectivityResult.entities.length
// "done" is for when subjectivityDone = true and Object.keys(result.entities).length < 1
return <Remove />;
} else {
return <ExpandMoreIcon />;
Expand Down Expand Up @@ -542,11 +543,21 @@ const AssistantCredSignals = () => {
<StyledAccordion
expanded={expandedAccordion === persuasionTitle}
onChange={handleChange(persuasionTitle)}
disabled={persuasionLoading || persuasionFail}
disabled={
persuasionLoading ||
persuasionFail ||
(persuasionDone &&
Object.keys(persuasionResult.entities).length < 1)
}
disableGutters
>
<AccordionSummary
expandIcon={getExpandIcon(persuasionLoading, persuasionFail)}
expandIcon={getExpandIcon(
persuasionLoading,
persuasionFail,
persuasionDone &&
Object.keys(persuasionResult.entities).length < 1,
)}
>
<Grid container wrap="wrap">
<Grid item xs={4} align="left">
Expand All @@ -571,6 +582,14 @@ const AssistantCredSignals = () => {
{renderEntityKeys(persuasionResult.entities)}
</Typography>
)}
{persuasionDone &&
Object.keys(persuasionResult.entities).length < 1 && (
<Typography
sx={{ color: "text.secondary", align: "left" }}
>
{keyword("none_detected")}
</Typography>
)}
</Grid>
</Grid>
</AccordionSummary>
Expand Down Expand Up @@ -646,13 +665,18 @@ const AssistantCredSignals = () => {
)}
{subjectivityDone && (
<Typography sx={{ color: "text.secondary", align: "left" }}>
{calculateSubjectivity(subjectivityResult.sentences)[0] !=
0
? keyword("subjective_sentences_detected") +
calculateSubjectivity(subjectivityResult.sentences)[1]
: keyword("no_subjective_sentences_detected")}
{keyword("subjective_sentences_detected")}{" "}
{calculateSubjectivity(subjectivityResult.sentences)}
</Typography>
)}
{subjectivityDone &&
Object.keys(subjectivityResult.entities).length < 1 && (
<Typography
sx={{ color: "text.secondary", align: "left" }}
>
{keyword("none_detected")}
</Typography>
)}
</Grid>
</Grid>
</AccordionSummary>
Expand Down

0 comments on commit 86febec

Please sign in to comment.