From 8f7f7cf591ec854e655ea173b4c0462786546121 Mon Sep 17 00:00:00 2001 From: anamontiaga Date: Fri, 8 Sep 2023 16:16:23 +0200 Subject: [PATCH 1/2] 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 && ( + + )}
- - )} -
+ )}
diff --git a/app/layout/project/sidebar/scenario/solutions/overview/index.tsx b/app/layout/project/sidebar/scenario/solutions/overview/index.tsx index 9cd447dd05..131e500a1a 100644 --- a/app/layout/project/sidebar/scenario/solutions/overview/index.tsx +++ b/app/layout/project/sidebar/scenario/solutions/overview/index.tsx @@ -7,6 +7,7 @@ import { useRouter } from 'next/router'; import { getScenarioEditSlice } from 'store/slices/scenarios/edit'; import { motion } from 'framer-motion'; +import { HiOutlineTable } from 'react-icons/hi'; import { useProject } from 'hooks/projects'; import { useScenario, useDownloadScenarioReport } from 'hooks/scenarios'; @@ -14,15 +15,12 @@ import { useSolution, useBestSolution } from 'hooks/solutions'; import { useToasts } from 'hooks/toast'; import Button from 'components/button'; -import Icon from 'components/icon'; import Loading from 'components/loading'; import Modal from 'components/modal'; import Section from 'layout/section'; import SolutionSelected from 'layout/solutions/selected'; import { formatFileName } from 'utils/units'; -import TABLE_SVG from 'svgs/ui/table.svg?sprite'; - import SolutionsTableForm from './table/table-form/component'; export const SolutionsOverview = (): JSX.Element => { @@ -179,7 +177,7 @@ export const SolutionsOverview = (): JSX.Element => { - -