From 9362e1de515c0282ca18f88807b40c6df9729679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Mon, 14 Oct 2024 15:09:28 +0200 Subject: [PATCH] Conditional fallback value for some table columns --- .../tables/national-highseas/hooks.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx b/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx index ea42c422..de234b90 100644 --- a/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx +++ b/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx @@ -423,7 +423,17 @@ export const useColumns = ( ), cell: ({ row }) => { const { mpaa_establishment_stage } = row.original; - const formattedValue = mpaa_establishment_stage.name || t('not-assessed'); + + const hasSubRowWithValue = + row.subRows.length > 0 && + row.subRows.some((row) => !!row.original.mpaa_establishment_stage); + + let fallbackValue = t('not-assessed'); + if (hasSubRowWithValue) { + fallbackValue = '−'; + } + + const formattedValue = mpaa_establishment_stage.name ?? fallbackValue; return <>{formattedValue}; }, }, @@ -448,7 +458,17 @@ export const useColumns = ( ), cell: ({ row }) => { const { mpaa_protection_level } = row.original; - const formattedValue = mpaa_protection_level.name || t('not-assessed'); + + const hasSubRowWithValue = + row.subRows.length > 0 && + row.subRows.some((row) => !!row.original.mpaa_protection_level); + + let fallbackValue = t('not-assessed'); + if (hasSubRowWithValue) { + fallbackValue = '−'; + } + + const formattedValue = mpaa_protection_level.name ?? fallbackValue; return <>{formattedValue}; }, },