forked from entur/enki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request entur#1391 from solita-sabinaf/TIS-565/fintraffic_…
…style_customisations TIS-565/Fintraffic UI customisations
- Loading branch information
Showing
34 changed files
with
1,068 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/ext/Fintraffic/CustomIntlProvider/FintrafficIntlProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { FintrafficIntlProvider } from './FintrafficIntlProvider'; | ||
export default FintrafficIntlProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const messages = { | ||
appTitle: 'RAE', | ||
appLogoTitle: 'Route and schedule editor', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const messages = { | ||
appTitle: 'RAE', | ||
appLogoTitle: 'Reitti- ja aikataulueditori', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const messages = { | ||
appTitle: 'RAE', | ||
appLogoTitle: 'Rutt- och schemaredigerare', | ||
}; |
4 changes: 4 additions & 0 deletions
4
src/ext/Fintraffic/CustomIntlProvider/translations/translationKeys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { FintrafficLogo } from './FintrafficLogo'; | ||
export default FintrafficLogo; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <></>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { FintrafficStyle } from './FintrafficStyle'; | ||
export default FintrafficStyle; |
Oops, something went wrong.