Skip to content

Commit

Permalink
Hide counts that are missing in API response
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow committed Dec 3, 2023
1 parent 5504d99 commit 687380d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ui/src/data-services/models/species.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class Species extends Taxon {
}

get numDetections(): number {
return this._species.detections_count
return this._species.detections_count || null
}

get numOccurrences(): number {
return this._species.occurrences_count
return this._species.occurrences_count || null
}

get trainingImagesLabel(): string {
Expand Down
3 changes: 2 additions & 1 deletion ui/src/design-system/components/info-block/info-block.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from 'classnames'
import { Link } from 'react-router-dom'
import { STRING } from 'utils/language'
import styles from './info-block.module.scss'

interface Field {
Expand All @@ -11,7 +12,7 @@ interface Field {
export const InfoBlock = ({ fields }: { fields: Field[] }) => (
<>
{fields.map((field, index) => {
const value = field.value !== undefined ? field.value : 'N/A'
const value = field.value !== undefined ? field.value : STRING.VALUE_NOT_AVAILABLE

return (
<p className={styles.field} key={index}>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/species-details/species-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const SpeciesDetails = ({ species }: { species: Species }) => {
value: species.trainingImagesLabel,
to: species.trainingImagesUrl,
},
]
].filter((field) => field.value !== null);

return (
<div className={styles.wrapper}>
Expand Down
4 changes: 3 additions & 1 deletion ui/src/utils/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export enum STRING {
UPDATING_DATA,
USER_INFO,
VERIFIED_BY,
VALUE_NOT_AVAILABLE,
}

const ENGLISH_STRINGS: { [key in STRING]: string } = {
Expand Down Expand Up @@ -242,7 +243,7 @@ const ENGLISH_STRINGS: { [key in STRING]: string } = {
[STRING.FIELD_LABEL_THUMBNAIL]: 'Thumbnail',
[STRING.FIELD_LABEL_TIME]: 'Time',
[STRING.FIELD_LABEL_TIMESTAMP]: 'Timestamp',
[STRING.FIELD_LABEL_TRAINING_IMAGES]: 'Training images',
[STRING.FIELD_LABEL_TRAINING_IMAGES]: 'Reference images',
[STRING.FIELD_LABEL_FIRST_DATE]: 'First date',
[STRING.FIELD_LABEL_LAST_DATE]: 'Last date',
[STRING.FIELD_LABEL_UPDATED_AT]: 'Updated at',
Expand Down Expand Up @@ -342,6 +343,7 @@ const ENGLISH_STRINGS: { [key in STRING]: string } = {
[STRING.UPDATING_DATA]: 'Updating data',
[STRING.USER_INFO]: 'User info',
[STRING.VERIFIED_BY]: 'Verified by\n{{name}}',
[STRING.VALUE_NOT_AVAILABLE]: 'n/a',
}

// When we have more translations available, this function could return a value based on current language settings.
Expand Down

0 comments on commit 687380d

Please sign in to comment.