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

Taxon show issue + Document count on taxon modal #286

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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: 2 additions & 2 deletions src/components/pages/common/status-badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ interface TaxonStatusBadgeProps {
function TaxonStatusBadge({ reco, taxonId, crumbs }: TaxonStatusBadgeProps) {
const { t } = useTranslation();

const taxonLink = `/taxonomy/list?taxonId=${taxonId}&showTaxon=${taxonId}`;
const taxonLink = `/taxonomy/list`;

switch (reco?.status) {
case "ACCEPTED":
return (
<LocalLink href={taxonLink}>
<LocalLink href={taxonLink} params={{ taxonId: taxonId, showTaxon: taxonId }}>
<Link>
<Badge colorScheme={TAXON_BADGE_COLORS.ACCEPTED}>{t("common:accepted")}</Badge>
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Box, Skeleton, Text } from "@chakra-ui/react";
import React from "react";

import useDocumentCount from "./use-document-count";

export function DocumentsLink({ showTaxon }) {
const { countsData } = useDocumentCount(showTaxon);
//const { t } = useTranslation();

return (
<div>
<Skeleton isLoaded={!countsData.isLoading} borderRadius="md">
<Box p={2} className="white-box" lineHeight={1} minWidth={200}>
<Text fontSize="3xl" mb={2}>
{countsData.value || 0}
</Text>
{/* <LocalLink href={`/observation/list`} params={{ taxon: showTaxon }}>
<ExternalBlueLink>{t("taxon:modal.data_links.observations")}</ExternalBlueLink>
</LocalLink> */}
<Text>Documents</Text>
</Box>
</Skeleton>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { axGetDocumentDataByTaxonId } from "@services/document.service";
import { useEffect, useState } from "react";

export default function useDocumentCount(taxon) {
const [count, setCount] = useState(null);
const [isLoading, setIsLoading] = useState(true);

const getData = async (taxon) => {
setIsLoading(true);

const { success, data } = await axGetDocumentDataByTaxonId(taxon);

if (success) {
setCount(data.length);
}

setIsLoading(false);
};

useEffect(() => {
getData(taxon);
}, []);

return {
countsData: { value: count, isLoading: isLoading }
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getInjectableHTML } from "@utils/text";
import useTranslation from "next-translate/useTranslation";
import React from "react";

import { DocumentsLink } from "../../document";
import { ObservationsLink } from "../../observation";
import { SpeciesPageLink } from "../../species";

Expand All @@ -20,6 +21,7 @@ export function TaxonAttributesTable() {
<HStack mb={4} spacing={4}>
<SpeciesPageLink showTaxon={showTaxon} />
<ObservationsLink showTaxon={showTaxon} />
<DocumentsLink showTaxon={showTaxon} />
</HStack>
<Heading as="h3" size="md" mb={4}>
{t("common:information")}
Expand Down
10 changes: 10 additions & 0 deletions src/services/document.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,13 @@ export const axUpdateScientifcNameToIsDeleted = async (nameId) => {
return { succes: false, data: {} };
}
};

export const axGetDocumentDataByTaxonId = async (taxonId) => {
try {
const { data } = await plainHttp.get(`${ENDPOINT.DOCUMENT}/v1/services/taxonomy/${taxonId}`);
return { success: true, data };
} catch (e) {
console.error(e);
return { succes: false, data: {} };
}
};