Skip to content

Commit

Permalink
Merge pull request #32 from AntaresSimulatorTeam/feature/page_area_link
Browse files Browse the repository at this point in the history
Feature/page area link
  • Loading branch information
melazaar authored Jan 9, 2025
2 parents d168e3c + 5b74fac commit 565286c
Show file tree
Hide file tree
Showing 21 changed files with 510 additions and 4 deletions.
3 changes: 3 additions & 0 deletions public/icons/common/battery_charging_full.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/icons/common/energy_savings_leaf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/icons/common/linked_services.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/icons/common/local_fire_department.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions public/icons/common/time-line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { THEME_COLOR } from './shared/types';
import { menuBottomData, menuTopData } from './routes';
import { PegaseToastContainer } from './shared/notification/containers';
import ProjectDetails from './pages/pegase/projects/projectDetails/ProjectDetails';
import StudyDetails from '@/pages/pegase/studies/studyDetails/studyDetails';

function App() {
return (
Expand All @@ -28,6 +29,7 @@ function App() {
<PegaseStar />
<Suspense>
<Routes>
<Route path="/study/:studyName" element={<StudyDetails />} />
<Route path="/project/:projectName" element={<ProjectDetails />} />
{Object.entries([...menuBottomData, ...menuTopData]).map(([key, route]) => (
<Route key={key} path={route.path} Component={route.component} />
Expand Down
13 changes: 10 additions & 3 deletions src/pages/pegase/home/components/StudyTableDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useTranslation } from 'react-i18next';
import StudyCreationModal from '../../studies/StudyCreationModal';
import { handleDelete } from '@/pages/pegase/home/components/studyService';
import {RdsButton} from "rte-design-system-react";
import { useStudyNavigation } from '@/pages/pegase/studies/useStudyNavigation';

interface StudyTableDisplayProps {
searchStudy: string | undefined;
Expand All @@ -34,6 +35,7 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =

// Reload trigger for re-fetching data
const [reloadStudies, setReloadStudies] = useState<boolean>(false);
const { navigateToStudy } = useStudyNavigation();

const handleSort = (column: string) => {
const newSortOrder = sortByState[column] === 'asc' ? 'desc' : 'asc';
Expand All @@ -56,7 +58,6 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =
isHeaderHovered,
);

// Pass reloadTrigger to refresh data
const { rows, count, intervalSize, current, setPage } = useStudyTableDisplay({
searchStudy,
projectId,
Expand All @@ -65,9 +66,7 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =
});

const selectedRowId = Object.keys(rowSelection)[0];

const selectedStatus = rows[Number.parseInt(selectedRowId || '-1')]?.status?.toUpperCase();

const isDuplicateActive = selectedStatus === StudyStatus.GENERATED;
const isDeleteActive = selectedStatus === StudyStatus.ERROR || selectedStatus === StudyStatus.IN_PROGRESS;

Expand All @@ -86,7 +85,14 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =
});
}
};
const handleStudyClick = (study: StudyDTO) => {
navigateToStudy(study);
};

const handleRowClick = () => {
const selectedStudy = rows[Number.parseInt(selectedRowId || '-1')];
handleStudyClick(selectedStudy);
};
return (
<div>
<div className="flex-1">
Expand All @@ -112,6 +118,7 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =
<div className="flex gap-2">
{selectedRowId !== undefined ? (
<>
<RdsButton label="Open" onClick={handleRowClick} variant="outlined" />
<RdsButton label="Duplicate" onClick={handleDuplicate} variant="outlined" disabled={!isDuplicateActive} />
<RdsButton
label="Delete"
Expand Down
79 changes: 79 additions & 0 deletions src/pages/pegase/studies/studyDetails/AreaLinkTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 https://mozilla.org/MPL/2.0/.
*/

import {useState} from 'react';
import {ColumnDef} from '@tanstack/react-table';
import StdSimpleTable from '@common/data/stdSimpleTable/StdSimpleTable';
import {RdsButton, RdsInputText} from "rte-design-system-react";


type RowStatus = 'Missing' | 'OK' | 'Error';

type RowData = {
hypothesis: string;
trajectory: string | null; // Null si aucune trajectoire n'est sélectionnée
status: RowStatus;
};

const AreaLinkTab = () => {
const [data, setData] = useState<RowData[]>([
{hypothesis: 'Areas', trajectory: null, status: 'Missing'},
{hypothesis: 'Links', trajectory: null, status: 'Missing'},
]);

const handleImport = (index: number) => {
const updatedData = [...data];
updatedData[index].trajectory = 'BP_23_ref';
updatedData[index].status = 'OK';
setData(updatedData);
};

const columns: ColumnDef<RowData>[] = [
{
header: 'Hypothesis',
accessorKey: 'hypothesis',
},
{
header: 'Trajectory to use',
cell: ({row}) => {
const index = row.index;
const {trajectory} = row.original;
return trajectory ? (
<div className="flex items-center space-x-2">
<span>{trajectory}</span>
</div>
) : (
<div className="flex items-center space-x-2">
<RdsInputText label=""
value=""
placeHolder="choose a Trajectory"
variant="outlined"/>
<span>or</span>
<RdsButton label="Import" onClick={() => handleImport(index)}/>
</div>
);
},
},
{
header: 'Status',
cell: ({row}) => {
const {status} = row.original;
if (status === 'Missing') return <span>❓ Missing</span>;
if (status === 'OK') return <span>✔ OK</span>;
if (status === 'Error') return <span>❌ Error</span>;
return null;
},
},
];

return (
<div className="flex-1">
<StdSimpleTable id="example-table" data={data} columns={columns} columnSize="meta"/>
</div>
);
};

export default AreaLinkTab;
31 changes: 31 additions & 0 deletions src/pages/pegase/studies/studyDetails/AreaLinkTableHeaders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 https://mozilla.org/MPL/2.0/.
*/

import { createColumnHelper } from '@tanstack/react-table';
import { useTranslation } from 'react-i18next';
import { RdsButton } from 'rte-design-system-react';

const columnHelper = createColumnHelper<any>();

const getAreaLinkTableHeaders = () => {
const { t } = useTranslation();
return [
columnHelper.accessor('hypothesis', {
header: t('home.@hypothesis'),
}),

columnHelper.accessor('trajectroy', {
header: t('home.@trajectory'),
cell: () => <RdsButton label="import" />,
}),

columnHelper.accessor('status', {
header: t('home.@status'),
}),
];
};

export default getAreaLinkTableHeaders;
17 changes: 17 additions & 0 deletions src/pages/pegase/studies/studyDetails/EnrTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 https://mozilla.org/MPL/2.0/.
*/

const EnrTab = () => {


return (
<div className="flex-1">
<h1>Energy</h1>
</div>
);
};

export default EnrTab;
17 changes: 17 additions & 0 deletions src/pages/pegase/studies/studyDetails/LoadTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 https://mozilla.org/MPL/2.0/.
*/

const LoadTab = () => {


return (
<div className="flex-1">
<h1>Load</h1>
</div>
);
};

export default LoadTab;
17 changes: 17 additions & 0 deletions src/pages/pegase/studies/studyDetails/MiscLinkTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 https://mozilla.org/MPL/2.0/.
*/

const MiscTab = () => {


return (
<div className="flex-1">
<h1>Misc</h1>
</div>
);
};

export default MiscTab;
48 changes: 48 additions & 0 deletions src/pages/pegase/studies/studyDetails/StudyDetailsContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 https://mozilla.org/MPL/2.0/.
*/

import { formatDateToDDMMYYYY } from '@/shared/utils/dateFormatter';
import { StudyDTO } from '@/shared/types';
import { RdsIcon, RdsIconId, RdsTagList } from 'rte-design-system-react';
import StdIcon from '@common/base/stdIcon/StdIcon';
import { StdIconId } from '@/shared/utils/common/mappings/iconMaps';

type ProjectDetailsContentProps = {
study: StudyDTO;
};

export const StudyDetailsContent = ({ study }: ProjectDetailsContentProps) => {
return (
<div className="flex flex-col gap-3 p-3">
<div className="group flex flex-col gap-3 rounded bg-primary-100 p-2" role="banner">
<div className="flex items-center justify-between font-sans font-light text-gray-500">
<div className="flex items-center gap-3">
<div className="flex flex-[1_0_0] items-center gap-6">
<div>Study : {study.name}</div>
<div className="flex items-center gap-2">
<RdsIcon name={RdsIconId.History} color="secondary" />
{formatDateToDDMMYYYY(study.creationDate)}
</div>
<div className="flex items-center gap-2">
<RdsIcon name={RdsIconId.Person} color="secondary" />
By : {study.createdBy}
</div>
<div className="flex items-center gap-2">
<StdIcon name={StdIconId.TimeLine} color="secondary" />
Horizon : {study.horizon}
</div>
<div className="flex h-3 w-32">
<RdsTagList id={`${study.id}-tag-list`} tags={study.keywords} />
</div>
</div>
</div>
</div>
</div>
</div>
);
};

export default StudyDetailsContent;
Loading

0 comments on commit 565286c

Please sign in to comment.