Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ui): replace MatrixInput with Matrix Glide Data Grid integration #2138

Merged
merged 43 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2b6b6b1
feat(ui): add `customColumns` prop to `Matrix`
hdinia Sep 11, 2024
5a33677
refactor(ui): update matrix views replacing `MatrixInput` with `Matrix`
hdinia Sep 12, 2024
9f26788
feat(ui): add `colWidth` prop to `Matrix` for custom columns width
hdinia Sep 11, 2024
1357bf8
feat(ui): add custom `rowHeaders` prop on `Matrix`
hdinia Sep 12, 2024
0f302be
feat(ui): add `enablePercentDisplay` prop on `Matrix`
hdinia Sep 12, 2024
4677c9b
feat(ui): add `enableReadOnly` prop on `Matrix`
hdinia Sep 12, 2024
5254feb
refactor(ui-hydro): update `HydroMatrix` to use glide data grid
hdinia Sep 13, 2024
97d901a
feat(ui): add `calculateMatrixAggregates` and update Hydro matrices
hdinia Sep 17, 2024
c03e5e6
refactor(ui-links): update `Links` matrices
hdinia Sep 17, 2024
eebd010
fix(ui): prevent 0 to be processed as falsy value
hdinia Sep 17, 2024
9ad6ac4
refactor(ui-results): update `Results` view matrices
hdinia Sep 18, 2024
b72a01c
refactor(ui-results): refresh and improve `ResultsDetails`
hdinia Sep 18, 2024
e309997
refactor(ui-bc): update `BindingConstraints` matrices
hdinia Sep 20, 2024
e5e5e8f
refactor(ui): use the number of updates as the indicator for the save…
hdinia Sep 20, 2024
359bec9
feat(ui): add dynamic aggregates changes at each update
hdinia Sep 20, 2024
e326c28
refactor(ui): change position of aggregates cols and background colors
hdinia Sep 20, 2024
d43782f
feat(ui): make the `dateTime` column sticky
hdinia Sep 20, 2024
6cdd151
feat(ui): add columns resize to `MatrixGrid`
hdinia Sep 23, 2024
39cb34c
feat(ui): change the decimal and thousand separator for number cells
hdinia Sep 23, 2024
eb3b1d2
refactor(ui): improve aggregates columns usage
hdinia Sep 26, 2024
5188e5e
feat(ui): update date generation using `date-fns` instead of `moment`
hdinia Sep 30, 2024
242e42a
feat(ui): add prompt for unsaved changes when switching views
hdinia Oct 1, 2024
c99bcc9
feat(ui): allow fill handle on any direction
hdinia Oct 1, 2024
4e13853
feat(ui): add month display to daily and hourly frequencies
hdinia Oct 9, 2024
c6f0131
feat(ui): reduce cells height and add smooth scroll
hdinia Oct 9, 2024
eb3eb37
feat(ui): disable copy/paste keybindings
hdinia Oct 14, 2024
dbb485f
fix(ui): resolve imports errors due to merge conflicts
hdinia Oct 21, 2024
f936584
fix(ui): prevent regex DoS vulnerability in `formatNumber` function
hdinia Oct 14, 2024
a818c49
refactor(ui): improves `Matrix` types and variables naming
hdinia Oct 21, 2024
e95c063
test(ui): enhance `utils` tests and add `MatrixActions` component tests
hdinia Oct 16, 2024
6f9cd44
feat(ui-debug): replace `MatrixInput` and add disable import prop
hdinia Oct 21, 2024
d84b6e1
fix(ui): correct display condition in `Matrix` to handle empty subarr…
hdinia Oct 23, 2024
a5365e7
feat(ui): enable aggregates on thermal and renewables clusters
hdinia Oct 23, 2024
5a95b8c
feat(ui): add `useMatrixPortal`to manage matrices on split views
hdinia Oct 24, 2024
7889c66
fix(ui): disable percent display on allocation and correlation matrices
hdinia Oct 24, 2024
d0e4200
test(ui): improve `Matrix` test suite organization and maintainability
hdinia Oct 24, 2024
5b79b23
refactor(ui): remove `MatrixInput`
hdinia Oct 24, 2024
c377f3b
refactor(ui): improves `Matrix` folder and files overall organization
hdinia Oct 25, 2024
d71e4a0
build(vite): exclude test files from production builds
hdinia Oct 25, 2024
212c777
refactor(ui): rename core folder
hdinia Oct 29, 2024
fb6f00f
refactor(ui): disable percents on daily power and reservoir levels
hdinia Oct 29, 2024
8897455
fix(ui): prevent undefined error in number formatting
hdinia Oct 29, 2024
bd53261
feat(ui-hydro): add data adapter for `Allocation` and `Correlation`
hdinia Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"clsx": "2.1.1",
"d3": "5.16.0",
"debug": "4.3.7",
"date-fns": "4.1.0",
"draft-convert": "2.1.13",
"draft-js": "0.11.7",
"draftjs-to-html": "0.9.1",
Expand Down Expand Up @@ -83,6 +84,7 @@
"@types/draft-js": "0.11.18",
"@types/draftjs-to-html": "0.8.4",
"@types/js-cookie": "3.0.6",
"@types/date-fns": "2.6.0",
"@types/jsoneditor": "9.9.5",
"@types/lodash": "4.17.9",
"@types/node": "22.7.3",
Expand Down
1 change: 1 addition & 0 deletions webapp/public/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"global.time.weekly": "Weekly",
"global.time.monthly": "Monthly",
"global.time.annual": "Annual",
"global.time.weekShort": "W.",
"global.update.success": "Update successful",
"global.errorLogs": "Error logs",
"global.error.emptyName": "Name cannot be empty",
Expand Down
1 change: 1 addition & 0 deletions webapp/public/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"global.time.weekly": "Hebdomadaire",
"global.time.monthly": "Mensuel",
"global.time.annual": "Annuel",
"global.time.weekShort": "S.",
"global.update.success": "Mise à jour réussie",
"global.errorLogs": "Logs d'erreurs",
"global.error.emptyName": "Le nom ne peut pas être vide",
Expand Down
21 changes: 21 additions & 0 deletions webapp/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,3 +661,24 @@ export interface TaskView {
}

