Skip to content

Commit

Permalink
Remote calculation controlled by Feature Flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Pettini committed May 4, 2023
1 parent f10b102 commit 32f47cc
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 15 deletions.
5 changes: 4 additions & 1 deletion packages/react-core/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { _FeatureFlags } from '.';

export {
getRequest,
postRequest,
Expand Down Expand Up @@ -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';
} from './utils/featureFlags';
1 change: 1 addition & 0 deletions packages/react-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export {
} from './utils/featureSelectionConstants';

export {
Flags as _FeatureFlags,
hasFlag as _hasFeatureFlag,
setFlags as _setFeatureFlags,
clearFlags as _clearFeatureFlags
Expand Down
3 changes: 3 additions & 0 deletions packages/react-core/src/utils/featureFlags.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export enum Flags {
DYNAMIC_TILING_V2 = '2023-dynamic-tiling-v-2'
}
export function setFlags(flags: Record<string, any> | string[]): void
export function clearFlags(): void
export function hasFlag(flag: string): boolean
4 changes: 4 additions & 0 deletions packages/react-core/src/utils/featureFlags.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
9 changes: 7 additions & 2 deletions packages/react-widgets/src/widgets/BarWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -77,7 +82,7 @@ function BarWidget({
},
global,
onError,
attemptRemoteCalculation: true
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2)
});

const sortedData = useMemo(() => {
Expand Down
9 changes: 7 additions & 2 deletions packages/react-widgets/src/widgets/CategoryWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,7 +79,7 @@ function CategoryWidget(props) {
},
global,
onError,
attemptRemoteCalculation: true
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2)
});

const handleSelectedCategoriesChange = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions packages/react-widgets/src/widgets/FormulaWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,7 +51,7 @@ function FormulaWidget({
},
global,
onError,
attemptRemoteCalculation: true
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2)
});

return (
Expand Down
9 changes: 7 additions & 2 deletions packages/react-widgets/src/widgets/HistogramWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -113,7 +118,7 @@ function HistogramWidget({
global,
onError,
enabled: !!ticks.length,
attemptRemoteCalculation: true
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2)
});

const thresholdsFromFilters = useWidgetFilterValues({
Expand Down
9 changes: 7 additions & 2 deletions packages/react-widgets/src/widgets/PieWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -76,7 +81,7 @@ function PieWidget({
},
global,
onError,
attemptRemoteCalculation: true
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2)
});

const handleSelectedCategoriesChange = useCallback(
Expand Down
8 changes: 6 additions & 2 deletions packages/react-widgets/src/widgets/RangeWidget.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -68,7 +72,7 @@ function RangeWidget({
},
global,
onError,
attemptRemoteCalculation: true
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2)
});

const handleSelectedRangeChange = useCallback(
Expand Down
6 changes: 4 additions & 2 deletions packages/react-widgets/src/widgets/TimeSeriesWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -136,7 +138,7 @@ function TimeSeriesWidget({
},
global,
onError,
attemptRemoteCalculation: true
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.DYNAMIC_TILING_V2)
});

const handleTimeWindowUpdate = useCallback(
Expand Down

0 comments on commit 32f47cc

Please sign in to comment.