From 2fbd4d2834a906fcbbe511287be963acfdaaa5be Mon Sep 17 00:00:00 2001 From: HelaKaraa Date: Fri, 15 Nov 2024 16:55:01 +0100 Subject: [PATCH 1/4] feat#893: add wipeData toggle button --- .../maif/izanami/web/ImportController.scala | 6 +- conf/routes | 2 +- izanami-frontend/src/pages/tenantSettings.tsx | 72 +++++++----- izanami-frontend/src/utils/queries.tsx | 106 +++--------------- izanami-frontend/src/utils/types.ts | 1 + 5 files changed, 64 insertions(+), 123 deletions(-) diff --git a/app/fr/maif/izanami/web/ImportController.scala b/app/fr/maif/izanami/web/ImportController.scala index c7e4510c4..42e5e13b3 100644 --- a/app/fr/maif/izanami/web/ImportController.scala +++ b/app/fr/maif/izanami/web/ImportController.scala @@ -194,6 +194,7 @@ class ImportController( version: Int, tenant: String, conflict: String, + wipeData: Option[Boolean], timezone: Option[String], deduceProject: Boolean, create: Option[Boolean], @@ -219,7 +220,7 @@ class ImportController( }) .getOrElse(BadRequest(Json.obj("message" -> "Missing timezone")).future) } else if (version == 2) { - importV2Data(request, tenant, conflict) + importV2Data(request, tenant, conflict, wipeData) } else { BadRequest(Json.obj("message" -> s"Invalid version: $version")).future } @@ -228,7 +229,8 @@ class ImportController( def importV2Data( request: UserNameRequest[MultipartFormData[Files.TemporaryFile]], tenant: String, - conflict: String + conflict: String, + wipeData: Option[Boolean] ): Future[Result] = { val files: Map[String, URI] = request.body.files.map(f => (f.key, f.ref.path.toUri)).toMap (for ( diff --git a/conf/routes b/conf/routes index c0dacd34a..421b73a56 100644 --- a/conf/routes +++ b/conf/routes @@ -96,7 +96,7 @@ PUT /api/admin/tenants/:tenant/local-scripts/:script DELETE /api/admin/local-scripts/_cache fr.maif.izanami.web.PluginController.clearWasmCache() DELETE /api/admin/tenants/:tenant/local-scripts/:script fr.maif.izanami.web.PluginController.deleteScript(tenant: String, script: String) -POST /api/admin/tenants/:tenant/_import fr.maif.izanami.web.ImportController.importData(version: Int, tenant: String, conflict: String, timezone: Option[String], deduceProject: Boolean ?= false, create: Option[Boolean], project: Option[String], projectPartSize: Option[Int], inlineScript: Option[Boolean]) +POST /api/admin/tenants/:tenant/_import fr.maif.izanami.web.ImportController.importData(version: Int, tenant: String, conflict: String,wipedData : Option[Boolean], timezone: Option[String], deduceProject: Boolean ?= false, create: Option[Boolean], project: Option[String], projectPartSize: Option[Int], inlineScript: Option[Boolean]) GET /api/admin/tenants/:tenant/_import/:id fr.maif.izanami.web.ImportController.readImportStatus(tenant: String, id: String) DELETE /api/admin/tenants/:tenant/_import/:id fr.maif.izanami.web.ImportController.deleteImportStatus(tenant: String, id: String) diff --git a/izanami-frontend/src/pages/tenantSettings.tsx b/izanami-frontend/src/pages/tenantSettings.tsx index f2fd78737..85d68eb28 100644 --- a/izanami-frontend/src/pages/tenantSettings.tsx +++ b/izanami-frontend/src/pages/tenantSettings.tsx @@ -400,15 +400,17 @@ function ImportForm(props: { const { cancel, submit } = props; const methods = useForm({ - defaultValues: {}, + defaultValues: { wipeData: false }, }); const { handleSubmit, register, + getValues, + watch, control, formState: { isSubmitting }, } = methods; - + watch(["wipeData"]); return (

Import data

+ {!getValues("wipeData") && ( +