Skip to content

Commit

Permalink
feat: soil data depth intervals/inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Oct 3, 2023
1 parent 236597d commit 197bff4
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-redux": "^8.1.2",
"terraso-backend": "github:techmatters/terraso-backend#4170565",
"terraso-backend": "github:techmatters/terraso-backend#0ac91bf",
"uuid": "^9.0.0"
},
"scripts": {
Expand Down
13 changes: 9 additions & 4 deletions src/project/projectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

import { createAction, createSlice } from '@reduxjs/toolkit';
import { createAction, createSlice, PayloadAction } from '@reduxjs/toolkit';
import { setUsers, User } from 'terraso-client-shared/account/accountSlice';
import { UserRole } from 'terraso-client-shared/graphqlSchema/graphql';
import * as projectService from 'terraso-client-shared/project/projectService';
import { setSites, Site } from 'terraso-client-shared/site/siteSlice';
import { Site, updateSites } from 'terraso-client-shared/site/siteSlice';
import {
createAsyncThunk,
dehydrated,
Expand All @@ -30,7 +30,7 @@ const { plural: dehydrateProjects, sing: dehydrateProject } = dehydrated<
HydratedProject
>({
users: setUsers,
sites: setSites,
sites: updateSites,
});

export type SerializableSet = Record<string, boolean>;
Expand Down Expand Up @@ -125,7 +125,11 @@ export const archiveProject = createAsyncThunk(
const projectSlice = createSlice({
name: 'project',
initialState,
reducers: {},
reducers: {
setProjects: (state, action: PayloadAction<Record<string, Project>>) => {
state.projects = action.payload;
},
},
extraReducers: builder => {
builder.addCase(
addSiteToProject,
Expand Down Expand Up @@ -192,4 +196,5 @@ const projectSlice = createSlice({
},
});

export const { setProjects } = projectSlice.actions;
export default projectSlice.reducer;
18 changes: 10 additions & 8 deletions src/site/siteSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

import { createAction, createSlice } from '@reduxjs/toolkit';
import { createAction, createSlice, PayloadAction } from '@reduxjs/toolkit';
import { SiteAddMutationInput } from 'terraso-client-shared/graphqlSchema/graphql';
import {
addSiteToProject,
Expand All @@ -42,8 +42,6 @@ const initialState = {
sites: {} as Record<string, Site>,
};

export const setSites = createAction<Record<string, Site>>('site/setSites');

export const fetchSite = createAsyncThunk(
'site/fetchSite',
siteService.fetchSite,
Expand Down Expand Up @@ -87,12 +85,15 @@ export const deleteSite = createAsyncThunk<string, Site>(
const siteSlice = createSlice({
name: 'site',
initialState,
reducers: {},
reducers: {
setSites: (state, { payload }: PayloadAction<Record<string, Site>>) => {
state.sites = payload;
},
updateSites: (state, { payload }: PayloadAction<Record<string, Site>>) => {
Object.assign(state.sites, payload.sites);
},
},
extraReducers: builder => {
builder.addCase(setSites, (state, { payload: sites }) => {
Object.assign(state.sites, sites);
});

// TODO: add case to delete site if not found
builder.addCase(fetchSite.fulfilled, (state, { payload: site }) => {
state.sites[site.id] = site;
Expand Down Expand Up @@ -135,4 +136,5 @@ const siteSlice = createSlice({
},
});

export const { setSites, updateSites } = siteSlice.actions;
export default siteSlice.reducer;
114 changes: 114 additions & 0 deletions src/soilId/soilIdFragments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright © 2023 Technology Matters
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

export const projectSoilSettings = /* GraphQL */ `
fragment projectSoilSettings on ProjectSoilSettingsNode {
depthIntervals {
depthInterval {
start
end
}
label
}
measurementUnits
depthIntervalPreset
soilPitRequired
slopeRequired
soilTextureRequired
soilColorRequired
verticalCrackingRequired
carbonatesRequired
phRequired
soilOrganicCarbonMatterRequired
electricalConductivityRequired
sodiumAdsorptionRatioRequired
soilStructureRequired
landUseLandCoverRequired
soilLimitationsRequired
photosRequired
notesRequired
}
`;

export const soilData = /* GraphQL */ `
fragment soilData on SoilDataNode {
downSlope
crossSlope
bedrock
slopeLandscapePosition
slopeAspect
slopeSteepnessSelect
slopeSteepnessPercent
slopeSteepnessDegree
depthIntervals {
...soilDataDepthInterval
}
depthDependentData {
...depthDependentSoilData
}
}
`;

export const soilDataDepthInterval = /* GraphQL */ `
fragment soilDataDepthInterval on SoilDataDepthIntervalNode {
label
depthInterval {
start
end
}
slopeEnabled
soilTextureEnabled
soilColorEnabled
verticalCrackingEnabled
carbonatesEnabled
phEnabled
soilOrganicCarbonMatterEnabled
electricalConductivityEnabled
sodiumAdsorptionRatioEnabled
soilStructureEnabled
landUseLandCoverEnabled
soilLimitationsEnabled
}
`;

export const depthDependentSoilData = /* GraphQL */ `
fragment depthDependentSoilData on DepthDependentSoilDataNode {
depthInterval {
start
end
}
texture
rockFragmentVolume
colorHueSubstep
colorHue
colorValue
colorChroma
conductivity
conductivityTest
conductivityUnit
structure
ph
phTestingSolution
phTestingMethod
soilOrganicCarbon
soilOrganicMatter
soilOrganicCarbonTesting
soilOrganicMatterTesting
sodiumAbsorptionRatio
carbonates
}
`;
Loading

0 comments on commit 197bff4

Please sign in to comment.