Skip to content

Commit

Permalink
add organization in moissonneur
Browse files Browse the repository at this point in the history
  • Loading branch information
fufeck committed Feb 12, 2024
1 parent 60be180 commit 7c8867c
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 178 deletions.
11 changes: 4 additions & 7 deletions components/api-depot/client/client-form/perimeter-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ interface PerimeterListProps {
}

const PerimeterList = ({perimeters, handlePerimeter}: PerimeterListProps) => {
console.log(perimeters)

const removePerimeter = useCallback((event: any, idx: number) => {
event.preventDefault()
const cpy: PerimeterType[] = [...perimeters]
console.log('remove')
console.log(cpy.length)
cpy.splice(idx, 1);
console.log(cpy.length)
handlePerimeter(cpy)
}, [perimeters, handlePerimeter])

Expand All @@ -42,8 +39,8 @@ const PerimeterList = ({perimeters, handlePerimeter}: PerimeterListProps) => {
return (
<div className='fr-grid-row fr-grid-row--gutters fr-grid-row--bottom'>
<div className='fr-col'>
<label className='fr-label'>Périmètre</label>
{perimeters.map((p, idx) => (
<h3>Périmètre</h3>
{perimeters && perimeters.map((p, idx) => (

<div key={idx} className='fr-container fr-my-2w fr-grid-row fr-grid-row--gutters fr-grid-row--bottom'>
<Perimeter
Expand All @@ -63,7 +60,7 @@ const PerimeterList = ({perimeters, handlePerimeter}: PerimeterListProps) => {
</div>
))}

{perimeters.every(({code}) => code.length > 0) && (
{perimeters && perimeters.every(({code}) => code.length > 0) && (
<div className='fr-col'>
<Button priority='secondary' iconId='fr-icon-add-line' onClick={addPerimeter}>
Ajouter un périmètre
Expand Down
2 changes: 1 addition & 1 deletion components/communes/revisions-item-moissoneur.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const RevisionItemMoissoneur = (
</td>
<td className='fr-col fr-my-1v'>
<Tooltip text={sourceId}>
<Link passHref href={{pathname: '/moissonneur-bal/sources', query: {sourceId}}}>
<Link passHref href={{pathname: `/moissonneur-bal/sources/${sourceId}`}}>
{sourceId}
</Link>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types'
import Router from 'next/router'

import Button from '@codegouvfr/react-dsfr/Button'
Expand All @@ -10,31 +9,32 @@ 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'

const StatusBadge = ({status, error}) => {
if (status === 'active') {
interface StatusBadgeProps {
status: HarvestStatus;
error: string;
}

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

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

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

StatusBadge.propTypes = {
status: PropTypes.oneOf(['completed', 'active', 'failed']),
error: PropTypes.string
}

const HarvestItem = ({_id, startedAt, finishedAt, status, error, updateStatus, updateRejectionReason, fileId}) => {
const HarvestItem = ({_id, startedAt, finishedAt, status, error, updateStatus, updateRejectionReason, fileId}: HarvestMoissonneurType) => {
const downloadFile = async () => {
const file = await getFile(fileId)
Router.push(file.url)
Expand Down Expand Up @@ -75,15 +75,4 @@ const HarvestItem = ({_id, startedAt, finishedAt, status, error, updateStatus, u
)
}

HarvestItem.propTypes = {
_id: PropTypes.string.isRequired,
startedAt: PropTypes.string.isRequired,
finishedAt: PropTypes.string,
status: PropTypes.string,
error: PropTypes.string,
updateStatus: PropTypes.oneOf(['unchanged', 'rejected', 'updated']),
updateRejectionReason: PropTypes.string,
fileId: PropTypes.string
}

export default HarvestItem
67 changes: 67 additions & 0 deletions components/moissonneur-bal/organizations/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { OrganizationMoissoneurType } from "types/moissoneur";
import { useState } from "react";
import MoissoneurOrganizationItem from "./moissonneur-organization-item";

type MoissoneurOrganizationsProps = {
organizations: OrganizationMoissoneurType[];
};

const MoissoneurOrganizations = ({ organizations }: MoissoneurOrganizationsProps) => {
const getFilteredOrganizations = (showDeleted: boolean): OrganizationMoissoneurType[] => {
if (showDeleted) {
return organizations;
}
return organizations.filter((s) => !s._deleted);
};

const [showDeleted, setShowDeleted] = useState<boolean>(false);
const [organizationsFiltered, setOrganizationsFiltered] = useState<
OrganizationMoissoneurType[]
>(getFilteredOrganizations(showDeleted));

const toggleShowDelete = () => {
const isShowDeleted = !showDeleted;
setShowDeleted(isShowDeleted);
setOrganizationsFiltered(getFilteredOrganizations(isShowDeleted));
};

return (
<div className="fr-container fr-py-12v">
<div className="fr-toggle">
<input
type="checkbox"
className="fr-toggle__input"
aria-describedby="toggle-source-hint-text"
id="toggle-source"
checked={showDeleted}
onChange={toggleShowDelete}
/>
<label className="fr-toggle__label" htmlFor="toggle-source">
Voir supprimé
</label>
</div>
<div className="fr-table">
<table>
<caption>Liste des sources moissonnées</caption>
<thead>
<tr>
<th scope="col">Nom</th>
<th scope="col">Page</th>
<th scope="col">Actif</th>
<th scope="col">Date de mise à jour</th>
<th scope="col" />
</tr>
</thead>

<tbody>
{organizationsFiltered.map((organization) => (
<MoissoneurOrganizationItem key={organization._id} {...organization} />
))}
</tbody>
</table>
</div>
</div>
);
};

export default MoissoneurOrganizations;
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Link from "next/link";

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

import { formatDate } from "@/lib/util/date";
import Badge from "@codegouvfr/react-dsfr/Badge";
import { OrganizationMoissoneurType } from "types/moissoneur";

const MoissoneurOrganizationItem = ({
_id,
name,
page,
_deleted,
_updated,
}: OrganizationMoissoneurType) => (
<tr>
<td className="fr-col fr-my-1v">{name}</td>
<td className="fr-col fr-my-1v">
<Link href={page} target="_blank" >
<Button>data.gouv</Button>
</Link>
</td>
<td>
{_deleted ? (
<Badge severity="error" style={{ marginRight: 2, marginBottom: 2 }}>
Supprimé
</Badge>
) : (
<Badge severity="success" style={{ marginRight: 2, marginBottom: 2 }}>
Actif
</Badge>
)}
</td>
<td className="fr-col fr-my-1v">
{_updated ? formatDate(_updated) : "inconnu"}
</td>
<td className="fr-col fr-my-1v">
<Link
passHref
href={{
pathname: `/moissonneur-bal/organizations/${_id}`,
}}
>
<Button iconId="fr-icon-arrow-right-line" iconPosition="right">
Consulter
</Button>
</Link>
</td>
</tr>
);

export default MoissoneurOrganizationItem;
67 changes: 67 additions & 0 deletions components/moissonneur-bal/sources/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import MoissoneurSourceItem from "@/components/moissonneur-bal/sources/moissonneur-source-item";
import { SourceMoissoneurType } from "types/moissoneur";
import { useState } from "react";

type MoissoneurSourcesProps = {
sources: SourceMoissoneurType[];
};

const MoissoneurSources = ({ sources }: MoissoneurSourcesProps) => {
const getFilteredSource = (showDeleted: boolean): SourceMoissoneurType[] => {
if (showDeleted) {
return sources;
}
return sources.filter((s) => !s._deleted);
};

const [showDeleted, setShowDeleted] = useState<boolean>(false);
const [sourcesFiltered, setSourcesFiltered] = useState<
SourceMoissoneurType[]
>(getFilteredSource(showDeleted));

const toggleShowDelete = () => {
const isShowDeleted = !showDeleted;
setShowDeleted(isShowDeleted);
setSourcesFiltered(getFilteredSource(isShowDeleted));
};

return (
<div className="fr-container fr-py-12v">
<div className="fr-toggle">
<input
type="checkbox"
className="fr-toggle__input"
aria-describedby="toggle-source-hint-text"
id="toggle-source"
checked={showDeleted}
onChange={toggleShowDelete}
/>
<label className="fr-toggle__label" htmlFor="toggle-source">
Voir supprimé
</label>
</div>
<div className="fr-table">
<table>
<caption>Liste des sources moissonnées</caption>
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Title</th>
<th scope="col">Actif</th>
<th scope="col">Date de mise à jour</th>
<th scope="col" />
</tr>
</thead>

<tbody>
{sourcesFiltered.map((source) => (
<MoissoneurSourceItem key={source._id} {...source} />
))}
</tbody>
</table>
</div>
</div>
);
};

export default MoissoneurSources;
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,34 @@ import Button from "@codegouvfr/react-dsfr/Button";

import { formatDate } from "@/lib/util/date";
import Badge from "@codegouvfr/react-dsfr/Badge";
import { SourceMoissoneurType } from "types/moissoneur";

interface MoissoneurSourceItemProps {
_id: string;
title: string;
model: string;
type: string;
_deleted: boolean;
_updated?: string;
}

const MoissoneurSourceItem = ({
_id,
title,
model,
type,
enabled,
_deleted,
_updated,
}: MoissoneurSourceItemProps) => (
}: SourceMoissoneurType) => (
<tr>
<td className="fr-col fr-my-1v">{_id}</td>
<td className="fr-col fr-my-1v">{title}</td>
<td className="fr-col fr-my-1v">{model}</td>
<td className="fr-col fr-my-1v">{type}</td>
<td>
{_deleted ? (
<Badge severity="error" style={{ marginRight: 2, marginBottom: 2 }}>
Supprimé
</Badge>
) : (
<Badge severity="success" style={{ marginRight: 2, marginBottom: 2 }}>
Actif
</Badge>
)}
) : enabled ? (
<Badge severity="success" style={{ marginRight: 2, marginBottom: 2 }}>
Activé
</Badge>
) : (
<Badge severity="error" style={{ marginRight: 2, marginBottom: 2 }}>
Désactivé
</Badge>
)
}
</td>
<td className="fr-col fr-my-1v">
{_updated ? formatDate(_updated) : "inconnu"}
Expand All @@ -44,8 +40,7 @@ const MoissoneurSourceItem = ({
<Link
passHref
href={{
pathname: "/moissonneur-bal/sources",
query: { sourceId: _id },
pathname: `/moissonneur-bal/sources/${_id}`,
}}
>
<Button iconId="fr-icon-arrow-right-line" iconPosition="right">
Expand Down
Loading

0 comments on commit 7c8867c

Please sign in to comment.