Skip to content

Commit

Permalink
Merge release into embed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-polk committed Nov 19, 2024
2 parents 027124e + e4d5675 commit 6fc4c88
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 41 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and Deploy

on:
push:
branches:
- master
- release
- embed
workflow_dispatch: # Allows manual triggering of the workflow

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
run: yarn install --frozen-lockfile --network-timeout 1000000000

# Not yet
# - name: Upload translations to Crowdin
# if: github.ref == 'refs/heads/release'
# # Push any new code-based strings to Crowdin
# run: crowdin-dangerous-upload
# env:
# bloomCrowdinApiToken: ${{ secrets.BLOOM_CROWDIN_TOKEN }}

- name: Download translations from Crowdin
run: yarn crowdin-download
env:
bloomCrowdinApiToken: ${{ secrets.BLOOM_CROWDIN_TOKEN }}

- name: Build
run: |
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
yarn build:ci:alpha
else
yarn build:ci
fi
- name: Run tests
run: yarn test:ci

# Not yet
# - name: Deploy to S3
# run: |
# aws s3 cp path/to/build/artifacts s3://your-bucket-name --recursive
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
11 changes: 8 additions & 3 deletions .github/workflows/main.yml → .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Lighthouse CI

on:
push:
branches:
- master
workflow_run:
workflows: ["Build and Deploy"]
types:
- completed
workflow_dispatch: # Allows manual triggering of the workflow

jobs:
lighthouse-on-live-site:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'master') }}
steps:
- uses: actions/checkout@v4
- name: Audit root using Lighthouse
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"async-retry": "^1.3.1",
"bloom-player": "^2.3.0",
"bloom-player": "^2.6.8-alpha.1",
"concurrently": "^5.1.0",
"decompress": "^4.2.1",
"download": "^8.0.0",
Expand Down
17 changes: 16 additions & 1 deletion src/components/Grid/GridColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface IGridColumn extends DevExpressColumn {
addToFilter?: (filter: IFilter, value: string) => void;
sortingEnabled?: boolean;
l10nId?: string; // the id to use for localization if it's a common one that we don't want to just fabricate for this context
// Returns a simple string representation of the value in the cell.
// If not provided, the only current caller (csv export) will fall back
// to using getCellValue if that doesn't return an object (component).
// Else it will fallback to b[key].toString().
getStringValue?: (b: Book) => string;
}

// For some tags, we want to give them their own column. So we don't want to show them in the tags column.
Expand All @@ -40,7 +45,6 @@ const kTagsToFilterOutOfTagsList = [
];

