mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-10-06 18:12:22 -04:00
MOB-1339: handle default cases as errors in search subject helpers
This commit is contained in:
1 parent
ad622fbffe
commit
f1ec83e1b9
1 file changed
+10
-2
@@ -1,7 +1,10 @@
|
||||
import type { ExploreV2Subject } from "providers/ExploreV2Context";
|
||||
import { log } from "sharedHelpers/logger";
|
||||
import { generateTaxonPieces } from "sharedHelpers/taxon";
|
||||
import type { UniversalSearchResultItem } from "sharedHooks/useUniversalSearch";
|
||||
|
||||
const logger = log.extend( "universalSearchSubject" );
|
||||
|
||||
// Translation layer between the universal search API results
|
||||
// (UniversalSearchResultItem) and the ExploreV2 context's subject shape
|
||||
// (ExploreV2Subject), plus the inverse mapping from a subject to the text shown
|
||||
@@ -28,7 +31,6 @@ export const resultToSubject = ( result: UniversalSearchResultItem ): ExploreV2S
|
||||
},
|
||||
};
|
||||
case "taxon":
|
||||
default:
|
||||
return {
|
||||
type: "taxon",
|
||||
taxon: {
|
||||
@@ -42,6 +44,9 @@ export const resultToSubject = ( result: UniversalSearchResultItem ): ExploreV2S
|
||||
rank_level: result.taxon.rank_level,
|
||||
},
|
||||
};
|
||||
default:
|
||||
throw new Error( `resultToSubject: Unknown explore
|
||||
subject result type: ${( result as { type: string } ).type}` );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -55,9 +60,12 @@ export const subjectToText = (
|
||||
case "project":
|
||||
return subject.project.title;
|
||||
case "taxon":
|
||||
default:
|
||||
return ( commonNameIsPrimary && subject.taxon.preferred_common_name )
|
||||
? generateTaxonPieces( subject.taxon ).commonName ?? subject.taxon.name
|
||||
: subject.taxon.name;
|
||||
default:
|
||||
logger.error( `subjectToText: Unknown explore
|
||||
subject type: ${( subject as { type: string } ).type}` );
|
||||
return "";
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user