Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable unused collection methods #570

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ export const DEPTH_INTERVAL_PRESETS = mapEntries(
export const DEFAULT_ENABLED_SOIL_PIT_METHODS: SoilPitMethod[] = [
'soilTexture',
'soilColor',
'soilStructure',
];

// export const DEFAULT_DISABLED_SOIL_PIT_METHODS: SoilPitMethod[] = [
// 'soilStructure',
// ];

export const DEFAULT_PROJECT_SOIL_INTERVAL = fromEntries(
soilPitMethods.map(method => [methodEnabled(method), false]),
);
Expand Down
18 changes: 9 additions & 9 deletions src/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,21 @@ const createProjectSettings = (
): Record<string, ProjectSoilSettings> => {
return {
[project.id]: {
carbonatesRequired: false,
// carbonatesRequired: false,
depthIntervalPreset: 'LANDPKS',
depthIntervals: [],
electricalConductivityRequired: false,
landUseLandCoverRequired: false,
// electricalConductivityRequired: false,
// landUseLandCoverRequired: false,
notesRequired: false,
phRequired: false,
photosRequired: false,
// phRequired: false,
// photosRequired: false,
slopeRequired: false,
sodiumAdsorptionRatioRequired: false,
// sodiumAdsorptionRatioRequired: false,
soilColorRequired: false,
soilLimitationsRequired: false,
soilOrganicCarbonMatterRequired: false,
// soilLimitationsRequired: false,
// soilOrganicCarbonMatterRequired: false,
soilPitRequired: false,
soilStructureRequired: false,
// soilStructureRequired: false,
soilTextureRequired: false,
verticalCrackingRequired: false,
...defaults,
Expand Down
6 changes: 6 additions & 0 deletions src/soilId/soilIdSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { setSites } from 'terraso-client-shared/site/siteSlice';
import * as soilDataService from 'terraso-client-shared/soilId/soilDataService';
import * as soilIdService from 'terraso-client-shared/soilId/soilIdService';
import {
CollectionMethod,
DisabledCollectionMethod,
LoadingState,
ProjectSoilSettings,
SoilData,
Expand All @@ -36,6 +38,10 @@ import {
export * from 'terraso-client-shared/soilId/soilIdTypes';
export * from 'terraso-client-shared/soilId/soilIdFunctions';

export type MethodRequired<
T extends CollectionMethod | DisabledCollectionMethod,
> = `${T}Required`;

export type SoilState = {
soilData: Record<string, SoilData | undefined>;
projectSettings: Record<string, ProjectSoilSettings | undefined>;
Expand Down
32 changes: 27 additions & 5 deletions src/soilId/soilIdTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,51 @@ import type {
SoilIdProjectSoilSettingsDepthIntervalPresetChoices,
SoilIdSoilDataSurfaceCracksSelectChoices,
} from 'terraso-client-shared/graphqlSchema/graphql';
import { MethodRequired } from 'terraso-client-shared/soilId/soilIdSlice';
import { Coords } from 'terraso-client-shared/types';

export type LoadingState = 'loading' | 'error' | 'ready';

export const soilPitMethods = [
'soilTexture',
'soilColor',
export const soilPitMethods = ['soilTexture', 'soilColor'] as const;
export const disabledSoilPitMethods = [
'soilStructure',
'carbonates',
'ph',
'electricalConductivity',
'soilOrganicCarbonMatter',
'sodiumAdsorptionRatio',
] as const;

export const allSoilPitMethods = [
...soilPitMethods,
...disabledSoilPitMethods,
] as const;

export const collectionMethods = [
'slope',
'verticalCracking',
...soilPitMethods,
'notes',
] as const;

export const disabledCollectionMethods = [
'soilLimitations',
'landUseLandCover',
'photos',
'notes',
...disabledSoilPitMethods,
] as const;

export const allCollectionMethods = [
...collectionMethods,
...disabledCollectionMethods,
] as const;

export type SoilPitMethod = (typeof soilPitMethods)[number];
export type CollectionMethod = (typeof collectionMethods)[number];

export type DisabledCollectionMethod =
(typeof disabledCollectionMethods)[number];

export { DepthInterval };
export type LabelledDepthInterval = {
label: string;
Expand All @@ -71,12 +89,16 @@ export type SoilData = Omit<
depthDependentData: DepthDependentSoilData[];
};
export type ProjectDepthInterval = Omit<ProjectDepthIntervalNode, 'project'>;
export type ProjectSoilSettings = Omit<
export type AllProjectSoilSettings = Omit<
ProjectSoilSettingsNode,
'project' | 'depthIntervals'
> & {
depthIntervals: ProjectDepthInterval[];
};
export type ProjectSoilSettings = Omit<
AllProjectSoilSettings,
MethodRequired<DisabledCollectionMethod>
>;

export type SoilTexture = SoilIdDepthDependentSoilDataTextureChoices;
export const textures = [
Expand Down
Loading