Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3515434
D7921.id27132.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D7921.id27132.diff
View Options
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
@@ -86,6 +86,12 @@
action,
);
+ const { reportStore, reportStoreOperations } = reduceReportStore(
+ state.reportStore,
+ action,
+ newInconsistencies,
+ );
+
return {
state: {
...state,
@@ -111,11 +117,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),
@@ -130,6 +132,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,14 @@
mediaReports: false,
},
};
- const result = reduceReportStore(defaultReportStore, action, [
- { ...mockErrorReport, id: 'new-id-error' },
- { ...mockMediaReport, id: 'new-id-media' },
- ]);
+ const { reportStore: result } = reduceReportStore(
+ defaultReportStore,
+ action,
+ [
+ { ...mockErrorReport, id: 'new-id-error' },
+ { ...mockMediaReport, id: 'new-id-media' },
+ ],
+ );
expect(result.queuedReports).toHaveLength(2);
const enabledReports = result.queuedReports.filter(
report => report.type === reportTypes.ERROR,
@@ -201,7 +225,7 @@
mediaReports: false,
},
};
- const result = reduceReportStore(reportStore, action, [
+ const { reportStore: result } = reduceReportStore(reportStore, action, [
{ ...mockErrorReport, id: 'new-id-error-inc' },
{ ...mockMediaReport, id: 'new-id-media-inc' },
]);
@@ -219,7 +243,7 @@
describe('sending report test', () => {
test('should remove sent report', () => {
- const reportStore = reduceReportStore(
+ const { reportStore } = reduceReportStore(
defaultEmptyReportStore,
defaultBaseAction,
[mockErrorReport, mockMediaReport],
@@ -234,14 +258,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],
@@ -256,7 +280,7 @@
},
loadingInfo,
};
- const result = reduceReportStore(reportStore, action, [
+ const { reportStore: result } = reduceReportStore(reportStore, action, [
mockInconsistencyReport,
]);
expect(result.queuedReports).toHaveLength(2);
@@ -267,7 +291,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 = {
diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js
--- a/native/redux/redux-setup.js
+++ b/native/redux/redux-setup.js
@@ -302,6 +302,7 @@
},
],
threadStoreOperations: [],
+ reportStoreOperations: [],
});
}
return state;
@@ -363,6 +364,7 @@
draftStoreOperations,
messageStoreOperations,
threadStoreOperations: threadStoreOperationsWithUnreadFix,
+ reportStoreOperations: [],
});
return state;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 8:54 AM (18 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2693352
Default Alt Text
D7921.id27132.diff (10 KB)
Attached To
Mode
D7921: [lib] refactor types to allow returning report store operations
Attached
Detach File
Event Timeline
Log In to Comment