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

migration: postgres moissonneur #92

Merged
merged 10 commits into from
Oct 21, 2024
2 changes: 1 addition & 1 deletion components/bal-widget/bal-widget-config-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const BALWidgetConfigForm = ({
label="Sources moissonnées caduques"
value={formData.communes?.outdatedHarvestSources || []}
options={harvestSources.map((source) => ({
value: source._id,
value: source.id,
label: source.title,
}))}
placeholder="Sélectionner les sources moissonnées caduques"
Expand Down
51 changes: 28 additions & 23 deletions components/communes/revisions-item-moissoneur.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
import Link from 'next/link'
import Link from "next/link";

import type {RevisionMoissoneurType} from '../../types/moissoneur'
import UpdateStatusBadge from '@/components/update-status-badge'
import {RevisionPublication} from '@/components/revision-publication'
import MongoId from '@/components/mongo-id'
import Tooltip from '@/components/tooltip'
import type { RevisionMoissoneurType } from "../../types/moissoneur";
import UpdateStatusBadge from "@/components/update-status-badge";
import { RevisionPublication } from "@/components/revision-publication";
import MongoId from "@/components/mongo-id";
import Tooltip from "@/components/tooltip";

export const RevisionItemMoissoneur = (
{_id, sourceId, nbRows, nbRowsWithErrors, updateStatus, updateRejectionReason, publication}: RevisionMoissoneurType,
) => (
<tr key={_id}>
<td className='fr-col fr-my-1v'>
<MongoId id={_id} />
export const RevisionItemMoissoneur = ({
id,
sourceId,
validation,
updateStatus,
updateRejectionReason,
publication,
}: RevisionMoissoneurType) => (
<tr key={id}>
<td className="fr-col fr-my-1v">
<MongoId id={id} />
</td>
<td className='fr-col fr-my-1v'>
<td className="fr-col fr-my-1v">
<Tooltip text={sourceId}>
<Link legacyBehavior passHref href={{pathname: `/moissonneur-bal/sources/${sourceId}`}}>
<Link
legacyBehavior
passHref
href={{ pathname: `/moissonneur-bal/sources/${sourceId}` }}
>
{sourceId}
</Link>
</Tooltip>
</td>
<td className='fr-col fr-my-1v'>
{nbRows}
</td>
<td className='fr-col fr-my-1v'>
{nbRowsWithErrors}
</td>
<td className="fr-col fr-my-1v">{validation.nbRows}</td>
<td className="fr-col fr-my-1v">{validation.nbRowsWithErrors}</td>

<td className='fr-col fr-my-1v'>
<td className="fr-col fr-my-1v">
<UpdateStatusBadge
updateStatus={updateStatus}
updateRejectionReason={updateRejectionReason}
/>
</td>
<td className='fr-col fr-my-1v'>
<td className="fr-col fr-my-1v">
<RevisionPublication {...publication} />
</td>
</tr>
)
);
83 changes: 51 additions & 32 deletions components/moissonneur-bal/harvest-item.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,97 @@
import Router from 'next/router'
import Router from "next/router";

import Button from '@codegouvfr/react-dsfr/Button'
import Badge from '@codegouvfr/react-dsfr/Badge'
import Button from "@codegouvfr/react-dsfr/Button";
import Badge from "@codegouvfr/react-dsfr/Badge";

import Tooltip from '../tooltip'
import {formatDate} from '@/lib/util/date'
import {getFile} from '@/lib/api-moissonneur-bal'
import Tooltip from "../tooltip";
import { formatDate } from "@/lib/util/date";
import { getFile } from "@/lib/api-moissonneur-bal";

import UpdateStatusBadge from '@/components/update-status-badge'
import MongoId from '@/components/mongo-id'
import { HarvestMoissonneurType, HarvestStatus } from 'types/moissoneur'
import UpdateStatusBadge from "@/components/update-status-badge";
import MongoId from "@/components/mongo-id";
import { HarvestMoissonneurType, HarvestStatus } from "types/moissoneur";

interface StatusBadgeProps {
status: HarvestStatus;
error: string;
}

const StatusBadge = ({status, error}: StatusBadgeProps) => {
const StatusBadge = ({ status, error }: StatusBadgeProps) => {
if (status === HarvestStatus.ACTIVE) {
return <Badge severity='info' noIcon>En cours…</Badge>
return (
<Badge severity="info" noIcon>
En cours…
</Badge>
);
}

if (status === HarvestStatus.FAILED) {
return (
<Tooltip text={error}>
<Badge severity='error' noIcon>Échec</Badge>
<Badge severity="error" noIcon>
Échec
</Badge>
</Tooltip>
)
);
}

if (status === HarvestStatus.COMPLETED) {
return <Badge severity='success' noIcon>Terminé</Badge>
return (
<Badge severity="success" noIcon>
Terminé
</Badge>
);
}
}
};

const HarvestItem = ({_id, startedAt, finishedAt, status, error, updateStatus, updateRejectionReason, fileId}: HarvestMoissonneurType) => {
const HarvestItem = ({
id,
startedAt,
finishedAt,
status,
error,
updateStatus,
updateRejectionReason,
fileId,
}: HarvestMoissonneurType) => {
const downloadFile = async () => {
const file = await getFile(fileId)
Router.push(file.url)
}
const file = await getFile(fileId);
Router.push(file.url);
};

return (
<tr>
<td className='fr-col fr-my-1v'>
<MongoId id={_id} />
<td className="fr-col fr-my-1v">
<MongoId id={id} />
</td>
<td className='fr-col fr-my-1v'>
<td className="fr-col fr-my-1v">
<a>{formatDate(startedAt)}</a>
</td>
<td className='fr-col fr-my-1v'>
<a>{finishedAt ? formatDate(finishedAt) : '…'}</a>
<td className="fr-col fr-my-1v">
<a>{finishedAt ? formatDate(finishedAt) : "…"}</a>
</td>
<td className='fr-col fr-my-1v'>
<td className="fr-col fr-my-1v">
<StatusBadge status={status} error={error} />
</td>
<td className='fr-col fr-my-1v'>
<td className="fr-col fr-my-1v">
<UpdateStatusBadge
updateStatus={updateStatus}
updateRejectionReason={updateRejectionReason}
/>
</td>
<td className='fr-col fr-my-1v'>
<td className="fr-col fr-my-1v">
{fileId && (
<Button
iconId='fr-icon-download-line'
iconPosition='right'
iconId="fr-icon-download-line"
iconPosition="right"
onClick={downloadFile}
>
Télécharger
</Button>
)}
</td>
</tr>
)
}
);
};

