diff --git a/src/actions/src/provider-actions.ts b/src/actions/src/provider-actions.ts index c2dc77bb73..50a7bd0bfe 100644 --- a/src/actions/src/provider-actions.ts +++ b/src/actions/src/provider-actions.ts @@ -104,7 +104,7 @@ export const resetProviderStatus: () => { } = createAction(ActionTypes.RESET_PROVIDER_STATUS); /** SET_CLOUD_PROVIDER */ -export type SetCloudProviderPayload = string; +export type SetCloudProviderPayload = string | null; export const setCloudProvider: ( p: SetCloudProviderPayload ) => { diff --git a/src/components/src/common/item-selector/typeahead.tsx b/src/components/src/common/item-selector/typeahead.tsx index abd79b9964..fa9ebb4e79 100644 --- a/src/components/src/common/item-selector/typeahead.tsx +++ b/src/components/src/common/item-selector/typeahead.tsx @@ -298,7 +298,11 @@ class Typeahead extends Component { } getSelection() { - let index = Number(this.state.selectionIndex); + let index: number | null = this.state.selectionIndex; + if (index === null) { + return null; + } + index = Number(index); if (this._hasCustomValue()) { if (index === 0) { diff --git a/src/components/src/map/map-popover.tsx b/src/components/src/map/map-popover.tsx index d41a913034..f48126075d 100644 --- a/src/components/src/map/map-popover.tsx +++ b/src/components/src/map/map-popover.tsx @@ -139,7 +139,13 @@ function createVirtualReference(container, x, y, size = 0) { right: left + size, bottom: top + size, width: size, - height: size + height: size, + // These properties are present to meet the DOMRect interface + y: top, + x: left, + toJSON() { + return this; + } }; } diff --git a/src/components/src/modals/cloud-tile.tsx b/src/components/src/modals/cloud-tile.tsx index 209c731bcf..1d886fb718 100644 --- a/src/components/src/modals/cloud-tile.tsx +++ b/src/components/src/modals/cloud-tile.tsx @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import React, {ReactNode} from 'react'; +import React from 'react'; import styled from 'styled-components'; import {Logout, Login} from '../common/icons'; import {CenterVerticalFlexbox, Button, CheckMark} from '../common/styled-components'; @@ -97,7 +97,7 @@ const LogoutButton = ({onClick}: OnClickProps) => ( interface ActionButtonProps { isConnected?: boolean; - actionName?: ReactNode | null; + actionName?: string | null; isReady?: boolean; } @@ -111,15 +111,15 @@ const ActionButton = ({isConnected, actionName = null, isReady}: ActionButtonPro interface CloudTileProps { onSelect?: React.MouseEventHandler; // default to login - onConnect?: React.MouseEventHandler | null; + onConnect?: (() => void) | null; // default to logout - onLogout?: React.MouseEventHandler | null; + onLogout?: (() => void) | null; // action name - actionName?: ReactNode | null; + actionName?: string | null; // cloud provider class cloudProvider: Provider; // function to take after login or logout - onSetCloudProvider; + onSetCloudProvider: (providerName: string | null) => void; // whether provider is selected as currentProvider isSelected?: boolean; // whether user has logged in diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts index 0c507a3eee..ca71a96433 100644 --- a/src/reducers/src/vis-state-updaters.ts +++ b/src/reducers/src/vis-state-updaters.ts @@ -270,10 +270,10 @@ export const INITIAL_VIS_STATE: VisState = { * Update state with updated layer and layerData * */ -export function updateStateWithLayerAndData( - state: S, +export function updateStateWithLayerAndData( + state: VisState, {layerData, layer, idx}: {layerData?: any; layer: Layer; idx: number} -): S { +): VisState { return { ...state, layers: state.layers.map((lyr, i) => (i === idx ? layer : lyr)), @@ -306,10 +306,10 @@ export function updateStateOnLayerVisibilityChange(state: S, * @memberof visStateUpdaters * @returns nextState */ -export function layerConfigChangeUpdater( - state: S, +export function layerConfigChangeUpdater( + state: VisState, action: VisStateActions.LayerConfigChangeUpdaterAction -): S { +): VisState { const {oldLayer} = action; const idx = state.layers.findIndex(l => l.id === oldLayer.id); const props = Object.keys(action.newConfig); @@ -396,10 +396,10 @@ function updateTextLabelPropAndValue(idx, prop, value, textLabel) { * @memberof visStateUpdaters * @returns nextState */ -export function layerTextLabelChangeUpdater( - state: S, +export function layerTextLabelChangeUpdater( + state: VisState, action: VisStateActions.LayerTextLabelChangeUpdaterAction -): S { +): VisState { const {oldLayer, idx, prop, value} = action; const {textLabel} = oldLayer.config; @@ -433,15 +433,15 @@ function validateExistingLayerWithData(dataset, layerClasses, layer) { * @memberof visStateUpdaters * @returns nextState */ -export function layerDataIdChangeUpdater( - state: S, +export function layerDataIdChangeUpdater( + state: VisState, action: { oldLayer: Layer; newConfig: { dataId: string; }; } -): S { +): VisState { const {oldLayer, newConfig} = action; const {dataId} = newConfig; @@ -522,10 +522,10 @@ function setInitialLayerConfig(layer, datasets, layerClasses) { * @memberof visStateUpdaters * @public */ -export function layerTypeChangeUpdater( - state: S, +export function layerTypeChangeUpdater( + state: VisState, action: VisStateActions.LayerTypeChangeUpdaterAction -): S { +): VisState { const {oldLayer, newType} = action; if (!oldLayer) { return state; @@ -595,10 +595,10 @@ export function layerTypeChangeUpdater( * @returns {Object} nextState * @public */ -export function layerVisualChannelChangeUpdater( - state: S, +export function layerVisualChannelChangeUpdater( + state: VisState, action: VisStateActions.LayerVisualChannelConfigChangeUpdaterAction -): S { +): VisState { const {oldLayer, newConfig, channel} = action; if (!oldLayer.config.dataId) { return state; @@ -621,10 +621,10 @@ export function layerVisualChannelChangeUpdater( * @memberof visStateUpdaters * @public */ -export function layerVisConfigChangeUpdater( - state: S, +export function layerVisConfigChangeUpdater( + state: VisState, action: VisStateActions.LayerVisConfigChangeUpdaterAction -): S { +): VisState { const {oldLayer} = action; const idx = state.layers.findIndex(l => l.id === oldLayer.id); const props = Object.keys(action.newVisConfig); @@ -649,10 +649,10 @@ export function layerVisConfigChangeUpdater( * @memberof visStateUpdaters * @public */ -export function setFilterAnimationTimeUpdater( - state: S, +export function setFilterAnimationTimeUpdater( + state: VisState, action: VisStateActions.SetFilterAnimationTimeUpdaterAction -): S { +): VisState { return setFilterUpdater(state, action); } @@ -661,10 +661,10 @@ export function setFilterAnimationTimeUpdater( * @memberof visStateUpdaters * @public */ -export function setFilterAnimationWindowUpdater( - state: S, +export function setFilterAnimationWindowUpdater( + state: VisState, {id, animationWindow}: VisStateActions.SetFilterAnimationWindowUpdaterAction -): S { +): VisState { return { ...state, filters: state.filters.map(f => @@ -682,10 +682,10 @@ export function setFilterAnimationWindowUpdater( * @memberof visStateUpdaters * @public */ -export function setFilterUpdater( - state: S, +export function setFilterUpdater( + state: VisState, action: VisStateActions.SetFilterUpdaterAction -): S { +): VisState { const {idx, prop, value, valueIndex = 0} = action; const oldFilter = state.filters[idx]; @@ -818,10 +818,10 @@ export function setFilterUpdater( * @memberof visStateUpdaters * @public */ -export const setFilterPlotUpdater = ( - state: S, +export const setFilterPlotUpdater = ( + state: VisState, {idx, newProp, valueIndex = 0}: VisStateActions.SetFilterPlotUpdaterAction -): S => { +): VisState => { let newFilter = {...state.filters[idx], ...newProp}; const prop = Object.keys(newProp)[0]; if (prop === 'yAxis') { @@ -847,10 +847,10 @@ export const setFilterPlotUpdater = ( * @memberof visStateUpdaters * @public */ -export const addFilterUpdater = ( - state: S, +export const addFilterUpdater = ( + state: VisState, action: VisStateActions.AddFilterUpdaterAction -): S => +): VisState => !action.dataId ? state : { @@ -862,10 +862,10 @@ export const addFilterUpdater = ( * Set layer color palette ui state * @memberof visStateUpdaters */ -export const layerColorUIChangeUpdater = ( - state: S, +export const layerColorUIChangeUpdater = ( + state: VisState, {oldLayer, prop, newConfig}: VisStateActions.LayerColorUIChangeUpdaterAction -): S => { +): VisState => { const oldVixConfig = oldLayer.config.visConfig[prop]; const newLayer = oldLayer.updateLayerColorUI(prop, newConfig); const newVisConfig = newLayer.config.visConfig[prop]; @@ -888,10 +888,10 @@ export const layerColorUIChangeUpdater = ( * @memberof visStateUpdaters * @public */ -export const toggleFilterAnimationUpdater = ( - state: S, +export const toggleFilterAnimationUpdater = ( + state: VisState, action: VisStateActions.ToggleFilterAnimationUpdaterAction -): S => ({ +): VisState => ({ ...state, filters: state.filters.map((f, i) => (i === action.idx ? {...f, isAnimating: !f.isAnimating} : f)) }); @@ -900,10 +900,10 @@ export const toggleFilterAnimationUpdater = ( * @memberof visStateUpdaters * @public */ -export const toggleLayerAnimationUpdater = ( - state: S, +export const toggleLayerAnimationUpdater = ( + state: VisState, action: VisStateActions.ToggleLayerAnimationUpdaterAction -): S => ({ +): VisState => ({ ...state, animationConfig: { ...state.animationConfig, @@ -916,10 +916,10 @@ export const toggleLayerAnimationUpdater = ( * @memberof visStateUpdaters * @public */ -export const toggleLayerAnimationControlUpdater = ( - state: S, +export const toggleLayerAnimationControlUpdater = ( + state: VisState, action: VisStateActions.ToggleLayerAnimationControlUpdaterAction -): S => ({ +): VisState => ({ ...state, animationConfig: { ...state.animationConfig, @@ -932,10 +932,10 @@ export const toggleLayerAnimationControlUpdater = ( * @memberof visStateUpdaters * @public */ -export const updateFilterAnimationSpeedUpdater = ( - state: S, +export const updateFilterAnimationSpeedUpdater = ( + state: VisState, action: VisStateActions.UpdateFilterAnimationSpeedUpdaterAction -): S => ({ +): VisState => ({ ...state, filters: state.filters.map((f, i) => (i === action.idx ? {...f, speed: action.speed} : f)) }); @@ -946,10 +946,10 @@ export const updateFilterAnimationSpeedUpdater = ( * @public * */ -export const setLayerAnimationTimeUpdater = ( - state: S, +export const setLayerAnimationTimeUpdater = ( + state: VisState, {value}: VisStateActions.SetLayerAnimationTimeUpdaterAction -): S => ({ +): VisState => ({ ...state, animationConfig: { ...state.animationConfig, @@ -963,10 +963,10 @@ export const setLayerAnimationTimeUpdater = ( * @public * */ -export const updateLayerAnimationSpeedUpdater = ( - state: S, +export const updateLayerAnimationSpeedUpdater = ( + state: VisState, {speed}: VisStateActions.UpdateLayerAnimationSpeedUpdaterAction -): S => { +): VisState => { return { ...state, animationConfig: { @@ -981,10 +981,10 @@ export const updateLayerAnimationSpeedUpdater = ( * @memberof visStateUpdaters * @public */ -export const enlargeFilterUpdater = ( - state: S, +export const enlargeFilterUpdater = ( + state: VisState, action: VisStateActions.EnlargeFilterUpdaterAction -): S => { +): VisState => { return { ...state, filters: state.filters.map((f, i) => @@ -1002,10 +1002,10 @@ export const enlargeFilterUpdater = ( * Toggles filter feature visibility * @memberof visStateUpdaters */ -export const toggleFilterFeatureUpdater = ( - state: S, +export const toggleFilterFeatureUpdater = ( + state: VisState, action: VisStateActions.ToggleFilterFeatureUpdaterAction -): S => { +): VisState => { const filter = state.filters[action.idx]; const isVisible = get(filter, ['value', 'properties', 'isVisible']); const newFilter = { @@ -1026,10 +1026,10 @@ export const toggleFilterFeatureUpdater = ( * @memberof visStateUpdaters * @public */ -export const removeFilterUpdater = ( - state: S, +export const removeFilterUpdater = ( + state: VisState, action: VisStateActions.RemoveFilterUpdaterAction -): S => { +): VisState => { const {idx} = action; const {dataId, id} = state.filters[idx]; @@ -1059,10 +1059,10 @@ export const removeFilterUpdater = ( * @memberof visStateUpdaters * @public */ -export const addLayerUpdater = ( - state: S, +export const addLayerUpdater = ( + state: VisState, action: VisStateActions.AddLayerUpdaterAction -): S => { +): VisState => { let newLayer; let newLayerData; if (action.config) { @@ -1102,10 +1102,10 @@ export const addLayerUpdater = ( * @memberof visStateUpdaters * @public */ -export const removeLayerUpdater = ( - state: S, +export const removeLayerUpdater = ( + state: VisState, {idx}: VisStateActions.RemoveLayerUpdaterAction -): S => { +): VisState => { const {layers, layerData, clicked, hoverInfo} = state; const layerToRemove = state.layers[idx]; const newMaps = removeLayerFromSplitMaps(state.splitMaps, layerToRemove); @@ -1129,10 +1129,10 @@ export const removeLayerUpdater = ( * @memberof visStateUpdaters * @public */ -export const duplicateLayerUpdater = ( - state: S, +export const duplicateLayerUpdater = ( + state: VisState, {idx}: VisStateActions.DuplicateLayerUpdaterAction -): S => { +): VisState => { const {layers} = state; const original = state.layers[idx]; const originalLayerOrderIdx = state.layerOrder.findIndex(i => i === idx); @@ -1182,10 +1182,10 @@ export const duplicateLayerUpdater = ( * @memberof visStateUpdaters * @public */ -export const reorderLayerUpdater = ( - state: S, +export const reorderLayerUpdater = ( + state: VisState, {order}: VisStateActions.ReorderLayerUpdaterAction -): S => ({ +): VisState => ({ ...state, layerOrder: order }); @@ -1195,10 +1195,10 @@ export const reorderLayerUpdater = ( * @memberof visStateUpdaters * @public */ -export const removeDatasetUpdater = ( - state: S, +export const removeDatasetUpdater = ( + state: VisState, action: VisStateActions.RemoveDatasetUpdaterAction -): S => { +): VisState => { // extract dataset key const {dataId: datasetKey} = action; const {datasets} = state; @@ -1259,10 +1259,10 @@ export const removeDatasetUpdater = ( * @memberof visStateUpdaters * @public */ -export const updateLayerBlendingUpdater = ( - state: S, +export const updateLayerBlendingUpdater = ( + state: VisState, action: VisStateActions.UpdateLayerBlendingUpdaterAction -): S => ({ +): VisState => ({ ...state, layerBlending: action.mode }); @@ -1272,10 +1272,10 @@ export const updateLayerBlendingUpdater = ( * @memberof visStateUpdaters * @public */ -export const showDatasetTableUpdater = ( - state: S, +export const showDatasetTableUpdater = ( + state: VisState, action: VisStateActions.ShowDatasetTableUpdaterAction -): S => { +): VisState => { return { ...state, editingDataset: action.dataId @@ -1314,27 +1314,26 @@ export const updateTableColorUpdater = ( * @memberof visStateUpdaters * @public */ -export const resetMapConfigUpdater = (state: S): S => - ({ - ...INITIAL_VIS_STATE, - ...state.initialState, - initialState: state.initialState - } as S); +export const resetMapConfigUpdater = (state: VisState): VisState => ({ + ...INITIAL_VIS_STATE, + ...state.initialState, + initialState: state.initialState +}); /** * Propagate `visState` reducer with a new configuration. Current config will be override. * @memberof visStateUpdaters * @public */ -export const receiveMapConfigUpdater = ( - state: S, +export const receiveMapConfigUpdater = ( + state: VisState, { payload: {config = {version: ''}, options = {}} }: { type?: typeof ActionTypes.RECEIVE_MAP_CONFIG; payload: ReceiveMapConfigPayload; } -): S => { +): VisState => { if (!config.visState) { return state; } @@ -1357,10 +1356,10 @@ export const receiveMapConfigUpdater = ( * @memberof visStateUpdaters * @public */ -export const layerHoverUpdater = ( - state: S, +export const layerHoverUpdater = ( + state: VisState, action: VisStateActions.OnLayerHoverUpdaterAction -): S => ({ +): VisState => ({ ...state, hoverInfo: { // deck.gl info is mutable @@ -1375,10 +1374,10 @@ export const layerHoverUpdater = ( * @memberof visStateUpdaters * @public */ -export function interactionConfigChangeUpdater( - state: S, +export function interactionConfigChangeUpdater( + state: VisState, action: VisStateActions.InteractionConfigChangeUpdaterAction -): S { +): VisState { const {config} = action; const interactionConfig = { @@ -1420,10 +1419,10 @@ export function interactionConfigChangeUpdater( * @memberof visStateUpdaters * @public */ -export const layerClickUpdater = ( - state: S, +export const layerClickUpdater = ( + state: VisState, action: VisStateActions.OnLayerClickUpdaterAction -): S => ({ +): VisState => ({ ...state, mousePos: state.interactionConfig.coordinate.enabled ? { @@ -1439,10 +1438,10 @@ export const layerClickUpdater = ( * @memberof visStateUpdaters * @public */ -export const mapClickUpdater = ( - state: S, +export const mapClickUpdater = ( + state: VisState, action: VisStateActions.OnMapClickUpdaterAction -): S => { +): VisState => { return { ...state, clicked: null @@ -1454,10 +1453,10 @@ export const mapClickUpdater = ( * @memberof visStateUpdaters * @public */ -export const mouseMoveUpdater = ( - state: S, +export const mouseMoveUpdater = ( + state: VisState, {evt}: VisStateActions.OnMouseMoveUpdaterAction -): S => { +): VisState => { if (Object.values(state.interactionConfig).some(config => config.enabled)) { return { ...state, @@ -1476,10 +1475,10 @@ export const mouseMoveUpdater = ( * @memberof visStateUpdaters * @public */ -export const toggleSplitMapUpdater = ( - state: S, +export const toggleSplitMapUpdater = ( + state: VisState, action: MapStateActions.ToggleSplitMapUpdaterAction -): S => +): VisState => state.splitMaps && state.splitMaps.length === 0 ? { ...state, @@ -1494,10 +1493,10 @@ export const toggleSplitMapUpdater = ( * @memberof visStateUpdaters * @public */ -export const toggleLayerForMapUpdater = ( - state: S, +export const toggleLayerForMapUpdater = ( + state: VisState, {mapIndex, layerId}: VisStateActions.ToggleLayerForMapUpdaterAction -): S => { +): VisState => { const {splitMaps} = state; return { @@ -1524,10 +1523,10 @@ export const toggleLayerForMapUpdater = ( */ /* eslint-disable max-statements */ // eslint-disable-next-line complexity -export const updateVisDataUpdater = ( - state: S, +export const updateVisDataUpdater = ( + state: VisState, action: VisStateActions.UpdateVisDataUpdaterAction -): S => { +): VisState => { // datasets can be a single data entries or an array of multiple data entries const {config, options} = action; const datasets = toArray(action.datasets); @@ -1615,10 +1614,10 @@ export const updateVisDataUpdater = ( * @memberof visStateUpdaters * @public */ -export function renameDatasetUpdater( - state: S, +export function renameDatasetUpdater( + state: VisState, action: VisStateActions.RenameDatasetUpdaterAction -): S { +): VisState { const {dataId, label} = action; const {datasets} = state; const existing = datasets[dataId]; @@ -1679,10 +1678,10 @@ export function closeSpecificMapAtIndex( * @memberof visStateUpdaters * @public */ -export const loadFilesUpdater = ( - state: S, +export const loadFilesUpdater = ( + state: VisState, action: VisStateActions.LoadFilesUpdaterAction -): S => { +): VisState => { const {files, onFinish = loadFilesSuccess} = action; if (!files.length) { return state; @@ -1709,10 +1708,10 @@ export const loadFilesUpdater = ( * @memberof visStateUpdaters * @public */ -export function loadFileStepSuccessUpdater( - state: S, +export function loadFileStepSuccessUpdater( + state: VisState, action: VisStateActions.LoadFileStepSuccessAction -): S { +): VisState { if (!state.fileLoading) { return state; } @@ -1739,7 +1738,7 @@ export function loadFileStepSuccessUpdater( * @memberof visStateUpdaters * @public */ -export function loadNextFileUpdater(state: S): S { +export function loadNextFileUpdater(state: VisState): VisState { if (!state.fileLoading) { return state; } @@ -1791,10 +1790,10 @@ export function makeLoadFileTask(file, fileCache, loaders: Loader[] = [], loadOp * @memberof visStateUpdaters * @public */ -export function processFileContentUpdater( - state: S, +export function processFileContentUpdater( + state: VisState, action: VisStateActions.ProcessFileContentUpdaterAction -): S { +): VisState { const {content, fileCache} = action.payload; const stateWithProgress = updateFileLoadingProgressUpdater(state, { @@ -1828,12 +1827,12 @@ export function parseProgress(prevProgress = {}, progress) { * @memberof visStateUpdaters * @public */ -export const nextFileBatchUpdater = ( - state: S, +export const nextFileBatchUpdater = ( + state: VisState, { payload: {gen, fileName, progress, accumulated, onFinish} }: VisStateActions.NextFileBatchUpdaterAction -): S => { +): VisState => { const stateWithProgress = updateFileLoadingProgressUpdater(state, { fileName, progress: parseProgress(state.fileLoadingProgress[fileName], progress) @@ -1862,10 +1861,10 @@ export const nextFileBatchUpdater = ( * @memberof visStateUpdaters * @public */ -export const loadFilesErrUpdater = ( - state: S, +export const loadFilesErrUpdater = ( + state: VisState, {error, fileName}: VisStateActions.LoadFilesErrUpdaterAction -): S => { +): VisState => { // update ui with error message Console.warn(error); if (!state.fileLoading) { @@ -1890,10 +1889,10 @@ export const loadFilesErrUpdater = ( * @memberof visStateUpdaters * @public */ -export const applyCPUFilterUpdater = ( - state: S, +export const applyCPUFilterUpdater = ( + state: VisState, {dataId}: VisStateActions.ApplyCPUFilterUpdaterAction -): S => { +): VisState => { // apply cpuFilter const dataIds = toArray(dataId); @@ -1905,10 +1904,10 @@ export const applyCPUFilterUpdater = ( * @memberof visStateUpdaters * @public */ -export const setMapInfoUpdater = ( - state: S, +export const setMapInfoUpdater = ( + state: VisState, action: VisStateActions.SetMapInfoUpdaterAction -): S => ({ +): VisState => ({ ...state, mapInfo: { ...state.mapInfo, @@ -1918,10 +1917,10 @@ export const setMapInfoUpdater = ( /** * Helper function to update All layer domain and layer data of state */ -export function addDefaultLayers( - state: S, +export function addDefaultLayers( + state: VisState, datasets: Datasets -): {state: S; newLayers: Layer[]} { +): {state: VisState; newLayers: Layer[]} { const empty: Layer[] = []; const defaultLayers = Object.values(datasets).reduce((accu, dataset) => { const foundLayers = findDefaultLayer(dataset, state.layerClasses); @@ -1981,11 +1980,11 @@ export function updateFileLoadingProgressUpdater(state, {fileName, progress}) { /** * Helper function to update layer domains for an array of datasets */ -export function updateAllLayerDomainData( - state: S, +export function updateAllLayerDomainData( + state: VisState, dataId: string | string[], updatedFilter?: Filter -): S { +): VisState { const dataIds = typeof dataId === 'string' ? [dataId] : dataId; const newLayers: Layer[] = []; const newLayerData: any[] = []; @@ -2067,10 +2066,10 @@ export function updateAnimationDomain(state: S): S { * Update the status of the editor * @memberof visStateUpdaters */ -export const setEditorModeUpdater = ( - state: S, +export const setEditorModeUpdater = ( + state: VisState, {mode}: VisStateActions.SetEditorModeUpdaterAction -): S => ({ +): VisState => ({ ...state, editor: { ...state.editor, @@ -2084,10 +2083,10 @@ export const setEditorModeUpdater = ( * Update editor features * @memberof visStateUpdaters */ -export function setFeaturesUpdater( - state: S, +export function setFeaturesUpdater( + state: VisState, {features = []}: VisStateActions.SetFeaturesUpdaterAction -): S { +): VisState { const lastFeature = features.length && features[features.length - 1]; const newState = { @@ -2131,10 +2130,10 @@ export function setFeaturesUpdater( * Set the current selected feature * @memberof uiStateUpdaters */ -export const setSelectedFeatureUpdater = ( - state: S, +export const setSelectedFeatureUpdater = ( + state: VisState, {feature}: VisStateActions.SetSelectedFeatureUpdaterAction -): S => ({ +): VisState => ({ ...state, editor: { ...state.editor, @@ -2146,10 +2145,10 @@ export const setSelectedFeatureUpdater = ( * Delete existing feature from filters * @memberof visStateUpdaters */ -export function deleteFeatureUpdater( - state: S, +export function deleteFeatureUpdater( + state: VisState, {feature}: VisStateActions.DeleteFeatureUpdaterAction -): S { +): VisState { if (!feature) { return state; } @@ -2185,10 +2184,10 @@ export function deleteFeatureUpdater( * Toggle feature as layer filter * @memberof visStateUpdaters */ -export function setPolygonFilterLayerUpdater( - state: S, +export function setPolygonFilterLayerUpdater( + state: VisState, payload: VisStateActions.SetPolygonFilterLayerUpdaterAction -): S { +): VisState { const {layer, feature} = payload; const filterId = getFilterIdInFeature(feature); @@ -2257,10 +2256,10 @@ export function setPolygonFilterLayerUpdater( * @memberof visStateUpdaters * @public */ -export function sortTableColumnUpdater( - state: S, +export function sortTableColumnUpdater( + state: VisState, {dataId, column, mode}: VisStateActions.SortTableColumnUpdaterAction -): S { +): VisState { const dataset = state.datasets[dataId]; if (!dataset) { return state; @@ -2282,10 +2281,10 @@ export function sortTableColumnUpdater( * @memberof visStateUpdaters * @public */ -export function pinTableColumnUpdater( - state: S, +export function pinTableColumnUpdater( + state: VisState, {dataId, column}: VisStateActions.PinTableColumnUpdaterAction -): S { +): VisState { const dataset = state.datasets[dataId]; if (!dataset) { return state; @@ -2300,10 +2299,10 @@ export function pinTableColumnUpdater( * @memberof visStateUpdaters * @public */ -export function copyTableColumnUpdater( - state: S, +export function copyTableColumnUpdater( + state: VisState, {dataId, column}: VisStateActions.CopyTableColumnUpdaterAction -): S { +): VisState { const dataset = state.datasets[dataId]; if (!dataset) { return state; @@ -2325,10 +2324,10 @@ export function copyTableColumnUpdater( /** * Update editor */ -export function toggleEditorVisibilityUpdater( - state: S, +export function toggleEditorVisibilityUpdater( + state: VisState, action: VisStateActions.ToggleEditorVisibilityUpdaterAction -): S { +): VisState { return { ...state, editor: { @@ -2338,10 +2337,10 @@ export function toggleEditorVisibilityUpdater( }; } -export function setFilterAnimationTimeConfigUpdater( - state: S, +export function setFilterAnimationTimeConfigUpdater( + state: VisState, {idx, config}: VisStateActions.SetFilterAnimationTimeConfigAction -): S { +): VisState { const oldFilter = state.filters[idx]; if (!oldFilter) { Console.error(`filters.${idx} is undefined`); @@ -2377,10 +2376,10 @@ function checkTimeConfigArgs(config) { /** * Update editor */ -export function setLayerAnimationTimeConfigUpdater( - state: S, +export function setLayerAnimationTimeConfigUpdater( + state: VisState, {config}: VisStateActions.SetLayerAnimationTimeConfigAction -): S { +): VisState { if (!config) { return state; } diff --git a/src/schemas/src/vis-state-schema.ts b/src/schemas/src/vis-state-schema.ts index 9679edce43..8519be80cf 100644 --- a/src/schemas/src/vis-state-schema.ts +++ b/src/schemas/src/vis-state-schema.ts @@ -59,7 +59,7 @@ export type modifiedType = { stroked?: boolean; }; -export type VisState = { +export interface VisState { mapInfo: MapInfo; layers: Layer[]; layerData: any[]; @@ -89,7 +89,7 @@ export type VisState = { mergers: VisStateMergers; schema: typeof KeplerGLSchema; preserveLayerOrder?: number[]; -}; +} export type Merger = { merge: (state: S, config: any, fromConfig?: boolean) => S; diff --git a/src/table/src/kepler-table.ts b/src/table/src/kepler-table.ts index 9cbb790c1b..6990f298cb 100644 --- a/src/table/src/kepler-table.ts +++ b/src/table/src/kepler-table.ts @@ -586,7 +586,8 @@ export function pinTableColumns(dataset: KeplerTable, column: string): KeplerTab // @ts-ignore return copyTableAndUpdate(dataset, {pinnedColumns}); } -export function copyTable(original: T): T { + +export function copyTable(original: KeplerTable): KeplerTable { return Object.assign(Object.create(Object.getPrototypeOf(original)), original); } @@ -594,10 +595,10 @@ export function copyTable(original: T): T { * @type * @returns */ -export function copyTableAndUpdate( - original: T, - options: Partial = {} -): T { +export function copyTableAndUpdate( + original: KeplerTable, + options: Partial = {} +): KeplerTable { return Object.entries(options).reduce((acc, entry) => { acc[entry[0]] = entry[1]; return acc; diff --git a/src/utils/src/data-utils.ts b/src/utils/src/data-utils.ts index ab59c225c6..6402092a0d 100644 --- a/src/utils/src/data-utils.ts +++ b/src/utils/src/data-utils.ts @@ -86,13 +86,17 @@ export function getSampleData(data, sampleSize = 500, getValue = d => d) { /** * Convert different time format to unix milliseconds */ -export function timeToUnixMilli(value: string | number, format: string): Millisecond | null { +export function timeToUnixMilli(value: string | number | Date, format: string): Millisecond | null { if (notNullorUndefined(value)) { - return typeof value === 'string' - ? moment.utc(value, format).valueOf() - : format === 'x' - ? value * 1000 - : value; + if (typeof value === 'string') { + return moment.utc(value, format).valueOf(); + } + if (typeof value === 'number') { + return format === 'x' ? value * 1000 : value; + } + if (value instanceof Date) { + return value.valueOf(); + } } return null; } diff --git a/test/browser-headless/component/map-container-test.js b/test/browser-headless/component/map-container-test.js index cf5b086842..11cbfd7130 100644 --- a/test/browser-headless/component/map-container-test.js +++ b/test/browser-headless/component/map-container-test.js @@ -153,6 +153,7 @@ test('MapContainerFactory - _renderDeckOverlay', t => { name: 'hover', events: [{type: 'mousemove', x: 200, y: 200}, {wait: 50}], onBeforeEvents, + // eslint-disable-next-line max-statements onAfterEvents: ({deck, layers}) => { assert.is(hoverEvents.length, 1, 'onHover is called'); assert.is(hoverEvents[0].info.index, 15, 'object is picked'); @@ -226,11 +227,15 @@ test('MapContainerFactory - _renderDeckOverlay', t => { left: 200, right: 200, top: 200, - width: 0 + width: 0, + y: 200, + x: 200 }; + const rect = tippyProps.getReferenceClientRect(); + t.deepEqual( - tippyProps.getReferenceClientRect(), + rect, expectedClientRect, 'getReferenceClientRect should return correct rect' );