-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ajoute possibilité dépublier un service
- Loading branch information
Showing
6 changed files
with
210 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
assets/pages/datasheet/DatasheetView/ServiceListTab/ServicesListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import Badge from "@codegouvfr/react-dsfr/Badge"; | ||
import Button from "@codegouvfr/react-dsfr/Button"; | ||
import { createModal } from "@codegouvfr/react-dsfr/Modal"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { FC } from "react"; | ||
import { createPortal } from "react-dom"; | ||
import { symToStr } from "tsafe/symToStr"; | ||
|
||
import api from "../../../../api"; | ||
import MenuList from "../../../../components/Utils/MenuList"; | ||
import functions from "../../../../functions"; | ||
import RQKeys from "../../../../modules/RQKeys"; | ||
import { routes } from "../../../../router/router"; | ||
import { Service } from "../../../../types/app"; | ||
|
||
const unpublishServiceConfirmModal = createModal({ | ||
id: "unpublish-service-confirm-modal", | ||
isOpenedByDefault: false, | ||
}); | ||
|
||
type ServicesListItemProps = { | ||
service: Service; | ||
datastoreId: string; | ||
datasheetName: string; | ||
}; | ||
const ServicesListItem: FC<ServicesListItemProps> = ({ service, datasheetName, datastoreId }) => { | ||
const queryClient = useQueryClient(); | ||
|
||
const handleUnpublishService = () => { | ||
api.service | ||
.unpublish(datastoreId, service._id) | ||
.then(() => { | ||
queryClient.refetchQueries({ queryKey: RQKeys.datastore_datasheet(datastoreId, datasheetName) }); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div key={service._id} className={fr.cx("fr-grid-row", "fr-grid-row--middle", "fr-mt-2v")}> | ||
<div className={fr.cx("fr-col")}> | ||
<div className={fr.cx("fr-grid-row", "fr-grid-row--middle")}> | ||
<Button iconId="ri-add-box-fill" title="Voir les données liées" className={fr.cx("fr-mr-2v")} /> | ||
{service.configuration.name} | ||
</div> | ||
</div> | ||
|
||
<div className={fr.cx("fr-col")}> | ||
<div className={fr.cx("fr-grid-row", "fr-grid-row--right", "fr-grid-row--middle")}> | ||
{/* TODO : afficher le bon type de service */} | ||
<Badge>Web Feature Service</Badge> | ||
<p className={fr.cx("fr-m-auto", "fr-mr-2v")}> | ||
{service?.configuration?.last_event?.date && functions.date.format(service?.configuration?.last_event?.date)} | ||
</p> | ||
<i className={fr.cx("fr-mr-2v", service.open ? "fr-icon-lock-unlock-fill" : "fr-icon-lock-fill")} /> | ||
|
||
<Button | ||
className={fr.cx("fr-mr-2v")} | ||
linkProps={routes.datastore_service_view({ datastoreId, offeringId: service._id, datasheetName: datasheetName }).link} | ||
> | ||
Visualiser | ||
</Button> | ||
<MenuList | ||
menuOpenButtonProps={{ | ||
iconId: "fr-icon-menu-2-fill", | ||
title: "Autres actions", | ||
}} | ||
items={[ | ||
{ | ||
text: "Copier l'URL de diffusion", | ||
iconId: "ri-file-copy-2-line", | ||
onClick: () => console.warn("Action non implémentée"), | ||
}, | ||
{ | ||
text: "Gérer les styles", | ||
iconId: "ri-flashlight-line", | ||
onClick: () => console.warn("Action non implémentée"), | ||
}, | ||
{ | ||
text: "Mettre à jour la légende", | ||
iconId: "ri-list-check", | ||
onClick: () => console.warn("Action non implémentée"), | ||
}, | ||
{ | ||
text: "Modifier les informations de publication", | ||
iconId: "ri-edit-box-line", | ||
onClick: () => console.warn("Action non implémentée"), | ||
}, | ||
{ | ||
text: "Remplacer les données", | ||
iconId: "fr-icon-refresh-line", | ||
onClick: () => console.warn("Action non implémentée"), | ||
}, | ||
{ | ||
text: "Dépublier", | ||
iconId: "ri-arrow-go-back-line", | ||
onClick: () => unpublishServiceConfirmModal.open(), | ||
}, | ||
]} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{createPortal( | ||
<unpublishServiceConfirmModal.Component | ||
title={`Êtes-vous sûr de dépublier le service ${service.type} ?`} | ||
buttons={[ | ||
{ | ||
children: "Non, annuler", | ||
doClosesModal: true, | ||
priority: "secondary", | ||
}, | ||
{ | ||
children: "Oui, supprimer", | ||
onClick: () => handleUnpublishService(), | ||
doClosesModal: true, | ||
priority: "primary", | ||
}, | ||
]} | ||
> | ||
<strong>Les éléments suivants seront supprimés :</strong> | ||
<ul> | ||
<li>1 offre ({service._id})</li> | ||
<li>1 configuration ({service.configuration._id})</li> | ||
</ul> | ||
</unpublishServiceConfirmModal.Component>, | ||
document.body | ||
)} | ||
</> | ||
); | ||
}; | ||
ServicesListItem.displayName = symToStr({ ServicesListItem }); | ||
|
||
export default ServicesListItem; |
28 changes: 28 additions & 0 deletions
28
assets/pages/datasheet/DatasheetView/ServiceListTab/ServicesListTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import { FC } from "react"; | ||
import { symToStr } from "tsafe/symToStr"; | ||
|
||
import Translator from "../../../../modules/Translator"; | ||
import { DatasheetDetailed } from "../../../../types/app"; | ||
import ServicesListItem from "./ServicesListItem"; | ||
|
||
type ServicesListTabProps = { | ||
datasheet?: DatasheetDetailed; | ||
datastoreId: string; | ||
}; | ||
const ServicesListTab: FC<ServicesListTabProps> = ({ datastoreId, datasheet }) => { | ||
if (!datasheet?.service_list || datasheet?.service_list.length === 0) { | ||
return ( | ||
<div className={fr.cx("fr-grid-row", "fr-grid-row--middle")}> | ||
<p>{Translator.trans("datasheet.view.services.no_service")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
return datasheet?.service_list?.map((service) => ( | ||
<ServicesListItem key={service._id} service={service} datasheetName={datasheet.name} datastoreId={datastoreId} /> | ||
)); | ||
}; | ||
ServicesListTab.displayName = symToStr({ ServicesListTab }); | ||
|
||
export default ServicesListTab; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters