From 2b36d53e120c8286e54026569bf031a60f7b155c Mon Sep 17 00:00:00 2001 From: Steve McConnel Date: Thu, 17 Oct 2024 09:48:35 -0600 Subject: [PATCH] Allow Reads and Downloads to be sorted in books grid (BL-13994) --- src/components/Grid/GridColumns.tsx | 12 ++++++------ src/connection/LibraryQueryHooks.ts | 30 ++++------------------------- src/model/Book.ts | 2 ++ 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/components/Grid/GridColumns.tsx b/src/components/Grid/GridColumns.tsx index 9d528e82..b3e0e6e5 100644 --- a/src/components/Grid/GridColumns.tsx +++ b/src/components/Grid/GridColumns.tsx @@ -366,16 +366,16 @@ export function getBookGridColumnsDefinitions(): IGridColumn[] { defaultVisible: false, }, { - // cannot be used for sorting or filtering until we have only one database source - name: "reads", - sortingEnabled: false, + name: "analytics_finishedCount", + title: "Reads", + sortingEnabled: true, getCellValue: (b: Book) => b.stats.finishedCount, defaultVisible: false, }, { - // cannot be used for sorting or filtering until we have only one database source - name: "downloadsForTranslation", - sortingEnabled: false, + name: "analytics_shellDownloads", + title: "Downloads for Translation", + sortingEnabled: true, getCellValue: (b: Book) => b.stats.shellDownloads, defaultVisible: false, }, diff --git a/src/connection/LibraryQueryHooks.ts b/src/connection/LibraryQueryHooks.ts index 087e6891..c9951611 100644 --- a/src/connection/LibraryQueryHooks.ts +++ b/src/connection/LibraryQueryHooks.ts @@ -7,7 +7,7 @@ import { getBloomApiUrl, getBloomApiHeaders, } from "./ApiConnection"; -import { retrieveBookData, retrieveBookStats } from "./LibraryQueries"; +import { retrieveBookData } from "./LibraryQueries"; import { Book, createBookFromParseServerData } from "../model/Book"; import { useContext, useMemo, useEffect, useState } from "react"; import { CachedTablesContext } from "../model/CacheProvider"; @@ -393,7 +393,8 @@ export const gridBookKeys = "title,baseUrl,license,licenseNotes,inCirculation,draft,summary,copyright,harvestState," + "harvestLog,harvestStartedAt,tags,pageCount,phashOfFirstContentImage,show,credits,country," + "features,internetLimits,librarianNote,uploader,langPointers,importedBookSourceUrl," + - "downloadCount,publisher,originalPublisher,brandingProjectName,keywords,edition,rebrand,leveledReaderLevel"; + "downloadCount,publisher,originalPublisher,brandingProjectName,keywords,edition,rebrand,leveledReaderLevel," + + "analytics_finishedCount,analytics_shellDownloads"; export const gridBookIncludeFields = "uploader,langPointers"; @@ -430,11 +431,6 @@ export function useGetBooksForGrid( trigger, doNotActuallyRunQuery ); - const stats = useAsync( - () => retrieveBookStats(query, order, skip, limit), - trigger, - doNotActuallyRunQuery - ); // Before we had this useEffect, we would get a new instance of each book, each time the grid re-rendered. // Besides being inefficient, it led to a very difficult bug in the embedded staff panel where we would @@ -466,26 +462,8 @@ export function useGetBooksForGrid( onePageOfMatchingBooks: onePageOfBooks, totalMatchingBooksCount: response["data"]["count"], }); - if ( - !stats.loading && - !stats.error && - stats.response && - stats.response["data"] && - stats.response["data"]["stats"] && - stats.response["data"]["stats"].length > 0 - ) { - joinBooksAndStats(onePageOfBooks, stats.response["data"]); - } } - }, [ - loading, - error, - response, - stats.loading, - stats.error, - stats.response, - doNotActuallyRunQuery, - ]); + }, [loading, error, response, doNotActuallyRunQuery]); return result; } diff --git a/src/model/Book.ts b/src/model/Book.ts index 5915022e..a0daa310 100644 --- a/src/model/Book.ts +++ b/src/model/Book.ts @@ -24,6 +24,8 @@ export function createBookFromParseServerData(pojo: any): Book { b.allTitles = parseAllTitles(pojo.allTitles); b.originalTitle = pojo.originalTitle; b.languages = pojo.langPointers; + b.stats.finishedCount = parseInt(pojo.analytics_finishedCount, 10) || 0; + b.stats.shellDownloads = parseInt(pojo.analytics_shellDownloads, 10) || 0; b.finishCreationFromParseServerData(pojo.objectId); return b;