export type ValidationReturn = string | true;

export interface MatrixConfig {
url: string;
titleKey: string;
columnsNames?: string[];
}

export interface SplitMatrixContent {
type: "split";
matrices: [MatrixConfig, MatrixConfig];
}

export interface SingleMatrixContent {
type: "single";
matrix: MatrixConfig;
}

export interface MatrixItem {
titleKey: string;
content: SplitMatrixContent | SingleMatrixContent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,11 @@
* This file is part of the Antares project.
*/

import { MatrixStats } from "../../../../../../common/types";
import MatrixInput from "../../../../../common/MatrixInput";
import Matrix from "../../../../../common/Matrix";
import type { DataCompProps } from "../utils";

function Matrix({ studyId, filename, filePath, canEdit }: DataCompProps) {
return (
<MatrixInput
title={filename}
study={studyId}
url={filePath}
computStats={MatrixStats.NOCOL}
disableImport={!canEdit}
/>
);
function DebugMatrix({ studyId, filename, filePath, canEdit }: DataCompProps) {
return <Matrix title={filename} url={filePath} isImportDisabled={!canEdit} />;
}

export default Matrix;
export default DebugMatrix;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "./utils";
import { SubmitHandlerPlus } from "../../../../../../../common/Form/types";
import HydroMatrixDialog from "../HydroMatrixDialog";
import { HydroMatrixType } from "../utils";
import { HydroMatrix } from "../utils";
import { FormBox, FormPaper } from "../style";
import ViewMatrixButton from "../ViewMatrixButton";

Expand Down Expand Up @@ -84,7 +84,7 @@ function Allocation() {
</FormPaper>
{matrixDialogOpen && (
<HydroMatrixDialog
type={HydroMatrixType.Allocation}
type={HydroMatrix.Allocation}
open={matrixDialogOpen}
onClose={() => setMatrixDialogOpen(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
* This file is part of the Antares project.
*/

import {
StudyMetadata,
Area,
MatrixType,
} from "../../../../../../../../common/types";
import { StudyMetadata, Area } from "../../../../../../../../common/types";
import client from "../../../../../../../../services/api/client";
import { MatrixDataDTO } from "../../../../../../../common/Matrix/shared/types";
import { AreaCoefficientItem } from "../utils";

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -58,7 +55,7 @@ export async function setAllocationFormFields(

export const getAllocationMatrix = async (
studyId: StudyMetadata["id"],
): Promise<MatrixType> => {
): Promise<MatrixDataDTO> => {
const res = await client.get(
`v1/studies/${studyId}/areas/hydro/allocation/matrix`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "./utils";
import Fields from "./Fields";
import HydroMatrixDialog from "../HydroMatrixDialog";
import { HydroMatrixType } from "../utils";
import { HydroMatrix } from "../utils";
import { FormBox, FormPaper } from "../style";
import ViewMatrixButton from "../ViewMatrixButton";

Expand Down Expand Up @@ -79,7 +79,7 @@ function Correlation() {
</FormPaper>
{matrixDialogOpen && (
<HydroMatrixDialog
type={HydroMatrixType.Correlation}
type={HydroMatrix.Correlation}
open={matrixDialogOpen}
onClose={() => setMatrixDialogOpen(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
* This file is part of the Antares project.
*/

import {
StudyMetadata,
Area,
MatrixType,
} from "../../../../../../../../common/types";
import { StudyMetadata, Area } from "../../../../../../../../common/types";
import client from "../../../../../../../../services/api/client";
import { MatrixDataDTO } from "../../../../../../../common/Matrix/shared/types";
import { AreaCoefficientItem } from "../utils";

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -58,7 +55,7 @@ export async function setCorrelationFormFields(

export async function getCorrelationMatrix(
studyId: StudyMetadata["id"],
): Promise<MatrixType> {
): Promise<MatrixDataDTO> {
const res = await client.get(
`v1/studies/${studyId}/areas/hydro/correlation/matrix`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
* This file is part of the Antares project.
*/

import { useOutletContext } from "react-router";
import { StudyMetadata } from "../../../../../../../common/types";
import useAppSelector from "../../../../../../../redux/hooks/useAppSelector";
import { getCurrentAreaId } from "../../../../../../../redux/selectors";
import MatrixInput from "../../../../../../common/MatrixInput";
import { Root } from "./style";
import { MATRICES, HydroMatrixType } from "./utils";
import Matrix from "../../../../../../common/Matrix";
import { Box } from "@mui/material";

interface Props {
type: HydroMatrixType;
}

function HydroMatrix({ type }: Props) {
const { study } = useOutletContext<{ study: StudyMetadata }>();
const areaId = useAppSelector(getCurrentAreaId);

const hydroMatrix = MATRICES[type];
Expand All @@ -35,19 +32,19 @@ function HydroMatrix({ type }: Props) {
////////////////////////////////////////////////////////////////

return (
<Root>
<MatrixInput
<Box sx={{ width: 1, height: 1, p: 1 }}>
<Matrix
title={hydroMatrix.title}
columnsNames={hydroMatrix.cols}
rowNames={hydroMatrix.rows}
study={study}
url={hydroMatrix.url.replace("{areaId}", areaId)}
computStats={hydroMatrix.stats}
fetchFn={hydroMatrix.fetchFn}
disableEdit={hydroMatrix.disableEdit}
enablePercentDisplay={hydroMatrix.enablePercentDisplay}
customColumns={hydroMatrix.columns}
customRowHeaders={hydroMatrix.rowHeaders}
aggregateColumns={hydroMatrix.aggregates}
enableDateTimeColumn={hydroMatrix.enableDateTimeColumn}
readOnly={hydroMatrix.readOnly}
showPercent={hydroMatrix.showPercent}
fetchMatrixData={hydroMatrix.fetchFn}
/>
</Root>
</Box>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,91 @@
* This file is part of the Antares project.
*/

import { Button, Box } from "@mui/material";
import { Button, Box, Skeleton } from "@mui/material";
import { useTranslation } from "react-i18next";
import { useState, useEffect } from "react";
import BasicDialog, {
BasicDialogProps,
} from "../../../../../../common/dialogs/BasicDialog";
import HydroMatrix from "./HydroMatrix";
import Matrix from "../../../../../../common/Matrix";
import { HydroMatrixType } from "./utils";
import { getAllocationMatrix } from "./Allocation/utils";
import { getCorrelationMatrix } from "./Correlation/utils";
import { useOutletContext } from "react-router";
import { StudyMetadata } from "../../../../../../../common/types";
import { MatrixDataDTO } from "@/components/common/Matrix/shared/types";
import useEnqueueErrorSnackbar from "@/hooks/useEnqueueErrorSnackbar";
import { AxiosError } from "axios";

interface AdaptedMatrixData {
data: number[][];
columns: string[];
index: string[];
}

interface Props {
open: boolean;
onClose: () => void;
type: HydroMatrixType;
}

const MATRIX_FETCHERS = {
Allocation: getAllocationMatrix,
Correlation: getCorrelationMatrix,
} as const;

function HydroMatrixDialog({ open, onClose, type }: Props) {
/**
* !TEMPORARY SOLUTION - Matrix Data Model Adaptation
*
* This component handles a specific case (Allocation, Correlation).
* They receive their columns and row headers from the backend as numeric arrays.
* This differs from the standard Matrix component usage where these properties expect string arrays
* representing actual header labels.
*
* Current scenario:
* - Backend returns {columns: number[], index: number[]} for these specific matrices
* - Matrix component expects {columns: string[], rowHeaders: string[]} for its headers
*
* Future API model update will:
* - Rename 'index' to 'rowHeaders' to better reflect its purpose
* - Return properly formatted string arrays for header labels
* - Allow using the standard HydroMatrix component without this adapter
*
* TODO - Once the API is updated:
* 1. The model adapter layer will be removed
* 2. These matrices will use the HydroMatrix component directly
* 3. All matrices will follow the same data structure pattern
*/

const { t } = useTranslation();
const { study } = useOutletContext<{ study: StudyMetadata }>();
const enqueueErrorSnackbar = useEnqueueErrorSnackbar();
const fetchFn = MATRIX_FETCHERS[type as keyof typeof MATRIX_FETCHERS];
const [matrix, setMatrix] = useState<AdaptedMatrixData | undefined>(
undefined,
);

const matrixModelAdapter = (apiData: MatrixDataDTO): AdaptedMatrixData => ({
data: apiData.data,
columns: apiData.columns.map(String),
index: apiData.index.map(String), // Will be renamed to rowHeaders in future API version
});

useEffect(() => {
const fetchData = async () => {
try {
const data = await fetchFn(study.id);
setMatrix(matrixModelAdapter(data));
} catch (error) {
enqueueErrorSnackbar(t("data.error.matrix"), error as AxiosError);
}
};

fetchData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [study.id, type, t]);

const dialogProps: BasicDialogProps = {
open,
onClose,
Expand All @@ -38,6 +107,10 @@ function HydroMatrixDialog({ open, onClose, type }: Props) {
),
};

////////////////////////////////////////////////////////////////
// JSX
////////////////////////////////////////////////////////////////

return (
<BasicDialog
{...dialogProps}
Expand All @@ -48,7 +121,21 @@ function HydroMatrixDialog({ open, onClose, type }: Props) {
maxWidth="xl"
>
<Box sx={{ width: 1, height: 1, p: 2 }}>
<HydroMatrix type={type} />
{matrix ? (
<Matrix
title={`${type} Matrix`}
url=""
customColumns={matrix.columns}
customRowHeaders={matrix.index}
fetchMatrixData={fetchFn}
readOnly
enableDateTimeColumn={false}
enableTimeSeriesColumns={false}
isImportDisabled
/>
) : (
<Skeleton sx={{ height: 1, transform: "none" }} />
)}
</Box>
</BasicDialog>
);
Expand Down
Loading
Loading