Page MenuHomePhabricator

D7923.id27141.diff
No OneTemporary

D7923.id27141.diff

diff --git a/lib/ops/report-store-ops.js b/lib/ops/report-store-ops.js
--- a/lib/ops/report-store-ops.js
+++ b/lib/ops/report-store-ops.js
@@ -46,4 +46,26 @@
return processedReports;
}
-export { processReportStoreOperations };
+function convertReportsToReplaceReportOps(
+ reports: $ReadOnlyArray<ClientReportCreationRequest>,
+): $ReadOnlyArray<ReplaceQueuedReportOperation> {
+ return reports.map(report => ({
+ type: 'replace_report',
+ payload: { report },
+ }));
+}
+
+function convertReportsToRemoveReportsOperation(
+ reports: $ReadOnlyArray<ClientReportCreationRequest>,
+): RemoveQueuedReportsOperation {
+ return {
+ type: 'remove_reports',
+ payload: { ids: reports.map(report => report.id) },
+ };
+}
+
+export {
+ processReportStoreOperations,
+ convertReportsToReplaceReportOps,
+ convertReportsToRemoveReportsOperation,
+};
diff --git a/lib/reducers/report-store-reducer.js b/lib/reducers/report-store-reducer.js
--- a/lib/reducers/report-store-reducer.js
+++ b/lib/reducers/report-store-reducer.js
@@ -12,6 +12,11 @@
logInActionTypes,
} from '../actions/user-actions.js';
import type { ReportStoreOperation } from '../ops/report-store-ops.js';
+import {
+ convertReportsToRemoveReportsOperation,
+ convertReportsToReplaceReportOps,
+ processReportStoreOperations,
+} from '../ops/report-store-ops.js';
import { isStaff } from '../shared/staff-utils.js';
import type { BaseAction } from '../types/redux-types.js';
import {
@@ -34,6 +39,10 @@
reportStore: ReportStore,
reportStoreOperations: $ReadOnlyArray<ReportStoreOperation>,
} {
+ const newReports = newInconsistencies.filter(report =>
+ isReportEnabled(report, state.enabledReports),
+ );
+
const updatedReports =
newInconsistencies.length > 0
? [...state.queuedReports, ...newInconsistencies].filter(report =>
@@ -43,15 +52,29 @@
if (action.type === updateReportsEnabledActionType) {
const newEnabledReports = { ...state.enabledReports, ...action.payload };
- const filteredReports = updatedReports.filter(report =>
+ const newFilteredReports = newReports.filter(report =>
isReportEnabled(report, newEnabledReports),
);
+ const reportsToRemove = state.queuedReports.filter(
+ report => !isReportEnabled(report, newEnabledReports),
+ );
+
+ const reportStoreOperations: $ReadOnlyArray<ReportStoreOperation> = [
+ convertReportsToRemoveReportsOperation(reportsToRemove),
+ ...convertReportsToReplaceReportOps(newFilteredReports),
+ ];
+
+ const queuedReports = processReportStoreOperations(
+ state.queuedReports,
+ reportStoreOperations,
+ );
+
return {
reportStore: {
- queuedReports: filteredReports,
+ queuedReports,
enabledReports: newEnabledReports,
},
- reportStoreOperations: [],
+ reportStoreOperations,
};
} else if (
action.type === logOutActionTypes.success ||

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 6:57 AM (18 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2693264
Default Alt Text
D7923.id27141.diff (2 KB)

Event Timeline