From e375a12ae7513341bd803c57d8cb7d41c409348b Mon Sep 17 00:00:00 2001 From: frozenhelium Date: Wed, 6 Mar 2024 15:51:45 +0545 Subject: [PATCH] Fix minor issues in various pages --- .../components/domain/AppealsTable/index.tsx | 1 - .../i18n.json | 4 +-- .../index.tsx | 2 +- app/src/views/GlobalThreeW/Map/index.tsx | 2 +- .../MovementActivitiesMap/index.tsx | 2 +- app/src/views/RegionThreeW/index.tsx | 2 +- app/src/views/ThreeWProjectDetail/index.tsx | 2 +- .../components/Table/ColumnShortcuts/index.ts | 2 +- packages/ui/src/utils/common.ts | 31 ++++++++++++++++++- 9 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/src/components/domain/AppealsTable/index.tsx b/app/src/components/domain/AppealsTable/index.tsx index 0b3a88bd7..387efc90d 100644 --- a/app/src/components/domain/AppealsTable/index.tsx +++ b/app/src/components/domain/AppealsTable/index.tsx @@ -173,7 +173,6 @@ function AppealsTable(props: Props) { createProgressColumn( 'amount_funded', strings.appealsTableFundedAmount, - // FIXME: use progress function (item) => ( getPercentage( item.amount_funded, diff --git a/app/src/views/CountryOngoingActivitiesThreeWProjects/i18n.json b/app/src/views/CountryOngoingActivitiesThreeWProjects/i18n.json index 5db9b43c0..a711c41c4 100644 --- a/app/src/views/CountryOngoingActivitiesThreeWProjects/i18n.json +++ b/app/src/views/CountryOngoingActivitiesThreeWProjects/i18n.json @@ -8,8 +8,8 @@ "failedToCreateExport": "Failed to generate export.", "totalProjectsTitle": "Total Projects", "ongoingProjectBudgetTitle": "Total Budget (CHF) for Ongoing Projects", - "threeWOngoingProjectsTitle": "All Projects", - "viewAllOngoingProjects": "View All Ongoing Projects", + "threeWOngoingProjectsTitle": "Ongoing Projects", + "viewAllProjects": "View all Projects in this Country", "threeWInCountryMapSidebarTitle": "Projects by Province", "provinceProjects": "{provinceName} ({numProjects} Projects)", "otherProjects": "Others ({numProjects} Projects)", diff --git a/app/src/views/CountryOngoingActivitiesThreeWProjects/index.tsx b/app/src/views/CountryOngoingActivitiesThreeWProjects/index.tsx index 4e08affc0..d5109c281 100644 --- a/app/src/views/CountryOngoingActivitiesThreeWProjects/index.tsx +++ b/app/src/views/CountryOngoingActivitiesThreeWProjects/index.tsx @@ -479,7 +479,7 @@ export function Component() { urlSearch={`country=${countryResponse?.id}`} withLinkIcon > - {strings.viewAllOngoingProjects} + {strings.viewAllProjects} )} diff --git a/app/src/views/GlobalThreeW/Map/index.tsx b/app/src/views/GlobalThreeW/Map/index.tsx index 97959519b..b558baca8 100644 --- a/app/src/views/GlobalThreeW/Map/index.tsx +++ b/app/src/views/GlobalThreeW/Map/index.tsx @@ -379,7 +379,7 @@ function GlobalThreeWMap(props: Props) { onCloseButtonClick={handlePointClose} heading={( diff --git a/app/src/views/RegionThreeW/index.tsx b/app/src/views/RegionThreeW/index.tsx index ebbea46a8..a453e41b1 100644 --- a/app/src/views/RegionThreeW/index.tsx +++ b/app/src/views/RegionThreeW/index.tsx @@ -193,7 +193,7 @@ export function Component() { title: (
{country.name} diff --git a/app/src/views/ThreeWProjectDetail/index.tsx b/app/src/views/ThreeWProjectDetail/index.tsx index f5007b8cd..2cb420ecc 100644 --- a/app/src/views/ThreeWProjectDetail/index.tsx +++ b/app/src/views/ThreeWProjectDetail/index.tsx @@ -159,7 +159,7 @@ export function Component() { value={( ( export function createProgressColumn( id: string, title: string, - accessor: (item: D) => number, + accessor: (item: D) => number | undefined, options?: Options, ) { const item: Column & { diff --git a/packages/ui/src/utils/common.ts b/packages/ui/src/utils/common.ts index 875a8b602..b9a09d972 100644 --- a/packages/ui/src/utils/common.ts +++ b/packages/ui/src/utils/common.ts @@ -81,12 +81,41 @@ export function roundSafe(value: number | undefined | null): number | undefined return Math.round(value); } +export function getPercentage( + value: null | undefined, + total: null | undefined, + isBounded?: boolean, +): undefined +export function getPercentage( + value: number, + total: null | undefined, + isBounded?: boolean, +): undefined +export function getPercentage( + value: null | undefined, + total: number, + isBounded?: boolean, +): undefined +export function getPercentage( + value: number, + total: number, + isBounded?: boolean, +): number +export function getPercentage( + value: number | null | undefined, + total: number | null | undefined, + isBounded?: boolean, +): number | undefined export function getPercentage( value: number | null | undefined, total: number | null | undefined, isBounded = true, ) { - if (isNotDefined(value) || isNotDefined(total) || total === 0) { + if (isNotDefined(value) || isNotDefined(total)) { + return undefined; + } + + if (total === 0) { return 0; }