Skip to content

Commit

Permalink
refactor: rename misleading 'soil id' slice to 'soil data'
Browse files Browse the repository at this point in the history
  • Loading branch information
tm-ruxandra committed Dec 12, 2024
1 parent bb22e76 commit 8141b57
Show file tree
Hide file tree
Showing 62 changed files with 120 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
selectSyncErrorSites,
selectUnsyncedSiteIds,
selectUnsyncedSites,
} from 'terraso-mobile-client/model/soilId/soilIdSelectors';
} from 'terraso-mobile-client/model/soilData/soilDataSelectors';
import {
markEntityError,
markEntityModified,
Expand All @@ -43,7 +43,7 @@ const appState = (): AppState => {
preferences: {colorWorkflow: 'MANUAL'},
project: {projects: {}},
site: {sites: {}},
soilId: {
soilData: {
projectSettings: {},
soilSync: {},
soilData: {},
Expand Down Expand Up @@ -72,8 +72,8 @@ describe('selectUnsyncedSites', () => {
test('selects unsynced sites only', () => {
const state = appState();
const now = Date.now();
markEntitySynced(state.soilId.soilSync, 'a', {value: soilData()}, now);
markEntityModified(state.soilId.soilSync, 'b', now);
markEntitySynced(state.soilData.soilSync, 'a', {value: soilData()}, now);
markEntityModified(state.soilData.soilSync, 'b', now);

const selected = renderSelectorHook(
() => useSelector(selectUnsyncedSites),
Expand All @@ -87,7 +87,7 @@ describe('selectUnsyncedSites', () => {

test('returns stable values for input states only', () => {
const stateA = appState();
markEntityModified(stateA.soilId.soilSync, 'a', Date.now());
markEntityModified(stateA.soilData.soilSync, 'a', Date.now());

const selectedA1 = renderSelectorHook(
() => useSelector(selectUnsyncedSites),
Expand All @@ -99,7 +99,7 @@ describe('selectUnsyncedSites', () => {
);

const stateB = cloneDeep(stateA);
markEntityModified(stateB.soilId.soilSync, 'b', Date.now());
markEntityModified(stateB.soilData.soilSync, 'b', Date.now());

const selectedB = renderSelectorHook(
() => useSelector(selectUnsyncedSites),
Expand All @@ -116,10 +116,10 @@ describe('selectUnsyncedSiteIds', () => {
test('selects unsynced site IDs only, sorted', () => {
const state = appState();
const now = Date.now();
markEntitySynced(state.soilId.soilSync, 'a', {value: soilData()}, now);
markEntitySynced(state.soilData.soilSync, 'a', {value: soilData()}, now);

markEntityModified(state.soilId.soilSync, 'c', now);
markEntityModified(state.soilId.soilSync, 'b', now);
markEntityModified(state.soilData.soilSync, 'c', now);
markEntityModified(state.soilData.soilSync, 'b', now);

const selected = renderSelectorHook(
() => useSelector(selectUnsyncedSiteIds),
Expand All @@ -131,7 +131,7 @@ describe('selectUnsyncedSiteIds', () => {

test('returns stable values for input states', () => {
const stateA = appState();
markEntityModified(stateA.soilId.soilSync, 'a', Date.now());
markEntityModified(stateA.soilData.soilSync, 'a', Date.now());

const selectedA1 = renderSelectorHook(
() => useSelector(selectUnsyncedSiteIds),
Expand All @@ -143,7 +143,7 @@ describe('selectUnsyncedSiteIds', () => {
);

const stateB = cloneDeep(stateA);
markEntityModified(stateB.soilId.soilSync, 'b', Date.now());
markEntityModified(stateB.soilData.soilSync, 'b', Date.now());

const selectedB = renderSelectorHook(
() => useSelector(selectUnsyncedSiteIds),
Expand All @@ -160,9 +160,9 @@ describe('selectSyncErrorSites', () => {
test('selects sync error sites only', () => {
const state = appState();
const now = Date.now();
markEntitySynced(state.soilId.soilSync, 'a', {value: soilData()}, now);
markEntitySynced(state.soilData.soilSync, 'a', {value: soilData()}, now);
markEntityError(
state.soilId.soilSync,
state.soilData.soilSync,
'b',
{revisionId: 1, value: 'DOES_NOT_EXIST'},
now,
Expand All @@ -185,7 +185,7 @@ describe('selectSyncErrorSites', () => {
test('returns stable values for input states', () => {
const stateA = appState();
markEntityError(
stateA.soilId.soilSync,
stateA.soilData.soilSync,
'a',
{value: 'DOES_NOT_EXIST'},
Date.now(),
Expand All @@ -202,7 +202,7 @@ describe('selectSyncErrorSites', () => {

const stateB = cloneDeep(stateA);
markEntityError(
stateB.soilId.soilSync,
stateB.soilData.soilSync,
'b',
{revisionId: 1, value: 'DOES_NOT_EXIST'},
Date.now(),
Expand Down
4 changes: 2 additions & 2 deletions dev-client/__tests__/integration/store/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {SerializableSet} from 'terraso-client-shared/store/utils';
import {
DEFAULT_ENABLED_SOIL_PIT_METHODS,
DEPTH_INTERVAL_PRESETS,
} from 'terraso-mobile-client/model/soilId/soilDataConstants';
} from 'terraso-mobile-client/model/soilData/soilDataConstants';
import {
DepthInterval,
methodEnabled,
Expand All @@ -47,7 +47,7 @@ import {
SoilPitMethod,
soilPitMethods,
SoilState,
} from 'terraso-mobile-client/model/soilId/soilIdSlice';
} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {createStore} from 'terraso-mobile-client/store';
import {
selectProjectMembershipsWithUsers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {SoilIdSoilDataDepthIntervalPresetChoices} from 'terraso-client-shared/gr

import * as appStateHooks from 'terraso-mobile-client/hooks/appStateHooks';
import * as connectivityHooks from 'terraso-mobile-client/hooks/connectivityHooks';
import {LoadingState} from 'terraso-mobile-client/model/soilId/soilIdSlice';
import {LoadingState} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {AppState as ReduxAppState} from 'terraso-mobile-client/store';
import * as syncHooks from 'terraso-mobile-client/store/sync/hooks/syncHooks';
import {PullDispatcher} from 'terraso-mobile-client/store/sync/PullDispatcher';
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('PullDispatcher', () => {
} as Partial<ReduxAppState>;

const stateWithUnsyncedSites = {
soilId: {
soilData: {
soilData: {},
projectSettings: {},
status: 'ready' as LoadingState,
Expand Down
4 changes: 2 additions & 2 deletions dev-client/__tests__/snapshot/SlopeScreen-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import {render} from '@testing/integration/utils';
import {collectionMethods} from 'terraso-client-shared/soilId/soilIdTypes';
import {fromEntries} from 'terraso-client-shared/utils';

import {methodRequired} from 'terraso-mobile-client/model/soilId/soilIdSlice';
import {methodRequired} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {SlopeScreen} from 'terraso-mobile-client/screens/SlopeScreen/SlopeScreen';

test('renders correctly', () => {
const screen = render(<SlopeScreen siteId="1" />, {
route: 'SITE_TABS',
initialState: {
...testState,
soilId: {
soilData: {
status: 'ready',
soilData: {
'1': {
Expand Down
2 changes: 1 addition & 1 deletion dev-client/src/components/AddDepthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {Box} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {
DepthInterval,
LabelledDepthInterval,
} from 'terraso-mobile-client/model/soilId/soilIdSlice';
} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {depthSchema} from 'terraso-mobile-client/schemas/depthSchema';

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion dev-client/src/components/SyncContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {Button} from 'native-base';

import {Text} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {RestrictByFlag} from 'terraso-mobile-client/components/RestrictByFlag';
import {selectUnsyncedSiteIds} from 'terraso-mobile-client/model/soilId/soilIdSelectors';
import {selectUnsyncedSiteIds} from 'terraso-mobile-client/model/soilData/soilDataSelectors';
import {selectPullRequested} from 'terraso-mobile-client/model/sync/syncSelectors';
import {setPullRequested} from 'terraso-mobile-client/model/sync/syncSlice';
import {useDispatch, useSelector} from 'terraso-mobile-client/store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
fullMunsellColor,
munsellToString,
} from 'terraso-mobile-client/model/color/colorConversions';
import {sameDepth} from 'terraso-mobile-client/model/soilId/soilIdSlice';
import {sameDepth} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {AggregatedInterval} from 'terraso-mobile-client/store/selectors';

export type SoilPropertiesDataTableRow = {
Expand Down
2 changes: 1 addition & 1 deletion dev-client/src/context/SoilIdMatchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {Coords} from 'terraso-client-shared/types';

import {useIsOffline} from 'terraso-mobile-client/hooks/connectivityHooks';
import {useValueSet} from 'terraso-mobile-client/hooks/useValueSet';
import {selectUnsyncedSiteIds} from 'terraso-mobile-client/model/soilId/soilIdSelectors';
import {selectUnsyncedSiteIds} from 'terraso-mobile-client/model/soilData/soilDataSelectors';
import {coordsKey} from 'terraso-mobile-client/model/soilIdMatch/soilIdMatches';
import {
selectDataBasedInputs,
Expand Down
8 changes: 4 additions & 4 deletions dev-client/src/model/project/projectGlobalReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
updateProjects,
} from 'terraso-mobile-client/model/project/projectSlice';
import {updateSites} from 'terraso-mobile-client/model/site/siteSlice';
import {updateProjectSettings} from 'terraso-mobile-client/model/soilId/soilIdSlice';
import {updateProjectSettings} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {createGlobalReducer} from 'terraso-mobile-client/store/reducers';

export const fetchProject = createAsyncThunk(
Expand Down Expand Up @@ -60,20 +60,20 @@ export const projectGlobalReducer = createGlobalReducer(builder => {
updateProjects(state.project, {[payload.project.id]: payload.project});
updateSites(state.site, payload.sites);
updateUsers(state.account, payload.users);
updateProjectSettings(state.soilId, payload.soilSettings);
updateProjectSettings(state.soilData, payload.soilSettings);
});

builder.addCase(addProject.fulfilled, (state, {payload}) => {
updateProjects(state.project, {[payload.project.id]: payload.project});
updateSites(state.site, payload.sites);
updateUsers(state.account, payload.users);
updateProjectSettings(state.soilId, payload.soilSettings);
updateProjectSettings(state.soilData, payload.soilSettings);
});

builder.addCase(updateProject.fulfilled, (state, {payload}) => {
updateProjects(state.project, {[payload.project.id]: payload.project});
updateSites(state.site, payload.sites);
updateUsers(state.account, payload.users);
updateProjectSettings(state.soilId, payload.soilSettings);
updateProjectSettings(state.soilData, payload.soilSettings);
});
});
4 changes: 2 additions & 2 deletions dev-client/src/model/site/siteGlobalReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
updateProjectOfSite,
updateSites,
} from 'terraso-mobile-client/model/site/siteSlice';
import {deleteSoilData} from 'terraso-mobile-client/model/soilId/soilIdSlice';
import {deleteSoilData} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {deleteSiteMatches} from 'terraso-mobile-client/model/soilIdMatch/soilIdMatchSlice';
import {deleteSoilMetadata} from 'terraso-mobile-client/model/soilMetadata/soilMetadataSlice';
import {createGlobalReducer} from 'terraso-mobile-client/store/reducers';
Expand Down Expand Up @@ -75,7 +75,7 @@ export const siteGlobalReducer = createGlobalReducer(builder => {
builder.addCase(deleteSite.fulfilled, (state, {payload}) => {
removeSiteFromAllProjects(state.project, payload);
deleteSites(state.site, [payload]);
deleteSoilData(state.soilId, [payload]);
deleteSoilData(state.soilData, [payload]);
deleteSoilMetadata(state.soilMetadata, [payload]);
deleteSiteMatches(state.soilIdMatch, [payload]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import {
DEPTH_DEPENDENT_SOIL_DATA_UPDATE_FIELDS,
DEPTH_INTERVAL_UPDATE_FIELDS,
SOIL_DATA_UPDATE_FIELDS,
} from 'terraso-mobile-client/model/soilId/actions/soilDataActionFields';
import {DEFAULT_DEPTH_INTERVAL_PRESET} from 'terraso-mobile-client/model/soilId/soilDataConstants';
} from 'terraso-mobile-client/model/soilData/actions/soilDataActionFields';
import {DEFAULT_DEPTH_INTERVAL_PRESET} from 'terraso-mobile-client/model/soilData/soilDataConstants';
import {
compareInterval,
sameDepth,
} from 'terraso-mobile-client/model/soilId/soilIdFunctions';
} from 'terraso-mobile-client/model/soilData/soilDataFunctions';

/*
* Logic ported from `apps/soil_id/graphql/soil_data.py` in backend project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ import {
updateFields,
updateSoilData,
updateSoilDataDepthInterval,
} from 'terraso-mobile-client/model/soilId/actions/localSoilDataActions';
} from 'terraso-mobile-client/model/soilData/actions/localSoilDataActions';
import {
DEPTH_DEPENDENT_SOIL_DATA_UPDATE_FIELDS,
DEPTH_INTERVAL_UPDATE_FIELDS,
SOIL_DATA_UPDATE_FIELDS,
} from 'terraso-mobile-client/model/soilId/actions/soilDataActionFields';
} from 'terraso-mobile-client/model/soilData/actions/soilDataActionFields';
import {
DepthDependentSoilData,
SoilData,
SoilDataDepthInterval,
} from 'terraso-mobile-client/model/soilId/soilIdSlice';
} from 'terraso-mobile-client/model/soilData/soilDataSlice';

describe('initializeResult', () => {
test('deep-copies soil data object', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
mutationResponseToResults,
unsyncedDataToMutationInput,
unsyncedDataToMutationInputEntry,
} from 'terraso-mobile-client/model/soilId/actions/remoteSoilDataActions';
import {SoilData} from 'terraso-mobile-client/model/soilId/soilIdSlice';
} from 'terraso-mobile-client/model/soilData/actions/remoteSoilDataActions';
import {SoilData} from 'terraso-mobile-client/model/soilData/soilDataSlice';
import {
SyncRecord,
SyncRecords,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
getChangedDepthIntervals,
getChangedSoilDataFields,
getDeletedDepthIntervals,
} from 'terraso-mobile-client/model/soilId/actions/soilDataDiff';
} from 'terraso-mobile-client/model/soilData/actions/soilDataDiff';
import {
getEntityRecord,
SyncRecord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
DepthDependentSoilData,
SoilData,
SoilDataDepthInterval,
} from 'terraso-mobile-client/model/soilId/soilIdSlice';
} from 'terraso-mobile-client/model/soilData/soilDataSlice';

/**
* The soil data fields which are covered by the update action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {SoilData} from 'terraso-client-shared/soilId/soilIdTypes';
import {ThunkAPI} from 'terraso-client-shared/store/utils';

import {isFlagEnabled} from 'terraso-mobile-client/config/featureFlags';
import * as localSoilData from 'terraso-mobile-client/model/soilId/actions/localSoilDataActions';
import * as remoteSoilData from 'terraso-mobile-client/model/soilId/actions/remoteSoilDataActions';
import * as localSoilData from 'terraso-mobile-client/model/soilData/actions/localSoilDataActions';
import * as remoteSoilData from 'terraso-mobile-client/model/soilData/actions/remoteSoilDataActions';
import {
getDataForRecords,
getEntityRecords,
Expand All @@ -49,11 +49,11 @@ export const pushSoilData = async (
state: AppState,
): Promise<SyncResults<SoilData, SoilDataPushFailureReason>> => {
const unsyncedChanges = getUnsyncedRecords(
getEntityRecords(state.soilId.soilSync, input),
getEntityRecords(state.soilData.soilSync, input),
);
const unsyncedData = getDataForRecords(
unsyncedChanges,
state.soilId.soilData,
state.soilData.soilData,
);
return remoteSoilData.pushSoilData(unsyncedChanges, unsyncedData);
};
Expand All @@ -69,7 +69,7 @@ export const updateSoilData = async (
state: AppState,
): Promise<SoilData> => {
if (isFlagEnabled('FF_offline')) {
const data = state.soilId.soilData[input.siteId];
const data = state.soilData.soilData[input.siteId];
return Promise.resolve(localSoilData.updateSoilData(input, data));
} else {
return soilDataService.updateSoilData(input);
Expand All @@ -87,7 +87,7 @@ export const deleteSoilDataDepthInterval = async (
state: AppState,
): Promise<SoilData> => {
if (isFlagEnabled('FF_offline')) {
const data = state.soilId.soilData[input.siteId];
const data = state.soilData.soilData[input.siteId];
return Promise.resolve(
localSoilData.deleteSoilDataDepthInterval(input, data),
);
Expand All @@ -107,7 +107,7 @@ export const updateSoilDataDepthInterval = async (
state: AppState,
): Promise<SoilData> => {
if (isFlagEnabled('FF_offline')) {
const data = state.soilId.soilData[input.siteId];
const data = state.soilData.soilData[input.siteId];
return Promise.resolve(
localSoilData.updateSoilDataDepthInterval(input, data),
);
Expand All @@ -127,7 +127,7 @@ export const updateDepthDependentSoilData = async (
state: AppState,
): Promise<SoilData> => {
if (isFlagEnabled('FF_offline')) {
const data = state.soilId.soilData[input.siteId];
const data = state.soilData.soilData[input.siteId];
return Promise.resolve(
localSoilData.updateDepthDependentSoilData(input, data),
);
Expand Down
Loading

0 comments on commit 8141b57

Please sign in to comment.