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

Include Species' Ecological Units on Standards Page #1484

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion api/src/models/standards-view.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { z } from 'zod';
import {
CBQualitativeMeasurementTypeDefinition,
CBQuantitativeMeasurementTypeDefinition
CBQuantitativeMeasurementTypeDefinition,
ICollectionCategory
} from '../services/critterbase-service';

const QualitativeMeasurementSchema = z.object({
Expand Down Expand Up @@ -50,4 +51,5 @@ export interface ISpeciesStandards {
qualitative: CBQualitativeMeasurementTypeDefinition[];
};
markingBodyLocations: { id: string; key: string; value: string }[];
ecologicalUnits: ICollectionCategory[];
}
26 changes: 25 additions & 1 deletion api/src/paths/standards/taxon/{tsn}/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GET.apiDoc = {
schema: {
type: 'object',
additionalProperties: false,
required: ['tsn', 'scientificName', 'measurements', 'markingBodyLocations'],
required: ['tsn', 'scientificName', 'measurements', 'markingBodyLocations', 'ecologicalUnits'],
properties: {
tsn: {
type: 'integer'
Expand Down Expand Up @@ -141,6 +141,30 @@ GET.apiDoc = {
}
}
},
ecologicalUnits: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is this intended to be the Collection Categories ('Population Unit'...) or is this supposed to be Collection units ('Telkwa'...)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're wanting it to pull collection categories (population unit for example), and then the accordion would expand to show the collection units (telkwa) - but I think currently there is no API request that returns both for a species so Macgregor mentioned there may need to be some updates to critterbase before we can finish this ticket. Currently the UI is only displaying a card for categories, with no collection unit options.

type: 'array',
items: {
type: 'object',
additionalProperties: false,
required: ['collection_category_id', 'category_name', 'description', 'itis_tsn'],
properties: {
collection_category_id: {
type: 'string',
format: 'uuid'
},
category_name: {
type: 'string'
},
description: {
type: 'string',
nullable: true
},
itis_tsn: {
type: 'integer'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: minimum 1

}
}
}
},
markingBodyLocations: {
type: 'array',
items: {
Expand Down
6 changes: 4 additions & 2 deletions api/src/services/standards-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ export class StandardsService extends DBService {
const response = await Promise.all([
this.platformService.getTaxonomyByTsns([tsn]),
this.critterbaseService.getTaxonBodyLocations(String(tsn)),
this.critterbaseService.getTaxonMeasurements(String(tsn))
this.critterbaseService.getTaxonMeasurements(String(tsn)),
this.critterbaseService.findTaxonCollectionCategories(String(tsn))
]);

return {
tsn: tsn,
scientificName: response[0][0].scientificName,
markingBodyLocations: response[1],
measurements: response[2]
measurements: response[2],
ecologicalUnits: response[3]
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mdiRuler, mdiTag } from '@mdi/js';
import { mdiBook, mdiRuler, mdiTag } from '@mdi/js';
import { Box, Divider, Stack, Typography } from '@mui/material';
import { blueGrey, grey } from '@mui/material/colors';
import ColouredRectangleChip from 'components/chips/ColouredRectangleChip';
Expand All @@ -10,7 +10,8 @@ import { useState } from 'react';

enum SpeciesStandardsViewEnum {
MEASUREMENTS = 'measurements',
MARKING_BODY_LOCATIONS = 'marking_body_locations'
MARKING_BODY_LOCATIONS = 'marking_body_locations',
ECOLOGICAL_UNIT = 'ecological_unit'
}

interface ISpeciesStandardsResultsProps {
Expand Down Expand Up @@ -43,7 +44,8 @@ const SpeciesStandardsResults = (props: ISpeciesStandardsResultsProps) => {
<CustomToggleButtonGroup
views={[
{ value: SpeciesStandardsViewEnum.MEASUREMENTS, label: 'Measurements', icon: mdiRuler },
{ value: SpeciesStandardsViewEnum.MARKING_BODY_LOCATIONS, label: 'Marking body locations', icon: mdiTag }
{ value: SpeciesStandardsViewEnum.MARKING_BODY_LOCATIONS, label: 'Marking body locations', icon: mdiTag },
{ value: SpeciesStandardsViewEnum.ECOLOGICAL_UNIT, label: 'Ecological Unit', icon: mdiBook }
]}
activeView={activeView}
onViewChange={setActiveView}
Expand Down Expand Up @@ -92,6 +94,31 @@ const SpeciesStandardsResults = (props: ISpeciesStandardsResultsProps) => {
))}
</>
)}
{activeView === SpeciesStandardsViewEnum.ECOLOGICAL_UNIT && (
<>
{props.data.ecologicalUnits.map((category) => (
<AccordionStandardCard
key={category.collection_category_id}
label={category.category_name}
subtitle={category.description}
colour={grey[100]}>
{/* <Stack gap={2} my={2}>
{props.data?.ecologicalUnits
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We can drop this deprecated code if it is not needed anymore

.filter((unit) => unit.collection_category_id === category.collection_category_id)
.map((unit) => (
<AccordionStandardCard
key={unit.collection_unit_id}
label={unit.unit_name}
subtitle={unit.description}
colour={grey[200]}
disableCollapse
/>
))}
</Stack> */}
</AccordionStandardCard>
))}
</>
)}
</Stack>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions app/src/interfaces/useStandardsApi.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CBQualitativeMeasurementTypeDefinition,
CBQuantitativeMeasurementTypeDefinition,
ICollectionUnit
ICollectionCategory
} from './useCritterApi.interface';

interface IStandardNameDescription {
Expand Down Expand Up @@ -35,7 +35,7 @@ export interface ISpeciesStandards {
key: string;
value: string;
}[];
ecologicalUnits: ICollectionUnit[];
ecologicalUnits: ICollectionCategory[];
}

/**
Expand Down
Loading