From 3810d96066461dbea5574cedc062c7a9cc08eecd Mon Sep 17 00:00:00 2001 From: camilovegag Date: Mon, 27 May 2024 12:56:35 +0200 Subject: [PATCH 1/4] Fix long usernames at comments table --- .../columns/comments-columns/CommentsColumns.styled.tsx | 2 +- .../components/tables/comment-table/CommentsTable.styled.tsx | 4 +++- .../src/components/tables/comment-table/CommentsTable.tsx | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/berlin/src/components/columns/comments-columns/CommentsColumns.styled.tsx b/packages/berlin/src/components/columns/comments-columns/CommentsColumns.styled.tsx index fe08b092..8d3fb671 100644 --- a/packages/berlin/src/components/columns/comments-columns/CommentsColumns.styled.tsx +++ b/packages/berlin/src/components/columns/comments-columns/CommentsColumns.styled.tsx @@ -8,7 +8,7 @@ export const Card = styled(Grid)` grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) 56px; @media (min-width: 600px) { - grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) minmax(100px, 150px) 56px; + grid-template-columns: minmax(200px, 600px) minmax(100px, 200px) minmax(80px, 100px) 56px; } `; diff --git a/packages/berlin/src/components/tables/comment-table/CommentsTable.styled.tsx b/packages/berlin/src/components/tables/comment-table/CommentsTable.styled.tsx index a2a4493f..a1749a50 100644 --- a/packages/berlin/src/components/tables/comment-table/CommentsTable.styled.tsx +++ b/packages/berlin/src/components/tables/comment-table/CommentsTable.styled.tsx @@ -11,7 +11,7 @@ export const Card = styled(Grid)` grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) 56px; @media (min-width: 600px) { - grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) minmax(100px, 150px) 56px; + grid-template-columns: minmax(200px, 600px) minmax(100px, 200px) minmax(80px, 100px) 56px; } `; @@ -19,6 +19,8 @@ export const Comment = styled(Body)``; export const Author = styled(Body)` font-weight: 600; + overflow: hidden; + text-overflow: ellipsis; `; export const FormattedDate = styled(Body)` diff --git a/packages/berlin/src/components/tables/comment-table/CommentsTable.tsx b/packages/berlin/src/components/tables/comment-table/CommentsTable.tsx index 34edcac3..725460d9 100644 --- a/packages/berlin/src/components/tables/comment-table/CommentsTable.tsx +++ b/packages/berlin/src/components/tables/comment-table/CommentsTable.tsx @@ -99,11 +99,11 @@ function CommentsTable({ comment }: CommentsTableProps) { }; return ( - + {comment.value} - @{comment.user?.username} + @{comment.user?.username} {formattedDate} Date: Mon, 27 May 2024 23:31:37 +0200 Subject: [PATCH 2/4] sort by lead if votes are equal --- packages/berlin/src/pages/Cycle.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/berlin/src/pages/Cycle.tsx b/packages/berlin/src/pages/Cycle.tsx index 76cab748..9c6e1df6 100644 --- a/packages/berlin/src/pages/Cycle.tsx +++ b/packages/berlin/src/pages/Cycle.tsx @@ -233,6 +233,11 @@ function Cycle() { ) => { const votesA = localUserVotes?.find((vote) => vote.optionId === a.id)?.numOfVotes || 0; const votesB = localUserVotes?.find((vote) => vote.optionId === b.id)?.numOfVotes || 0; + + if (votesA === votesB) { + return sortByLead(a, b, order); + } + return order === 'desc' ? votesB - votesA : votesA - votesB; }; From b8b678e00f046f785bbba4b1df88d6f49f53a8f0 Mon Sep 17 00:00:00 2001 From: Diego Alzate Date: Mon, 27 May 2024 23:41:24 +0200 Subject: [PATCH 3/4] sort by id if votes are equal --- packages/berlin/src/pages/Cycle.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/berlin/src/pages/Cycle.tsx b/packages/berlin/src/pages/Cycle.tsx index 9c6e1df6..38e1b74e 100644 --- a/packages/berlin/src/pages/Cycle.tsx +++ b/packages/berlin/src/pages/Cycle.tsx @@ -235,7 +235,10 @@ function Cycle() { const votesB = localUserVotes?.find((vote) => vote.optionId === b.id)?.numOfVotes || 0; if (votesA === votesB) { - return sortByLead(a, b, order); + const idA = a.id.toUpperCase(); + const idB = b.id.toUpperCase(); + + return order === 'desc' ? idB.localeCompare(idA) : idA.localeCompare(idB); } return order === 'desc' ? votesB - votesA : votesA - votesB; From 348058595358b62bc02b71d30fd44b81dc31982c Mon Sep 17 00:00:00 2001 From: Diego Alzate Date: Mon, 27 May 2024 23:46:16 +0200 Subject: [PATCH 4/4] add sort fallback by id --- packages/berlin/src/pages/Cycle.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/berlin/src/pages/Cycle.tsx b/packages/berlin/src/pages/Cycle.tsx index 38e1b74e..2fe0557b 100644 --- a/packages/berlin/src/pages/Cycle.tsx +++ b/packages/berlin/src/pages/Cycle.tsx @@ -211,15 +211,32 @@ function Cycle() { const currentCycle = cycle?.forumQuestions[0]; + const sortId = (a: QuestionOption, b: QuestionOption, order: Order) => { + const idA = a.id.toUpperCase(); + const idB = b.id.toUpperCase(); + + return order === 'desc' ? idB.localeCompare(idA) : idA.localeCompare(idB); + }; + const sortByLead = (a: QuestionOption, b: QuestionOption, order: Order) => { const leadA = (a.user.lastName || a.user.username).toUpperCase(); const leadB = (b.user.lastName || b.user.username).toUpperCase(); + + if (leadA === leadB) { + return sortId(a, b, order); + } + return order === 'desc' ? leadB.localeCompare(leadA) : leadA.localeCompare(leadB); }; const sortByAffiliation = (a: QuestionOption, b: QuestionOption, order: Order) => { const affiliationA = a.user.group?.name.toUpperCase(); const affiliationB = b.user.group?.name.toUpperCase() ?? ''; + + if (affiliationA === affiliationB) { + return sortId(a, b, order); + } + return order === 'desc' ? affiliationB.localeCompare(affiliationA) : affiliationA.localeCompare(affiliationB); @@ -235,10 +252,7 @@ function Cycle() { const votesB = localUserVotes?.find((vote) => vote.optionId === b.id)?.numOfVotes || 0; if (votesA === votesB) { - const idA = a.id.toUpperCase(); - const idB = b.id.toUpperCase(); - - return order === 'desc' ? idB.localeCompare(idA) : idA.localeCompare(idB); + return sortId(a, b, order); } return order === 'desc' ? votesB - votesA : votesA - votesB;