Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Feat] Disable a layer after an error in Deck (#2072)

Igor Dykhta14ef4366ca88
diff --git a/src/actions/src/action-types.ts b/src/actions/src/action-types.ts
index 42860b8eb..58a813827 100644
--- a/src/actions/src/action-types.ts
+++ b/src/actions/src/action-types.ts
@@ -63,6 +63,7 @@ const ActionTypes = {
DUPLICATE_LAYER: `${ACTION_PREFIX}DUPLICATE_LAYER`,
INTERACTION_CONFIG_CHANGE: `${ACTION_PREFIX}INTERACTION_CONFIG_CHANGE`,
LAYER_CONFIG_CHANGE: `${ACTION_PREFIX}LAYER_CONFIG_CHANGE`,
+ LAYER_SET_IS_VALID: `${ACTION_PREFIX}LAYER_SET_IS_VALID`,
LAYER_VISUAL_CHANNEL_CHANGE: `${ACTION_PREFIX}LAYER_VISUAL_CHANNEL_CHANGE`,
LAYER_TYPE_CHANGE: `${ACTION_PREFIX}LAYER_TYPE_CHANGE`,
LAYER_VIS_CONFIG_CHANGE: `${ACTION_PREFIX}LAYER_VIS_CONFIG_CHANGE`,
diff --git a/src/actions/src/vis-state-actions.ts b/src/actions/src/vis-state-actions.ts
index 175a3f119..a8f182bcc 100644
--- a/src/actions/src/vis-state-actions.ts
+++ b/src/actions/src/vis-state-actions.ts
@@ -89,6 +89,31 @@ export function layerTextLabelChange(
value
};
}
+
+export type LayerSetIsValidUpdaterAction = {
+ oldLayer: Layer;
+ isValid: boolean;
+};
+
+/**
+ * Changes value of isValid flag for a layer.
+ * The action also updates visibility of the layer based on isValid.
+ * @param oldLayer - layer to be updated
+ * @param isValid - new value for isValid flag
+ * @returns action
+ * @public
+ */
+export function layerSetIsValid(
+ oldLayer: Layer,
+ isValid: boolean
+): Merge<LayerSetIsValidUpdaterAction, {type: typeof ActionTypes.LAYER_SET_IS_VALID}> {
+ return {
+ type: ActionTypes.LAYER_SET_IS_VALID,
+ oldLayer,
+ isValid
+ };
+}
+
export type LayerTypeChangeUpdaterAction = {
oldLayer: Layer;
newType: string;
diff --git a/src/components/src/common/styled-components.tsx b/src/components/src/common/styled-components.tsx
index b593f17e1..0d4853872 100644
--- a/src/components/src/common/styled-components.tsx
+++ b/src/components/src/common/styled-components.tsx
@@ -330,6 +330,7 @@ export interface StyledPanelHeaderProps {
active?: boolean;
labelRCGColorValues?: RGBColor | null;
warning?: boolean;
+ isValid?: boolean;
}
export const StyledPanelHeader = styled.div<StyledPanelHeaderProps>`
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 6344caf41..27c5fe2e9 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -389,21 +389,36 @@ export default function MapContainerFactory(
};
_onDeckError = (error, layer) => {
- const errorMessage = `An error in deck.gl: ${error.message} in ${layer.id}`;
- const notificationId = `${layer.id}-${error.message}`;
+ const errorMessage = error?.message || 'unknown-error';
+ const layerMessage = layer?.id ? ` in ${layer.id} layer` : '';
+ const errorMessageFull = `An error in deck.gl: ${errorMessage}${layerMessage}.`;
// Throttle error notifications, as React doesn't like too many state changes from here.
- const lastShown = this._deckGLErrorsElapsed[notificationId];
+ const lastShown = this._deckGLErrorsElapsed[errorMessageFull];
if (!lastShown || lastShown < Date.now() - THROTTLE_NOTIFICATION_TIME) {
- this._deckGLErrorsElapsed[notificationId] = Date.now();
+ this._deckGLErrorsElapsed[errorMessageFull] = Date.now();
+
+ // Mark layer as invalid
+ let extraLayerMessage = '';
+ const {visStateActions} = this.props;
+ if (layer) {
+ let topMostLayer = layer;
+ while (topMostLayer.parent) {
+ topMostLayer = topMostLayer.parent;
+ }
+ if (topMostLayer.props?.id) {
+ visStateActions.layerSetIsValid(topMostLayer, false);
+ extraLayerMessage = 'The layer has been disabled and highlighted.';
+ }
+ }
// Create new error notification or update existing one with same id.
// Update is required to preserve the order of notifications as they probably are going to "jump" based on order of errors.
const {uiStateActions} = this.props;
uiStateActions.addNotification(
errorNotification({
- message: errorMessage,
- id: notificationId
+ message: `${errorMessageFull} ${extraLayerMessage}`,
+ id: errorMessageFull // treat the error message as id
})
);
}
diff --git a/src/components/src/notification-panel/notification-item.tsx b/src/components/src/notification-panel/notification-item.tsx
index 2d28a8590..9f4931840 100644
--- a/src/components/src/notification-panel/notification-item.tsx
+++ b/src/components/src/notification-panel/notification-item.tsx
@@ -24,6 +24,19 @@ import {Delete, Info, Warning, Checkmark} from '../common/icons';
import ReactMarkdown from 'react-markdown';
import {ActionHandler, removeNotification as removeNotificationActions} from '@kepler.gl/actions';
+interface NotificationItemContentBlockProps {
+ isExpanded?: boolean;
+}
+
+const NotificationItemContentBlock = styled.div.attrs({
+ className: 'notification-item--content-block'
+})<NotificationItemContentBlockProps>`
+ display: block;
+ position: relative;
+ width: ${props => props.theme.notificationPanelItemWidth * (1 + Number(props.isExpanded))}px;
+ margin-left: auto;
+`;
+
interface NotificationItemContentProps {
type: string;
isExpanded?: boolean;
@@ -46,6 +59,30 @@ const NotificationItemContent = styled.div<NotificationItemContentProps>`
const DeleteIcon = styled(Delete)`
cursor: pointer;
+ width: 13px;
+ height: 13px;
+`;
+
+interface NotificationCounterProps {
+ type: string;
+}
+
+const NotificationCounter = styled.div.attrs({
+ className: 'notification-item--counter'
+})<NotificationCounterProps>`
+ position: absolute;
+ font-size: 11px;
+ font-weight: bold;
+ text-align: center;
+ left: -4px;
+ bottom: -4px;
+ border-radius: 50%;
+ width: 20px;
+ height: 20px;
+ background-color: #ffffff;
+ border: 1px solid ${props => props.theme.notificationColors[props.type] || '#000'};
+ color: ${props => props.theme.notificationColors[props.type] || '#000'};
+ box-shadow: ${props => props.theme.boxShadow};
`;
interface NotificationMessageProps {
@@ -96,6 +133,7 @@ interface NotificationItemProps {
id: string;
type: string;
message: string;
+ count?: number;
};
isExpanded?: boolean;
removeNotification?: ActionHandler<typeof removeNotificationActions>;
@@ -119,24 +157,31 @@ export default function NotificationItemFactory() {
const {isExpanded} = this.state;
return (
- <NotificationItemContent
- className="notification-item"
- type={notification.type}
- isExpanded={isExpanded}
- onClick={() => this.setState({isExpanded: !isExpanded})}
- >
- <NotificationIcon className="notification-item--icon">
- {icons[notification.type]}
- </NotificationIcon>
- <NotificationMessage isExpanded={isExpanded} theme={this.props.theme}>
- <ReactMarkdown source={notification.message} renderers={{link: LinkRenderer}} />
- </NotificationMessage>
- {typeof removeNotification === 'function' ? (
- <div className="notification-item--action">
- <DeleteIcon height="10px" onClick={() => removeNotification(notification.id)} />
- </div>
+ <NotificationItemContentBlock isExpanded={isExpanded} theme={this.props.theme}>
+ {(notification.count || 0) > 1 ? (
+ <NotificationCounter type={notification.type} theme={this.props.theme}>
+ {notification.count}
+ </NotificationCounter>
) : null}
- </NotificationItemContent>
+ <NotificationItemContent
+ className="notification-item"
+ type={notification.type}
+ isExpanded={isExpanded}
+ onClick={() => this.setState({isExpanded: !isExpanded})}
+ >
+ <NotificationIcon className="notification-item--icon">
+ {icons[notification.type]}
+ </NotificationIcon>
+ <NotificationMessage isExpanded={isExpanded} theme={this.props.theme}>
+ <ReactMarkdown source={notification.message} renderers={{link: LinkRenderer}} />
+ </NotificationMessage>
+ {typeof removeNotification === 'function' ? (
+ <div className="notification-item--action">
+ <DeleteIcon height="10px" onClick={() => removeNotification(notification.id)} />
+ </div>
+ ) : null}
+ </NotificationItemContent>
+ </NotificationItemContentBlock>
);
}
};
diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
index cf5e5a00d..a2e2edd26 100644
--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
@@ -37,6 +37,7 @@ import VisConfigSliderFactory from './vis-config-slider';
import LayerConfigGroupFactory, {ConfigGroupCollapsibleContent} from './layer-config-group';
import TextLabelPanelFactory from './text-label-panel';
import HowToButton from './how-to-button';
+import LayerErrorMessage from './layer-error-message';
import {capitalizeFirstLetter} from '@kepler.gl/utils';
@@ -1045,6 +1046,7 @@ export default function LayerConfiguratorFactory(
updateLayerConfig={updateLayerConfig}
/>
</ConfigGroupCollapsibleContent>
+ {layer.errorMessage ? <LayerErrorMessage errorMessage={layer.errorMessage} /> : null}
</LayerConfigGroup>
{renderTemplate &&
this[renderTemplate] &&
diff --git a/src/components/src/side-panel/layer-panel/layer-error-message.tsx b/src/components/src/side-panel/layer-panel/layer-error-message.tsx
new file mode 100644
index 000000000..52d18f69f
--- /dev/null
+++ b/src/components/src/side-panel/layer-panel/layer-error-message.tsx
@@ -0,0 +1,50 @@
+// Copyright (c) 2023 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+import styled from 'styled-components';
+
+import {FormattedMessage} from '@kepler.gl/localization';
+
+const LayerErrorMessageContent = styled.div.attrs({
+ className: 'layer-error-message-content'
+})`
+ background-color: ${props => props.theme.notificationColors.error || '#000'};
+ color: #fff;
+ display: block;
+ width: 100%;
+ font-size: 11px;
+ padding: 1em;
+ border-radius: 4px;
+`;
+
+type LayerErrorMessageProps = {
+ errorMessage: string;
+};
+
+const LayerErrorMessage: React.FC<LayerErrorMessageProps> = ({errorMessage}) => {
+ return (
+ <LayerErrorMessageContent>
+ <FormattedMessage id={'layer.layerUpdateError'} values={{errorMessage}} />
+ </LayerErrorMessageContent>
+ );
+};
+
+export default LayerErrorMessage;
diff --git a/src/components/src/side-panel/layer-panel/layer-list.tsx b/src/components/src/side-panel/layer-panel/layer-list.tsx
index c11255ef2..62f95e936 100644
--- a/src/components/src/side-panel/layer-panel/layer-list.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-list.tsx
@@ -114,7 +114,8 @@ function LayerListFactory(LayerPanel: ReturnType<typeof LayerPanelFactory>) {
layerVisConfigChange: visStateActions.layerVisConfigChange,
layerTextLabelChange: visStateActions.layerTextLabelChange,
removeLayer: visStateActions.removeLayer,
- duplicateLayer: visStateActions.duplicateLayer
+ duplicateLayer: visStateActions.duplicateLayer,
+ layerSetIsValid: visStateActions.layerSetIsValid
};
const panelProps = {
diff --git a/src/components/src/side-panel/layer-panel/layer-panel-header.tsx b/src/components/src/side-panel/layer-panel/layer-panel-header.tsx
index 01ec7206d..264b329bd 100644
--- a/src/components/src/side-panel/layer-panel/layer-panel-header.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-panel-header.tsx
@@ -37,7 +37,8 @@ import {
EyeUnseen,
Trash,
VertDots,
- WarningSign
+ WarningSign,
+ Reset
} from '../../common/icons';
import {InlineInput, StyledPanelHeader} from '../../common/styled-components';
@@ -65,11 +66,13 @@ type LayerTitleSectionProps = {
type LayerPanelHeaderProps = {
layerId: string;
isVisible: boolean;
+ isValid: boolean;
onToggleVisibility: MouseEventHandler;
onUpdateLayerLabel: ChangeEventHandler;
onToggleEnableConfig: MouseEventHandler;
onRemoveLayer: MouseEventHandler;
onDuplicateLayer: MouseEventHandler;
+ onResetIsValid: MouseEventHandler;
isConfigActive: boolean;
showRemoveLayer?: boolean;
label?: string;
@@ -114,7 +117,7 @@ const StyledLayerPanelHeader = styled(StyledPanelHeader)`
padding: 10px;
}
- ${props => (props.warning ? getBorderCss('warning') : '')}
+ ${props => (props.warning ? getBorderCss('warning') : props.isValid ? '' : getBorderCss('error'))}
:hover {
cursor: pointer;
@@ -282,7 +285,8 @@ const defaultActionIcons = {
visible: EyeSeen,
hidden: EyeUnseen,
enableConfig: ArrowDown,
- duplicate: Copy
+ duplicate: Copy,
+ resetIsValid: Reset
};
function LayerPanelHeaderFactory(
@@ -294,6 +298,7 @@ function LayerPanelHeaderFactory(
allowDuplicate,
isDragNDropEnabled,
isVisible,
+ isValid,
warning,
label,
layerId,
@@ -304,6 +309,7 @@ function LayerPanelHeaderFactory(
onToggleEnableConfig,
onDuplicateLayer,
onRemoveLayer,
+ onResetIsValid,
showRemoveLayer,
actionIcons = defaultActionIcons
}) => {
@@ -314,6 +320,7 @@ function LayerPanelHeaderFactory(
className={classnames('layer-panel__header', {
'sort--handle': !isConfigActive
})}
+ isValid={isValid}
warning={warning}
active={isConfigActive}
labelRCGColorValues={labelRCGColorValues}
@@ -365,13 +372,23 @@ function LayerPanelHeaderFactory(
disabled={!allowDuplicate}
/>
</StyledPanelHeaderHiddenActions>
- <PanelHeaderAction
- className="layer__visibility-toggle"
- id={layerId}
- tooltip={isVisible ? 'tooltip.hideLayer' : 'tooltip.showLayer'}
- onClick={onToggleVisibility}
- IconComponent={isVisible ? actionIcons.visible : actionIcons.hidden}
- />
+ {isValid ? (
+ <PanelHeaderAction
+ className="layer__visibility-toggle"
+ id={layerId}
+ tooltip={isVisible ? 'tooltip.hideLayer' : 'tooltip.showLayer'}
+ onClick={onToggleVisibility}
+ IconComponent={isVisible ? actionIcons.visible : actionIcons.hidden}
+ />
+ ) : (
+ <PanelHeaderAction
+ className="layer__is-valid-refresh"
+ id={layerId}
+ tooltip={'tooltip.resetAfterError'}
+ onClick={onResetIsValid}
+ IconComponent={actionIcons.resetIsValid}
+ />
+ )}
<PanelHeaderAction
className={classnames('layer__enable-config ', {
'is-open': isConfigActive
diff --git a/src/components/src/side-panel/layer-panel/layer-panel.tsx b/src/components/src/side-panel/layer-panel/layer-panel.tsx
index 4f355f4c6..b5c334261 100644
--- a/src/components/src/side-panel/layer-panel/layer-panel.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-panel.tsx
@@ -55,6 +55,7 @@ type LayerPanelProps = {
layerVisualChannelConfigChange: ActionHandler<
typeof VisStateActions.layerVisualChannelConfigChange
>;
+ layerSetIsValid: ActionHandler<typeof VisStateActions.layerSetIsValid>;
layerTypeChange: ActionHandler<typeof VisStateActions.layerTypeChange>;
layerVisConfigChange: ActionHandler<typeof VisStateActions.layerVisConfigChange>;
layerTextLabelChange: ActionHandler<typeof VisStateActions.layerTextLabelChange>;
@@ -67,7 +68,6 @@ const PanelWrapper = styled.div<{active: boolean}>`
border-radius: 1px;
margin-bottom: 8px;
z-index: 1000;
-
&.dragging {
cursor: move;
}
@@ -114,6 +114,12 @@ function LayerPanelFactory(
this.updateLayerConfig({isVisible});
};
+ _resetIsValid: MouseEventHandler = e => {
+ e.stopPropagation();
+ // Make the layer valid and visible again after an error
+ this.props.layerSetIsValid(this.props.layer, true);
+ };
+
_toggleEnableConfig: MouseEventHandler = e => {
e.stopPropagation();
const {
@@ -136,7 +142,7 @@ function LayerPanelFactory(
render() {
const {layer, datasets, isDraggable, layerTypeOptions} = this.props;
- const {config} = layer;
+ const {config, isValid} = layer;
const {isConfigActive} = config;
const allowDuplicate = typeof layer.isValidToSave === 'function' && layer.isValidToSave();
@@ -152,12 +158,14 @@ function LayerPanelFactory(
isConfigActive={isConfigActive}
layerId={layer.id}
isVisible={config.isVisible}
+ isValid={isValid}
label={config.label}
labelRCGColorValues={config.dataId ? datasets[config.dataId].color : null}
layerType={layer.type}
allowDuplicate={allowDuplicate}
onToggleEnableConfig={this._toggleEnableConfig}
onToggleVisibility={this._toggleVisibility}
+ onResetIsValid={this._resetIsValid}
onUpdateLayerLabel={this._updateLayerLabel}
onRemoveLayer={this._removeLayer}
onDuplicateLayer={this._duplicateLayer}
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index 558b880f6..2cc1ca6b1 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -876,7 +876,7 @@ export const DEFAULT_NOTIFICATION_TOPICS = keyMirror({
});
// Minimum time between identical notifications about deck.gl errors
-export const THROTTLE_NOTIFICATION_TIME = 2500;
+export const THROTTLE_NOTIFICATION_TIME = 330;
// Animation
export const BASE_SPEED = 600;
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index 0a7a0c0d8..f12807f3a 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -230,6 +230,9 @@ class Layer {
// TODO: define _oldDataUpdateTriggers
_oldDataUpdateTriggers: any;
+ isValid: boolean;
+ errorMessage: string | null;
+
constructor(
props: {
id?: string;
@@ -247,6 +250,10 @@ class Layer {
columns: this.getLayerColumns(),
...props
});
+
+ // false indicates that the layer caused an error, and was disabled
+ this.isValid = true;
+ this.errorMessage = null;
}
get layerIcon(): React.ElementType {
diff --git a/src/localization/src/translations/ca.ts b/src/localization/src/translations/ca.ts
index 2de2974db..2fa077d1c 100644
--- a/src/localization/src/translations/ca.ts
+++ b/src/localization/src/translations/ca.ts
@@ -119,7 +119,9 @@ export default {
trip: 'viatge',
s2: 'S2',
'3d': '3D'
- }
+ },
+ layerUpdateError:
+ "S'ha produït un error durant l'actualització de la capa: {errorMessage}. Assegureu-vos que el format de les dades d’entrada sigui vàlid."
},
layerVisConfigs: {
angle: 'Angle',
@@ -195,6 +197,7 @@ export default {
hide: 'amaga',
show: 'mostra',
removeLayer: 'Elimina capa',
+ resetAfterError: 'Intenteu habilitar la capa després dun error',
layerSettings: 'Configuració de capa',
closePanel: 'Tanca panel actual',
switchToDualView: 'Canvia a la vista de mapa dual',
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index 59320207c..65d3c6562 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -120,7 +120,9 @@ export default {
trip: 'trip',
s2: 'S2',
'3d': '3D'
- }
+ },
+ layerUpdateError:
+ 'An error occurred during layer update: {errorMessage}. Make sure the format of the input data is valid.'
},
layerVisConfigs: {
angle: 'Angle',
@@ -196,6 +198,7 @@ export default {
show: 'show',
removeLayer: 'Remove layer',
duplicateLayer: 'Duplicate layer',
+ resetAfterError: 'Try to enable the layer after an error',
layerSettings: 'Layer settings',
closePanel: 'Close current panel',
switchToDualView: 'Switch to dual map view',
diff --git a/src/localization/src/translations/es.ts b/src/localization/src/translations/es.ts
index 7c6236d14..001cae921 100644
--- a/src/localization/src/translations/es.ts
+++ b/src/localization/src/translations/es.ts
@@ -119,7 +119,9 @@ export default {
trip: 'viaje',
s2: 'S2',
'3d': '3D'
- }
+ },
+ layerUpdateError:
+ 'Se produjo un error durante la actualización de la capa: {errorMessage}. Asegúrese de que el formato de los datos de entrada sea válido.'
},
layerVisConfigs: {
angle: 'Ángulo',
@@ -196,6 +198,7 @@ export default {
hide: 'Ocultar',
show: 'Mostrar',
removeLayer: 'Eliminar capa',
+ resetAfterError: 'Intente habilitar la capa después de un error',
layerSettings: 'Configuración de capa',
closePanel: 'Cerrar el panel actual',
switchToDualView: 'Cambiar a la vista de mapa dual',
diff --git a/src/localization/src/translations/fi.ts b/src/localization/src/translations/fi.ts
index 2e0fa6d8f..6548333a9 100644
--- a/src/localization/src/translations/fi.ts
+++ b/src/localization/src/translations/fi.ts
@@ -118,7 +118,9 @@ export default {
trip: 'matka',
s2: 'S2',
'3d': '3D'
- }
+ },
+ layerUpdateError:
+ 'Tason päivityksen aikana tapahtui virhe: {errorMessage}. Varmista, että syötetietojen muoto on kelvollinen.'
},
layerVisConfigs: {
strokeWidth: 'Viivan paksuus',
@@ -193,6 +195,7 @@ export default {
hide: 'piilota',
show: 'näytä',
removeLayer: 'Poista taso',
+ resetAfterError: 'Yritä ottaa taso käyttöön virheen jälkeen',
layerSettings: 'Tason asetukset',
closePanel: 'Sulje paneeli',
switchToDualView: 'Vaihda kaksoiskarrtanäkymään',
diff --git a/src/localization/src/translations/pt.ts b/src/localization/src/translations/pt.ts
index 25ca07b56..be345964e 100644
--- a/src/localization/src/translations/pt.ts
+++ b/src/localization/src/translations/pt.ts
@@ -118,7 +118,9 @@ export default {
trip: 'viagem',
s2: 'S2',
'3d': '3D'
- }
+ },
+ layerUpdateError:
+ 'Ocorreu um erro ao atualizar a camada: {errorMessage}. Certifique-se de que o formato dos dados de entrada seja válido.'
},
layerVisConfigs: {
strokeWidth: 'Largura do Traço',
@@ -194,6 +196,7 @@ export default {
hide: 'esconder',
show: 'mostrar',
removeLayer: 'Remover Camada',
+ resetAfterError: 'Tente habilitar a camada após um erro',
layerSettings: 'Configurações de Camada',
closePanel: 'Fechar painel atual',
switchToDualView: 'Trocar para visualização dupla de mapa',
diff --git a/src/reducers/src/layer-utils.ts b/src/reducers/src/layer-utils.ts
index cb2a0de32..3184e27e8 100644
--- a/src/reducers/src/layer-utils.ts
+++ b/src/reducers/src/layer-utils.ts
@@ -97,8 +97,10 @@ export function findDefaultLayer(dataset: KeplerTable, layerClasses: LayerClasse
}
/**
- * calculate layer data based on layer type, col Config,
- * return updated layer if colorDomain, dataMap has changed
+ * Calculate layer data based on layer type, col Config,
+ * return updated layer if colorDomain, dataMap has changed.
+ * Also, returns updated layer in case the input layer was in invalid state.
+ * Adds an error message to the layer in case of an exception.
*/
export function calculateLayerData(
layer: Layer,
@@ -108,14 +110,43 @@ export function calculateLayerData(
layerData: any;
layer: Layer;
} {
- const {type} = layer;
+ let layerData;
+ try {
+ // Make sure the layer updates data after an error
+ if (!layer.isValid) {
+ layer._oldDataUpdateTriggers = undefined;
+ }
+
+ if (!layer.type || !layer.hasAllColumns() || !layer.config.dataId) {
+ return {layer, layerData: {}};
+ }
+
+ layerData = layer.formatLayerData(state.datasets, oldLayerData);
- if (!type || !layer.hasAllColumns() || !layer.config.dataId) {
- return {layer, layerData: {}};
+ // At this point the data for the layer is updated without errors
+ if (!layer.isValid) {
+ // Switch to visible after an error
+ layer = layer.updateLayerConfig({
+ isVisible: true
+ });
+ }
+ layer.isValid = true;
+ layer.errorMessage = null;
+ } catch (err) {
+ layer = layer.updateLayerConfig({
+ isVisible: false
+ });
+ layer.isValid = false;
+
+ layer.errorMessage = err?.message ? err.message.substring(0, 100) : 'Unknown error';
+
+ layerData = {};
}
- const layerData = layer.formatLayerData(state.datasets, oldLayerData);
- return {layerData, layer};
+ return {
+ layer,
+ layerData
+ };
}
/**
diff --git a/src/reducers/src/ui-state-updaters.ts b/src/reducers/src/ui-state-updaters.ts
index 3464bd29c..f89847447 100644
--- a/src/reducers/src/ui-state-updaters.ts
+++ b/src/reducers/src/ui-state-updaters.ts
@@ -268,7 +268,6 @@ export const INITIAL_UI_STATE: UiState = {
/* Updaters */
/**
* @memberof uiStateUpdaters
-
*/
export const initUiStateUpdater = (
state: UiState,
@@ -682,17 +681,18 @@ export const addNotificationUpdater = (
state: UiState,
{payload}: UIStateActions.AddNotificationUpdaterAction
): UiState => {
- let notifications;
-
+ const oldNotifications = state.notifications || [];
// @ts-expect-error
const payloadId = payload?.id;
- const notificationToUpdate = payloadId ? state.notifications.find(n => n.id === payloadId) : null;
+ const notificationToUpdate = payloadId ? oldNotifications.find(n => n.id === payloadId) : null;
+
+ let notifications;
if (notificationToUpdate) {
- notifications = state.notifications.map(n =>
- n.id === payloadId ? createNotification(payload) : n
+ notifications = oldNotifications.map(n =>
+ n.id === payloadId ? createNotification({...payload, count: n.count + 1}) : n
);
} else {
- notifications = [...(state.notifications || []), createNotification(payload)];
+ notifications = [...oldNotifications, createNotification(payload)];
}
return {...state, notifications};
diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts
index c1cb42829..254143385 100644
--- a/src/reducers/src/vis-state-updaters.ts
+++ b/src/reducers/src/vis-state-updaters.ts
@@ -333,13 +333,12 @@ export function layerConfigChangeUpdater(
let layerData;
- // let newLayer;
if (newLayer.shouldCalculateLayerData(props)) {
const oldLayerData = state.layerData[idx];
- const updateLayerDataResult = calculateLayerData(newLayer, state, oldLayerData);
- layerData = updateLayerDataResult.layerData;
+ const updateLayerDataResult = calculateLayerData(newLayer, state, oldLayerData);
newLayer = updateLayerDataResult.layer;
+ layerData = updateLayerDataResult.layerData;
}
let newState = state;
@@ -354,6 +353,43 @@ export function layerConfigChangeUpdater(
});
}
+/**
+ * Updates isValid flag of a layer.
+ * Updates isVisible based on the value of isValid.
+ * Triggers update of data for the layer in order to get errors again during next update iteration.
+ * @memberof visStateUpdaters
+ * @returns nextState
+ */
+export function layerSetIsValidUpdater(
+ state: VisState,
+ action: VisStateActions.LayerSetIsValidUpdaterAction
+): VisState {
+ const {oldLayer, isValid} = action;
+
+ const idx = state.layers.findIndex(l => l.id === oldLayer.id);
+ const layerToUpdate = state.layers[idx];
+ if (layerToUpdate) {
+ let newLayer;
+ let newData = null;
+
+ if (isValid) {
+ // Trigger data update in order to show errors again if present.
+ const {layer, layerData} = calculateLayerData(layerToUpdate, state, undefined);
+ newLayer = layer;
+ newData = layerData;
+ } else {
+ newLayer = layerToUpdate.updateLayerConfig({
+ isVisible: false
+ });
+ newLayer.isValid = false;
+ }
+
+ return updateStateWithLayerAndData(state, {idx, layer: newLayer, layerData: newData});
+ }
+
+ return state;
+}
+
function addOrRemoveTextLabels(newFields, textLabel) {
let newTextLabel = textLabel.slice();
diff --git a/src/reducers/src/vis-state.ts b/src/reducers/src/vis-state.ts
index 3e10bfc3b..02acc429d 100644
--- a/src/reducers/src/vis-state.ts
+++ b/src/reducers/src/vis-state.ts
@@ -41,6 +41,8 @@ const actionHandler = {
[ActionTypes.LAYER_CONFIG_CHANGE]: visStateUpdaters.layerConfigChangeUpdater,
+ [ActionTypes.LAYER_SET_IS_VALID]: visStateUpdaters.layerSetIsValidUpdater,
+
[ActionTypes.LAYER_HOVER]: visStateUpdaters.layerHoverUpdater,
[ActionTypes.LAYER_TYPE_CHANGE]: visStateUpdaters.layerTypeChangeUpdater,
diff --git a/src/utils/src/notifications-utils.ts b/src/utils/src/notifications-utils.ts
index e6c7bba9d..14d5cfb95 100644
--- a/src/utils/src/notifications-utils.ts
+++ b/src/utils/src/notifications-utils.ts
@@ -34,8 +34,9 @@ import {
* @param opt.message - Message to display during the notification
* @param opt.type - The type of message. One of DEFAULT_NOTIFICATION_TYPES
* @param opt.topic - The topic the notification belongs to. One of DEFAULT_NOTIFICATION_TOPICS
- * @param opt.id optional id for notification. If not provided it will be generated by the method
- * @param opt.options - Extra parameters to store as part of hte notification
+ * @param opt.id - Optional id for the notification. If not provided it will be generated by the method
+ * @param opt.count - Number of identical notifications present at the moment
+ * @param opt.options - Extra parameters to store as part of the notification
* @returns
*/
export function createNotification({
@@ -43,12 +44,14 @@ export function createNotification({
type = DEFAULT_NOTIFICATION_TYPES.info,
topic = DEFAULT_NOTIFICATION_TOPICS.global,
id = generateHashId(DEFAULT_UUID_COUNT),
+ count = 1,
...options
}: {
message?: string;
type?: string;
topic?: string;
id?: string;
+ count?: number;
options?: any;
}) {
return {
@@ -56,7 +59,8 @@ export function createNotification({
id,
message,
type,
- topic
+ topic,
+ count: count > 99 ? 99 : count // no more than 2 digits
};
}
@@ -83,6 +87,7 @@ export const successNotification = options => ({
export const exportImageError = options =>
errorNotification({
...options,
+ id: 'EXPORT_IMAGE_ERROR_ID',
topic: DEFAULT_NOTIFICATION_TOPICS.global,
message: `Failed to export image, please take a screenshot of the javascript console, report the with [this link](${BUG_REPORT_LINK}) `
});
diff --git a/test/browser/components/side-panel/layer-panel-header-test.js b/test/browser/components/side-panel/layer-panel-header-test.js
index 5f754e590..30f6cb91c 100644
--- a/test/browser/components/side-panel/layer-panel-header-test.js
+++ b/test/browser/components/side-panel/layer-panel-header-test.js
@@ -31,6 +31,7 @@ const nop = () => {};
const defaultProps = {
layerId: 'taro',
isVisible: true,
+ isValid: true,
isConfigActive: false,
onToggleVisibility: nop,
onUpdateLayerLabel: nop,
@@ -57,5 +58,18 @@ test('Components -> LayerPanelHeader.mount -> no prop', t => {
t.ok(wrapper.find('.layer__visibility-toggle').length, 'should render visibility toggle');
t.ok(wrapper.find('.layer__enable-config').length, 'should render enable config toggle');
+ // mount
+ const layerAfterErrorProps = {...defaultProps, ...{isValid: false}};
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <IntlWrapper>
+ <LayerPanelHeader {...layerAfterErrorProps} />
+ </IntlWrapper>
+ );
+ }, 'LayerPanelHeader should not fail without props');
+
+ t.ok(!wrapper.find('.layer__visibility-toggle').length, "shouldn't render visibility toggle");
+ t.ok(wrapper.find('.layer__is-valid-refresh').length, 'should render validity refresh icon');
+
t.end();
});
diff --git a/test/helpers/comparison-utils.js b/test/helpers/comparison-utils.js
index e59440375..ae993175d 100644
--- a/test/helpers/comparison-utils.js
+++ b/test/helpers/comparison-utils.js
@@ -97,7 +97,7 @@ export function cmpLayers(t, expectedLayer, actualLayer, opt = {}) {
cmpObjectKeys(t, expectedLayer.config, actualLayer.config, `layer.${actualLayer.id}`);
Object.keys(expectedLayer.config).forEach(key => {
- // test everything except color and id, which is auto generated
+ // test everything except color and id, which are auto generated
// also skip functions
switch (key) {
// list of fields
diff --git a/test/node/reducers/ui-state-test.js b/test/node/reducers/ui-state-test.js
index 134ed139e..698657643 100644
--- a/test/node/reducers/ui-state-test.js
+++ b/test/node/reducers/ui-state-test.js
@@ -271,7 +271,8 @@ test('#uiStateReducer -> ADD_NOTIFICATION', t => {
type: DEFAULT_NOTIFICATION_TYPES.error,
message: 'TEST',
topic: DEFAULT_NOTIFICATION_TOPICS.global,
- id: 'test-1'
+ id: 'test-1',
+ count: 1
};
const state0 = reducer(INITIAL_UI_STATE, addNotification(notification1));
t.equal(state0.notifications.length, 1, 'AddNotification should add one new notification');
@@ -285,7 +286,8 @@ test('#uiStateReducer -> ADD_NOTIFICATION', t => {
type: DEFAULT_NOTIFICATION_TYPES.info,
message: 'TEST',
topic: DEFAULT_NOTIFICATION_TOPICS.file,
- id: sharedNotificationId
+ id: sharedNotificationId,
+ count: 1
};
const state1 = reducer(state0, addNotification(notification2));
t.equal(state1.notifications.length, 2, 'AddNotification should add second notification');
@@ -299,7 +301,8 @@ test('#uiStateReducer -> ADD_NOTIFICATION', t => {
type: DEFAULT_NOTIFICATION_TYPES.error,
message: 'TEST-updated-message',
topic: DEFAULT_NOTIFICATION_TOPICS.global,
- id: sharedNotificationId
+ id: sharedNotificationId,
+ count: 2
};
const state2 = reducer(state1, addNotification(updatedNotification));
t.equal(
@@ -334,7 +337,8 @@ test('#uiStateReducer -> REMOVE_NOTIFICATION', t => {
type: DEFAULT_NOTIFICATION_TYPES.error,
message: 'TEST',
topic: DEFAULT_NOTIFICATION_TOPICS.global,
- id: 'test-1'
+ id: 'test-1',
+ count: 1
},
'AddNotification should have propagated data correctly '
);
@@ -364,7 +368,8 @@ test('#uiStateReducer -> LOAD_FILES_ERR', t => {
type: 'error',
topic: 'global',
message: 'this is an error',
- id: expectedId
+ id: expectedId,
+ count: 1
}
],
'should add an error notification'
diff --git a/test/node/utils/notifications-utils-test.js b/test/node/utils/notifications-utils-test.js
index e599bfbfe..86332d317 100644
--- a/test/node/utils/notifications-utils-test.js
+++ b/test/node/utils/notifications-utils-test.js
@@ -30,7 +30,8 @@ test('#notificationsUtils -> errorNotification', t => {
id: 'test-1',
message: 'test',
type: 'error',
- topic: 'global'
+ topic: 'global',
+ count: 1
},
'ErrorNotification creates an error notification'
);
@@ -47,7 +48,8 @@ test('#notificationsUtils -> successNotification', t => {
id: 'test-1',
message: 'test',
type: 'success',
- topic: 'global'
+ topic: 'global',
+ count: 1
},
'SuccessNotification creates an error notification'
);