-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui-digest): add frontend digest rework
- Loading branch information
Showing
9 changed files
with
247 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
webapp/src/components/common/dialogs/DigestDialog/DigestMatrix.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Box sx={{ p: 2 }}> | ||
<Box sx={{ width: 1, height: 800 }}> | ||
{!matrix.data[0]?.length ? ( | ||
<EmptyView title={t("matrix.message.matrixEmpty")} icon={GridOff} /> | ||
) : ( | ||
<MatrixGridSynthesis data={matrix.data} columns={columns} /> | ||
)} | ||
</Box> | ||
</Box> | ||
); | ||
} | ||
|
||
export default DigestMatrix; |
59 changes: 59 additions & 0 deletions
59
webapp/src/components/common/dialogs/DigestDialog/DigestTabs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 && <DigestMatrix matrix={matrices.area} />, | ||
}, | ||
{ | ||
label: "Districts", | ||
content: matrices.districts && ( | ||
<DigestMatrix matrix={matrices.districts} /> | ||
), | ||
}, | ||
{ | ||
label: "Flow Linear", | ||
content: matrices.flowLinear && ( | ||
<DigestMatrix matrix={matrices.flowLinear} /> | ||
), | ||
}, | ||
{ | ||
label: "Flow Quadratic", | ||
content: matrices.flowQuadratic && ( | ||
<DigestMatrix matrix={matrices.flowQuadratic} /> | ||
), | ||
}, | ||
]; | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// JSX | ||
//////////////////////////////////////////////////////////////// | ||
|
||
return ( | ||
<Box sx={{ height: "100%", display: "flex", flexDirection: "column" }}> | ||
<TabsView items={tabItems} divider /> | ||
</Box> | ||
); | ||
} |
72 changes: 72 additions & 0 deletions
72
webapp/src/components/common/dialogs/DigestDialog/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<OkDialogProps, "open" | "onOk" | "onClose"> { | ||
studyId: LaunchJob["studyId"]; | ||
outputId: LaunchJob["outputId"]; | ||
} | ||
|
||
function DigestDialog({ | ||
studyId, | ||
outputId, | ||
...dialogProps | ||
}: DigestDialogProps) { | ||
const { t } = useTranslation(); | ||
|
||
const digestRes = usePromiseWithSnackbarError( | ||
() => | ||
client.get<DigestData>( | ||
`/v1/private/studies/${studyId}/outputs/${outputId}/digest-ui`, | ||
), | ||
{ | ||
errorMessage: t("data.error.matrix"), | ||
deps: [studyId, outputId], | ||
}, | ||
); | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// JSX | ||
//////////////////////////////////////////////////////////////// | ||
|
||
return ( | ||
<OkDialog | ||
{...dialogProps} | ||
title="Digest" | ||
okButtonText={t("global.close")} | ||
fullScreen | ||
sx={{ m: 5 }} | ||
> | ||
<UsePromiseCond | ||
response={digestRes} | ||
ifPending={() => <Skeleton sx={{ height: 1, transform: "none" }} />} | ||
ifFulfilled={(matrices) => | ||
matrices.data && <DigestTabs matrices={matrices.data} /> | ||
} | ||
/> | ||
</OkDialog> | ||
); | ||
} | ||
|
||
export default DigestDialog; |
26 changes: 26 additions & 0 deletions
26
webapp/src/components/common/dialogs/DigestDialog/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |