Skip to content

Commit

Permalink
feat(request): add request to get contributors name from scanR
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Jun 6, 2024
1 parent 9dc0221 commit f0a45fe
Show file tree
Hide file tree
Showing 15 changed files with 399 additions and 50 deletions.
108 changes: 106 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-query": "^3.39.3",
"react-router-dom": "^6.11.1",
"react-select": "^5.8.0",
"react-spinners": "^0.13.8",
"react-toastify": "^10.0.5",
"sib-api-v3-sdk": "^8.5.0"
"sib-api-v3-sdk": "^8.5.0",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@types/node": "^20.12.7",
Expand All @@ -43,4 +45,4 @@
"typescript": "^5.2.2",
"vite": "^5.0.4"
}
}
}
53 changes: 53 additions & 0 deletions src/api/contribution-api/getNames.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useQuery } from "@tanstack/react-query";
import { postHeaders } from "../../config/api";

const NameFromScanr = (id) => {
const url =
"https://scanr.enseignementsup-recherche.gouv.fr/api/scanr-publications/_search";

const fetchContributions = async () => {
const body = {
_source: ["authors"],
query: {
bool: {
filter: [
{
term: {
"id.keyword": id,
},
},
],
},
},
};

const response = await fetch(url, {
method: "POST",
headers: postHeaders,
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};

const { data, isLoading, isError, refetch } = useQuery(
[url, id],
fetchContributions
);
const fullName =
data?.hits?.hits[0]?._source?.authors.map((author) => author.fullName) ||
[];
const firstName =
data?.hits?.hits[0]?._source?.authors.map((author) => author.firstName) ||
[];

const lastName =
data?.hits?.hits[0]?._source?.authors.map((author) => author.lastName) ||
[];

return { fullName, firstName, lastName, isLoading, isError, refetch };
};

export default NameFromScanr;
40 changes: 40 additions & 0 deletions src/api/contribution-api/getNamesFromIdref.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useQuery } from "@tanstack/react-query";
import { postHeaders } from "../../config/api";

const NameFromIdref = (id) => {
const url =
"https://scanr.enseignementsup-recherche.gouv.fr/api/scanr-persons/_search";

const fetchContributions = async () => {
const body = {
_source: ["id", "fullName"],
query: {
bool: {
filter: [
{
term: {
id: id,
},
},
],
},
},
};

const response = await fetch(url, {
method: "POST",
headers: postHeaders,
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};

const { data, refetch } = useQuery([url, id], fetchContributions);
const fullNameFromIdref = data?.hits?.hits[0]?._source?.fullName || "";
return { fullNameFromIdref, refetch };
};

export default NameFromIdref;
5 changes: 2 additions & 3 deletions src/components/edit-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ const EditModal: React.FC<EditModalProps> = ({
}
const isDevelopment = import.meta.env.VITE_HEADER_TAG === "Development";
const url = isDevelopment
? `${window.location.origin}/api/${basePath}/${data._id}`
: `https://your-production-url/api/${basePath}/${data._id}`;

? `https://scanr-api.dataesr.ovh/${basePath}/${data._id}`
: `${window.location.origin}/api/${basePath}/${data._id}`;
const [inputs, setInputs] = useState<Inputs>({
team: [user],
status: "treated",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import StaffProductionActions from "./staff-production-action";
const ContributionProductionItem = ({
data,
refetch,
setDataList,
}: {
data: Contribute_Production;
refetch;
setDataList;
}) => {
const renderAccordion = () => (
<Container fluid className="accordion">
Expand Down Expand Up @@ -66,7 +68,11 @@ const ContributionProductionItem = ({
return (
<AccordionGroup>
<Accordion title={renderAccordion}>
<ContributorProductionInfo data={data} refetch={refetch} />
<ContributorProductionInfo
data={data}
refetch={refetch}
setDataList={setDataList}
/>
<StaffProductionActions data={data} refetch={refetch} />
</Accordion>
</AccordionGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/api-operation-page/contributor-production-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import MessagePreview from "./message-preview";
const ContributorProductionInfo = ({
data,
refetch,
setDataList,
}: {
data: Contribute_Production;
refetch;
setDataList;
}) => {
return <MessagePreview data={data} refetch={refetch} />;
return (
<MessagePreview data={data} refetch={refetch} setDataList={setDataList} />
);
};

export default ContributorProductionInfo;
Loading

0 comments on commit f0a45fe

Please sign in to comment.