Changeset View
Changeset View
Standalone View
Standalone View
lib/reducers/report-store-reducer.js
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | return { | ||||
reportStoreOperations: [{ type: 'remove_all_reports' }], | reportStoreOperations: [{ type: 'remove_all_reports' }], | ||||
}; | }; | ||||
} else if ( | } else if ( | ||||
(action.type === sendReportActionTypes.success || | (action.type === sendReportActionTypes.success || | ||||
action.type === sendReportsActionTypes.success) && | action.type === sendReportsActionTypes.success) && | ||||
action.payload | action.payload | ||||
) { | ) { | ||||
const { payload } = action; | const { payload } = action; | ||||
const unsentReports = updatedReports.filter( | const sentReports = state.queuedReports.filter(response => | ||||
response => !payload.reports.includes(response), | payload.reports.includes(response), | ||||
); | ); | ||||
if (unsentReports.length === updatedReports.length) { | |||||
return { reportStore: state, reportStoreOperations: [] }; | const reportStoreOperations: $ReadOnlyArray<ReportStoreOperation> = [ | ||||
} | convertReportsToRemoveReportsOperation(sentReports), | ||||
...convertReportsToReplaceReportOps(newReports), | |||||
]; | |||||
const queuedReports = processReportStoreOperations( | |||||
state.queuedReports, | |||||
reportStoreOperations, | |||||
); | |||||
return { | return { | ||||
reportStore: { ...state, queuedReports: unsentReports }, | reportStore: { ...state, queuedReports }, | ||||
reportStoreOperations: [], | reportStoreOperations, | ||||
}; | }; | ||||
} else if (action.type === queueReportsActionType) { | } else if (action.type === queueReportsActionType) { | ||||
const { reports } = action.payload; | const { reports } = action.payload; | ||||
const filteredReports = [...updatedReports, ...reports].filter(report => | const filteredReports = [...updatedReports, ...reports].filter(report => | ||||
isReportEnabled(report, state.enabledReports), | isReportEnabled(report, state.enabledReports), | ||||
); | ); | ||||
return { | return { | ||||
reportStore: { | reportStore: { | ||||
Show All 13 Lines |