From 8f7f7cf591ec854e655ea173b4c0462786546121 Mon Sep 17 00:00:00 2001 From: anamontiaga Date: Fri, 8 Sep 2023 16:16:23 +0200 Subject: [PATCH] change solutions report btn --- .../sidebar/project/scenarios-list/index.tsx | 51 +++++++++++++++++-- .../scenario/solutions/overview/index.tsx | 49 +----------------- 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/app/layout/project/sidebar/project/scenarios-list/index.tsx b/app/layout/project/sidebar/project/scenarios-list/index.tsx index 8beda93581..8643780753 100644 --- a/app/layout/project/sidebar/project/scenarios-list/index.tsx +++ b/app/layout/project/sidebar/project/scenarios-list/index.tsx @@ -16,6 +16,7 @@ import { useScenarios, useDuplicateScenario, useCancelRunScenario, + useDownloadSolutionsSummary, } from 'hooks/scenarios'; import { useToasts } from 'hooks/toast'; @@ -42,8 +43,9 @@ export const ScenariosList: React.FC = () => { const queryClient = useQueryClient(); const { addToast } = useToasts(); - const [modal, setModal] = useState(false); + const [modal, setModal] = useState(false); const [deleteScenario, setDelete] = useState(null); + const [solutionsReportLoader, setSolutionsReportLoader] = useState(false); const { search, filters, sort } = useSelector((state) => state['/projects/[id]']); @@ -187,6 +189,33 @@ export const ScenariosList: React.FC = () => { [addToast, cancelRunMutation] ); + const downloadSolutionsSummary = useDownloadSolutionsSummary(); + + const onDownloadSolutionsSummary = useCallback(() => { + setSolutionsReportLoader(true); + + downloadSolutionsSummary.mutate( + { id: pid }, + { + onError: () => { + addToast( + 'download-error', + <> +

Error!

+
    Solutions report not downloaded
+ , + { + level: 'error', + } + ); + }, + onSettled: () => { + setSolutionsReportLoader(false); + }, + } + ); + }, [downloadSolutionsSummary, addToast, pid]); + return (
{ className="relative flex flex-grow flex-col space-y-3 overflow-hidden" > {(hasScenarios || search || hasFilters) && } -
{ )}
- {!hasScenarios && !search && !hasFilters && scenariosIsFetched && (
{ )} {(hasScenarios || search || hasFilters) && ( -
+
+ {hasScenarios && ( + + )}
- -