Skip to content

Commit

Permalink
[Enhancement] add changedFilters to datasets when filter data is call…
Browse files Browse the repository at this point in the history
…ed (#1396)

* add colorMap in layer-factory, pass fields to layer.getHoverData
* add filterRecord and changedFilters to datasets
* better handle item-selector placeholder default value

Signed-off-by: Shan He <heshan0131@gmail.com>
  • Loading branch information
heshan0131 committed Jan 17, 2021
1 parent 8d68001 commit f0e5174
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/common/item-selector/chickleted-input.js
Expand Up @@ -132,7 +132,7 @@ const ChickletedInput = ({
})
) : (
<span className={`${className} chickleted-input__placeholder`}>
<FormattedMessage id={placeholder} />
<FormattedMessage id={placeholder || 'placeholder.enterValue'} />
</span>
)}
</ChickletedInputContainer>
Expand Down
4 changes: 3 additions & 1 deletion src/components/common/item-selector/item-selector.js
Expand Up @@ -313,7 +313,9 @@ class ItemSelector extends Component {
light={this.props.inputTheme === 'light'}
/>
) : (
<FormattedMessage id={this.props.placeholder} />
<FormattedMessage
id={this.props.placeholder || 'placeholder.selectValue'}
/>
)}
</DropdownSelectValue>
{this.props.erasable && hasValue ? (
Expand Down
Expand Up @@ -61,7 +61,7 @@ function FieldPanelWithFieldSelectFactory(
]);

const fieldValue = useMemo(
() => (Array.isArray(filter.name) ? filter.name[0] : filter.name),
() => ((Array.isArray(filter.name) ? filter.name[0] : filter.name)),
[filter.name]
);

Expand Down
1 change: 1 addition & 0 deletions src/layers/layer-factory.d.ts
Expand Up @@ -6,6 +6,7 @@ export type ColorRange = {
category: string;
colors: HexColor[];
reversed?: boolean;
colorMap?: Map | object;
};

export type LayerTextLabel = {
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/vis-state-updaters.js
Expand Up @@ -557,8 +557,8 @@ export function setFilterAnimationWindowUpdater(state, {id, animationWindow}) {
*/
export function setFilterUpdater(state, action) {
const {idx, prop, value, valueIndex = 0} = action;

const oldFilter = state.filters[idx];

if (!oldFilter) {
Console.error(`filters.${idx} is undefined`);
return state;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/filter-utils.js
Expand Up @@ -488,7 +488,7 @@ export function filterDataset(dataset, filters, layers, opt) {
// if there is no filters
const filterRecord = getFilterRecord(dataId, filters, opt || {});

const newDataset = set(['filterRecord'], filterRecord, dataset);
let newDataset = set(['filterRecord'], filterRecord, dataset);

if (!filters.length) {
return {
Expand All @@ -500,6 +500,7 @@ export function filterDataset(dataset, filters, layers, opt) {
}

const changedFilters = diffFilters(filterRecord, oldFilterRecord);
newDataset = set(['changedFilters'], changedFilters, newDataset);

// generate 2 sets of filter result
// filteredIndex used to calculate layer data
Expand Down
2 changes: 1 addition & 1 deletion src/utils/layer-utils.js
Expand Up @@ -96,7 +96,7 @@ export function getLayerHoverProp({
return null;
}
const {allData, fields} = datasets[dataId];
const data = layer.getHoverData(object, allData);
const data = layer.getHoverData(object, allData, fields);
const fieldsToShow = interactionConfig.tooltip.config.fieldsToShow[dataId];

return {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/test-hex-id-data.js
Expand Up @@ -455,5 +455,11 @@ export const expectedMergedDataset = {
fixedDomain: [],
cpu: [],
gpu: [mergedFilters[0]]
},
changedFilters: {
dynamicDomain: {byjasfp0u: 'added'},
fixedDomain: null,
cpu: null,
gpu: {byjasfp0u: 'added'}
}
};
14 changes: 13 additions & 1 deletion test/node/reducers/vis-state-merger-test.js
Expand Up @@ -1615,6 +1615,12 @@ test('VisStateMerger.v1 -> mergeFilters -> multiFilters', t => {
],
result: [1474588800000 - 1474588800000, 1472688000000 - 1472688000000, 0, 0]
}
},
changedFilters: {
dynamicDomain: {'date-2': 'added'},
fixedDomain: {'time-0': 'added', 'epoch-4': 'added'},
cpu: {'date-2': 'added'},
gpu: {'time-0': 'added', 'epoch-4': 'added'}
}
},
[testGeoJsonDataId]: {
Expand Down Expand Up @@ -1667,7 +1673,13 @@ test('VisStateMerger.v1 -> mergeFilters -> multiFilters', t => {
color: 'donot test me',
filteredIndex: [0],
filteredIndexForDomain: [0],
fieldPairs: oldGeoJsonData.fieldPairs
fieldPairs: oldGeoJsonData.fieldPairs,
changedFilters: {
dynamicDomain: {'RATE-1': 'added', 'TRIPS-3': 'added'},
fixedDomain: null,
cpu: {'RATE-1': 'added'},
gpu: {'TRIPS-3': 'added'}
}
}
};

Expand Down
52 changes: 42 additions & 10 deletions test/node/reducers/vis-state-test.js
Expand Up @@ -1624,7 +1624,13 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {
},
suffix: ['lat', 'lng']
}
]
],
changedFilters: {
dynamicDomain: {'38chejr': 'added'},
fixedDomain: null,
cpu: null,
gpu: {'38chejr': 'added'}
}
}
};

Expand Down Expand Up @@ -1904,7 +1910,8 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
},
suffix: ['lat', 'lng']
}
]
],
changedFilters: {dynamicDomain: null, fixedDomain: null, cpu: null, gpu: null}
};

