Page MenuHomePhabricator

D7921.id26805.diff
No OneTemporary

D7921.id26805.diff

diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js
--- a/lib/reducers/master-reducer.js
+++ b/lib/reducers/master-reducer.js
@@ -85,6 +85,12 @@
action,
);
+ const { reportStore, reportStoreOperations } = reduceReportStore(
+ state.reportStore,
+ action,
+ newInconsistencies,
+ );
+
return {
state: {
...state,
@@ -106,11 +112,7 @@
connection,
lifecycleState: reduceLifecycleState(state.lifecycleState, action),
enabledApps: reduceEnabledApps(state.enabledApps, action),
- reportStore: reduceReportStore(
- state.reportStore,
- action,
- newInconsistencies,
- ),
+ reportStore,
nextLocalID: reduceNextLocalID(state.nextLocalID, action),
dataLoaded: reduceDataLoaded(state.dataLoaded, action),
userPolicies: policiesReducer(state.userPolicies, action),
@@ -124,6 +126,7 @@
draftStoreOperations,
threadStoreOperations,
messageStoreOperations,
+ reportStoreOperations,
},
};
}
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
@@ -11,6 +11,7 @@
deleteAccountActionTypes,
logInActionTypes,
} from '../actions/user-actions.js';
+import type { ReportStoreOperation } from '../ops/report-store-ops.js';
import { isStaff } from '../shared/staff-utils.js';
import type { BaseAction } from '../types/redux-types.js';
import {
@@ -29,7 +30,10 @@
state: ReportStore,
action: BaseAction,
newInconsistencies: $ReadOnlyArray<ClientReportCreationRequest>,
-): ReportStore {
+): {
+ reportStore: ReportStore,
+ reportStoreOperations: $ReadOnlyArray<ReportStoreOperation>,
+} {
const updatedReports =
newInconsistencies.length > 0
? [...state.queuedReports, ...newInconsistencies].filter(report =>
@@ -43,8 +47,11 @@
isReportEnabled(report, newEnabledReports),
);
return {
- queuedReports: filteredReports,
- enabledReports: newEnabledReports,
+ reportStore: {
+ queuedReports: filteredReports,
+ enabledReports: newEnabledReports,
+ },
+ reportStoreOperations: [],
};
} else if (
action.type === logOutActionTypes.success ||
@@ -53,19 +60,27 @@
action.payload.sessionChange.cookieInvalidated)
) {
return {
- queuedReports: [],
- enabledReports: isDev ? defaultDevEnabledReports : defaultEnabledReports,
+ reportStore: {
+ queuedReports: [],
+ enabledReports: isDev
+ ? defaultDevEnabledReports
+ : defaultEnabledReports,
+ },
+ reportStoreOperations: [],
};
} else if (
action.type === logInActionTypes.success ||
action.type === siweAuthActionTypes.success
) {
return {
- queuedReports: [],
- enabledReports:
- isStaff(action.payload.currentUserInfo.id) || isDev
- ? defaultDevEnabledReports
- : defaultEnabledReports,
+ reportStore: {
+ queuedReports: [],
+ enabledReports:
+ isStaff(action.payload.currentUserInfo.id) || isDev
+ ? defaultDevEnabledReports
+ : defaultEnabledReports,
+ },
+ reportStoreOperations: [],
};
} else if (
(action.type === sendReportActionTypes.success ||
@@ -77,20 +92,29 @@
response => !payload.reports.includes(response),
);
if (unsentReports.length === updatedReports.length) {
- return state;
+ return { reportStore: state, reportStoreOperations: [] };
}
- return { ...state, queuedReports: unsentReports };
+ return {
+ reportStore: { ...state, queuedReports: unsentReports },
+ reportStoreOperations: [],
+ };
} else if (action.type === queueReportsActionType) {
const { reports } = action.payload;
const filteredReports = [...updatedReports, ...reports].filter(report =>
isReportEnabled(report, state.enabledReports),
);
return {
- ...state,
- queuedReports: filteredReports,
+ reportStore: {
+ ...state,
+ queuedReports: filteredReports,
+ },
+ reportStoreOperations: [],
};
}
- return updatedReports !== state.queuedReports
- ? { ...state, queuedReports: updatedReports }
- : state;
+ const reportStore =
+ updatedReports !== state.queuedReports
+ ? { ...state, queuedReports: updatedReports }
+ : state;
+
+ return { reportStore, reportStoreOperations: [] };
}
diff --git a/lib/reducers/report-store-reducer.test.js b/lib/reducers/report-store-reducer.test.js
--- a/lib/reducers/report-store-reducer.test.js
+++ b/lib/reducers/report-store-reducer.test.js
@@ -89,15 +89,21 @@
test('should handle log out', () => {
const action = { ...defaultAction, type: 'LOG_OUT_SUCCESS' };
- const result = reduceReportStore(defaultReportStore, action, []);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [],
+ );
expect(result.queuedReports).toHaveLength(0);
});
test('should handle log out with new inconsistencies', () => {
const action = { ...defaultAction, type: 'LOG_OUT_SUCCESS' };
- const result = reduceReportStore(defaultReportStore, action, [
- mockErrorReport,
- ]);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [mockErrorReport],
+ );
expect(result.queuedReports).toHaveLength(0);
});
@@ -107,7 +113,11 @@
payload: mockLogInResult,
loadingInfo,
};
- const result = reduceReportStore(defaultReportStore, action, []);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [],
+ );
expect(result.queuedReports).toHaveLength(0);
});
@@ -117,9 +127,11 @@
payload: mockLogInResult,
loadingInfo,
};
- const result = reduceReportStore(defaultReportStore, action, [
- mockErrorReport,
- ]);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [mockErrorReport],
+ );
expect(result.queuedReports).toHaveLength(0);
});
});
@@ -130,7 +142,11 @@
type: 'UPDATE_REPORTS_ENABLED',
payload: defaultEnabledReports,
};
- const result = reduceReportStore(defaultReportStore, action, []);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [],
+ );
expect(result.queuedReports).toStrictEqual(
defaultReportStore.queuedReports,
);
@@ -145,7 +161,11 @@
mediaReports: false,
},
};
- const result = reduceReportStore(defaultReportStore, action, []);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [],
+ );
expect(result.queuedReports).toHaveLength(1);
const enabledReportsExist = result.queuedReports.some(
report => report.type === reportTypes.ERROR,
@@ -166,10 +186,11 @@
mediaReports: false,
},
};
- const result = reduceReportStore(defaultReportStore, action, [
- mockMediaReport,
- mockErrorReport,
- ]);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [mockMediaReport, mockErrorReport],
+ );
expect(result.queuedReports).toHaveLength(2);
const enabledReports = result.queuedReports.filter(
report => report.type === reportTypes.ERROR,
@@ -198,7 +219,7 @@
mediaReports: false,
},
};
- const result = reduceReportStore(reportStore, action, [
+ const { reportStore: result } = reduceReportStore(reportStore, action, [
mockErrorReport,
mockInconsistencyReport,
]);
@@ -216,7 +237,7 @@
describe('sending report test', () => {
test('should remove sent report', () => {
- const reportStore = reduceReportStore(
+ const { reportStore } = reduceReportStore(
defaultEmptyReportStore,
defaultBaseAction,
[mockErrorReport, mockMediaReport],
@@ -231,14 +252,14 @@
},
loadingInfo,
};
- const result = reduceReportStore(reportStore, action, []);
+ const { reportStore: result } = reduceReportStore(reportStore, action, []);
expect(result.queuedReports).toHaveLength(1);
expect(result.queuedReports).toContain(notSentReport);
expect(result.queuedReports).not.toContain(sentReport);
});
test('should remove sent report and handle new inconsistencies', () => {
- const reportStore = reduceReportStore(
+ const { reportStore } = reduceReportStore(
defaultEmptyReportStore,
defaultBaseAction,
[mockErrorReport, mockMediaReport],
@@ -253,7 +274,7 @@
},
loadingInfo,
};
- const result = reduceReportStore(reportStore, action, [
+ const { reportStore: result } = reduceReportStore(reportStore, action, [
mockInconsistencyReport,
]);
expect(result.queuedReports).toHaveLength(2);
@@ -264,7 +285,7 @@
describe('new inconsistencies test', () => {
test('should handle new inconsistencies without any action', () => {
- const reportStore = reduceReportStore(
+ const { reportStore } = reduceReportStore(
{
queuedReports: [mockErrorReport],
enabledReports: {
diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js
--- a/lib/types/store-ops-types.js
+++ b/lib/types/store-ops-types.js
@@ -16,11 +16,13 @@
ClientDBThreadStoreOperation,
ThreadStoreOperation,
} from './thread-types.js';
+import type { ReportStoreOperation } from '../ops/report-store-ops.js';
export type StoreOperations = {
+draftStoreOperations: $ReadOnlyArray<DraftStoreOperation>,
+threadStoreOperations: $ReadOnlyArray<ThreadStoreOperation>,
+messageStoreOperations: $ReadOnlyArray<MessageStoreOperation>,
+ +reportStoreOperations: $ReadOnlyArray<ReportStoreOperation>,
};
export type ClientDBStoreOperations = {

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 8:23 AM (17 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2694124
Default Alt Text
D7921.id26805.diff (9 KB)

Event Timeline