From c751a73900bcb1fb7d8980d6ee991acbc01e42f9 Mon Sep 17 00:00:00 2001 From: rutujaac Date: Thu, 2 May 2024 18:53:33 +0530 Subject: [PATCH] Add sort by date recent for active users and docs --- .../app/pebblo-ui/src/constants/constant.js | 50 +++++++++++-------- pebblo/app/pebblo-ui/src/util.js | 15 ++++++ 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/pebblo/app/pebblo-ui/src/constants/constant.js b/pebblo/app/pebblo-ui/src/constants/constant.js index ce5d8112..5724ac6c 100644 --- a/pebblo/app/pebblo-ui/src/constants/constant.js +++ b/pebblo/app/pebblo-ui/src/constants/constant.js @@ -17,6 +17,7 @@ import { getFormattedDate, getMaxValue, getStringOfNItems, + sortByDate, } from "../util.js"; import { KEYWORD_MAPPING } from "./keywordMapping.js"; import { @@ -910,30 +911,39 @@ export const TABS_ARR_FOR_APP_DETAILS_RETRIEVAL = [ let retrievalAppUserBasedRetrievalTotal = 0; let retrievalAppDocumentRetrievalTotal = 0; + const retrievalAppActiveUsersData = APP_DATA?.activeUsers - ? Object.keys(APP_DATA?.activeUsers)?.map((activeUser, index) => { - const data = APP_DATA?.activeUsers[activeUser]; - retrievalAppUserBasedRetrievalTotal += data?.retrievals?.length || 0; - return { - ...data, - id: index + 1, - name: activeUser, - retrievalCount: data?.retrievals?.length, - }; - }) + ? sortByDate( + Object.keys(APP_DATA?.activeUsers)?.map((activeUser, index) => { + const data = APP_DATA?.activeUsers[activeUser]; + retrievalAppUserBasedRetrievalTotal += data?.retrievals?.length || 0; + return { + ...data, + id: index + 1, + name: activeUser, + retrievalCount: data?.retrievals?.length, + }; + }), + "last_accessed_time", + "desc" + ) : []; const retrievalAppDocumentData = APP_DATA?.documents - ? Object.keys(APP_DATA?.documents)?.map((document, index) => { - const data = APP_DATA?.documents[document]; - retrievalAppDocumentRetrievalTotal += data?.retrievals?.length || 0; - return { - ...data, - id: index + 1, - name: document, - retrievalCount: data?.retrievals?.length, - }; - }) + ? sortByDate( + Object.keys(APP_DATA?.documents)?.map((document, index) => { + const data = APP_DATA?.documents[document]; + retrievalAppDocumentRetrievalTotal += data?.retrievals?.length || 0; + return { + ...data, + id: index + 1, + name: document, + retrievalCount: data?.retrievals?.length, + }; + }), + "last_accessed_time", + "desc" + ) : []; export const TAB_PANEL_FOR_APP_ACTIVE_USERS = [ diff --git a/pebblo/app/pebblo-ui/src/util.js b/pebblo/app/pebblo-ui/src/util.js index 4f758c03..6e5499d7 100644 --- a/pebblo/app/pebblo-ui/src/util.js +++ b/pebblo/app/pebblo-ui/src/util.js @@ -151,3 +151,18 @@ export const getDifferenceInDays = (date1, date2) => { export const capitalizeFirstLetter = (str) => str ? str.charAt(0).toUpperCase() + str.slice(1) : ""; + +export const sortByDate = (arr, key, order = "asc") => { + return arr + ? arr.sort((date1, date2) => { + if (date1[key] && date2[key]) { + if (order === "asc") { + return new Date(date1[key]) - new Date(date2[key]); + } else { + return new Date(date2[key]) - new Date(date1[key]); + } + } + return 0; + }) + : []; +};