From dcbfedcc7aa1deae9bc62bd45280ea637dc3735f Mon Sep 17 00:00:00 2001 From: Rosanna Milner Date: Tue, 6 Aug 2024 09:22:15 +0100 Subject: [PATCH] changes requested --- .../NavItems/Assistant/Assistant.jsx | 7 -- .../AssistantApiHandlers/useAssistantApi.jsx | 96 ------------------- .../ExtractedSourceCredibilityDBKFDialog.jsx | 40 ++++---- .../SourceCredibilityResult.jsx | 3 - .../AssistantTextClassification.jsx | 51 +--------- .../AssistantTextSpanClassification.jsx | 5 +- .../ColourGradientTooltipContent.jsx | 52 ++++++++++ .../AssistantScrapeResults/assistantUtils.jsx | 25 ----- 8 files changed, 70 insertions(+), 209 deletions(-) create mode 100644 src/components/NavItems/Assistant/AssistantScrapeResults/ColourGradientTooltipContent.jsx diff --git a/src/components/NavItems/Assistant/Assistant.jsx b/src/components/NavItems/Assistant/Assistant.jsx index cdcc397d9..8906cf816 100644 --- a/src/components/NavItems/Assistant/Assistant.jsx +++ b/src/components/NavItems/Assistant/Assistant.jsx @@ -53,13 +53,6 @@ const Assistant = () => { //third party check states const neResult = useSelector((state) => state.assistant.neResultCategory); - const newsFramingResult = useSelector( - (state) => state.assistant.newsFramingResult, - ); - const newsGenreResult = useSelector( - (state) => state.assistant.newsGenreResult, - ); - const hpResult = useSelector((state) => state.assistant.hpResult); // source credibility const positiveSourceCred = useSelector( diff --git a/src/components/NavItems/Assistant/AssistantApiHandlers/useAssistantApi.jsx b/src/components/NavItems/Assistant/AssistantApiHandlers/useAssistantApi.jsx index 1c7917228..800c5f39c 100644 --- a/src/components/NavItems/Assistant/AssistantApiHandlers/useAssistantApi.jsx +++ b/src/components/NavItems/Assistant/AssistantApiHandlers/useAssistantApi.jsx @@ -166,101 +166,6 @@ export default function assistantApiCalls() { ); }; - const MAX_NUM_RETRIES = 3; - - /** - * Calls an async function that throws an exception when it fails, will retry for numMaxRetries - * @param numMaxRetries Number of times the function will be retried - * @param asyncFunc The async function to call - * @param errorFunc Called when asyncFunc throws an error when there are additional retries - * @returns {Promise<*>} Output of asyncFunc - */ - async function callAsyncWithNumRetries( - numMaxRetries, - asyncFunc, - errorFunc = null, - ) { - for (let retryCount = 0; retryCount < numMaxRetries; retryCount++) { - try { - return await asyncFunc(); - } catch (e) { - if (retryCount + 1 >= MAX_NUM_RETRIES) { - throw e; - } else { - if (errorFunc) errorFunc(retryCount, e); - } - } - } - } - - const callNewsFramingService = async (text) => { - return await callAsyncWithNumRetries( - MAX_NUM_RETRIES, - async () => { - const result = await axios.post( - assistantEndpoint + "gcloud/news-framing-clfr", - { text: text }, - ); - return result.data; - }, - (numTries) => { - console.log( - "Could not connect to news framing service, tries " + - (numTries + 1) + - "/" + - MAX_NUM_RETRIES, - ); - }, - ); - }; - - const callNewsGenreService = async (text) => { - return await callAsyncWithNumRetries( - MAX_NUM_RETRIES, - async () => { - const result = await axios.post( - assistantEndpoint + "gcloud/news-genre-clfr", - { text: text }, - ); - return result.data; - }, - (numTries) => { - console.log( - "Could not connect to news genre service, tries " + - (numTries + 1) + - "/" + - MAX_NUM_RETRIES, - ); - }, - ); - }; - - const callPersuasionService = async (text) => { - return await callAsyncWithNumRetries( - MAX_NUM_RETRIES, - async () => { - const result = await axios.post( - assistantEndpoint + "gcloud/persuasion-span-clfr", - { text: text }, - ); - return result.data; - }, - (numTries) => { - console.log( - "Could not connect to persuasion service, tries " + - (numTries + 1) + - "/" + - MAX_NUM_RETRIES, - ); - }, - ); - }; - - const callOcrScriptService = async () => { - const result = await axios.get(assistantEndpoint + "gcloud/ocr-scripts"); - return result.data; - }; - const callSubjectivityService = async (text) => { return await callAsyncWithNumRetries( MAX_NUM_RETRIES, @@ -332,7 +237,6 @@ export default function assistantApiCalls() { callSourceCredibilityService, callNamedEntityService, callOcrService, - callOcrScriptService, callNewsFramingService, callNewsGenreService, callPersuasionService, diff --git a/src/components/NavItems/Assistant/AssistantCheckResults/ExtractedSourceCredibilityDBKFDialog.jsx b/src/components/NavItems/Assistant/AssistantCheckResults/ExtractedSourceCredibilityDBKFDialog.jsx index 45ab449e7..681b6e3cb 100644 --- a/src/components/NavItems/Assistant/AssistantCheckResults/ExtractedSourceCredibilityDBKFDialog.jsx +++ b/src/components/NavItems/Assistant/AssistantCheckResults/ExtractedSourceCredibilityDBKFDialog.jsx @@ -139,30 +139,22 @@ const ExtractedSourceCredibilityDBKFDialog = ({ ? sourceCredibilityResults.map((value, key) => ( }> - {sourceCredibilityResults[key] ? ( - sourceCredibilityResults[ - key - ].credibilityScope.includes("/") ? ( - - {` ${keyword("this")}`} - {getUrlTypeFromCredScope( - value.credibilityScope, - )} - {` ${keyword( - "source_credibility_warning_account", - )} ${" "}${value.credibilitySource}`} - - ) : sourceCredibilityResults[key] - .credibilityScope ? ( - - {` ${keyword( - "source_cred_popup_header_domain", - )} ${ - sourceCredibilityResults[key] - .credibilitySource - } `} - - ) : null + {value.credibilityScope.includes("/") ? ( + + {` ${keyword("this")}`} + {getUrlTypeFromCredScope( + value.credibilityScope, + )} + {` ${keyword( + "source_credibility_warning_account", + )} ${" "}${value.credibilitySource}`} + + ) : value.credibilityScope ? ( + + {` ${keyword( + "source_cred_popup_header_domain", + )} ${value.credibilitySource} `} + ) : null} diff --git a/src/components/NavItems/Assistant/AssistantCheckResults/SourceCredibilityResult.jsx b/src/components/NavItems/Assistant/AssistantCheckResults/SourceCredibilityResult.jsx index a406b7a75..aa26f6f92 100644 --- a/src/components/NavItems/Assistant/AssistantCheckResults/SourceCredibilityResult.jsx +++ b/src/components/NavItems/Assistant/AssistantCheckResults/SourceCredibilityResult.jsx @@ -40,9 +40,6 @@ const SourceCredibilityResult = (props) => { {value.credibilityScope.includes("/") ? ( {` ${keyword("this")}`} - {/* {inputUrlType - ? capitaliseFirstLetter(inputUrlType) - : null} */} {getUrlTypeFromCredScope(value.credibilityScope)} {` ${keyword( "source_credibility_warning_account", diff --git a/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextClassification.jsx b/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextClassification.jsx index c78641520..6dbce8576 100644 --- a/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextClassification.jsx +++ b/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextClassification.jsx @@ -1,6 +1,4 @@ import React, { useState } from "react"; -import { useDispatch } from "react-redux"; - import Card from "@mui/material/Card"; import { CardHeader, @@ -22,10 +20,10 @@ import { interpRgb, rgbToString, rgbToLuminance, - rgbListToGradient, treeMapToElements, wrapPlainTextSpan, } from "./assistantUtils"; +import ColourGradientTooltipContent from "./ColourGradientTooltipContent"; import "./assistantTextResultStyle.css"; @@ -290,50 +288,3 @@ export function ClassifiedText({ return {output}; } - -export function ColourGradientScale({ textLow, textHigh, rgbList }) { - return ( - <> - - - - {textLow} - - - - - {textHigh} - - - -
- - ); -} - -export function ColourGradientTooltipContent({ - description = "", - colourScaleText, - textLow = "Low", - textHigh = "High", - rgbLow = [0, 0, 0], - rgbHigh = [255, 255, 255], -}) { - return ( -
- {description} -

{colourScaleText}

- -
- ); -} diff --git a/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextSpanClassification.jsx b/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextSpanClassification.jsx index 49ba3c43f..46a930b82 100644 --- a/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextSpanClassification.jsx +++ b/src/components/NavItems/Assistant/AssistantScrapeResults/AssistantTextSpanClassification.jsx @@ -1,7 +1,4 @@ import React, { useState } from "react"; -import { useDispatch } from "react-redux"; - -import { Button } from "@mui/material"; import Card from "@mui/material/Card"; import { CardHeader, Chip, List, ListItem, ListItemText } from "@mui/material"; @@ -23,7 +20,7 @@ import { mergeSpanIndices, wrapPlainTextSpan, } from "./assistantUtils"; -import { ColourGradientTooltipContent } from "./AssistantTextClassification"; +import ColourGradientTooltipContent from "./ColourGradientTooltipContent"; import { styled } from "@mui/system"; // Had to create a custom styled span as the default style attribute does not support diff --git a/src/components/NavItems/Assistant/AssistantScrapeResults/ColourGradientTooltipContent.jsx b/src/components/NavItems/Assistant/AssistantScrapeResults/ColourGradientTooltipContent.jsx new file mode 100644 index 000000000..9ef768942 --- /dev/null +++ b/src/components/NavItems/Assistant/AssistantScrapeResults/ColourGradientTooltipContent.jsx @@ -0,0 +1,52 @@ +import React from "react"; +import Grid from "@mui/material/Grid"; +import Typography from "@mui/material/Typography"; + +import { rgbListToGradient } from "./assistantUtils"; + +export function ColourGradientScale({ textLow, textHigh, rgbList }) { + return ( + <> + + + + {textLow} + + + + + {textHigh} + + + +
+ + ); +} + +export default function ColourGradientTooltipContent({ + description = "", + colourScaleText, + textLow = "Low", + textHigh = "High", + rgbLow = [0, 0, 0], + rgbHigh = [255, 255, 255], +}) { + return ( +
+ {description} +

{colourScaleText}

+ +
+ ); +} diff --git a/src/components/NavItems/Assistant/AssistantScrapeResults/assistantUtils.jsx b/src/components/NavItems/Assistant/AssistantScrapeResults/assistantUtils.jsx index 481d82d64..0755491a5 100644 --- a/src/components/NavItems/Assistant/AssistantScrapeResults/assistantUtils.jsx +++ b/src/components/NavItems/Assistant/AssistantScrapeResults/assistantUtils.jsx @@ -1,7 +1,5 @@ import React from "react"; import _ from "lodash"; -import { ColourGradientTooltipContent } from "./AssistantTextClassification"; -import Tooltip from "@mui/material/Tooltip"; /** * Interpolate RGB between an arbitrary range @@ -85,35 +83,17 @@ function treeMapToElementsRecursive( if ("span" in treeElem) { const span = treeElem.span; if (spanHighlightIndices === null) { - console.log("No span highlight: ", text.substring(span.start, span.end)); childElems.push(text.substring(span.start, span.end)); } else { - console.log("Span highlight: ", text.substring(span.start, span.end)); let currentIndex = span.start; for (let i = 0; i < spanHighlightIndices.length; i++) { const hSpan = spanHighlightIndices[i]; - console.log( - "Matching span", - span.start, - span.end, - hSpan.indices[0], - hSpan.indices[1], - ); const hSpanStart = hSpan.indices[0]; const hSpanEnd = hSpan.indices[1]; if ( (span.start <= hSpanStart && hSpanStart <= span.end) || (span.start <= hSpanEnd && hSpanEnd <= span.end) ) { - //If there's an overlap - console.log( - "Found lapping span ", - span.start, - span.end, - hSpanStart, - hSpanEnd, - ); - // If span doesn't start before the current index if (hSpanStart > currentIndex) { childElems.push(text.substring(currentIndex, hSpanStart)); @@ -123,7 +103,6 @@ function treeMapToElementsRecursive( hSpanStart < span.start ? span.start : hSpanStart; const boundedEnd = hSpanEnd > span.end ? span.end : hSpanEnd; if (wrapFunc) { - console.log("Wrapping: ", text.substring(boundedStart, boundedEnd)); childElems.push( wrapFunc( text.substring(boundedStart, boundedEnd), @@ -133,10 +112,6 @@ function treeMapToElementsRecursive( ), ); } else { - // console.log( - // "Not wrapping: ", - // text.substring(boundedStart, boundedEnd), - // ); childElems.push(text.substring(boundedStart, boundedEnd)); }