Skip to content

Commit

Permalink
Add sort by date recent for active users and docs (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
rutujaac authored May 2, 2024
1 parent 0440d1f commit 310275e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
50 changes: 30 additions & 20 deletions pebblo/app/pebblo-ui/src/constants/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getFormattedDate,
getMaxValue,
getStringOfNItems,
sortByDate,
} from "../util.js";
import { KEYWORD_MAPPING } from "./keywordMapping.js";
import {
Expand Down Expand Up @@ -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 = [
Expand Down
15 changes: 15 additions & 0 deletions pebblo/app/pebblo-ui/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
: [];
};

0 comments on commit 310275e

Please sign in to comment.