Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort by date recent for active users and docs #377

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
})
: [];
};