Skip to content

Commit

Permalink
fix: ProjectSoilSettings type now does not expect disabled methods (#688
Browse files Browse the repository at this point in the history
)

Co-authored-by: Carissa Knipe <[email protected]>
  • Loading branch information
paulschreiber and knipec authored Jun 27, 2024
1 parent ef07d40 commit e420113
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
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
5 changes: 5 additions & 0 deletions src/soilId/soilIdSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as soilDataService from 'terraso-client-shared/soilId/soilDataService';
import {
CollectionMethod,
DepthInterval,
DisabledCollectionMethod,
ProjectSoilSettings,
SoilData,
SoilPitMethod,
Expand All @@ -42,6 +43,10 @@ export const methodRequired = <T extends CollectionMethod>(
method: T,
): `${T}Required` => `${method}Required`;

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

export type SoilState = {
soilData: Record<string, SoilData | undefined>;
projectSettings: Record<string, ProjectSoilSettings | undefined>;
Expand Down
11 changes: 10 additions & 1 deletion src/soilId/soilIdTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
SoilIdProjectSoilSettingsDepthIntervalPresetChoices,
SoilIdSoilDataSurfaceCracksSelectChoices,
} from 'terraso-client-shared/graphqlSchema/graphql';
import { MethodRequired } from 'terraso-client-shared/soilId/soilIdSlice';

export const soilPitMethods = ['soilTexture', 'soilColor'] as const;
export const disabledSoilPitMethods = [
Expand Down Expand Up @@ -54,6 +55,7 @@ export const disabledCollectionMethods = [
'soilLimitations',
'landUseLandCover',
'photos',
...disabledSoilPitMethods,
] as const;

export const allCollectionMethods = [
Expand All @@ -64,6 +66,9 @@ export const allCollectionMethods = [
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 @@ -79,12 +84,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

0 comments on commit e420113

Please sign in to comment.