Skip to content

Commit

Permalink
- add customized name
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriel-Sautron committed Jan 15, 2025
1 parent e83a2ad commit 490b727
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { hasConflicts, hasResults } from 'applications/stdcm/utils/simulationOutputUtils';
import { type TrackRange } from 'common/api/osrdEditoastApi';
import NewMap from 'modules/trainschedule/components/ManageTrainSchedule/NewMap';
import useLogo from 'utils/hooks/useLogo';

import SimulationReportSheet from './SimulationReportSheet';
import StdcmDebugResults from './StdcmDebugResults';
Expand Down Expand Up @@ -50,6 +51,7 @@ const StcdmResults = ({
pathTrackRanges,
}: StcdmResultsProps) => {
const { t } = useTranslation('stdcm', { keyPrefix: 'simulation.results' });
const { stdcmName } = useLogo();

const selectedSimulation = simulationsList[selectedSimulationIndex];
const { outputs } = selectedSimulation || {};
Expand Down Expand Up @@ -112,7 +114,7 @@ const StcdmResults = ({
operationalPointsList={operationalPointsList}
/>
}
fileName={`STDCM-${simulationReportSheetNumber}.pdf`}
fileName={`${stdcmName}-${simulationReportSheetNumber}.pdf`}
>
<Button
data-testid="download-simulation-button"
Expand Down
4 changes: 2 additions & 2 deletions front/src/main/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export default function Home() {
rollingStockEditorAllowed,
mapAllowed,
} = useAllowedUserRoles();
const { digitalTwin } = useLogo();
const { digitalTwinLogoWithName } = useLogo();

return (
<ModalProvider>
<NavBarSNCF logo={digitalTwin.logoWithName} />
<NavBarSNCF logo={digitalTwinLogoWithName} />
<main className="mastcontainer mastcontainer-no-mastnav">
<div className="cardscontainer">
<div className="row justify-content-center mb-2">
Expand Down
72 changes: 51 additions & 21 deletions front/src/utils/hooks/useLogo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,81 @@ const MONTH_VALUES = {
JUNE: 5,
DECEMBER: 11,
};
type DeploymentSetting = {
digitalTwinName: string;
digitalTwinLogo: string;
digitalTwinLogoWithName: string;
stdcmName: string;
stdcmLogo?: string;
stdcmSimulationSheetLogo?: string;
isCustomizedDeployment: boolean;
};

const useLogo = () => {
const [digitalTwin, setDigitalTwin] = useState<{ logo: string; logoWithName: string }>({
logo: defaultLogo,
logoWithName: defaultOsrdLogo,
});
const [stdcm, setStdcm] = useState<{ stdcmLogo?: string; stdcmPngLogo?: string }>({
stdcmLogo: undefined,
stdcmPngLogo: undefined,
});
const [customizedDeployment, setCustomizedDeployment] = useState(false);
const [customizedDeploymentSetting, setCustomizedDeploymentSetting] = useState<DeploymentSetting>(
{
digitalTwinName: 'Osrd',
digitalTwinLogo: defaultLogo,
digitalTwinLogoWithName: defaultOsrdLogo,
stdcmName: 'Stdcm',
stdcmLogo: undefined,
stdcmSimulationSheetLogo: undefined,
isCustomizedDeployment: false,
}
);

useEffect(() => {
const fetchInternalProd = async () => {
try {
const response = await fetch('/overrides/overrides.json');
if (!response.ok || response.headers.get('Content-Type') !== 'application/json') {
setCustomizedDeployment(false);
setCustomizedDeploymentSetting((prev) => ({
...prev,
isCustomizedDeployment: false,
}));

if (new Date().getMonth() === MONTH_VALUES.JUNE) {
setDigitalTwin({ logo: proudLogo, logoWithName: proudOsrdLogo });
setCustomizedDeploymentSetting((prev) => ({
...prev,
digitalTwinLogo: proudLogo,
digitalTwinLogoWithName: proudOsrdLogo,
}));
}
if (new Date().getMonth() === MONTH_VALUES.DECEMBER) {
setDigitalTwin({ logo: xmasLogo, logoWithName: xmasOsrdLogo });
setCustomizedDeploymentSetting((prev) => ({
...prev,
digitalTwinLogo: xmasLogo,
digitalTwinLogoWithName: xmasOsrdLogo,
}));
}
} else {
const overridesData = await response.json();
const { icons } = overridesData;
const { icons, name } = overridesData;

const lmrLogoPath = `/overrides/${icons.stdcm.light}.svg`;
const lmrPngLogoPath = `/overrides/${icons.stdcm.light}@2x.png`;
const horizonFullLogoPath = `/overrides/${icons.digital_twin.dark}.svg`;
const horizonLogoPath = `/overrides/${icons.digital_twin.dark}_logo.svg`;
const horizonLogoWithNamePath = `/overrides/${icons.digital_twin.dark}_Grey10.svg`;
const horizonLogoPath = `/overrides/Logo_OSRD_Grey40.svg`;

setCustomizedDeployment(true);
setStdcm({ stdcmLogo: lmrLogoPath, stdcmPngLogo: lmrPngLogoPath });
setDigitalTwin({ logo: horizonLogoPath, logoWithName: horizonFullLogoPath });
setCustomizedDeploymentSetting((prev) => ({
...prev,
digitalTwinName: name.digital_twin,
digitalTwinLogo: horizonLogoPath,
digitalTwinLogoWithName: horizonLogoWithNamePath,
stdcmName: name.stdcm,
stdcmLogo: lmrLogoPath,
stdcmSimulationSheetLogo: lmrPngLogoPath,
isCustomizedDeployment: true,
}));
}
} catch {
setCustomizedDeployment(false);
} catch (error) {
console.error('Error fetching overrides.json', error);
}
};
fetchInternalProd();
}, []);

return { digitalTwin, stdcm, customizedDeployment };
return { ...customizedDeploymentSetting };
};

export default useLogo;

0 comments on commit 490b727

Please sign in to comment.