export function getBookGridColumnsDefinitions(): IGridColumn[] {
// Note, the order here is also the default order in the table
const definitions: IGridColumn[] = [
{
name: "title",
Expand Down Expand Up @@ -144,6 +148,10 @@ export function getBookGridColumnsDefinitions(): IGridColumn[] {
getCellValue: (b: Book) => (
<TagCheckbox book={b} tag={"system:Incoming"} />
),
getStringValue: (b: Book) =>
b.tags.filter((tag) => tag === "system:Incoming").length
? "true"
: "false",
getCustomFilterComponent: (props: TableFilterRow.CellProps) => (
<TagExistsFilterCell {...props} />
),
Expand Down Expand Up @@ -185,6 +193,11 @@ export function getBookGridColumnsDefinitions(): IGridColumn[] {
{t.replace(/topic:/, "")}
</GridSearchLink>
)),
getStringValue: (b: Book) =>
b.tags
.filter((tag) => tag.startsWith("topic:"))
.map((topic) => topic.replace("topic:", ""))
.join(", "),
addToFilter: (filter: IFilter, value: string) => {
filter.topic = titleCase(value);
},
Expand Down Expand Up @@ -265,6 +278,7 @@ export function getBookGridColumnsDefinitions(): IGridColumn[] {
{
name: "Is Rebrand",
getCellValue: (b: Book) => <RebrandCheckbox book={b} />,
getStringValue: (b: Book) => (b.rebrand ? "true" : "false"),
getCustomFilterComponent: (props: TableFilterRow.CellProps) => (
<ChoicesFilterCell
choices={["All", "Only Rebranded", "Hide Rebranded"]}
Expand Down Expand Up @@ -343,6 +357,7 @@ export function getBookGridColumnsDefinitions(): IGridColumn[] {
{b.uploader?.username}
</GridSearchLink>
),
getStringValue: (b: Book) => b.uploader?.username ?? "",
addToFilter: (filter: IFilter, value: string) => {
filter.search += ` uploader:${value} `;
},
Expand Down
64 changes: 32 additions & 32 deletions src/components/Grid/GridExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
retrieveBookData,
retrieveBookStats,
} from "../../connection/LibraryQueries";
import { getBookGridColumnsDefinitions, IGridColumn } from "./GridColumns";

let static_books: Book[] = [];
let static_columnsInOrder: string[] = [];
Expand All @@ -22,6 +23,11 @@ let static_sortingArray: Array<{
}> = [];
let static_completeFilter: IFilter;

const static_keyToColumnDefinition: Map<string, IGridColumn> = new Map();
getBookGridColumnsDefinitions().forEach((columnDefinition) => {
static_keyToColumnDefinition.set(columnDefinition.name, columnDefinition);
});

export function setGridExportFilter(
completeFilter: IFilter, //includes the search box
gridColumnFilters: GridFilter[] //just the filters from the headers of the columns
Expand Down Expand Up @@ -75,48 +81,42 @@ function exportData(): string[][] {
const iTitle = headerRow.indexOf("title");
headerRow.splice(iTitle + 1, 0, "url");

all.push(headerRow);
all.push(
headerRow.map(
(key) => static_keyToColumnDefinition.get(key)?.title ?? key
)
);

static_books.forEach((book) => {
//const valueRow = Object.values(row).map((v) => v ? v.toString() : "") as string[];
const valueRow = headerRow.map((key) => getStringForItem(book, key));
all.push(valueRow);
});
return all;
}

function getStringForItem(book: Book, key: string): string {
switch (key) {
case "url":
// Excel and Google Sheets will interpret =HYPERLINK to make it a link, even in a csv. Supposedly Libre Office will, too.
return `=HYPERLINK("${window.location.origin}/book/${book.id}")`;
case "languages":
return book.languages.map((lang) => lang.name).join(", ");
case "languagecodes":
return book.languages.map((lang) => lang.isoCode).join(", ");
case "uploader":
return book.uploader?.username ?? "";
case "topic":
return book.tags
.filter((tag) => tag.startsWith("topic:"))
.map((topic) => topic.replace("topic:", ""))
.join(", ");
case "incoming":
return book.tags.filter((tag) => tag === "system:Incoming").length
? "true"
: "false";
case "tags":
return book.tags
.filter(
(tag) =>
!tag.startsWith("topic:") && tag !== "system:Incoming"
)
.join(", ");
case "reads":
return book.stats.finishedCount.toString();
case "downloadsForTranslation":
return book.stats.shellDownloads.toString();
// url is a special case since it only exists in the export, not in the grid.
if (key === "url") {
// Excel and Google Sheets will interpret =HYPERLINK to make it a link, even in a csv. Supposedly Libre Office will, too.
return `=HYPERLINK("${window.location.origin}/book/${book.id}")`;
}

// Try getStringValue first. If defined, that's what we want; just the string representation.
const columnDefinition = static_keyToColumnDefinition.get(key);
if (columnDefinition?.getStringValue)
return columnDefinition.getStringValue(book);

// Otherwise, we might just want the same value as the grid shows.
// But not if the result is an object (React component).
if (columnDefinition?.getCellValue) {
const valAsAny = columnDefinition.getCellValue(book, key);
if (valAsAny !== undefined && typeof valAsAny !== "object") {
return valAsAny.toString();
}
}

// If there's no getStringValue or getCellValue (or getCellValue returns a component),
// just get the raw value from the book object based on the key.
const item = book[key as keyof Book];
return item ? item.toString() : "";
}
1 change: 1 addition & 0 deletions src/components/ReadBookPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const ReadBookPage: React.FunctionComponent<IReadBookPageProps> = (props) => {
border: none;
width: 100%;
height: 100%;
display: block; // Prevent a 4px white bar at the bottom of the iframe. See BL-14065.
`}
src={iframeSrc}
//src={"https://google.com"}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7215,10 +7215,10 @@ bl@^1.0.0:
readable-stream "^2.3.5"
safe-buffer "^5.1.1"

bloom-player@^2.3.0:
version "2.6.4"
resolved "https://registry.yarnpkg.com/bloom-player/-/bloom-player-2.6.4.tgz#767da393d891268de4fdb4ef2e1640081e1f34c1"
integrity sha512-jtIoRcdqgeSRgHMZ5TfvDEadg/ZfTq/J6BbZTv1HudjGflIGe4DOYGSTsFcQtELrWWmqhx0PYxlKnYXirZdDaw==
bloom-player@^2.6.8-alpha.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/bloom-player/-/bloom-player-2.7.1.tgz#1ae1f14e3f12bdb36d2ecf3ee1486421bcf0fd32"
integrity sha512-2WqiHHeJkmTwuvsSBDDdJVu/m4k6smx1ViHtDq4MwvyOqJu9S7fawtHTgLNflRZZrWJ9Xusu8gm2Dg2FGpw2Fw==

bluebird@^3.3.5, bluebird@^3.5.5:
version "3.7.1"
Expand Down

0 comments on commit 6fc4c88

Please sign in to comment.