Skip to content

Commit

Permalink
Merge pull request #571 from StephenMcConnel/BL-13994-SortReadsAndDow…
Browse files Browse the repository at this point in the history
…nloads

Allow Reads and Downloads to be sorted in books grid (BL-13994)
  • Loading branch information
hatton authored Oct 17, 2024
2 parents c3f016c + 2b36d53 commit 47a3e57
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/components/Grid/GridColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
30 changes: 4 additions & 26 deletions src/connection/LibraryQueryHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/model/Book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 47a3e57

Please sign in to comment.