From 32f47cce5638d0f4eb7ec24dc5061e849931ab71 Mon Sep 17 00:00:00 2001 From: Stefano Pettini Date: Wed, 3 May 2023 17:10:16 +0200 Subject: [PATCH] Remote calculation controlled by Feature Flag --- packages/react-core/src/index.d.ts | 5 ++++- packages/react-core/src/index.js | 1 + packages/react-core/src/utils/featureFlags.d.ts | 3 +++ packages/react-core/src/utils/featureFlags.js | 4 ++++ packages/react-widgets/src/widgets/BarWidget.js | 9 +++++++-- packages/react-widgets/src/widgets/CategoryWidget.js | 9 +++++++-- packages/react-widgets/src/widgets/FormulaWidget.js | 4 ++-- packages/react-widgets/src/widgets/HistogramWidget.js | 9 +++++++-- packages/react-widgets/src/widgets/PieWidget.js | 9 +++++++-- packages/react-widgets/src/widgets/RangeWidget.js | 8 ++++++-- packages/react-widgets/src/widgets/TimeSeriesWidget.js | 6 ++++-- 11 files changed, 52 insertions(+), 15 deletions(-) diff --git a/packages/react-core/src/index.d.ts b/packages/react-core/src/index.d.ts index f067bffd9..191a3f252 100644 --- a/packages/react-core/src/index.d.ts +++ b/packages/react-core/src/index.d.ts @@ -1,3 +1,5 @@ +import { _FeatureFlags } from '.'; + export { getRequest, postRequest, @@ -38,7 +40,8 @@ export { SpatialIndex } from './operations/constants/SpatialIndexTypes' export { FEATURE_SELECTION_MODES, EDIT_MODES, MASK_ID } from './utils/featureSelectionConstants'; export { + Flags as _FeatureFlags, hasFlag as _hasFeatureFlag, setFlags as _setFeatureFlags, clearFlags as _clearFeatureFlags -} from './utils/featureFlags'; \ No newline at end of file +} from './utils/featureFlags'; diff --git a/packages/react-core/src/index.js b/packages/react-core/src/index.js index 31456ac87..39744a0b6 100644 --- a/packages/react-core/src/index.js +++ b/packages/react-core/src/index.js @@ -49,6 +49,7 @@ export { } from './utils/featureSelectionConstants'; export { + Flags as _FeatureFlags, hasFlag as _hasFeatureFlag, setFlags as _setFeatureFlags, clearFlags as _clearFeatureFlags diff --git a/packages/react-core/src/utils/featureFlags.d.ts b/packages/react-core/src/utils/featureFlags.d.ts index 3b18740e9..04872d147 100644 --- a/packages/react-core/src/utils/featureFlags.d.ts +++ b/packages/react-core/src/utils/featureFlags.d.ts @@ -1,3 +1,6 @@ +export enum Flags { + DYNAMIC_TILING_V2 = '2023-dynamic-tiling-v-2' +} export function setFlags(flags: Record | string[]): void export function clearFlags(): void export function hasFlag(flag: string): boolean diff --git a/packages/react-core/src/utils/featureFlags.js b/packages/react-core/src/utils/featureFlags.js index a91489645..48801ef2b 100644 --- a/packages/react-core/src/utils/featureFlags.js +++ b/packages/react-core/src/utils/featureFlags.js @@ -1,5 +1,9 @@ let featureFlags = []; +export const Flags = Object.freeze({ + DYNAMIC_TILING_V2: '2023-dynamic-tiling-v-2' +}); + export function setFlags(flags) { const isValidFlag = (f) => typeof f === 'string' && f; diff --git a/packages/react-widgets/src/widgets/BarWidget.js b/packages/react-widgets/src/widgets/BarWidget.js index ed87556c8..f457af8a0 100644 --- a/packages/react-widgets/src/widgets/BarWidget.js +++ b/packages/react-widgets/src/widgets/BarWidget.js @@ -3,7 +3,12 @@ import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import { addFilter, removeFilter } from '@carto/react-redux'; import { BarWidgetUI, WrapperWidgetUI } from '@carto/react-ui'; -import { _FilterTypes as FilterTypes, AggregationTypes } from '@carto/react-core'; +import { + _FilterTypes as FilterTypes, + AggregationTypes, + _hasFeatureFlag, + _FeatureFlags +} from '@carto/react-core'; import { getCategories } from '../models'; import { useWidgetFilterValues } from '../hooks/useWidgetFilterValues'; import { columnAggregationOn } from './utils/propTypesFns'; @@ -77,7 +82,7 @@ function BarWidget({ }, global, onError, - attemptRemoteCalculation: true + attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2) }); const sortedData = useMemo(() => { diff --git a/packages/react-widgets/src/widgets/CategoryWidget.js b/packages/react-widgets/src/widgets/CategoryWidget.js index 4d9d6a0b7..632e43f7f 100644 --- a/packages/react-widgets/src/widgets/CategoryWidget.js +++ b/packages/react-widgets/src/widgets/CategoryWidget.js @@ -3,7 +3,12 @@ import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import { addFilter, removeFilter } from '@carto/react-redux'; import { WrapperWidgetUI, CategoryWidgetUI } from '@carto/react-ui'; -import { _FilterTypes as FilterTypes, AggregationTypes } from '@carto/react-core'; +import { + _FilterTypes as FilterTypes, + AggregationTypes, + _hasFeatureFlag, + _FeatureFlags +} from '@carto/react-core'; import { getCategories } from '../models'; import { useWidgetFilterValues } from '../hooks/useWidgetFilterValues'; import { columnAggregationOn } from './utils/propTypesFns'; @@ -74,7 +79,7 @@ function CategoryWidget(props) { }, global, onError, - attemptRemoteCalculation: true + attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2) }); const handleSelectedCategoriesChange = useCallback( diff --git a/packages/react-widgets/src/widgets/FormulaWidget.js b/packages/react-widgets/src/widgets/FormulaWidget.js index 4e2831e4f..11d69f952 100644 --- a/packages/react-widgets/src/widgets/FormulaWidget.js +++ b/packages/react-widgets/src/widgets/FormulaWidget.js @@ -2,7 +2,7 @@ import React from 'react'; import { PropTypes } from 'prop-types'; import { WrapperWidgetUI, FormulaWidgetUI } from '@carto/react-ui'; import { getFormula } from '../models'; -import { AggregationTypes } from '@carto/react-core'; +import { AggregationTypes, _FeatureFlags, _hasFeatureFlag } from '@carto/react-core'; import { checkFormulaColumn, columnAggregationOn } from './utils/propTypesFns'; import useWidgetFetch from '../hooks/useWidgetFetch'; import WidgetWithAlert from './utils/WidgetWithAlert'; @@ -51,7 +51,7 @@ function FormulaWidget({ }, global, onError, - attemptRemoteCalculation: true + attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2) }); return ( diff --git a/packages/react-widgets/src/widgets/HistogramWidget.js b/packages/react-widgets/src/widgets/HistogramWidget.js index 05414dba9..580cd06f4 100644 --- a/packages/react-widgets/src/widgets/HistogramWidget.js +++ b/packages/react-widgets/src/widgets/HistogramWidget.js @@ -3,7 +3,12 @@ import { useDispatch } from 'react-redux'; import { PropTypes } from 'prop-types'; import { addFilter, removeFilter } from '@carto/react-redux'; import { WrapperWidgetUI, HistogramWidgetUI } from '@carto/react-ui'; -import { _FilterTypes as FilterTypes, AggregationTypes } from '@carto/react-core'; +import { + _FilterTypes as FilterTypes, + AggregationTypes, + _hasFeatureFlag, + _FeatureFlags +} from '@carto/react-core'; import { getHistogram } from '../models'; import { useWidgetFilterValues } from '../hooks/useWidgetFilterValues'; import useWidgetFetch from '../hooks/useWidgetFetch'; @@ -113,7 +118,7 @@ function HistogramWidget({ global, onError, enabled: !!ticks.length, - attemptRemoteCalculation: true + attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2) }); const thresholdsFromFilters = useWidgetFilterValues({ diff --git a/packages/react-widgets/src/widgets/PieWidget.js b/packages/react-widgets/src/widgets/PieWidget.js index 0338d6b82..1d42611e1 100644 --- a/packages/react-widgets/src/widgets/PieWidget.js +++ b/packages/react-widgets/src/widgets/PieWidget.js @@ -3,7 +3,12 @@ import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import { addFilter, removeFilter } from '@carto/react-redux'; import { WrapperWidgetUI, PieWidgetUI } from '@carto/react-ui'; -import { _FilterTypes as FilterTypes, AggregationTypes } from '@carto/react-core'; +import { + _FilterTypes as FilterTypes, + AggregationTypes, + _hasFeatureFlag, + _FeatureFlags +} from '@carto/react-core'; import { getCategories } from '../models'; import { useWidgetFilterValues } from '../hooks/useWidgetFilterValues'; import { columnAggregationOn } from './utils/propTypesFns'; @@ -76,7 +81,7 @@ function PieWidget({ }, global, onError, - attemptRemoteCalculation: true + attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2) }); const handleSelectedCategoriesChange = useCallback( diff --git a/packages/react-widgets/src/widgets/RangeWidget.js b/packages/react-widgets/src/widgets/RangeWidget.js index 5bed3c738..39dca5143 100644 --- a/packages/react-widgets/src/widgets/RangeWidget.js +++ b/packages/react-widgets/src/widgets/RangeWidget.js @@ -1,7 +1,11 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { PropTypes } from 'prop-types'; -import { _FilterTypes as FilterTypes } from '@carto/react-core'; +import { + _FilterTypes as FilterTypes, + _FeatureFlags, + _hasFeatureFlag +} from '@carto/react-core'; import { WrapperWidgetUI } from '@carto/react-ui'; import { addFilter, selectSourceById } from '@carto/react-redux/'; import { getRange } from '../models/RangeModel'; @@ -68,7 +72,7 @@ function RangeWidget({ }, global, onError, - attemptRemoteCalculation: true + attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2) }); const handleSelectedRangeChange = useCallback( diff --git a/packages/react-widgets/src/widgets/TimeSeriesWidget.js b/packages/react-widgets/src/widgets/TimeSeriesWidget.js index b96f18571..0796d1924 100644 --- a/packages/react-widgets/src/widgets/TimeSeriesWidget.js +++ b/packages/react-widgets/src/widgets/TimeSeriesWidget.js @@ -11,7 +11,9 @@ import { import { GroupDateTypes, AggregationTypes, - _FilterTypes as FilterTypes + _FilterTypes as FilterTypes, + _hasFeatureFlag, + _FeatureFlags } from '@carto/react-core'; import { capitalize, Menu, MenuItem, SvgIcon } from '@mui/material'; import { PropTypes } from 'prop-types'; @@ -136,7 +138,7 @@ function TimeSeriesWidget({ }, global, onError, - attemptRemoteCalculation: true + attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2) }); const handleTimeWindowUpdate = useCallback(