diff --git a/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx b/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx index 3aaaf4509b..5000dd2634 100644 --- a/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx @@ -196,7 +196,7 @@ function ResultDetails() { type: Column.DateTime, editable: false, }, - ...generateResultColumns(resultColHeaders), + ...generateResultColumns({ titles: resultColHeaders }), ]); }, [matrixRes.data, resultColHeaders]); diff --git a/webapp/src/components/common/Matrix/components/MatrixGridSynthesis/index.tsx b/webapp/src/components/common/Matrix/components/MatrixGridSynthesis/index.tsx index ad56f83b49..04af258ce1 100644 --- a/webapp/src/components/common/Matrix/components/MatrixGridSynthesis/index.tsx +++ b/webapp/src/components/common/Matrix/components/MatrixGridSynthesis/index.tsx @@ -88,7 +88,7 @@ export function MatrixGridSynthesis({ rows={data.length} columns={columns} getCellContent={getCellContent} - rowMarkers="both" + rowMarkers="none" smoothScrollX smoothScrollY rowHeight={30} diff --git a/webapp/src/components/common/Matrix/shared/types.ts b/webapp/src/components/common/Matrix/shared/types.ts index 6faae0402f..306785df86 100644 --- a/webapp/src/components/common/Matrix/shared/types.ts +++ b/webapp/src/components/common/Matrix/shared/types.ts @@ -75,6 +75,11 @@ export type ResultColumn = Omit & { title: string[]; }; +export interface ResultColumnsOptions { + titles: string[][]; + width?: number; +} + export type AggregateConfig = AggregateType[] | boolean | "stats" | "all"; export interface MatrixAggregates { diff --git a/webapp/src/components/common/Matrix/shared/utils.ts b/webapp/src/components/common/Matrix/shared/utils.ts index b9233c11a7..92072ccba3 100644 --- a/webapp/src/components/common/Matrix/shared/utils.ts +++ b/webapp/src/components/common/Matrix/shared/utils.ts @@ -23,6 +23,7 @@ import { type FormatGridNumberOptions, DataColumnsConfig, ResultColumn, + ResultColumnsOptions, } from "./types"; import { parseISO, Locale } from "date-fns"; import { fr, enUS } from "date-fns/locale"; @@ -383,16 +384,21 @@ export function groupResultColumns( * - [0]: Variable name (e.g., "OV. COST") * - [1]: Unit (e.g., "Euro", "MW") * - [2]: Statistic type (e.g., "MIN", "MAX", "STD") - * + * @param width - The width of each column * @returns Array of ResultColumn objects ready for use in result matrices * * @see groupResultColumns - Use this function to apply grouping to the generated columns */ -export function generateResultColumns(titles: string[][]): ResultColumn[] { + +export function generateResultColumns({ + titles, + width, +}: ResultColumnsOptions): ResultColumn[] { return titles.map((title, index) => ({ id: `custom${index + 1}`, - title: title, + title, type: Column.Number, + width, editable: false, })); } diff --git a/webapp/src/components/common/dialogs/DigestDialog.tsx b/webapp/src/components/common/dialogs/DigestDialog.tsx deleted file mode 100644 index db169ecaf1..0000000000 --- a/webapp/src/components/common/dialogs/DigestDialog.tsx +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright (c) 2024, RTE (https://www.rte-france.com) - * - * See AUTHORS.txt - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - * - * This file is part of the Antares project. - */ - -import { Skeleton } from "@mui/material"; -import OkDialog, { OkDialogProps } from "./OkDialog"; -import UsePromiseCond from "../utils/UsePromiseCond"; -import type { LaunchJob } from "../../../common/types"; -import { getStudyData } from "../../../services/api/study"; -import usePromise from "../../../hooks/usePromise"; -import { useTranslation } from "react-i18next"; -import { AxiosError } from "axios"; -import EmptyView from "../page/SimpleContent"; -import SearchOffIcon from "@mui/icons-material/SearchOff"; -import { generateDataColumns } from "@/components/common/Matrix/shared/utils"; -import { MatrixGridSynthesis } from "@/components/common/Matrix/components/MatrixGridSynthesis"; - -export interface DigestDialogProps - extends Pick { - studyId: LaunchJob["studyId"]; - outputId: LaunchJob["outputId"]; -} - -function DigestDialog({ - studyId, - outputId, - ...dialogProps -}: DigestDialogProps) { - const { t } = useTranslation(); - - const synthesisRes = usePromise( - () => - getStudyData(studyId, `output/${outputId}/economy/mc-all/grid/digest`), - { - deps: [studyId, outputId], - }, - ); - - return ( - - } - ifRejected={(error) => { - if (error instanceof AxiosError && error.response?.status === 404) { - return ( - - ); - } - return ; - }} - ifFulfilled={(matrix) => - matrix && ( - - ) - } - /> - - ); -} - -export default DigestDialog; diff --git a/webapp/src/components/common/dialogs/DigestDialog/DigestMatrix.tsx b/webapp/src/components/common/dialogs/DigestDialog/DigestMatrix.tsx new file mode 100644 index 0000000000..b4e6a5b593 --- /dev/null +++ b/webapp/src/components/common/dialogs/DigestDialog/DigestMatrix.tsx @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2024, RTE (https://www.rte-france.com) + * + * See AUTHORS.txt + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + * + * This file is part of the Antares project. + */ + +import { MatrixGridSynthesis } from "@/components/common/Matrix/components/MatrixGridSynthesis"; +import { + generateDataColumns, + generateResultColumns, + groupResultColumns, +} from "@/components/common/Matrix/shared/utils"; +import { Box } from "@mui/material"; +import type { DigestMatrix } from "./types"; +import EmptyView from "../../page/SimpleContent"; +import { GridOff } from "@mui/icons-material"; +import { useTranslation } from "react-i18next"; + +const isGroupedColumns = ( + columns: string[] | string[][], +): columns is string[][] => { + return Array.isArray(columns[0]); +}; + +const isColumns = (columns: string[] | string[][]): columns is string[] => { + return !isGroupedColumns(columns); +}; + +interface DigestMatrixProps { + matrix: DigestMatrix; +} + +function DigestMatrix({ matrix }: DigestMatrixProps) { + const [t] = useTranslation(); + + const columns = matrix.groupedColumns + ? groupResultColumns( + generateResultColumns({ + titles: isGroupedColumns(matrix.columns) ? matrix.columns : [], + width: 130, + }), + ) + : generateDataColumns({ + timeSeriesColumns: false, + count: matrix.columns.length, + customColumns: isColumns(matrix.columns) ? matrix.columns : undefined, + }); + + //////////////////////////////////////////////////////////////// + // JSX + //////////////////////////////////////////////////////////////// + + return ( + + + {!matrix.data[0]?.length ? ( + + ) : ( + + )} + + + ); +} + +export default DigestMatrix; diff --git a/webapp/src/components/common/dialogs/DigestDialog/DigestTabs.tsx b/webapp/src/components/common/dialogs/DigestDialog/DigestTabs.tsx new file mode 100644 index 0000000000..ea51cf9810 --- /dev/null +++ b/webapp/src/components/common/dialogs/DigestDialog/DigestTabs.tsx @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2024, RTE (https://www.rte-france.com) + * + * See AUTHORS.txt + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + * + * This file is part of the Antares project. + */ + +import { Box } from "@mui/material"; +import TabsView from "@/components/common/TabsView"; +import { DigestData } from "./types"; +import DigestMatrix from "./DigestMatrix"; + +interface DigestTabsProps { + matrices: DigestData; +} + +export function DigestTabs({ matrices }: DigestTabsProps) { + const tabItems = [ + { + label: "Area", + content: matrices.area && , + }, + { + label: "Districts", + content: matrices.districts && ( + + ), + }, + { + label: "Flow Linear", + content: matrices.flowLinear && ( + + ), + }, + { + label: "Flow Quadratic", + content: matrices.flowQuadratic && ( + + ), + }, + ]; + + //////////////////////////////////////////////////////////////// + // JSX + //////////////////////////////////////////////////////////////// + + return ( + + + + ); +} diff --git a/webapp/src/components/common/dialogs/DigestDialog/index.tsx b/webapp/src/components/common/dialogs/DigestDialog/index.tsx new file mode 100644 index 0000000000..e302a8451a --- /dev/null +++ b/webapp/src/components/common/dialogs/DigestDialog/index.tsx @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2024, RTE (https://www.rte-france.com) + * + * See AUTHORS.txt + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + * + * This file is part of the Antares project. + */ + +import { Skeleton } from "@mui/material"; +import OkDialog, { OkDialogProps } from "../OkDialog"; +import UsePromiseCond from "../../utils/UsePromiseCond"; +import type { LaunchJob } from "../../../../common/types"; +import { useTranslation } from "react-i18next"; +import { DigestTabs } from "./DigestTabs"; +import client from "@/services/api/client"; +import { DigestData } from "./types"; +import usePromiseWithSnackbarError from "@/hooks/usePromiseWithSnackbarError"; + +interface DigestDialogProps + extends Pick { + studyId: LaunchJob["studyId"]; + outputId: LaunchJob["outputId"]; +} + +function DigestDialog({ + studyId, + outputId, + ...dialogProps +}: DigestDialogProps) { + const { t } = useTranslation(); + + const digestRes = usePromiseWithSnackbarError( + () => + client.get( + `/v1/private/studies/${studyId}/outputs/${outputId}/digest-ui`, + ), + { + errorMessage: t("data.error.matrix"), + deps: [studyId, outputId], + }, + ); + + //////////////////////////////////////////////////////////////// + // JSX + //////////////////////////////////////////////////////////////// + + return ( + + } + ifFulfilled={(matrices) => + matrices.data && + } + /> + + ); +} + +export default DigestDialog; diff --git a/webapp/src/components/common/dialogs/DigestDialog/types.ts b/webapp/src/components/common/dialogs/DigestDialog/types.ts new file mode 100644 index 0000000000..089f7ebdf4 --- /dev/null +++ b/webapp/src/components/common/dialogs/DigestDialog/types.ts @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2024, RTE (https://www.rte-france.com) + * + * See AUTHORS.txt + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + * + * This file is part of the Antares project. + */ + +export interface DigestMatrix { + columns: string[] | string[][]; + data: string[][]; + groupedColumns: boolean; +} + +export interface DigestData { + area: DigestMatrix; + districts: DigestMatrix; + flowLinear: DigestMatrix; + flowQuadratic: DigestMatrix; +}