Skip to content

Commit

Permalink
feat: sync diff (#2414)
Browse files Browse the repository at this point in the history
Description
Enhance the basic soilDataDiff system introduced in #2279 to support tracking changes to all fields. The new methods plug into the remoteSoilDataActions methods for generating push input and populate the push input with the diff of the last-synced data from the server.

Note: this PR must be reviewed after #2413, as it builds on that changeset.
  • Loading branch information
tm-ruxandra authored Nov 13, 2024
1 parent 2e1ca7d commit 15bbaa0
Show file tree
Hide file tree
Showing 4 changed files with 485 additions and 60 deletions.
23 changes: 19 additions & 4 deletions dev-client/src/model/soilId/actions/remoteSoilDataActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import {
import * as remoteSoilData from 'terraso-client-shared/soilId/soilDataService';
import {SoilData} from 'terraso-client-shared/soilId/soilIdTypes';

import {getDeletedDepthIntervals} from 'terraso-mobile-client/model/soilId/actions/soilDataDiff';
import {
getChangedDepthDependentData,
getChangedDepthIntervals,
getChangedSoilDataFields,
getDeletedDepthIntervals,
} from 'terraso-mobile-client/model/soilId/actions/soilDataDiff';
import {
getEntityRecord,
SyncRecord,
Expand Down Expand Up @@ -69,13 +74,23 @@ export const unsyncedDataToMutationInputEntry = (
return {
siteId,
soilData: {
...soilData,
depthIntervals: soilData.depthIntervals,
depthDependentData: soilData.depthDependentData,
...getChangedSoilDataFields(soilData, record.lastSyncedData),
depthIntervals: getChangedDepthIntervals(
soilData,
record.lastSyncedData,
).map(changes => {
return {depthInterval: changes.depthInterval, ...changes.changedFields};
}),
deletedDepthIntervals: getDeletedDepthIntervals(
soilData,
record.lastSyncedData,
),
depthDependentData: getChangedDepthDependentData(
soilData,
record.lastSyncedData,
).map(changes => {
return {depthInterval: changes.depthInterval, ...changes.changedFields};
}),
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const SOIL_DATA_UPDATE_FIELDS = [
'waterTableDepthSelect',
] as const satisfies (keyof SoilData)[] & (keyof SoilDataUpdateMutationInput)[];

export type UpdateField = (typeof SOIL_DATA_UPDATE_FIELDS)[number];
export type SoilDataUpdateField = (typeof SOIL_DATA_UPDATE_FIELDS)[number];

/**
* The soil data depth interval fields which are covered by the depth interval update action.
Expand Down
Loading

0 comments on commit 15bbaa0

Please sign in to comment.