Skip to content

Commit

Permalink
Merge pull request entur#1391 from solita-sabinaf/TIS-565/fintraffic_…
Browse files Browse the repository at this point in the history
…style_customisations

TIS-565/Fintraffic UI customisations
  • Loading branch information
testower authored Jun 17, 2024
2 parents c589ad6 + 5601c23 commit 2b91b85
Show file tree
Hide file tree
Showing 34 changed files with 1,068 additions and 86 deletions.
56 changes: 55 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"react-redux": "8.1.3",
"react-router-dom": "6.23.1",
"redux-sentry-middleware": "0.2.2",
"uuid": "10.0.0"
"uuid": "10.0.0",
"@fintraffic/fds-coreui-css": "0.1.3"
},
"devDependencies": {
"@redux-devtools/extension": "3.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/JourneyPatterns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const JourneyPatterns = ({ journeyPatterns, onChange, children }: Props) => {
})}
ref={textFieldRef}
/>
<div>
<div className={'confirm-dialog-buttons'}>
<SecondaryButton
onClick={() => setShowModal(false)}
className="margin-right"
Expand Down
4 changes: 3 additions & 1 deletion src/config/ConfigContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import { Config } from './config';

export const ConfigContext = createContext<Config>({});

export const useConfig = () => useContext(ConfigContext);
export const useConfig = () => {
return useContext(ConfigContext);
};
17 changes: 16 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { Locale } from '../i18n';
* For multi-level features, only the top-level featureName should be
* toggled.
*/
export interface SandboxFeatures {}
export interface SandboxFeatures {
/**
* Fintraffic's custom features or assets grouped in one location;
* For example: custom styles override, logo component and translations provider.
*/
Fintraffic: boolean;
}

export interface Config {
/**
Expand Down Expand Up @@ -74,4 +80,13 @@ export interface Config {
* Sandbox feature configuration
*/
sandboxFeatures?: SandboxFeatures;

/**
* Path to folder inder /ext that contains features or assets of a company that adopted Nplan.
* This is used e.g. for:
* CustomStyle, when determining the relevant custom style class;
* CustomLogo;
* overriding translations (case appTitle)
*/
extPath?: string;
}
62 changes: 62 additions & 0 deletions src/ext/Fintraffic/CustomIntlProvider/FintrafficIntlProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Suspense, useDeferredValue, useEffect, useState } from 'react';
import { IntlProvider } from 'react-intl';
import { selectLocale, updateConfiguredLocale } from 'i18n/intlSlice';
import { getMessages } from 'i18n';
import { useAppSelector, useAppDispatch } from '../../../store/hooks';
import { useConfig } from '../../../config/ConfigContext';
import { getExtMessages } from './getExtMessages';

/**
* Main objective of this was to override certain translation values (e.g. appTitle)
* and use additional translation keys that are relevant only for the custom Fintraffic features;
*
* @param children
* @constructor
*/
export const FintrafficIntlProvider = ({
children,
}: {
children: React.ReactNode;
}) => {
const [messages, setMessages] = useState<Record<string, string> | undefined>(
undefined,
);
const { defaultLocale, extPath } = useConfig();
const selectedLocale = useAppSelector(selectLocale);
const deferredMessages = useDeferredValue(messages);
const dispatch = useAppDispatch();

useEffect(() => {
if (defaultLocale) {
dispatch(updateConfiguredLocale(defaultLocale));
}
}, [defaultLocale]);

useEffect(() => {
getMessages(selectedLocale).then(async (messagesForLocale) => {
setMessages(() => messagesForLocale);
if (extPath) {
const extMessages = await getExtMessages(extPath, selectedLocale);
const combinedMessages = {
...messagesForLocale,
...extMessages,
} as Record<string, string>;
setMessages(() => combinedMessages);
}
});
}, [selectedLocale, extPath]);

return (
<Suspense>
{deferredMessages !== null && (
<IntlProvider
locale={selectedLocale}
messages={messages}
defaultLocale={defaultLocale || 'fi'}
>
{children}
</IntlProvider>
)}
</Suspense>
);
};
14 changes: 14 additions & 0 deletions src/ext/Fintraffic/CustomIntlProvider/getExtMessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Locale } from '../../../i18n';
import { ExtMessages } from './translations/translationKeys';

/**
* Getting translation overrides or additional translations related specifically to external company that adopted Nplan
* @param extPath
* @param locale
*/
export const getExtMessages = async (
extPath: string,
locale: Locale,
): Promise<Record<ExtMessages, string>> => {
return (await import(`./translations/${locale}.ts`)).messages;
};
2 changes: 2 additions & 0 deletions src/ext/Fintraffic/CustomIntlProvider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { FintrafficIntlProvider } from './FintrafficIntlProvider';
export default FintrafficIntlProvider;
4 changes: 4 additions & 0 deletions src/ext/Fintraffic/CustomIntlProvider/translations/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const messages = {
appTitle: 'RAE',
appLogoTitle: 'Route and schedule editor',
};
4 changes: 4 additions & 0 deletions src/ext/Fintraffic/CustomIntlProvider/translations/fi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const messages = {
appTitle: 'RAE',
appLogoTitle: 'Reitti- ja aikataulueditori',
};
4 changes: 4 additions & 0 deletions src/ext/Fintraffic/CustomIntlProvider/translations/sv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const messages = {
appTitle: 'RAE',
appLogoTitle: 'Rutt- och schemaredigerare',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { messages as fiMessages } from './fi';

export type ExtMessagesKey = typeof fiMessages;
export type ExtMessages = keyof ExtMessagesKey;
19 changes: 19 additions & 0 deletions src/ext/Fintraffic/CustomLogo/FintrafficLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import './styles.scss';
import { useIntl } from 'react-intl';
import logo from './logo.png';
import React from 'react';

export const FintrafficLogo = () => {
const { formatMessage } = useIntl();

return (
<div className="custom-logo-wrapper">
<img
className="logo"
src={logo}
alt={formatMessage({ id: 'navBarRootLinkLogoAltText' })}
/>
<div>{formatMessage({ id: 'appLogoTitle' })}</div>
</div>
);
};
2 changes: 2 additions & 0 deletions src/ext/Fintraffic/CustomLogo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { FintrafficLogo } from './FintrafficLogo';
export default FintrafficLogo;
Binary file added src/ext/Fintraffic/CustomLogo/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/ext/Fintraffic/CustomLogo/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@import '@fintraffic/fds-coreui-css/dist/tokens';

.custom-logo-wrapper {
cursor: pointer;
margin-top: 16px;
margin-bottom: 16px;
padding-left: 30px;
padding-right: 30px;
height: auto;
}

.custom-logo-wrapper > div {
color: #3388ff;
width: fit-content;
font-size: 1rem;
font-weight: 600;
}

.logo {
width: 150px;
}
8 changes: 8 additions & 0 deletions src/ext/Fintraffic/CustomStyle/FintrafficStyle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import './styles.scss';

/**
* Main point in here is just to import the style overrides
*/
export const FintrafficStyle = () => {
return <></>;
};
2 changes: 2 additions & 0 deletions src/ext/Fintraffic/CustomStyle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { FintrafficStyle } from './FintrafficStyle';
export default FintrafficStyle;
Loading

0 comments on commit 2b91b85

Please sign in to comment.