cmpDataset(t, expectedDataset, stateWithFilterName.datasets.smoothie);
Expand All @@ -1924,7 +1931,6 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
cmpFilters(t, expectedFilterWValue, stateWithFilterValue.filters[0]);

const updatedFilterWValue = stateWithFilterValue.filters[0];

const expectedFilteredDataset = {
...expectedDataset,
filterRecord: {
Expand All @@ -1935,7 +1941,13 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
},
allData,
filteredIndex: [17, 18, 19, 20, 21, 22],
filteredIndexForDomain: [17, 18, 19, 20, 21, 22]
filteredIndexForDomain: [17, 18, 19, 20, 21, 22],
changedFilters: {
dynamicDomain: {[updatedFilterWValue.id]: 'added'},
fixedDomain: null,
cpu: {[updatedFilterWValue.id]: 'added'},
gpu: null
}
};

cmpDataset(t, expectedFilteredDataset, stateWithFilterValue.datasets.smoothie);
Expand Down Expand Up @@ -2101,7 +2113,7 @@ function testSetFilterDynamicDomainGPU(t, setFilter) {

// set filter value
const stateWithFilterValue = reducer(stateWithFilterName, setFilter(0, 'value', [8, 20]));

const filterId = stateWithFilterName.filters[0].id;
const expectedFilterWValue = {
...expectedFilterWName,
value: [8, 20]
Expand Down Expand Up @@ -2150,7 +2162,13 @@ function testSetFilterDynamicDomainGPU(t, setFilter) {
},
filteredIndex: geojsonData.features.map((_, i) => i),
filteredIndexForDomain: [0, 2],
allIndexes: geojsonData.features.map((_, i) => i)
allIndexes: geojsonData.features.map((_, i) => i),
changedFilters: {
dynamicDomain: {[filterId]: 'value_changed'},
fixedDomain: null,
cpu: null,
gpu: {[filterId]: 'value_changed'}
}
};

const actualTripField = stateWithFilterValue.datasets.milkshake.fields[4];
Expand Down Expand Up @@ -2243,11 +2261,13 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
}
]);

const filterId = stateWidthTsFilter.filters[0].id;

const expectedFilterTs = {
dataId: ['smoothie'],
freeze: true,
fixedDomain: true,
id: 'dont test me',
id: filterId,
name: ['gps_data.utc_timestamp'],
type: 'timeRange',
fieldIdx: [0],
Expand Down Expand Up @@ -2345,7 +2365,13 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
},
// copy everything
filteredIndex: datasetSmoothie.allData.map((d, i) => i),
filteredIndexForDomain: datasetSmoothie.allData.map((d, i) => i)
filteredIndexForDomain: datasetSmoothie.allData.map((d, i) => i),
changedFilters: {
dynamicDomain: null,
fixedDomain: {[filterId]: 'value_changed'},
cpu: null,
gpu: {[filterId]: 'value_changed'}
}
};

// check filter by ts
Expand All @@ -2367,7 +2393,7 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
payload: [1, 'value', ['2016-09-24', '2016-10-10']]
}
]);

const filterId1 = stateWidthTsAndNameFilter.filters[1].id;
const expectedFilteredDataset = {
...stateWidthTsFilter.datasets.smoothie,
fields: stateWidthTsFilter.datasets.smoothie.fields.map(f =>
Expand Down Expand Up @@ -2409,7 +2435,13 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
gpu: [stateWidthTsAndNameFilter.filters[0]]
},
filteredIndex: [7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22],
filteredIndexForDomain: [7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22]
filteredIndexForDomain: [7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22],
changedFilters: {
dynamicDomain: {[filterId1]: 'added'},
fixedDomain: null,
cpu: {[filterId1]: 'added'},
gpu: null
}
};

cmpDataset(t, expectedFilteredDataset, stateWidthTsAndNameFilter.datasets.smoothie);
Expand Down

0 comments on commit f0e5174

Please sign in to comment.