Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATAP-1548 - Aggregations api logic bug fix #547

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/actions/__tests__/complaints.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const mockStore = configureMockStore(middlewares);
*/
function setupStore(tab) {
return mockStore({
aggs: {},
map: {},
query: {
tab,
Expand Down Expand Up @@ -83,6 +84,7 @@ describe('action::complaints', () => {
});
/* eslint-enable id-length */
store = mockStore({
aggs: {},
query: {
date_received_min: new Date(2013, 1, 3),
from: 0,
Expand All @@ -104,7 +106,7 @@ describe('action::complaints', () => {

it('discards duplicate API calls', () => {
const state = store.getState();
state.results.loadingAggregations = true;
state.aggs.activeCall = '@@API?foo&size=0';
store = mockStore(state);

store.dispatch(sut.getAggregations());
Expand Down Expand Up @@ -236,15 +238,17 @@ describe('action::complaints', () => {
});
/* eslint-enable id-length */
it('calls the API', () => {
const store = mockStore({});
const store = mockStore({ detail: {} });
store.dispatch(sut.getComplaintDetail('123'));
expect(global.fetch).toHaveBeenCalled();
});

describe('when the API call is finished', () => {
let store;
beforeEach(() => {
store = mockStore({});
store = mockStore({
detail: {},
});
store.dispatch(sut.getComplaintDetail('123'));
});

Expand Down
15 changes: 12 additions & 3 deletions src/actions/complaints.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ export function sendHitsQuery() {
export function getAggregations() {
return (dispatch, getState) => {
const store = getState();
const qs = store.query.queryString;
const regex = /&size=\d+&/gm;
// remove the duplicate size from the qs
const qs = store.query.queryString.replace(regex, '&');
const uri = API_PLACEHOLDER + qs + '&size=0';

// This call is already in process
if (store.results.loadingAggregations) {
if (uri === store.aggs.activeCall) {
return null;
}

Expand Down Expand Up @@ -133,8 +135,15 @@ export function getComplaints() {
* @returns {Promise} a chain of promises that will update the Redux store
*/
export function getComplaintDetail(id) {
return (dispatch) => {
return (dispatch, getState) => {
const store = getState();
const uri = API_PLACEHOLDER + id;

// This call is already in process
if (uri === store.detail.activeCall) {
return null;
}

dispatch(callingApi(COMPLAINT_DETAIL_CALLED, uri));
fetch(uri)
.then((result) => result.json())
Expand Down
1 change: 1 addition & 0 deletions src/middleware/__tests__/queryManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function setupStore(viewMode = 'Map') {
const middlewares = [thunk, queryManager];
const mockStore = configureMockStore(middlewares);
return mockStore({
aggs: {},
map: {
activeCall: '',
},
Expand Down
1 change: 0 additions & 1 deletion src/reducers/aggs/aggs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const defaultAggs = {
error: '',
lastUpdated: null,
lastIndexed: null,
loadingAggregations: false,
hasDataIssue: false,
isDataStale: false,
company: [],
Expand Down