Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

show layer specific notices within a zot tooltip

Jason Kente9dab112c674
diff --git a/web/css/sidebar-panel.css b/web/css/sidebar-panel.css
index 14d1dee42..bf7037452 100644
--- a/web/css/sidebar-panel.css
+++ b/web/css/sidebar-panel.css
@@ -388,27 +388,29 @@ li.item.productsitem.inmotion,
background: #dacf00;
cursor: default;
display: none;
-}
-
-.productsitem div.zot:hover {
- background: #fff200;
-}
-
-.productsitem div.zot b {
- text-align: center;
- height: 20px;
- line-height: 20px;
- position: absolute;
- top: 50%;
- left: 0;
- right: 0;
- margin-top: -10px;
+ &:hover {
+ background: #fff200;
+ }
+ b {
+ text-align: center;
+ height: 20px;
+ line-height: 20px;
+ position: absolute;
+ top: 50%;
+ left: 0;
+ right: 0;
+ margin-top: -10px;
+ }
}
.productsitem.zotted div.zot {
display: block;
}
+.zot-tooltip div {
+ margin: 6px 0;
+}
+
.productsitem a.button.wv-layers-close {
display: block;
float: right;
diff --git a/web/js/containers/info.js b/web/js/containers/info.js
index 177fed571..e95813135 100644
--- a/web/js/containers/info.js
+++ b/web/js/containers/info.js
@@ -1,29 +1,45 @@
-import React, { Component } from 'react';
+import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import googleTagManager from 'googleTagManager';
import {
openCustomContent,
} from '../modules/modal/actions';
-import toggleDistractionFreeMode from '../modules/ui/actions';
+import toggleDistractionFreeModeAction from '../modules/ui/actions';
import AboutPage from '../components/about/about-page';
import IconList from '../components/util/list';
import onClickFeedback from '../modules/feedback/util';
import { addToLocalStorage } from '../modules/notifications/util';
import initFeedback from '../modules/feedback/actions';
-import { startTour, endTour } from '../modules/tour/actions';
+import {
+ startTour as startTourAction,
+ endTour as endTourAction,
+} from '../modules/tour/actions';
import { notificationsSeen } from '../modules/notifications/actions';
import Notifications from './notifications';
-class InfoList extends Component {
- getNotificationListItem(obj) {
- const { notifications, notificationClick } = this.props;
- const { number, type, object } = notifications;
+function InfoList (props) {
+ const {
+ sendFeedback,
+ feedbackIsInitiated,
+ aboutClick,
+ config,
+ startTour,
+ isDistractionFreeModeActive,
+ isTourActive,
+ isMobile,
+ toggleDistractionFreeMode,
+ notifications,
+ notificationClick,
+ } = props;
+ function getNotificationListItem(obj) {
+ const { number, type, object } = notifications;
return {
text: 'Notifications',
iconClass: 'ui-icon',
+ // eslint-disable-next-line no-nested-ternary
iconName: type === 'message'
? 'faGift'
: type === 'outage'
@@ -38,19 +54,7 @@ class InfoList extends Component {
};
}
- getListArray() {
- const {
- sendFeedback,
- feedbackIsInitiated,
- aboutClick,
- notifications,
- config,
- startTour,
- isDistractionFreeModeActive,
- isTourActive,
- isMobile,
- toggleDistractionFreeMode,
- } = this.props;
+ function getListArray() {
const distractionFreeObj = {
text: isDistractionFreeModeActive ? 'Exit Distraction Free' : 'Distraction Free',
iconClass: 'ui-icon',
@@ -125,36 +129,35 @@ class InfoList extends Component {
arr.push(distractionFreeObj);
}
if (notifications.isActive) {
- const obj = this.getNotificationListItem();
- arr.splice(4, 0, obj);
+ arr.splice(4, 0, getNotificationListItem());
}
return arr;
}
return [distractionFreeObj];
}
- render() {
- const infoArray = this.getListArray();
- return <IconList list={infoArray} size="small" />;
- }
+
+ return (<IconList list={getListArray()} size="small" />);
}
function mapStateToProps(state) {
- const { isInitiated } = state.feedback;
+ const {
+ ui, feedback, tour, notifications, config, models, browser,
+ } = state;
return {
- feedbackIsInitiated: isInitiated,
- isDistractionFreeModeActive: state.ui.isDistractionFreeModeActive,
- isTourActive: state.tour.active,
- notifications: state.notifications,
- config: state.config,
- models: state.models,
- isMobile: state.browser.lessThan.medium,
+ feedbackIsInitiated: feedback.isInitiated,
+ isDistractionFreeModeActive: ui.isDistractionFreeModeActive,
+ isTourActive: tour.active,
+ notifications,
+ config,
+ models,
+ isMobile: browser.lessThan.medium,
};
}
const mapDispatchToProps = (dispatch) => ({
toggleDistractionFreeMode: () => {
- dispatch(toggleDistractionFreeMode());
+ dispatch(toggleDistractionFreeModeAction());
},
sendFeedback: (isInitiated) => {
onClickFeedback(isInitiated);
@@ -178,12 +181,12 @@ const mapDispatchToProps = (dispatch) => ({
},
startTour: (isTourActive) => {
if (isTourActive) {
- dispatch(endTour());
+ dispatch(endTourAction());
setTimeout(() => {
- dispatch(startTour());
+ dispatch(startTourAction());
}, 100);
} else {
- dispatch(startTour());
+ dispatch(startTourAction());
}
},
aboutClick: () => {
diff --git a/web/js/containers/notifications.js b/web/js/containers/notifications.js
index bdc210129..6e4fb695f 100644
--- a/web/js/containers/notifications.js
+++ b/web/js/containers/notifications.js
@@ -6,22 +6,30 @@ import { getNumberOfTypeNotSeen } from '../modules/notifications/util';
const Notifications = (props) => {
const { object } = props;
+ const {
+ messages, outages, alerts, layerNotices,
+ } = object;
return (
<div className="wv-notify-modal">
<NotificationBlock
- arr={object.outages}
+ arr={outages}
type="outage"
- numberNotSeen={getNumberOfTypeNotSeen('outage', object.outages)}
+ numberNotSeen={getNumberOfTypeNotSeen('outage', outages)}
/>
<NotificationBlock
- arr={object.alerts}
+ arr={alerts}
type="alert"
- numberNotSeen={getNumberOfTypeNotSeen('alert', object.alerts)}
+ numberNotSeen={getNumberOfTypeNotSeen('alert', alerts)}
/>
<NotificationBlock
- arr={object.messages}
+ arr={messages}
type="message"
- numberNotSeen={getNumberOfTypeNotSeen('message', object.messages)}
+ numberNotSeen={getNumberOfTypeNotSeen('message', messages)}
+ />
+ <NotificationBlock
+ arr={layerNotices}
+ type="message"
+ numberNotSeen={getNumberOfTypeNotSeen('layerNotices', layerNotices)}
/>
</div>
);
diff --git a/web/js/containers/sidebar/layer-list.js b/web/js/containers/sidebar/layer-list.js
index 001907e1c..238b88301 100644
--- a/web/js/containers/sidebar/layer-list.js
+++ b/web/js/containers/sidebar/layer-list.js
@@ -132,7 +132,7 @@ class LayerList extends React.Component {
key={object.id}
index={i}
layerClasses="item productsitem"
- zot={zots[object.id] ? zots[object.id].value : null}
+ zot={zots[object.id]}
names={getNames(object.id)}
checkerBoardPattern={checkerBoardPattern}
isDisabled={!available(object.id)}
@@ -186,7 +186,7 @@ function mapStateToProps(state, ownProps) {
const { id } = proj;
const activeLayers = state.layers[layerGroupName];
const zots = lodashGet(map, 'ui.selected')
- ? getZotsForActiveLayers(config, proj, map, activeLayers)
+ ? getZotsForActiveLayers(state)
: {};
return {
zots,
diff --git a/web/js/containers/sidebar/layer.js b/web/js/containers/sidebar/layer.js
index 48de982e2..e2790f867 100644
--- a/web/js/containers/sidebar/layer.js
+++ b/web/js/containers/sidebar/layer.js
@@ -26,6 +26,7 @@ import {
layerHover,
} from '../../modules/layers/actions';
import OrbitTrack from './orbit-track';
+import Zot from './zot';
import { isVectorLayerClickable } from '../../modules/layers/util';
import { MODAL_PROPERTIES } from '../../modules/alerts/constants';
@@ -212,10 +213,6 @@ class Layer extends React.Component {
? faEyeSlash
: faEye;
- const zotTitle = zot
- ? `Layer is overzoomed by ${zot.toString()}x its maximum zoom level`
- : '';
-
return (
<Draggable
draggableId={`${util.encodeId(layer.id)}-${layerGroupName}`}
@@ -245,12 +242,7 @@ class Layer extends React.Component {
<FontAwesomeIcon icon={visibilityIconClass} className="layer-eye-icon" />
</a>
- <div
- className="zot"
- title={zotTitle}
- >
- <b>!</b>
- </div>
+ <Zot zot={zot} layer={layer.id} />
<div className="layer-main">
<div className="layer-info">
diff --git a/web/js/containers/sidebar/zot.js b/web/js/containers/sidebar/zot.js
new file mode 100644
index 000000000..43ce26203
--- /dev/null
+++ b/web/js/containers/sidebar/zot.js
@@ -0,0 +1,40 @@
+import React, { useState } from 'react';
+import PropTypes from 'prop-types';
+import { Tooltip } from 'reactstrap';
+
+export default function Zot (props) {
+ const { zot, layer } = props;
+ const [tooltipVisible, toggleTooltip] = useState(false);
+
+ let zotString = '';
+ if (zot && zot.overZoomValue) {
+ zotString += `Layer is overzoomed by ${zot.overZoomValue.toString()}x its maximum zoom level <br/>`;
+ }
+ if (zot && zot.layerNotices) {
+ zotString += zot.layerNotices;
+ }
+
+ return (
+ <div
+ id={`${layer}-zot`}
+ className="zot"
+ >
+ <Tooltip
+ className="zot-tooltip"
+ isOpen={tooltipVisible}
+ target={`${layer}-zot`}
+ placement="right"
+ toggle={() => toggleTooltip(!tooltipVisible)}
+ delay={{ show: 0, hide: 300 }}
+ >
+ <div dangerouslySetInnerHTML={{ __html: zotString }} />
+ </Tooltip>
+ <b>!</b>
+ </div>
+ );
+}
+
+Zot.propTypes = {
+ layer: PropTypes.string,
+ zot: PropTypes.object,
+};
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.js
index f6876a88a..f3bee605e 100644
--- a/web/js/modules/layers/selectors.js
+++ b/web/js/modules/layers/selectors.js
@@ -11,6 +11,7 @@ import {
import { createSelector } from 'reselect';
import update from 'immutability-helper';
import util from '../../util/util';
+import { getLayerNoticesForLayer } from '../notifications/util';
// State selectors
const getLayersState = ({ layers }) => layers;
@@ -475,16 +476,23 @@ export function replaceSubGroup(
return pushToBottom(layerId, layers, layerSplit);
}
-export function getZotsForActiveLayers(config, projection, map, activeLayers) {
+export function getZotsForActiveLayers(state) {
+ const {
+ config, proj, map, notifications,
+ } = state;
const zotObj = {};
const { sources } = config;
- const proj = projection.selected.id;
+ const projection = proj.selected.id;
const zoom = map.ui.selected.getView().getZoom();
- lodashEach(activeLayers, (layer) => {
- if (layer.projections[proj]) {
- const overZoomValue = getZoomLevel(layer, zoom, proj, sources);
- if (overZoomValue) {
- zotObj[layer.id] = { value: overZoomValue };
+ lodashEach(getActiveLayers(state), (layer) => {
+ if (layer.projections[projection]) {
+ const overZoomValue = getZoomLevel(layer, zoom, projection, sources);
+ const layerNotices = getLayerNoticesForLayer(layer.id, notifications);
+ if (overZoomValue || layerNotices.length) {
+ zotObj[layer.id] = {
+ overZoomValue,
+ layerNotices,
+ };
}
}
});
diff --git a/web/js/modules/notifications/actions.js b/web/js/modules/notifications/actions.js
index 34488c293..bee8723ec 100644
--- a/web/js/modules/notifications/actions.js
+++ b/web/js/modules/notifications/actions.js
@@ -1,18 +1,22 @@
import { requestAction } from '../core/actions';
-
import {
REQUEST_NOTIFICATIONS,
SET_NOTIFICATIONS,
NOTIFICATIONS_SEEN,
} from './constants';
+import { getActiveLayers } from '../layers/selectors';
export function requestNotifications(location, type) {
return (dispatch) => requestAction(dispatch, REQUEST_NOTIFICATIONS, location);
}
export function setNotifications(array) {
- return {
- type: SET_NOTIFICATIONS,
- array,
+ return (dispatch, getState) => {
+ const activeLayers = getActiveLayers(getState());
+ dispatch({
+ type: SET_NOTIFICATIONS,
+ array,
+ activeLayers,
+ });
};
}
export function notificationsSeen() {
diff --git a/web/js/modules/notifications/reducers.js b/web/js/modules/notifications/reducers.js
index 78be1036c..71756f4e6 100644
--- a/web/js/modules/notifications/reducers.js
+++ b/web/js/modules/notifications/reducers.js
@@ -1,6 +1,9 @@
-import { assign } from 'lodash';
import { requestReducer } from '../core/reducers';
-import { getCount, separateByType, getPriority } from './util';
+import {
+ getCount,
+ separateByType,
+ getPriority,
+} from './util';
import {
REQUEST_NOTIFICATIONS,
SET_NOTIFICATIONS,
@@ -22,20 +25,25 @@ export function notificationsReducer(state = notificationReducerState, action) {
switch (action.type) {
case SET_NOTIFICATIONS:
if (action.array.length > 0) {
- const sortedNotificationObject = separateByType(action.array);
- return assign({}, state, {
- number: getCount(sortedNotificationObject),
- type: getPriority(sortedNotificationObject),
+ const notificationsByType = separateByType(action.array);
+
+ return {
+ ...state,
+ number: getCount(notificationsByType, action.activeLayers),
+ type: getPriority(notificationsByType),
isActive: true,
- object: sortedNotificationObject,
- });
- } return state;
+ object: notificationsByType,
+ };
+ }
+ return state;
+
case NOTIFICATIONS_SEEN:
- return assign({}, state, {
+ return {
+ ...state,
number: null,
type: '',
isActive: true,
- });
+ };
default:
return state;
}
diff --git a/web/js/modules/notifications/selectors.js b/web/js/modules/notifications/selectors.js
new file mode 100644
index 000000000..e69de29bb
diff --git a/web/js/modules/notifications/util.js b/web/js/modules/notifications/util.js
index 0e0c4721c..9806f1aa9 100644
--- a/web/js/modules/notifications/util.js
+++ b/web/js/modules/notifications/util.js
@@ -6,6 +6,10 @@ const {
NOTIFICATION_MSG,
} = safeLocalStorage.keys;
+// Notifications containing this string in their path property will be treated
+// as layer notices which only show if the specified layers are in the active list
+const LAYER_NOTICE = 'layer-notice';
+
/**
* Categorizes the returned array
* @function separateByType
@@ -18,15 +22,18 @@ export function separateByType(notifications) {
const alerts = [];
const outages = [];
const layerNotices = [];
+ const orderByDate = (obj) => {
+ obj.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
+ return obj;
+ };
notifications.forEach((notification) => {
const { notification_type: type, path } = notification;
- if (path.contains('layer-notice')) {
+ if (path.contains(LAYER_NOTICE)) {
layerNotices.push(notification);
return;
}
-
if (type === NOTIFICATION_MSG) {
messages.push(notification);
} else if (type === NOTIFICATION_ALERT) {
@@ -40,32 +47,9 @@ export function separateByType(notifications) {
messages: orderByDate(messages),
alerts: orderByDate(alerts),
outages: orderByDate(outages),
- layerNotices: orderByDate(layerNotices),
+ layerNotices: transformLayerNotices(orderByDate(layerNotices)),
};
}
-/**
- * Organizes array by date created
- * @function orderByDate
- * @private
- * @param {object} obj - array
- * @returns {void}
- */
-function orderByDate(obj) {
- obj.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
- return obj;
-}
-/**
- * Checks to see if id or smaller #id is in localstorage
- * @function localStorageValueMatches
- * @private
- * @param {String} property - name of category type
- * @param {string} value - id of notification
- * @returns {Boolean}
- */
-function localStorageValueMatches(property, value) {
- const oldValue = safeLocalStorage.getItem(property);
- return oldValue && new Date(value) <= new Date(oldValue);
-}
/**
* Sets active state global values
@@ -93,20 +77,39 @@ export function getPriority(sortedNotifications) {
priority = NOTIFICATION_OUTAGE;
}
+ // TODO need to determine how and when layer notices affect priority
+
return priority;
}
+
/**
* Gets a total count of the unseen notifications
* @function getCounts
* @private
* @returns {Number}
*/
-export function getCount({ messages, outages, alerts }) {
+export function getCount(notifications, activeLayers) {
+ const {
+ messages, outages, alerts, layerNotices,
+ } = notifications;
+ const activeLayerIds = Object.keys(activeLayers);
const messageCount = getNumberOfTypeNotSeen(NOTIFICATION_MSG, messages);
const alertCount = getNumberOfTypeNotSeen(NOTIFICATION_ALERT, alerts);
const outageCount = getNumberOfTypeNotSeen(NOTIFICATION_OUTAGE, outages);
- return messageCount + outageCount + alertCount;
+
+
+ // If any of the layers marked in layerNotices array are currently active,
+ // include in the count.
+ let layerNoticeCount = 0;
+ layerNotices.forEach((notice) => {
+ if (activeLayerIds.some((id) => notice.layers.includes(id))) {
+ layerNoticeCount += 1;
+ }
+ });
+
+ return messageCount + outageCount + alertCount + layerNoticeCount;
}
+
export function addToLocalStorage({ messages, outages, alerts }) {
const [message] = messages;
const [outage] = outages;
@@ -122,6 +125,7 @@ export function addToLocalStorage({ messages, outages, alerts }) {
safeLocalStorage.setItem(NOTIFICATION_MSG, message.created_at);
}
}
+
/**
* Determines the number of status of this type that the user is yet to see
* @function getNumberOfTypeNotSeen
@@ -149,6 +153,7 @@ export function getNumberOfTypeNotSeen(type, arra) {
return count;
}
+
/**
* Determines if most recent notification has already been seen
* @function objectAlreadySeen
@@ -161,10 +166,30 @@ function objectAlreadySeen(obj) {
const idString = obj.created_at.toString();
let fieldValueMatches = false;
const fieldExists = !!safeLocalStorage.getItem(type);
+ const localStorageValueMatches = (property, value) => {
+ const oldValue = safeLocalStorage.getItem(property);
+ return oldValue && new Date(value) <= new Date(oldValue);
+ };
if (fieldExists) {
fieldValueMatches = localStorageValueMatches(type, idString);
}
-
return fieldValueMatches;
}
+
+export function transformLayerNotices(notifications) {
+ return notifications.map((notice) => {
+ const splitPath = notice.path.split('/');
+ const layers = splitPath.slice(2, splitPath.length);
+ return {
+ ...notice,
+ layers,
+ };
+ });
+}
+
+export function getLayerNoticesForLayer(layer, notifications) {
+ const { layerNotices } = notifications.object;
+ const notices = (layerNotices || []).filter((notice) => notice.layers.includes(layer));
+ return notices.reduce((noticeStr, notice) => `${noticeStr} <div>${notice.message}</div>`, '');
+}