diff --git a/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/SelectMultipleTextMultipleTags.tsx b/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/SelectMultipleTextMultipleTags.tsx index 45446ea2..1e5e3acb 100644 --- a/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/SelectMultipleTextMultipleTags.tsx +++ b/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/SelectMultipleTextMultipleTags.tsx @@ -1,9 +1,9 @@ -import React, { FC, useEffect, useState, useContext } from "react"; +import React, { FC, useEffect, useState } from "react"; import { Button } from "react-bootstrap"; import { TokenAnnotator } from "react-text-annotate"; -import useFetch from "use-http"; import { PacmanLoader } from "react-spinners"; import Swal from "sweetalert2"; +import useFetch from "use-http"; import { ContextConfigType } from "new_front/types/createSamples/createSamples/annotationContext"; import { ContextAnnotationFactoryType } from "new_front/types/createSamples/createSamples/annotationFactory"; @@ -59,6 +59,7 @@ const SelectMultipleTextMultipleTags: FC< const [text, setText] = useState(undefined); const [contextId, setContextId] = useState(null); const [realRoundId, setRealRoundId] = useState(null); + const [loading2, setLoading2] = useState(false); const submitButton: HTMLElement | null = document.getElementById("submit"); @@ -95,31 +96,47 @@ const SelectMultipleTextMultipleTags: FC< } }, [preferedTag]); - const handleSubmit = async (value: string | null) => { + useEffect(() => { + text?.length && setLoading2(false); + }, [text]); + + const handleSubmit = (value: string | null) => { !value && (value = tagSelection.back_label); submitButton && (submitButton.hidden = false); - const bringContext = await post( - "/context/get_random_context_from_key_value/", + setLoading2(true); + setSelectionInfo([]); + fetch( + `${process.env.REACT_APP_API_HOST_2}/context/get_random_context_from_key_value/`, { - key_name: field_names_for_the_model?.tag_name_search, - key_value: value, + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + key_name: field_names_for_the_model?.tag_name_search, + key_value: value, + }), }, - ); - if (response.ok) { - !bringContext && - Swal.fire({ - title: instruction?.context_alert_title, - text: instruction?.context_alert_text, - icon: "warning", - confirmButtonText: "Ok", - }).then(() => { - handleSubmit(field_names_for_the_model?.default_tag); - }); - console.log("bringContext", bringContext); - setText(bringContext?.content); - setContextId(bringContext?.id); - setRealRoundId(bringContext?.round_id); - } + ) + .then((response) => response.json()) + .then((data) => { + !data && + Swal.fire({ + title: instruction?.context_alert_title, + text: instruction?.context_alert_text, + icon: "warning", + confirmButtonText: "Ok", + }).then(() => { + handleSubmit(field_names_for_the_model?.default_tag); + }); + console.log("bringContext", data); + setText(data?.content); + setContextId(data?.id); + setRealRoundId(data?.round_id); + }) + .catch((error) => { + console.warn("error", error); + }); }; const handleSelectAll = async () => { @@ -137,11 +154,13 @@ const SelectMultipleTextMultipleTags: FC< const handleSubmitExample = async () => { const newSelectionInfo = cleanUpSelection(selectionInfo, "color"); - const response = await post("/example/create_example/", { + const sendText = text; + setText(undefined); + await post("/example/create_example/", { context_id: contextId, user_id: userId, input_json: { labels: newSelectionInfo }, - text: text, + text: sendText, task_id: taskId, round_id: realRoundId, increment_context: true, @@ -172,7 +191,7 @@ const SelectMultipleTextMultipleTags: FC< > {!text ? ( <> - {!loading ? ( + {!loading && !loading2 ? (
{instruction?.preselection && (
@@ -202,7 +221,11 @@ const SelectMultipleTextMultipleTags: FC<
Data is being prepared, please wait...
- +
)} @@ -224,6 +247,20 @@ const SelectMultipleTextMultipleTags: FC<
+
+
+ +
+
)} /> - -
-
- -
-
-
-
- +
+
+ +
+
+ +
diff --git a/frontends/web/src/new_front/components/Inputs/DropdownSearch.tsx b/frontends/web/src/new_front/components/Inputs/DropdownSearch.tsx index 93d8a60e..24a3fb37 100644 --- a/frontends/web/src/new_front/components/Inputs/DropdownSearch.tsx +++ b/frontends/web/src/new_front/components/Inputs/DropdownSearch.tsx @@ -40,7 +40,9 @@ const DropdownSearch: FC = ({
{value}
) : ( -
+