From 40e76bac0c9673e1009ffec1539bfff22edb22b3 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Wed, 22 Mar 2023 19:05:13 -0800 Subject: [PATCH] feat: filter details for zero values (#364) * filter details for zero values * ensure exhaustive checks * update event listener to only bind when collapsable --- frontend/components/Base/Card.vue | 50 +++++++++++++++---- .../components/global/DetailsSection/types.ts | 20 ++++++++ frontend/pages/item/[id]/index.vue | 45 +++++++++++++---- 3 files changed, 95 insertions(+), 20 deletions(-) diff --git a/frontend/components/Base/Card.vue b/frontend/components/Base/Card.vue index 464066f..88fef80 100644 --- a/frontend/components/Base/Card.vue +++ b/frontend/components/Base/Card.vue @@ -1,16 +1,46 @@ + + diff --git a/frontend/components/global/DetailsSection/types.ts b/frontend/components/global/DetailsSection/types.ts index 92c6f90..74135fb 100644 --- a/frontend/components/global/DetailsSection/types.ts +++ b/frontend/components/global/DetailsSection/types.ts @@ -36,3 +36,23 @@ export type Detail = BaseDetail & { export type AnyDetail = DateDetail | CurrencyDetail | LinkDetail | MarkdownDetail | Detail; export type Details = Array; + +export function filterZeroValues(details: Details): Details { + return details.filter(detail => { + switch (detail.type) { + case "date": + return validDate(detail.text); + case "currency": + return !!detail.text; + case "link": + return !!detail.text && !!detail.href; + case undefined: + case "text": + case "markdown": + return detail.text !== null && detail.text !== "" && detail.text !== undefined; + default: + console.warn("Unknown detail type (this should never happen)", detail); + return false; + } + }); +} diff --git a/frontend/pages/item/[id]/index.vue b/frontend/pages/item/[id]/index.vue index 5794a77..e9fb281 100644 --- a/frontend/pages/item/[id]/index.vue +++ b/frontend/pages/item/[id]/index.vue @@ -1,5 +1,5 @@