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

front: move the deployment settings in high level context #10852

Merged
merged 1 commit into from
Feb 19, 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
3 changes: 3 additions & 0 deletions front/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ npm-debug.log*
/.env
# .env.local is up to the developer
/.env.local

# config overrides
/overrides
22 changes: 16 additions & 6 deletions front/src/applications/stdcm/components/StdcmHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ import { useSelector } from 'react-redux';
import { getIsSuperUser } from 'reducers/user/userSelectors';
import useDeploymentSettings from 'utils/hooks/useDeploymentSettings';

const LogoSTDCM = ({ logo }: { logo: string | undefined }) => {
if (logo) {
return <img src={logo} data-testid="lmr-logo" alt="LMR Logo" className="stdcm-header__logo" />;
const LogoSTDCM = () => {
const deploymentSettings = useDeploymentSettings();

if (deploymentSettings) {
return deploymentSettings.stdcmLogo ? (
<img
src={deploymentSettings.stdcmLogo}
data-testid="lmr-logo"
alt="LMR Logo"
className="stdcm-header__logo"
/>
) : (
<span className="stdcm-header__title pl-5">STDCM</span>
);
}
return <span className="stdcm-header__title pl-5">ST DCM</span>;
return null;
};

type StdcmHeaderProps = {
Expand All @@ -28,11 +39,10 @@ const StdcmHeader = ({
}: StdcmHeaderProps) => {
const { t } = useTranslation(['stdcm', 'translation']);
const isSuperUser = useSelector(getIsSuperUser);
const { stdcmLogo } = useDeploymentSettings();

return (
<div className="stdcm-header d-flex">
<LogoSTDCM logo={stdcmLogo} />
<LogoSTDCM />
<div className="flex-grow-1 d-flex justify-content-center">
<span className="stdcm-header__notification " id="notification">
{t('stdcm:notificationTitle')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import logoSNCF from 'assets/simulationReportSheet/logo_sncf_reseau.png';
import i18n from 'i18n';
import type { StdcmPathStep } from 'reducers/osrdconf/types';
import { dateToHHMMSS, formatDateToString, formatDay } from 'utils/date';
import useDeploymentSettings from 'utils/hooks/useDeploymentSettings';
import { msToKmh } from 'utils/physics';
import { capitalizeFirstLetter } from 'utils/strings';
import { secToMin } from 'utils/timeManipulation';
Expand Down Expand Up @@ -36,9 +35,10 @@ const getArrivalTimes = (step: StdcmPathStep, t: TFunction, shouldDisplay: boole
return '';
};

const LogoSTDCM = ({ logo, t }: { logo: string | undefined; t: TFunction }) => {
if (logo) {
return <Image src={logo} style={styles.header.lmrLogo} />;
const LogoSTDCM = ({ logoUrl }: { logoUrl?: string }) => {
const { t } = useTranslation(['stdcm-simulation-report-sheet']);
if (logoUrl) {
return <Image src={logoUrl} style={styles.header.lmrLogo} />;
}
return (
<>
Expand All @@ -54,8 +54,8 @@ const SimulationReportSheet = ({
consist,
simulationReportSheetNumber,
operationalPointsList,
simulationSheetLogo,
}: SimulationReportSheetProps) => {
const { stdcmSimulationSheetLogo } = useDeploymentSettings();
const { t } = useTranslation(['stdcm-simulation-report-sheet', 'stdcm']);
let renderedIndex = 0;

Expand All @@ -77,7 +77,7 @@ const SimulationReportSheet = ({
<View style={styles.header.numberDateBanner}>
<View style={styles.header.stdcmTitleBox}>
<View style={styles.header.stdcm}>
<LogoSTDCM logo={stdcmSimulationSheetLogo} t={t} />
<LogoSTDCM logoUrl={simulationSheetLogo} />
</View>
</View>
<View style={styles.header.numericInfo}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const StcdmResults = ({
}: StcdmResultsProps) => {
const infraId = useInfraID();
const { t } = useTranslation('stdcm', { keyPrefix: 'simulation.results' });
const { stdcmName } = useDeploymentSettings();
const deploymentSettings = useDeploymentSettings();

const selectedSimulation = useSelector(getSelectedSimulation);
const retainedSimulationIndex = useSelector(getRetainedSimulationIndex);
Expand Down Expand Up @@ -111,9 +111,10 @@ const StcdmResults = ({
consist={selectedSimulation.inputs.consist}
simulationReportSheetNumber={simulationReportSheetNumber}
operationalPointsList={operationalPointsList}
simulationSheetLogo={deploymentSettings?.stdcmSimulationSheetLogo}
/>
}
fileName={`${stdcmName}-${simulationReportSheetNumber}.pdf`}
fileName={`${deploymentSettings?.stdcmName || 'Stdcm'}-${simulationReportSheetNumber}.pdf`}
>
<Button
data-testid="download-simulation-button"
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type SimulationReportSheetProps = {
simulationReportSheetNumber: string;
operationalPointsList: StdcmResultsOperationalPoint[];
userName?: string;
simulationSheetLogo?: string;
};

export type StdcmResultsOperationalPoint = {
Expand Down
43 changes: 32 additions & 11 deletions front/src/common/BootstrapSNCF/NavBarSNCF.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ReactElement } from 'react';
import { useMemo, type ReactElement } from 'react';

import { Gear, Info, Report, ShieldCheck, SignOut } from '@osrd-project/ui-icons';
import cx from 'classnames';
Expand All @@ -22,30 +22,51 @@ import { useModal } from './ModalSNCF';

type Props = {
appName?: string | ReactElement;
logo?: string;
showLogoWithName?: boolean;
};

const LegacyNavBarSNCF = ({ appName, logo }: Props) => {
const LegacyNavBarSNCF = ({ appName, showLogoWithName }: Props) => {
const { openModal } = useModal();
const { digitalTwinLogo, digitalTwinName, isCustomizedDeployment } = useDeploymentSettings();
const deploymentSettings = useDeploymentSettings();
const safeWord = useSelector(getUserSafeWord);
const { t } = useTranslation('home/navbar');
const { logout, username } = useAuth();

const { logoUrl, name } = useMemo(() => {
if (!deploymentSettings)
return {
logoUrl: undefined,
name: 'Osrd',
};
return {
logoUrl: showLogoWithName
? deploymentSettings.digitalTwinLogoWithName
: deploymentSettings.digitalTwinLogo,
name: deploymentSettings.digitalTwinName,
};
}, [deploymentSettings, showLogoWithName]);

return (
<div className="mastheader">
<div
className={cx(
isCustomizedDeployment && logo ? `mastheader-logo__horizon` : `mastheader-logo`,
`flex-grow-0`
'flex-grow-0',
deploymentSettings?.isCustomizedDeployment && showLogoWithName
? 'mastheader-logo-with-name'
: 'mastheader-logo',
{ 'without-image': logoUrl }
)}
>
<Link to="/">
<img
src={logo ?? digitalTwinLogo}
data-testid={`${digitalTwinName.toLowerCase()}-logo`}
alt={`${digitalTwinName.toUpperCase()} Logo`}
/>
{logoUrl ? (
<img
src={logoUrl}
data-testid={`${name.toLowerCase()}-logo`}
alt={`${name.toUpperCase()} Logo`}
/>
) : (
<div style={{ width: '24px' }} />
)}
</Link>
</div>
<header role="banner" className="mastheader-title d-flex flex-grow-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import LicenseAttributions from './LicenseAttributions';

function ReleaseInformations() {
const { t } = useTranslation('home/navbar');
const { digitalTwinLogo } = useDeploymentSettings();
const deploymentSettings = useDeploymentSettings();
const { data: editoastVersion } = osrdEditoastApi.endpoints.getVersion.useQuery();
const { data: coreVersion } = osrdEditoastApi.endpoints.getVersionCore.useQuery();

Expand Down Expand Up @@ -46,7 +46,7 @@ function ReleaseInformations() {
rel="noopener noreferrer"
onMouseEnter={motriceParty}
>
<img src={digitalTwinLogo} alt="OSRD logo" width={192} />
<img src={deploymentSettings?.digitalTwinLogo} alt="OSRD logo" width={192} />
</a>
<h2>OSRD</h2>
<h3>Open Source Railway Designer</h3>
Expand Down
9 changes: 6 additions & 3 deletions front/src/main/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { stdcmConfSlice } from 'reducers/osrdconf/stdcmConf';
import stdcmConfSelectors from 'reducers/osrdconf/stdcmConf/selectors';
import { useAppDispatch } from 'store';
import useAuth from 'utils/hooks/OsrdAuth';
import { DeploymentContextProvider } from 'utils/hooks/useDeploymentSettings';

import('@sncf/bootstrap-sncf.metier.reseau/dist/css/bootstrap-sncf.min.css');

Expand Down Expand Up @@ -125,9 +126,11 @@ export default function App() {
const { isLoading } = useAuth();
return (
<Suspense fallback={<Loader />}>
<NotificationsState />
{!isLoading && <RouterProvider router={router} />}
{isLoading && <Loader />}
<DeploymentContextProvider>
<NotificationsState />
{!isLoading && <RouterProvider router={router} />}
{isLoading && <Loader />}
</DeploymentContextProvider>
</Suspense>
);
}
4 changes: 1 addition & 3 deletions front/src/main/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import useAllowedUserRoles from 'common/authorization/hooks/useAllowedUserRoles'
import Card from 'common/BootstrapSNCF/CardSNCF/CardSNCF';
import { ModalProvider } from 'common/BootstrapSNCF/ModalSNCF/ModalProvider';
import NavBarSNCF from 'common/BootstrapSNCF/NavBarSNCF';
import useDeploymentSettings from 'utils/hooks/useDeploymentSettings';

export default function Home() {
const { t } = useTranslation('home/home');
Expand All @@ -20,11 +19,10 @@ export default function Home() {
rollingStockEditorAllowed,
mapAllowed,
} = useAllowedUserRoles();
const { digitalTwinLogoWithName } = useDeploymentSettings();

return (
<ModalProvider>
<NavBarSNCF logo={digitalTwinLogoWithName} />
<NavBarSNCF showLogoWithName />
<main className="mastcontainer mastcontainer-no-mastnav">
<div className="cardscontainer">
<div className="row justify-content-center mb-2">
Expand Down
8 changes: 7 additions & 1 deletion front/src/styles/scss/_body.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ body {
height: 24px !important;
}

&__horizon {
&-with-name {
img {
height: 40px;
}
}

.without-image {
img {
width: 24px;
}
}
}

.actionbar.fullscreen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
position: relative;
height: 560px;

img {
min-height: 192px;
}

.license-attributions {
background-color: var(--coolgray1);
padding: 8px;
Expand Down
Loading
Loading