export default HarvestItem
export default HarvestItem;
6 changes: 3 additions & 3 deletions components/moissonneur-bal/organizations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const MoissoneurOrganizations = ({
);

if (!showDeleted) {
organisationsSort = organisationsSort.filter((s) => !s._deleted);
organisationsSort = organisationsSort.filter((s) => !s.deletedAt);
}

return organisationsSort.map((orga) => ({
...orga,
partenaire: partenaires.find(
({ dataGouvOrganizationId }) =>
dataGouvOrganizationId?.includes(orga._id)
dataGouvOrganizationId?.includes(orga.id)
),
}));
};
Expand Down Expand Up @@ -78,7 +78,7 @@ const MoissoneurOrganizations = ({
<tbody>
{organizationsFiltered.map((organization) => (
<MoissoneurOrganizationItem
key={organization._id}
key={organization.id}
{...organization}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { OrganizationBalAdminType } from "types/moissoneur";
import Checkbox from "@codegouvfr/react-dsfr/Checkbox";

const MoissoneurOrganizationItem = ({
_id,
id,
name,
page,
perimeters,
_deleted,
_updated,
updatedAt,
deletedAt,
partenaire,
}: OrganizationBalAdminType) => (
<tr>
Expand All @@ -24,7 +24,7 @@ const MoissoneurOrganizationItem = ({
</Link>
</td>
<td>
{_deleted ? (
{deletedAt ? (
<Badge severity="error" style={{ marginRight: 2, marginBottom: 2 }}>
Supprimé
</Badge>
Expand Down Expand Up @@ -54,13 +54,13 @@ const MoissoneurOrganizationItem = ({
)}
</td>
<td className="fr-col fr-my-1v">
{_updated ? formatDate(_updated) : "inconnu"}
{updatedAt ? formatDate(updatedAt) : "inconnu"}
</td>
<td className="fr-col fr-my-1v">
<Link
passHref
href={{
pathname: `/moissonneur-bal/organizations/${_id}`,
pathname: `/moissonneur-bal/organizations/${id}`,
}}
>
<Button iconId="fr-icon-arrow-right-line" iconPosition="right">
Expand Down
6 changes: 3 additions & 3 deletions components/moissonneur-bal/revision-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const RevisionItem = ({
return (
<tr>
<td className="fr-col fr-my-1v">
<MongoId id={revision._id} />
<MongoId id={revision.id} />
</td>
<td className="fr-col fr-my-1v">
<a>
Expand All @@ -58,11 +58,11 @@ const RevisionItem = ({
</a>
</td>
<td className="fr-col fr-my-1v">
{revision._created ? formatDate(revision._created) : "inconnu"}
{revision.createdAt ? formatDate(revision.createdAt) : "inconnu"}
</td>

<td className="fr-col fr-my-1v">
{revision.nbRows} / {revision.nbRowsWithErrors}
{revision.validation.nbRows} / {revision.validation.nbRowsWithErrors}
</td>
<td className="fr-col fr-my-1v">
<UpdateStatusBadge
Expand Down
5 changes: 2 additions & 3 deletions components/moissonneur-bal/sources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ const MoissoneurSources = ({ sources }: MoissoneurSourcesProps) => {
const resSources = sources.sort(({ harvestError, nbRevisionError }) =>
harvestError || nbRevisionError > 0 ? -1 : 1
);
console.log(showDeleted, showDisabled);
return resSources
.filter(({ _deleted }) => (showDeleted ? true : !_deleted))
.filter(({ deletedAt }) => (showDeleted ? true : !deletedAt))
.filter(({ enabled }) => (showDisabled ? true : enabled));
}, [showDeleted, showDisabled, sources]);

Expand Down Expand Up @@ -65,7 +64,7 @@ const MoissoneurSources = ({ sources }: MoissoneurSourcesProps) => {

<tbody>
{sourcesFiltered.map((source) => (
<MoissoneurSourceItem key={source._id} {...source} />
<MoissoneurSourceItem key={source.id} {...source} />
))}
</tbody>
</table>
Expand Down
14 changes: 7 additions & 7 deletions components/moissonneur-bal/sources/moissonneur-source-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import Badge from "@codegouvfr/react-dsfr/Badge";
import { ExtendedSourceMoissoneurType } from "types/moissoneur";

const MoissoneurSourceItem = ({
_id,
id,
title,
enabled,
_deleted,
_updated,
deletedAt,
updatedAt,
harvestError,
nbRevisionError,
}: ExtendedSourceMoissoneurType) => (
<tr>
<td className="fr-col fr-my-1v">{_id}</td>
<td className="fr-col fr-my-1v">{id}</td>
<td className="fr-col fr-my-1v">{title}</td>
<td>
{_deleted ? (
{deletedAt ? (
<Badge severity="error" style={{ marginRight: 2, marginBottom: 2 }}>
Supprimé
</Badge>
Expand All @@ -34,7 +34,7 @@ const MoissoneurSourceItem = ({
)}
</td>
<td className="fr-col fr-my-1v">
{_updated ? formatDate(_updated) : "inconnu"}
{updatedAt ? formatDate(updatedAt) : "inconnu"}
</td>
<td className="fr-col fr-my-1v">
{harvestError && (
Expand All @@ -54,7 +54,7 @@ const MoissoneurSourceItem = ({
<Link
passHref
href={{
pathname: `/moissonneur-bal/sources/${_id}`,
pathname: `/moissonneur-bal/sources/${id}`,
}}
>
<Button iconId="fr-icon-arrow-right-line" iconPosition="right">
Expand Down
2 changes: 1 addition & 1 deletion components/partenaires-de-la-charte/partenaire-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const PartenaireForm = ({
const organisations: OrganizationMoissoneurType[] =
await getOrganizations();
setOptionOrganizations(
organisations.map(({ _id, name }) => ({ value: _id, label: name }))
organisations.map(({ id, name }) => ({ value: id, label: name }))
);
}

Expand Down
6 changes: 3 additions & 3 deletions pages/moissonneur-bal/organizations/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const OrganizationPage = ({

const onUpdatePerimeter = async () => {
try {
const res = await updateOrganization(organization._id, { perimeters });
const res = await updateOrganization(organization.id, { perimeters });
organization.perimeters = [...perimeters];
onResetPerimeter();
toast("Modifications enregistrées", { type: "success" });
Expand All @@ -67,7 +67,7 @@ const OrganizationPage = ({
<div className="fr-grid-row fr-grid-row--gutters">
<div className="fr-col">
<h3>{organization.name}</h3>
<CopyToClipBoard text={organization._id} title="Id" />
<CopyToClipBoard text={organization.id} title="Id" />
{partenaire ? (
<>
<h3>Partenaire de la charte</h3>
Expand Down Expand Up @@ -125,7 +125,7 @@ const OrganizationPage = ({

<tbody>
{sources.map((source) => (
<MoissoneurSourceItem key={source._id} {...source} />
<MoissoneurSourceItem key={source.id} {...source} />
))}
</tbody>
</table>
Expand Down
Loading
Loading