From 8bbe00b55a0ac9250322682dfa23ce08aa061b23 Mon Sep 17 00:00:00 2001 From: Owen Sellner <43042601+owen-sellner@users.noreply.github.com> Date: Sun, 3 Dec 2023 17:20:50 -0500 Subject: [PATCH] Note, Tags, and Residents Column Formatting (#208) * add tags formatting * add formatting for residents * add notes formatting * fix table header * add variable for constant value * fix dropdown overlap --- frontend/src/components/forms/EditLog.tsx | 2 +- .../pages/HomePage/LogRecordsTable.tsx | 76 +++++++++++++------ .../pages/HomePage/SearchAndFilters.tsx | 2 +- frontend/src/theme/common/tableStyles.tsx | 1 + 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/forms/EditLog.tsx b/frontend/src/components/forms/EditLog.tsx index a32b83b1..12fcdda0 100644 --- a/frontend/src/components/forms/EditLog.tsx +++ b/frontend/src/components/forms/EditLog.tsx @@ -221,7 +221,7 @@ const EditLog = ({ ); setBuildingId(logRecord.building.id); const residentIds = residentOptions.filter( - (item) => logRecord.residents.includes(item.label), + (item) => logRecord.residents && logRecord.residents.includes(item.label), ).map((item) => item.value); setResidents(residentIds); const tagIds = tagOptions.filter( diff --git a/frontend/src/components/pages/HomePage/LogRecordsTable.tsx b/frontend/src/components/pages/HomePage/LogRecordsTable.tsx index 6fc80934..b18690c7 100644 --- a/frontend/src/components/pages/HomePage/LogRecordsTable.tsx +++ b/frontend/src/components/pages/HomePage/LogRecordsTable.tsx @@ -50,6 +50,28 @@ const DELETE_CONFIRMATION_HEADER = "Delete Log Record"; const DELETE_CONFIRMATION_MESSAGE = "Are you sure you want to delete this log record? Deleting a log record will permanently remove it from your system."; +const formatNote = (note: string) => { + const NOTE_LIMIT = 150; + if (note.length > NOTE_LIMIT) { + return note.substring(0, NOTE_LIMIT).concat("..."); + } + return note; +}; + +const formatList = (strArr: string[]) => { + const strLength = strArr?.length; + if (strLength === 1) { + return strArr[0]; + } + if (strLength === 2) { + return strArr?.join(", "); + } + if (strLength > 2) { + return `${strArr?.slice(0, 2).join(", ")}, ...`; + } + return ""; +}; + const LogRecordsTable = ({ logRecords, tableRef, @@ -183,6 +205,7 @@ const LogRecordsTable = ({