Skip to content

Commit

Permalink
Merge branch 'v3' into DT-5659-part2
Browse files Browse the repository at this point in the history
  • Loading branch information
optionsome committed Jul 31, 2023
2 parents a1d1ecb + 5357913 commit 9039031
Show file tree
Hide file tree
Showing 65 changed files with 2,170 additions and 909 deletions.
5 changes: 5 additions & 0 deletions app/action/CountryActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const updateCountries = (actionContext, countries) => {
actionContext.dispatch('UpdateCountries', countries);
};

export default updateCountries;
4 changes: 4 additions & 0 deletions app/action/SearchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export function saveSearch(actionContext, endpoint) {
actionContext.dispatch('SaveSearch', endpoint);
}

export function removeSearch(actionContext, endpoint) {
actionContext.dispatch('RemoveSearch', endpoint);
}

export function saveSearchItems(actionContext, items) {
actionContext.dispatch('SaveSearchItems', items);
}
2 changes: 2 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import UserStore from './store/UserStore';
import FavouriteStore from './store/FavouriteStore';
import RoutingSettingsStore from './store/RoutingSettingsStore';
import FutureRouteStore from './store/FutureRouteStore';
import CountryStore from './store/CountryStore';

export default config => {
const app = new Fluxible({
Expand All @@ -39,6 +40,7 @@ export default config => {
app.registerStore(FavouriteStore);
app.registerStore(RoutingSettingsStore);
app.registerStore(FutureRouteStore);
app.registerStore(CountryStore);

app.plug({
name: 'extra-context-plugin',
Expand Down
7 changes: 7 additions & 0 deletions app/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
initAnalyticsClientSide,
addAnalyticsEvent,
} from './util/analyticsUtils';
import { configureCountry } from './util/configureCountry';

const plugContext = f => () => ({
plugComponentContext: f,
Expand Down Expand Up @@ -101,6 +102,12 @@ async function init() {

const context = await app.rehydrate(window.state);

// Get additional feedIds and searchParams from localstorage
if (config.mainMenu.countrySelection) {
const selectedCountries = context.getStore('CountryStore').getCountries();
configureCountry(config, selectedCountries);
}

// For Google Tag Manager
if (!config.useCookiesPrompt) {
initAnalyticsClientSide();
Expand Down
12 changes: 9 additions & 3 deletions app/component/AboutPage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import PropTypes from 'prop-types';
/* eslint-disable react/no-array-index-key */
import React from 'react';
import React, { useEffect, useState } from 'react';
import Link from 'found/Link';
import { FormattedMessage } from 'react-intl';
import connectToStores from 'fluxible-addons-react/connectToStores';

const AboutPage = ({ currentLanguage }, { config }) => {
const about = config.aboutThisService[currentLanguage];
const [about, setAbout] = useState([]);
useEffect(() => {
setAbout(config.aboutThisService[currentLanguage]);
}, []);
return (
<div className="about-page fullscreen">
<div className="page-frame fullscreen momentum-scroll">
Expand All @@ -16,7 +19,10 @@ const AboutPage = ({ currentLanguage }, { config }) => {
<h1 className="about-header">{section.header}</h1>
{section.paragraphs &&
section.paragraphs.map((p, j) => (
<p key={`about-section-${i}-p-${j}`}>{p}</p>
<p
key={`about-section-${i}-p-${j}`}
dangerouslySetInnerHTML={{ __html: p }}
/>
))}
{section.link && (
<a href={section.link}>
Expand Down
6 changes: 5 additions & 1 deletion app/component/AppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const AppBar = (
) => {
const { location } = match;
const [disruptionInfoOpen, setDisruptionInfoOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(
window.sessionStorage.menuOpen === 'true',
);
const url = encodeURI(`${window.location?.origin || ''}${location.pathname}`);
const params = location.search && location.search.substring(1);

Expand All @@ -29,6 +31,8 @@ const AppBar = (
action: newState ? 'OpenMenu' : 'CloseMenu',
name: null,
});
// Set sessionStorage menuOpen to false on closing the menu so it doesn't pop up opened on later refreshes.
window.sessionStorage.setItem('menuOpen', false);
setMenuOpen(newState);
};

Expand Down
12 changes: 12 additions & 0 deletions app/component/AppBarHsl.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.hslfi-cb__button-primary {
&:hover {
background-color: #0062A1 !important;
color: white !important;
}
}

.hslfi-cb__button-secondary {
&:hover {
color: #0062A1 !important;
}
}
6 changes: 5 additions & 1 deletion app/component/CarLeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ function CarLeg(props, { config, intl }) {
<div className="itinerary-leg-action">
<div className="itinerary-leg-action-content">
<FormattedMessage
id="car-distance-duration"
id={
config.hideCarSuggestionDuration
? 'car-distance-no-duration'
: 'car-distance-duration'
}
values={{ distance, duration }}
defaultMessage="Drive {distance} ({duration})}"
/>
Expand Down
32 changes: 20 additions & 12 deletions app/component/EmbeddedSearch/EmbeddedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,18 @@ const EmbeddedSearch = (props, context) => {
};

useEffect(() => {
import(
/* webpackChunkName: "embedded-search" */ `../../configurations/images/${
config.secondaryLogo || config.logo
}`
).then(l => {
setLogo(l.default);
if (config.secondaryLogo || config.logo) {
import(
/* webpackChunkName: "embedded-search" */ `../../configurations/images/${
config.secondaryLogo || config.logo
}`
).then(l => {
setLogo(l.default);
setLoading(false);
});
} else {
setLoading(false);
});
}
}, []);

if (i18next.language !== lang) {
Expand Down Expand Up @@ -318,11 +322,15 @@ const EmbeddedSearch = (props, context) => {
{...locationSearchProps}
/>
<div className="embedded-search-button-container">
<img
src={logo}
className="brand-logo"
alt={`${config.title} logo`}
/>
{logo ? (
<img
src={logo}
className="brand-logo"
alt={`${config.title} logo`}
/>
) : (
<span className="brand-logo">{config.title}</span>
)}
<button
ref={buttonRef}
className="search-button"
Expand Down
5 changes: 4 additions & 1 deletion app/component/ItinerarySummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ItinerarySummary = ({
futureText,
isMultiRow,
isMobile,
hideBottomDivider,
}) => {
return (
<div className="itinerary-summary">
Expand Down Expand Up @@ -50,7 +51,7 @@ const ItinerarySummary = ({
mode="car"
/>
)}
<div className={cx('divider-bottom')} />
{!hideBottomDivider && <div className={cx('divider-bottom')} />}
</div>
);
};
Expand All @@ -66,6 +67,7 @@ ItinerarySummary.propTypes = {
futureText: PropTypes.string,
isMultiRow: PropTypes.bool,
isMobile: PropTypes.bool,
hideBottomDivider: PropTypes.bool,
};

ItinerarySummary.defaultTypes = {
Expand All @@ -75,6 +77,7 @@ ItinerarySummary.defaultTypes = {
futureText: '',
isMultiRow: false,
isMobile: false,
hideBottomDivider: false,
};

ItinerarySummary.displayName = 'ItinerarySummary';
Expand Down
1 change: 1 addition & 0 deletions app/component/ItineraryTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class ItineraryTab extends React.Component {
futureText={extraProps.futureText}
isMultiRow={extraProps.isMultiRow}
isMobile={this.props.isMobile}
hideBottomDivider={shouldShowFarePurchaseInfo(config,breakpoint,fares)}
/>
) : (
<>
Expand Down
1 change: 1 addition & 0 deletions app/component/LogoSmall.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const LogoSmall = ({ logo, title }, { config }) => {
</span>
);
}

return (
<div
className="logo"
Expand Down
97 changes: 76 additions & 21 deletions app/component/MainMenu.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import PropTypes from 'prop-types';
import React from 'react';
import React, { useState } from 'react';
import { FormattedMessage, intlShape } from 'react-intl';
import Link from 'found/Link';

import { connectToStores } from 'fluxible-addons-react';
import DisruptionInfoButtonContainer from './DisruptionInfoButtonContainer';
import Icon from './Icon';
import LangSelect from './LangSelect';
import MainMenuLinks from './MainMenuLinks';
import { addAnalyticsEvent } from '../util/analyticsUtils';
import { updateCountries } from '../action/CountryActions';
import Toggle from './customizesearch/Toggle';
import searchContext from '../util/searchContext';
import intializeSearchContext from '../util/DTSearchContextInitializer';

function MainMenu(props, { config, intl }) {
const [countries, setCountries] = useState(props.countries);
return (
<div className="main-menu no-select">
<div className="main-menu no-select" tabIndex={-1}>
<div className="main-menu-top-section">
<button
type="button"
ref={input => input && input.focus()}
onClick={props.closeMenu}
className="close-button cursor-pointer"
aria-label={intl.formatMessage({
Expand Down Expand Up @@ -77,23 +82,59 @@ function MainMenu(props, { config, intl }) {
</Link>
</div>
)}
{config.appBarLink && config.appBarLink.name && config.appBarLink.href && (
<div className="offcanvas-section">
<a
id="appBarLink"
href={config.appBarLink.href}
onClick={() => {
addAnalyticsEvent({
category: 'Navigation',
action: 'appBarLink',
name: null,
});
}}
>
{config.appBarLink.name}
</a>
</div>
)}
{config.mainMenu.countrySelection &&
config.mainMenu.countrySelection.map(country => (
<div key={country} className="offcanvas-section">
<FormattedMessage
id={`include-${country}`}
defaultMessage={`include-${country}`}
/>
<div style={{ float: 'right', display: 'inline-block' }}>
{/* eslint-disable jsx-a11y/label-has-associated-control */}
<label key={country} htmlFor={`toggle-${country}`}>
<Toggle
id={`toggle-${country}`}
toggled={!!countries[country]}
onToggle={() => {
setCountries({
...countries,
[country]: !countries[country],
});
props.updateCountries({
...countries,
[country]: !countries[country],
});
// Update searchContext to reflect changes in config
intializeSearchContext({ config }, searchContext);
// On changing country filters, set sessionStorage menuOpen to true. This item is used in AppBar.js to initially open the menu after refresh for visual confirmation.
window.sessionStorage.setItem('menuOpen', true);
window.location.reload();
}}
/>
</label>
</div>
</div>
))}
{config.appBarLink &&
config.appBarLink.name &&
config.appBarLink.href &&
!config.hideAppBarLink && (
<div className="offcanvas-section">
<a
id="appBarLink"
href={config.appBarLink.href}
onClick={() => {
addAnalyticsEvent({
category: 'Navigation',
action: 'appBarLink',
name: null,
});
}}
>
{config.appBarLink.name}
</a>
</div>
)}
</section>
<section className="menu-section secondary-links">
<MainMenuLinks
Expand All @@ -113,6 +154,8 @@ MainMenu.propTypes = {
setDisruptionInfoOpen: PropTypes.func.isRequired,
closeMenu: PropTypes.func.isRequired,
homeUrl: PropTypes.string.isRequired,
countries: PropTypes.object,
updateCountries: PropTypes.func,
};

MainMenu.contextTypes = {
Expand All @@ -121,4 +164,16 @@ MainMenu.contextTypes = {
intl: intlShape.isRequired,
};

export default MainMenu;
const connectedComponent = connectToStores(
MainMenu,
['CountryStore'],
({ getStore, executeAction }) => ({
countries: getStore('CountryStore').getCountries(),
updateCountries: countries => executeAction(updateCountries, countries),
}),
{
executeAction: PropTypes.func,
},
);

export { connectedComponent as default, MainMenu as Component };
1 change: 1 addition & 0 deletions app/component/MenuDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function MenuDrawer({
className={classNames}
overlayClassName={overlayClassNames}
onRequestClose={onRequestChange}
shouldFocusAfterRender={false}
>
{children}
</Modal>
Expand Down
Loading

0 comments on commit 9039031

Please sign in to comment.