From 84432c487717d00a63a9f79da392149fe3f3d5d8 Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Wed, 20 May 2020 10:41:25 -0400 Subject: [PATCH 1/6] fix(mapbox-url): update URL for deprecating service --- lib/common/util/maps.js | 14 ++++++++++---- .../components/map/EditorMapLayersControl.js | 3 ++- lib/gtfs/components/GtfsMap.js | 5 +++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/common/util/maps.js b/lib/common/util/maps.js index 5894cc4b0..f1b72ed21 100644 --- a/lib/common/util/maps.js +++ b/lib/common/util/maps.js @@ -2,11 +2,17 @@ import { Browser } from 'leaflet' +/** + * Get the default Mapbox tile URL used for use in a leaflet map. Optionally + * takes a map ID (e.g., mapbox/outdoors-v11). + */ export function defaultTileURL (mapId: ?string): string { - const MAPBOX_MAP_ID = mapId || process.env.MAPBOX_MAP_ID + // If no mapId is provided, default to id defined in env.yml or, ultimately, + // fall back on default value. + const id = mapId || process.env.MAPBOX_MAP_ID || 'mapbox/outdoors-v11' const MAPBOX_ACCESS_TOKEN = process.env.MAPBOX_ACCESS_TOKEN - if (!MAPBOX_MAP_ID || !MAPBOX_ACCESS_TOKEN) { - throw new Error('Mapbox ID and token not defined') + if (!MAPBOX_ACCESS_TOKEN) { + throw new Error('Mapbox token not defined') } - return `https://api.tiles.mapbox.com/v4/${MAPBOX_MAP_ID}/{z}/{x}/{y}${Browser.retina ? '@2x' : ''}.png?access_token=${MAPBOX_ACCESS_TOKEN}` + return `https://api.mapbox.com/styles/v1/${id}/tiles/{z}/{x}/{y}${Browser.retina ? '@2x' : ''}?access_token=${MAPBOX_ACCESS_TOKEN}` } diff --git a/lib/editor/components/map/EditorMapLayersControl.js b/lib/editor/components/map/EditorMapLayersControl.js index 5ac5285d9..099cd7ca4 100644 --- a/lib/editor/components/map/EditorMapLayersControl.js +++ b/lib/editor/components/map/EditorMapLayersControl.js @@ -12,6 +12,7 @@ import { import {getUserMetadataProperty} from '../../../common/util/user' import {isExtensionEnabled} from '../../../common/util/config' +import {defaultTileURL} from '../../../common/util/maps' import StopLayer from '../../../scenario-editor/components/StopLayer' import {MAP_LAYERS} from '../../util/map' @@ -76,7 +77,7 @@ export default class EditorMapLayersControl extends Component { key={layer.id} checked={activeMapLayerIndex !== -1 ? index === activeMapLayerIndex : index === 0}> ))} diff --git a/lib/gtfs/components/GtfsMap.js b/lib/gtfs/components/GtfsMap.js index 9a2ed84c0..663cc9d24 100644 --- a/lib/gtfs/components/GtfsMap.js +++ b/lib/gtfs/components/GtfsMap.js @@ -2,12 +2,13 @@ import React, { Component } from 'react' import { shallowEqual } from 'react-pure-render' -import { Browser, latLngBounds } from 'leaflet' +import { latLngBounds } from 'leaflet' import { FeatureGroup, Map, Polyline, Rectangle, TileLayer } from 'react-leaflet' import * as filterActions from '../actions/filter' import * as generalActions from '../actions/general' import {getFeedsBounds, convertToArrayBounds} from '../../common/util/geo' +import {defaultTileURL} from '../../common/util/maps' import PatternGeoJson from './PatternGeoJson' import StopMarker from './StopMarker' @@ -249,7 +250,7 @@ export default class GtfsMap extends Component { onLayerAdd={this.layerAddHandler} className='Gtfs-Map'> {/* Feed version bounding box (show if not set to default indicating invalid version bounds) */} {showBounds && versionBoundingBox && From 86118a1f9c403f00138d29c552e6939fc3b48681 Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Wed, 20 May 2020 15:11:34 -0400 Subject: [PATCH 2/6] refactor(TileLayer): change util to return layer props --- lib/common/components/MapModal.js | 7 +--- lib/common/user/Auth0Manager.js | 2 +- lib/common/util/maps.js | 42 +++++++++++++++++-- lib/editor/components/map/EditorMap.js | 7 ++-- .../components/map/EditorMapLayersControl.js | 18 +++----- lib/editor/util/map.js | 24 ----------- lib/gtfs/components/GtfsMap.js | 6 +-- .../components/DeploymentConfirmModal.js | 6 +-- lib/manager/components/DeploymentViewer.js | 6 +-- lib/types/index.js | 15 +++++++ 10 files changed, 72 insertions(+), 61 deletions(-) diff --git a/lib/common/components/MapModal.js b/lib/common/components/MapModal.js index 28f9b9e72..c6bcfbf16 100644 --- a/lib/common/components/MapModal.js +++ b/lib/common/components/MapModal.js @@ -4,7 +4,7 @@ import React, {Component} from 'react' import { Modal, Button } from 'react-bootstrap' import { Map, Marker, TileLayer } from 'react-leaflet' -import {defaultTileURL} from '../util/maps' +import {defaultTileLayerProps} from '../util/maps' import type {LatLng} from '../../types' @@ -93,7 +93,6 @@ export default class MapModal extends Component { position={[this.state.marker.lat, this.state.marker.lng]} key={Math.random()} /> : null - const MAPBOX_ATTRIBUTION = process.env.MAPBOX_ATTRIBUTION return (
@@ -106,9 +105,7 @@ export default class MapModal extends Component { bounds={bounds} style={mapStyle} onClick={this.clickHandler}> - + {marker} diff --git a/lib/common/user/Auth0Manager.js b/lib/common/user/Auth0Manager.js index 6dc373b11..0892fc980 100644 --- a/lib/common/user/Auth0Manager.js +++ b/lib/common/user/Auth0Manager.js @@ -283,7 +283,7 @@ class Auth0Manager { const accessToken = getAccessToken() if (!accessToken) return logout(userIsLoggedIn) - + console.log(accessToken); // try to get the profile from localStorage return this._getProfileFromToken(accessToken) .then((profile) => { diff --git a/lib/common/util/maps.js b/lib/common/util/maps.js index f1b72ed21..87f266949 100644 --- a/lib/common/util/maps.js +++ b/lib/common/util/maps.js @@ -2,17 +2,53 @@ import { Browser } from 'leaflet' +import type {TileLayerProps, MapLayer} from '../../types' + +const DEFAULT_MAP_ID = 'mapbox/outdoors-v11' + +/** + * Default map layers for the GTFS editor. (Note: this is defined in the common + * util file in order to keep all refs to mapbox IDs in a single file.) + */ +export const EDITOR_MAP_LAYERS: Array = [ + { + name: 'Streets', + id: DEFAULT_MAP_ID + }, + { + name: 'Light', + id: 'mapbox/light-v10' + }, + { + name: 'Dark', + id: 'mapbox/dark-v10' + }, + { + name: 'Satellite', + id: 'mapbox/satellite-streets-v11' + } +] + /** * Get the default Mapbox tile URL used for use in a leaflet map. Optionally * takes a map ID (e.g., mapbox/outdoors-v11). */ -export function defaultTileURL (mapId: ?string): string { +export function defaultTileLayerProps (mapId: ?string): TileLayerProps { // If no mapId is provided, default to id defined in env.yml or, ultimately, // fall back on default value. - const id = mapId || process.env.MAPBOX_MAP_ID || 'mapbox/outdoors-v11' + const id = mapId || process.env.MAPBOX_MAP_ID || DEFAULT_MAP_ID + const attribution = process.env.MAPBOX_ATTRIBUTION || `© Mapbox © OpenStreetMap Improve this map` const MAPBOX_ACCESS_TOKEN = process.env.MAPBOX_ACCESS_TOKEN if (!MAPBOX_ACCESS_TOKEN) { throw new Error('Mapbox token not defined') } - return `https://api.mapbox.com/styles/v1/${id}/tiles/{z}/{x}/{y}${Browser.retina ? '@2x' : ''}?access_token=${MAPBOX_ACCESS_TOKEN}` + const url = `https://api.mapbox.com/styles/v1/${id}/tiles/{z}/{x}/{y}${Browser.retina ? '@2x' : ''}?access_token=${MAPBOX_ACCESS_TOKEN}` + const retinaProps = Browser.retina + ? {tileSize: 512, zoomOffset: -1} + : {} + return { + attribution, + ...retinaProps, + url + } } diff --git a/lib/editor/components/map/EditorMap.js b/lib/editor/components/map/EditorMap.js index 74d879532..e099ea6bb 100644 --- a/lib/editor/components/map/EditorMap.js +++ b/lib/editor/components/map/EditorMap.js @@ -9,6 +9,7 @@ import * as editorActions from '../../actions/editor' import * as mapActions from '../../actions/map' import * as stopStrategiesActions from '../../actions/map/stopStrategies' import * as tripPatternActions from '../../actions/tripPattern' +import {EDITOR_MAP_LAYERS} from '../../../common/util/maps' import * as userActions from '../../../manager/actions/user' import AddableStopsLayer from './AddableStopsLayer' import EditorMapLayersControl from './EditorMapLayersControl' @@ -18,7 +19,7 @@ import PatternDebugLines from './pattern-debug-lines' import PatternsLayer from './PatternsLayer' import PatternStopsLayer from './PatternStopsLayer' import StopsLayer from './StopsLayer' -import {MAP_LAYERS, constructStop, clickToLatLng, getFeedBounds} from '../../util/map' +import {constructStop, clickToLatLng, getFeedBounds} from '../../util/map' import {entityIsNew} from '../../util/objects' import type { @@ -181,8 +182,8 @@ export default class EditorMap extends Component { } _mapBaseLayerChanged = (e: any) => { - const layer = MAP_LAYERS.find(l => l.name === e.name) - if (!layer) return console.warn(`Could not locate map layer with name=${e.name}`, MAP_LAYERS) + const layer = EDITOR_MAP_LAYERS.find(l => l.name === e.name) + if (!layer) return console.warn(`Could not locate map layer with name=${e.name}`, EDITOR_MAP_LAYERS) this.props.updateUserMetadata(this.props.user.profile, {editor: {map_id: layer.id}}) } diff --git a/lib/editor/components/map/EditorMapLayersControl.js b/lib/editor/components/map/EditorMapLayersControl.js index 099cd7ca4..dc46fd805 100644 --- a/lib/editor/components/map/EditorMapLayersControl.js +++ b/lib/editor/components/map/EditorMapLayersControl.js @@ -12,13 +12,11 @@ import { import {getUserMetadataProperty} from '../../../common/util/user' import {isExtensionEnabled} from '../../../common/util/config' -import {defaultTileURL} from '../../../common/util/maps' +import {defaultTileLayerProps, EDITOR_MAP_LAYERS} from '../../../common/util/maps' import StopLayer from '../../../scenario-editor/components/StopLayer' -import {MAP_LAYERS} from '../../util/map' -import type {GtfsStop} from '../../../types' +import type {GtfsStop, MapLayer} from '../../../types' import type {ManagerUserState} from '../../../types/reducers' -import type {MapLayer} from '../../util/map' type Props = { stops: Array, @@ -62,23 +60,17 @@ export default class EditorMapLayersControl extends Component { component: } ] - const activeMapLayerIndex: number = MAP_LAYERS.findIndex( + const activeMapLayerIndex: number = EDITOR_MAP_LAYERS.findIndex( (l: MapLayer) => l.id === getUserMetadataProperty(user.profile, 'editor.map_id') ) - const MAPBOX_ACCESS_TOKEN: string = process.env.MAPBOX_ACCESS_TOKEN - ? process.env.MAPBOX_ACCESS_TOKEN - : 'NO_TOKEN_FOUND' - const MAPBOX_ATTRIBUTION: ?string = process.env.MAPBOX_ATTRIBUTION return ( - {MAP_LAYERS.map((layer: MapLayer, index: number) => ( + {EDITOR_MAP_LAYERS.map((layer: MapLayer, index: number) => ( - + ))} {isExtensionEnabled('nysdot') && diff --git a/lib/editor/util/map.js b/lib/editor/util/map.js index 2f35d39de..0f74465a7 100644 --- a/lib/editor/util/map.js +++ b/lib/editor/util/map.js @@ -34,11 +34,6 @@ import type { StopTime } from '../../types' -export type MapLayer = { - id: string, - name: string -} - type R5Response = { data: { features: Array @@ -73,25 +68,6 @@ export const getStopIcon = ( iconSize: [24, 24] }) -export const MAP_LAYERS: Array = [ - { - name: 'Streets', - id: 'mapbox.streets' - }, - { - name: 'Light', - id: 'mapbox.light' - }, - { - name: 'Dark', - id: 'mapbox.dark' - }, - { - name: 'Satellite', - id: 'mapbox.streets-satellite' - } -] - export function clickToLatLng ( latlng: LatLng ): {stop_lat: number, stop_lon: number} { diff --git a/lib/gtfs/components/GtfsMap.js b/lib/gtfs/components/GtfsMap.js index 663cc9d24..33996f928 100644 --- a/lib/gtfs/components/GtfsMap.js +++ b/lib/gtfs/components/GtfsMap.js @@ -8,7 +8,7 @@ import { FeatureGroup, Map, Polyline, Rectangle, TileLayer } from 'react-leaflet import * as filterActions from '../actions/filter' import * as generalActions from '../actions/general' import {getFeedsBounds, convertToArrayBounds} from '../../common/util/geo' -import {defaultTileURL} from '../../common/util/maps' +import {defaultTileLayerProps} from '../../common/util/maps' import PatternGeoJson from './PatternGeoJson' import StopMarker from './StopMarker' @@ -249,9 +249,7 @@ export default class GtfsMap extends Component { onMoveEnd={this.mapMoved} onLayerAdd={this.layerAddHandler} className='Gtfs-Map'> - + {/* Feed version bounding box (show if not set to default indicating invalid version bounds) */} {showBounds && versionBoundingBox && { bounds={bounds} scrollWheelZoom={false} style={{width: '100%', height: '300px'}}> - + {!isMissingBounds && { bounds={bounds} scrollWheelZoom={false} style={{width: '100%', height: '300px'}}> - + {!isMissingBounds && } } + + +// Map types (primarily for use in editor and common/util/maps.js) + +export type MapLayer = { + id: string, + name: string +} + +export type TileLayerProps = { + attribution: string, + tileSize?: number, + url: string, + zoomOffset?: number +} From 92254752575b0ffc987e20e6dac5d8e300bb2a4b Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Wed, 20 May 2020 17:27:08 -0400 Subject: [PATCH 3/6] refactor(user): remove user metadata updates This feature is no longer working in Auth0. This is essentially dead code and should be added back only once the user storage is happening in MongoDB. --- lib/common/components/Sidebar.js | 22 +-------- lib/common/containers/ActiveSidebar.js | 3 -- lib/common/user/Auth0Manager.js | 1 - lib/editor/components/EditorHelpModal.js | 5 --- lib/editor/components/GtfsEditor.js | 6 +-- lib/editor/components/map/EditorMap.js | 5 ++- lib/editor/containers/ActiveGtfsEditor.js | 4 -- lib/manager/actions/ui.js | 33 -------------- lib/manager/actions/user.js | 54 +++++------------------ lib/types/actions.js | 2 - 10 files changed, 15 insertions(+), 120 deletions(-) delete mode 100644 lib/manager/actions/ui.js diff --git a/lib/common/components/Sidebar.js b/lib/common/components/Sidebar.js index 3e8bd191a..f69bab8c8 100644 --- a/lib/common/components/Sidebar.js +++ b/lib/common/components/Sidebar.js @@ -2,11 +2,10 @@ import moment from 'moment' import React, {PureComponent, type Node} from 'react' -import {Navbar, Checkbox} from 'react-bootstrap' +import {Navbar} from 'react-bootstrap' import {Link} from 'react-router' import * as statusActions from '../../manager/actions/status' -import * as uiActions from '../../manager/actions/ui' import * as userActions from '../../manager/actions/user' import JobMonitor from './JobMonitor' import SidebarNavItem from './SidebarNavItem' @@ -39,8 +38,6 @@ type Props = ContainerProps & { removeRetiredJob: typeof statusActions.removeRetiredJob, revokeToken: typeof userActions.revokeToken, setJobMonitorVisible: typeof statusActions.setJobMonitorVisible, - setSidebarExpanded: typeof uiActions.setSidebarExpanded, - setTutorialHidden: typeof uiActions.setTutorialHidden, startJobMonitor: typeof statusActions.startJobMonitor, user: ManagerUserState } @@ -85,16 +82,11 @@ export default class Sidebar extends PureComponent { _select = (key: ?$Values) => this.setState({visiblePopover: (key === this.state.visiblePopover) ? null : key}) - _toggleLabels = () => this.props.setSidebarExpanded(!this.props.expanded) - - _toggleTutorial = () => this.props.setTutorialHidden(!this.props.hideTutorial) - render () { const { appInfo, children, expanded, - hideTutorial, jobMonitor, removeRetiredJob, user @@ -170,18 +162,6 @@ export default class Sidebar extends PureComponent { width={300} >
- - Show Sidebar Labels - - - Hide editor tutorial -
About this app
diff --git a/lib/common/containers/ActiveSidebar.js b/lib/common/containers/ActiveSidebar.js index e57ab53bf..63a5e2dbc 100644 --- a/lib/common/containers/ActiveSidebar.js +++ b/lib/common/containers/ActiveSidebar.js @@ -10,7 +10,6 @@ import { startJobMonitor, setJobMonitorVisible } from '../../manager/actions/status' -import {setSidebarExpanded, setTutorialHidden} from '../../manager/actions/ui' import type {AppState} from '../../types/reducers' @@ -32,8 +31,6 @@ const mapDispatchToProps = { removeRetiredJob, revokeToken, setJobMonitorVisible, - setSidebarExpanded, - setTutorialHidden, startJobMonitor } diff --git a/lib/common/user/Auth0Manager.js b/lib/common/user/Auth0Manager.js index 0892fc980..4b81e3163 100644 --- a/lib/common/user/Auth0Manager.js +++ b/lib/common/user/Auth0Manager.js @@ -283,7 +283,6 @@ class Auth0Manager { const accessToken = getAccessToken() if (!accessToken) return logout(userIsLoggedIn) - console.log(accessToken); // try to get the profile from localStorage return this._getProfileFromToken(accessToken) .then((profile) => { diff --git a/lib/editor/components/EditorHelpModal.js b/lib/editor/components/EditorHelpModal.js index 99d57fabc..b934c8d57 100644 --- a/lib/editor/components/EditorHelpModal.js +++ b/lib/editor/components/EditorHelpModal.js @@ -7,7 +7,6 @@ import {LinkContainer} from 'react-router-bootstrap' import * as snapshotActions from '../actions/snapshots' import {getConfigProperty} from '../../common/util/config' -import * as uiActions from '../../manager/actions/ui' import type {Feed} from '../../types' import type {EditorStatus} from '../../types/reducers' @@ -19,7 +18,6 @@ type Props = { isNewFeed: boolean, loadFeedVersionForEditing: typeof snapshotActions.loadFeedVersionForEditing, refreshEditor: () => void, - setTutorialHidden: typeof uiActions.setTutorialHidden, show: boolean, status: EditorStatus } @@ -60,9 +58,6 @@ export default class EditorHelpModal extends Component { } close = () => { - if (this.state.hideTutorial !== this.props.hideTutorial) { - this.props.setTutorialHidden(!this.props.hideTutorial) - } this.setState({ showModal: false }) } diff --git a/lib/editor/components/GtfsEditor.js b/lib/editor/components/GtfsEditor.js index b1615ccb6..0f88c48fc 100644 --- a/lib/editor/components/GtfsEditor.js +++ b/lib/editor/components/GtfsEditor.js @@ -13,7 +13,6 @@ import CurrentStatusMessage from '../../common/containers/CurrentStatusMessage' import ConfirmModal from '../../common/components/ConfirmModal' import Title from '../../common/components/Title' import CurrentStatusModal from '../../common/containers/CurrentStatusModal' -import * as uiActions from '../../manager/actions/ui' import * as userActions from '../../manager/actions/user' import EditorMap from './map/EditorMap' import EditorHelpModal from './EditorHelpModal' @@ -102,7 +101,6 @@ type Props = ContainerProps & { setActiveGtfsEntity: typeof activeActions.setActiveGtfsEntity, setActivePatternSegment: typeof tripPatternActions.setActivePatternSegment, setActiveStop: typeof tripPatternActions.setActiveStop, - setTutorialHidden: typeof uiActions.setTutorialHidden, showConfirmModal: ({body: string, onConfirm: () => void, title: string}) => void, sidebarExpanded: boolean, status: EditorStatus, @@ -117,7 +115,7 @@ type Props = ContainerProps & { updateEditSetting: typeof activeActions.updateEditSetting, updateMapSetting: typeof mapActions.updateMapSetting, updatePatternStops: typeof tripPatternActions.updatePatternStops, - updateUserMetadata: typeof userActions.updateUserMetadata, + updateUserData: typeof userActions.updateUserData, uploadBrandingAsset: typeof editorActions.uploadBrandingAsset, user: ManagerUserState, validationErrors: Array, @@ -292,7 +290,6 @@ export default class GtfsEditor extends Component { loadFeedVersionForEditing, mapState, routeParams, - setTutorialHidden, sidebarExpanded, status, subSubComponent, @@ -348,7 +345,6 @@ export default class GtfsEditor extends Component { loadFeedVersionForEditing={loadFeedVersionForEditing} isNewFeed refreshEditor={this._refreshEditor} - setTutorialHidden={setTutorialHidden} show status={status} /> : null diff --git a/lib/editor/components/map/EditorMap.js b/lib/editor/components/map/EditorMap.js index e099ea6bb..0bdd09b9b 100644 --- a/lib/editor/components/map/EditorMap.js +++ b/lib/editor/components/map/EditorMap.js @@ -81,7 +81,6 @@ type Props = { updateEditSetting: typeof activeActions.updateEditSetting, updateMapSetting: typeof mapActions.updateMapSetting, updatePatternStops: typeof tripPatternActions.updatePatternStops, - updateUserMetadata: typeof userActions.updateUserMetadata, user: ManagerUserState, zoomToTarget: ?number } @@ -184,7 +183,9 @@ export default class EditorMap extends Component { _mapBaseLayerChanged = (e: any) => { const layer = EDITOR_MAP_LAYERS.find(l => l.name === e.name) if (!layer) return console.warn(`Could not locate map layer with name=${e.name}`, EDITOR_MAP_LAYERS) - this.props.updateUserMetadata(this.props.user.profile, {editor: {map_id: layer.id}}) + // FIXME: Once we refactor users to be stored in MongoDB we may want to add + // back a way to store the preferred map layer. + // this.props.updateUserMetadata(this.props.user.profile, {editor: {map_id: layer.id}}) } /** diff --git a/lib/editor/containers/ActiveGtfsEditor.js b/lib/editor/containers/ActiveGtfsEditor.js index eec81e627..cc025783f 100644 --- a/lib/editor/containers/ActiveGtfsEditor.js +++ b/lib/editor/containers/ActiveGtfsEditor.js @@ -45,9 +45,7 @@ import { uploadBrandingAsset } from '../actions/editor' import {createSnapshot, loadFeedVersionForEditing} from '../actions/snapshots' -import {updateUserMetadata} from '../../manager/actions/user' import {findProjectByFeedSource} from '../../manager/util' -import {setTutorialHidden} from '../../manager/actions/ui' import {getActivePatternStops, getControlPoints, getValidationErrors} from '../selectors' import {getTableById, getIdsFromParams} from '../util/gtfs' @@ -165,13 +163,11 @@ const mapDispatchToProps = { setActiveGtfsEntity, setActivePatternSegment, setActiveStop, - setTutorialHidden, undoActiveTripPatternEdits, updateActiveGtfsEntity, updateEditSetting, updateMapSetting, updatePatternStops, - updateUserMetadata, uploadBrandingAsset } diff --git a/lib/manager/actions/ui.js b/lib/manager/actions/ui.js deleted file mode 100644 index 627abde8e..000000000 --- a/lib/manager/actions/ui.js +++ /dev/null @@ -1,33 +0,0 @@ -// @flow - -import {createAction, type ActionType} from 'redux-actions' - -import { updateUserMetadata } from './user' - -import type {dispatchFn, getStateFn} from '../../types/reducers' - -const settingSidebarExpanded = createAction( - 'SETTING_SIDEBAR_EXPANDED', - (payload: boolean) => payload -) -const settingTutorialVisibility = createAction( - 'SETTING_TUTORIAL_VISIBILITY', - (payload: boolean) => payload -) - -export type UiActions = ActionType | - ActionType - -export function setSidebarExpanded (value: boolean) { - return function (dispatch: dispatchFn, getState: getStateFn) { - dispatch(settingSidebarExpanded(value)) - dispatch(updateUserMetadata(getState().user.profile, {sidebarExpanded: value})) - } -} - -export function setTutorialHidden (value: boolean) { - return function (dispatch: dispatchFn, getState: getStateFn) { - dispatch(settingTutorialVisibility(value)) - dispatch(updateUserMetadata(getState().user.profile, {hideTutorial: value})) - } -} diff --git a/lib/manager/actions/user.js b/lib/manager/actions/user.js index 59f8b2c7a..f53efd7f1 100644 --- a/lib/manager/actions/user.js +++ b/lib/manager/actions/user.js @@ -146,41 +146,6 @@ export function resendEmailConfirmation (user: ManagerUserState): Promise response.json()) - .then(user => user) - } -} - export function receiveTokenAndProfile (authResult: ?{profile: UserProfile, token: string}) { // authResult can be null in case of first-time user if (!authResult) { @@ -252,25 +217,26 @@ export function updateUserData (user: any, userData: any) { dispatch(updatingUserData()) // FIXME: Currently there are some implementations of this method that pass // profile as an argument and others that pass user. - const appMetadata = user.profile ? user.profile.app_metadata : user.app_metadata - const dtIndex = appMetadata.datatools.findIndex(findClientId) - - if (dtIndex === -1) { + const profile = user.profile || user + const metadata = profile.app_metadata + const clientIndex = metadata.datatools.findIndex(findClientId) + if (clientIndex === -1) { return dispatch(setErrorMessage({ message: `Could not find user metadata\n${JSON.stringify(user)}` })) } // Update each key in existing datatools object with updated user data. for (const key in userData) { - appMetadata.datatools[dtIndex][key] = userData[key] + objectPath.set(metadata, `datatools.${clientIndex}.${key}`, userData[key]) } const url = `/api/manager/secure/user/${user.user_id}` + const payload = { + user_id: profile.user_id, + app_metadata: metadata.datatools + } let status // Make request to server - return dispatch(secureFetch(url, 'put', { - user_id: user.user_id, - data: appMetadata.datatools - })) + return dispatch(secureFetch(url, 'put', payload)) .then(response => { status = response.status return response.json() diff --git a/lib/types/actions.js b/lib/types/actions.js index 8c515b25e..de1a837cc 100644 --- a/lib/types/actions.js +++ b/lib/types/actions.js @@ -23,7 +23,6 @@ import type {LanguageActions} from '../manager/actions/languages' import type {NoteActions} from '../manager/actions/notes' import type {ProjectActions} from '../manager/actions/projects' import type {StatusActions} from '../manager/actions/status' -import type {UiActions} from '../manager/actions/ui' import type {UserActions} from '../manager/actions/user' import type {VersionActions} from '../manager/actions/versions' import type {VisibilityFilterActions} from '../manager/actions/visibilityFilter' @@ -60,7 +59,6 @@ export type Action2 = ActiveAlertActions | RouteActions | SnapshotActions | StatusActions | - UiActions | UserActions | VersionActions | VisibilityFilterActions From b9e1fbd881828c72bd050b763c8753855165c86a Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Thu, 21 May 2020 10:33:24 -0400 Subject: [PATCH 4/6] test(snapshot): update snaps --- .../__snapshots__/ActiveProjectViewer.js.snap | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/lib/manager/containers/__tests__/__snapshots__/ActiveProjectViewer.js.snap b/lib/manager/containers/__tests__/__snapshots__/ActiveProjectViewer.js.snap index d7ac68c5b..d494bc823 100644 --- a/lib/manager/containers/__tests__/__snapshots__/ActiveProjectViewer.js.snap +++ b/lib/manager/containers/__tests__/__snapshots__/ActiveProjectViewer.js.snap @@ -412,8 +412,6 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr removeRetiredJob={[Function]} revokeToken={[Function]} setJobMonitorVisible={[Function]} - setSidebarExpanded={[Function]} - setTutorialHidden={[Function]} startJobMonitor={[Function]} user={ Object { @@ -1470,48 +1468,6 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr className="popover-content" >
- -
- -
-
- -
- -
-
From 6bd6628fa8c4a192717b8aa02a63dc7877f4186d Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Fri, 22 May 2020 09:19:04 -0400 Subject: [PATCH 5/6] refactor: fix lint --- lib/editor/components/map/EditorMap.js | 1 - lib/gtfs/components/GtfsMap.js | 8 ++------ lib/types/index.js | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/editor/components/map/EditorMap.js b/lib/editor/components/map/EditorMap.js index 0bdd09b9b..ed129b6cb 100644 --- a/lib/editor/components/map/EditorMap.js +++ b/lib/editor/components/map/EditorMap.js @@ -10,7 +10,6 @@ import * as mapActions from '../../actions/map' import * as stopStrategiesActions from '../../actions/map/stopStrategies' import * as tripPatternActions from '../../actions/tripPattern' import {EDITOR_MAP_LAYERS} from '../../../common/util/maps' -import * as userActions from '../../../manager/actions/user' import AddableStopsLayer from './AddableStopsLayer' import EditorMapLayersControl from './EditorMapLayersControl' import ControlPointsLayer from './ControlPointsLayer' diff --git a/lib/gtfs/components/GtfsMap.js b/lib/gtfs/components/GtfsMap.js index 33996f928..4940dd965 100644 --- a/lib/gtfs/components/GtfsMap.js +++ b/lib/gtfs/components/GtfsMap.js @@ -194,6 +194,7 @@ export default class GtfsMap extends Component { render () { const { disableScroll, + entities, feeds, height, mapState, @@ -231,11 +232,6 @@ export default class GtfsMap extends Component { const displayedPatterns = (patterns && showStops && patternFilter) ? patterns.filter(ptn => ptn.pattern_id === patternFilter) : patterns - - // set as empty string if environment variable doesn't exist to make flow happy - const MAPBOX_MAP_ID = process.env.MAPBOX_MAP_ID || '' - const MAPBOX_ACCESS_TOKEN = process.env.MAPBOX_ACCESS_TOKEN || '' - const MAPBOX_ATTRIBUTION = process.env.MAPBOX_ATTRIBUTION || '' const versionBoundingBox = this._getVersionBounds() const feedsBounds = feeds && getFeedsBounds(feeds) const feedsArrayBounds = feedsBounds && convertToArrayBounds(feedsBounds) @@ -259,7 +255,7 @@ export default class GtfsMap extends Component { {/* Stops from map bounds search */} { - (showStops || (this.props.entities && this.props.entities.indexOf('stops') !== -1)) && + (showStops || (entities && entities.indexOf('stops') !== -1)) && stops && stops.length && diff --git a/lib/types/index.js b/lib/types/index.js index c719abd61..2853ae6a5 100644 --- a/lib/types/index.js +++ b/lib/types/index.js @@ -983,7 +983,6 @@ export type DataToolsConfig = { } } - // Map types (primarily for use in editor and common/util/maps.js) export type MapLayer = { From 049231cd7799667c53d9ef6cd23773c65ec270e4 Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Fri, 22 May 2020 12:52:33 -0400 Subject: [PATCH 6/6] refactor: address Binh PR comments --- lib/common/components/MapModal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/common/components/MapModal.js b/lib/common/components/MapModal.js index c6bcfbf16..656764965 100644 --- a/lib/common/components/MapModal.js +++ b/lib/common/components/MapModal.js @@ -1,8 +1,8 @@ // @flow import React, {Component} from 'react' -import { Modal, Button } from 'react-bootstrap' -import { Map, Marker, TileLayer } from 'react-leaflet' +import {Modal, Button} from 'react-bootstrap' +import {Map, Marker, TileLayer} from 'react-leaflet' import {defaultTileLayerProps} from '../util/maps'