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

editoast, front : fix step update erasing parts of the study in studies page #10382

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions editoast/Cargo.lock

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

1 change: 1 addition & 0 deletions editoast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ serde_json.workspace = true
serde_qs = { version = "0.13.0", git = "https://github.com/Atrox/serde_qs", rev = "2cfa3ee0", features = [
"axum",
] }
serde_with = "3.12.0"
serde_yaml = "0.9.34"
sha1 = "0.10"
strum.workspace = true
Expand Down
28 changes: 17 additions & 11 deletions editoast/src/views/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use editoast_models::DbConnection;
use editoast_models::DbConnectionPoolV2;
use serde::Deserialize;
use serde::Serialize;
use serde_with::rust::double_option;
use thiserror::Error;
use utoipa::IntoParams;
use utoipa::ToSchema;
Expand Down Expand Up @@ -294,14 +295,19 @@ struct ProjectPatchForm {
#[schema(max_length = 128)]
pub name: Option<String>,
#[schema(max_length = 1024)]
pub description: Option<String>,
#[serde(default, with = "double_option")]
pub description: Option<Option<String>>,
#[schema(max_length = 4096)]
pub objectives: Option<String>,
#[serde(default, with = "double_option")]
pub objectives: Option<Option<String>>,
#[schema(max_length = 1024)]
pub funders: Option<String>,
pub budget: Option<i32>,
#[serde(default, with = "double_option")]
pub funders: Option<Option<String>>,
#[serde(default, with = "double_option")]
pub budget: Option<Option<i32>>,
/// The id of the image document
pub image: Option<i64>,
#[serde(default, with = "double_option")]
pub image: Option<Option<i64>>,
#[schema(max_length = 255)]
pub tags: Option<Tags>,
}
Expand All @@ -310,11 +316,11 @@ impl From<ProjectPatchForm> for Changeset<Project> {
fn from(project: ProjectPatchForm) -> Self {
Project::changeset()
.flat_name(project.name)
.description(project.description)
.objectives(project.objectives)
.funders(project.funders)
.flat_budget(Some(project.budget))
.flat_image(Some(project.image))
.flat_description(project.description)
.flat_objectives(project.objectives)
.flat_funders(project.funders)
.flat_budget(project.budget)
.flat_image(project.image)
.flat_tags(project.tags)
.last_modification(Utc::now().naive_utc())
}
Expand Down Expand Up @@ -348,7 +354,7 @@ async fn patch(
return Err(AuthorizationError::Forbidden.into());
}
let conn = &mut db_pool.get().await?;
if let Some(image) = form.image {
if let Some(Some(image)) = form.image {
check_image_content(conn, image).await?;
}
let project_changeset: Changeset<Project> = form.into();
Expand Down
2 changes: 2 additions & 0 deletions editoast/src/views/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use editoast_models::DbConnection;
use editoast_models::DbConnectionPoolV2;
use serde::Deserialize;
use serde::Serialize;
use serde_with::rust::double_option;
use thiserror::Error;
use utoipa::IntoParams;
use utoipa::ToSchema;
Expand Down Expand Up @@ -327,6 +328,7 @@ struct ScenarioPatchForm {
pub description: Option<String>,
pub tags: Option<Tags>,
pub infra_id: Option<i64>,
#[serde(default, with = "double_option")]
pub electrical_profile_set_id: Option<Option<i64>>,
}

Expand Down
41 changes: 25 additions & 16 deletions editoast/src/views/study.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use editoast_models::DbConnection;
use editoast_models::DbConnectionPoolV2;
use serde::Deserialize;
use serde::Serialize;
use serde_with::rust::double_option;
use thiserror::Error;
use utoipa::IntoParams;
use utoipa::ToSchema;
Expand Down Expand Up @@ -274,32 +275,40 @@ async fn get(
#[derivative(Default)]
struct StudyPatchForm {
pub name: Option<String>,
pub description: Option<String>,
pub start_date: Option<NaiveDate>,
pub expected_end_date: Option<NaiveDate>,
pub actual_end_date: Option<NaiveDate>,
pub business_code: Option<String>,
pub service_code: Option<String>,
pub budget: Option<i32>,
#[serde(default, with = "double_option")]
pub description: Option<Option<String>>,
#[serde(default, with = "double_option")]
pub start_date: Option<Option<NaiveDate>>,
#[serde(default, with = "double_option")]
pub expected_end_date: Option<Option<NaiveDate>>,
#[serde(default, with = "double_option")]
pub actual_end_date: Option<Option<NaiveDate>>,
#[serde(default, with = "double_option")]
pub business_code: Option<Option<String>>,
#[serde(default, with = "double_option")]
pub service_code: Option<Option<String>>,
#[serde(default, with = "double_option")]
pub budget: Option<Option<i32>>,
pub tags: Option<Tags>,
pub state: Option<String>,
pub study_type: Option<String>,
#[serde(default, with = "double_option")]
pub study_type: Option<Option<String>>,
}

impl StudyPatchForm {
pub fn into_study_changeset(self) -> Result<Changeset<Study>> {
let study_changeset = Study::changeset()
.flat_name(self.name)
.description(self.description)
.business_code(self.business_code)
.service_code(self.service_code)
.flat_start_date(Some(self.start_date))
.flat_expected_end_date(Some(self.expected_end_date))
.flat_actual_end_date(Some(self.actual_end_date))
.flat_budget(Some(self.budget))
.flat_description(self.description)
.flat_business_code(self.business_code)
.flat_service_code(self.service_code)
.flat_start_date(self.start_date)
.flat_expected_end_date(self.expected_end_date)
.flat_actual_end_date(self.actual_end_date)
.flat_budget(self.budget)
.flat_tags(self.tags)
.flat_state(self.state)
.study_type(self.study_type);
.flat_study_type(self.study_type);
Study::validate(&study_changeset)?;
Ok(study_changeset)
}
Expand Down
8 changes: 4 additions & 4 deletions front/public/locales/en/operationalStudies/study.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"createScenario": "Create a scenario",
"dates": {
"creation": "Creation",
"estimatedend": "Expected ending",
"expectedEnd": "Expected end",
"modified": "Updated",
"realend": "Real end",
"start": "Started"
"realEnd": "Real end",
"start": "Start"
},
"deleteScenarios": "Delete",
"deleteItems": "Delete",
Expand Down Expand Up @@ -58,7 +58,7 @@
"studyDescription": "Description",
"studyDescriptionInvalid": "The description for the study must not exceed 1024 characters",
"studyDescriptionPlaceholder": "Short description of the study",
"studyEstimatedEndDate": "Expected end date",
"studyExpectedEndDate": "Expected end date",
"studyModificationTitle": "Edit a study",
"studyModifyButton": "Save",
"studyName": "Study name",
Expand Down
6 changes: 3 additions & 3 deletions front/public/locales/fr/operationalStudies/study.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"createScenario": "Créer un scénario",
"dates": {
"creation": "Création",
"estimatedend": "Fin estimée",
"expectedEnd": "Fin estimée",
"modified": "Modification",
"realend": "Fin réelle",
"realEnd": "Fin réelle",
"start": "Début"
},
"confirmDeleteMessage": "Voulez-vous supprimer le scénario ?",
Expand Down Expand Up @@ -57,7 +57,7 @@
"studyDescription": "Description",
"studyDescriptionInvalid": "La description de l'étude ne doit pas dépasser 1024 caractères",
"studyDescriptionPlaceholder": "Courte description de l'étude",
"studyEstimatedEndDate": "Fin estimée",
"studyExpectedEndDate": "Fin estimée",
"studyModificationTitle": "Modifier une étude",
"studyModifyButton": "Enregistrer",
"studyName": "Nom de l'étude",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,36 @@ import cx from 'classnames';
import { useTranslation } from 'react-i18next';

import type { StudyState } from 'applications/operationalStudies/consts';
import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import { osrdEditoastApi, type StudyResponse } from 'common/api/osrdEditoastApi';
import { setSuccess } from 'reducers/main';
import { useAppDispatch } from 'store';

type Props = {
projectID: number;
studyID: number;
study: StudyResponse;
number: number;
studyName: string;
state: StudyState;
done: boolean;
tags: string[];
};

export default function StateStep({
projectID,
studyID,
number,
studyName,
state,
done,
tags,
}: Props) {
export default function StateStep({ study, number, state, done }: Props) {
const { t } = useTranslation('operationalStudies/study');
const dispatch = useAppDispatch();
const [patchStudy] =
osrdEditoastApi.endpoints.patchProjectsByProjectIdStudiesAndStudyId.useMutation();

const changeStudyState = async () => {
try {
const actual_end_date =
state === 'finish' ? new Date().toISOString().split('T')[0] : study.actual_end_date;
await patchStudy({
projectId: projectID,
studyId: studyID,
studyPatchForm: { name: studyName, state, tags },
projectId: study.project.id,
studyId: study.id,
studyPatchForm: { actual_end_date, state },
});
dispatch(
setSuccess({
title: t('studyUpdated'),
text: t('studyUpdatedDetails', { name: studyName }),
text: t('studyUpdatedDetails', { name: study.name }),
})
);
} catch (error) {
Expand Down
13 changes: 5 additions & 8 deletions front/src/applications/operationalStudies/views/Study.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ const Study = () => {
/>
<DateBox
date={study.expected_end_date ? new Date(study.expected_end_date) : null}
className="estimatedend"
translation="estimatedend"
className="expected-end"
translation="expectedEnd"
withoutTime
/>
<DateBox
date={study.actual_end_date ? new Date(study.actual_end_date) : null}
className="realend"
translation="realend"
className="real-end"
translation="realEnd"
withoutTime
/>
<DateBox
Expand Down Expand Up @@ -288,13 +288,10 @@ const Study = () => {
study.state && (
<StateStep
key={nextId()}
projectID={study.project.id}
studyID={study.id}
study={study}
number={idx + 1}
studyName={study.name}
state={state}
done={idx <= studyStates.indexOf(study.state as StudyState)}
tags={study.tags}
/>
)
)}
Expand Down
6 changes: 3 additions & 3 deletions front/src/modules/study/components/AddOrEditStudyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ const AddOrEditStudyModal = ({ editionMode, study, scenarios }: AddOrEditStudyMo
max={getEarliestDate(currentStudy?.expected_end_date, currentStudy?.actual_end_date)}
/>
<InputSNCF
id="studyInputEstimatedEndDate"
id="studyInputExpectedEndDate"
type="date"
name="studyInputEstimatedEndDate"
name="studyInputExpectedEndDate"
label={
<div className="d-flex align-items-center">
<span className="mr-2 text-warning">
<RiCalendarLine />
</span>
{t('studyEstimatedEndDate')}
{t('studyExpectedEndDate')}
</div>
}
value={formatDateForInput(currentStudy?.expected_end_date)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
&.start {
border-color: var(--green);
}
&.estimatedend {
&.expected-end {
border-color: var(--yellow);
}
&.realend {
&.real-end {
border-color: var(--orange);
}
}
Expand Down
Loading
Loading