Skip to content

Commit

Permalink
Merge branch 'main' of github.com:paranext/paranext-core into rtl-nav…
Browse files Browse the repository at this point in the history
…igation-content-search
  • Loading branch information
Jolie Rabideau authored and Jolie Rabideau committed Sep 3, 2024
2 parents 069ea4c + c3f115e commit 7f57af5
Show file tree
Hide file tree
Showing 94 changed files with 6,272 additions and 4,087 deletions.
10 changes: 9 additions & 1 deletion assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@
"%mainMenu_window%": "Window",
"%some_localization_key%": "This is the English text for %some_localization_key%.",
"%submitButton%": "Submit",
"%scrollGroup_undefined%": "Ø",
"%scrollGroup_0%": "A",
"%scrollGroup_1%": "B",
"%scrollGroup_2%": "C",
"%scrollGroup_3%": "D",
"%scrollGroup_4%": "E",
"%webView_edit%": "Edit",
"%webView_openProjectSettings%": "Open Project Settings",
"%webView_project%": "Project",
"%webView_projectAssignmentsAndProgress%": "Assignments and Progress",
"%wordList%": "Word List",
"%settings_platform_group1_label%": "Platform Settings",
"%settings_platform_group1_description%": "Settings pertaining to the software overall",
"%settings_platform_verseRef_label%": "Current Verse Reference",
"%settings_platform_verseRef_label%": "Current Verse Reference for Scroll Group A (Deprecated)",
"%settings_platform_verseRef_description%": "Current Verse Reference for Scroll Group A. Deprecated - please use `papi.scrollGroups` and `useWebViewScrollGroupScrRef`",
"%settings_platform_interfaceLanguage_label%": "Interface Language",
"%settings_platform_interfaceLanguage_description%": "List of locales to use when localizing the interface. First in the list receives highest priority. 'en' (English) is always added at the end, so everything localizes to English if it does not have a localization in a higher-priority locale.",
"%settings_platform_ptxUtilsMementoData_label%": "PtxUtils Memento Data",
"%settings_platform_paratextDataLastRegistryDataCachedTimes_label%": "ParatextData Last Registry Data Cached Times",
"%project_settings_platform_group1_label%": "Platform Settings",
Expand Down
2 changes: 1 addition & 1 deletion extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"tsconfig-paths-webpack-plugin": "^4.1.0",
"tsx": "^4.7.1",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"zip-folder-promise": "^1.2.0"
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/hello-someone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"zip-build": "^1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"zip-build": "^1.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ import {
import type { WebViewProps } from '@papi/core';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import type { HelloWorldEvent } from 'hello-world';
import { debounce, ScriptureReference } from 'platform-bible-utils';
import { debounce } from 'platform-bible-utils';
import Clock from './components/clock.component';
import Logo from '../../assets/offline.svg';
import ProjectSettingsEditor from './hello-world-project/project-settings-editor.component';
import useHelloWorldProjectSettings from './hello-world-project/use-hello-world-project-settings.hook';

const NAME = 'Hello World React WebView';

const defaultScrRef: ScriptureReference = {
bookNum: 1,
chapterNum: 1,
verseNum: 1,
};

// Test fetching
papi
.fetch('https://www.example.com', { mode: 'no-cors' })
Expand All @@ -45,9 +39,10 @@ globalThis.webViewComponent = function HelloWorld({
projectId,
useWebViewState,
updateWebViewDefinition,
useWebViewScrollGroupScrRef,
}: WebViewProps) {
const [clicks, setClicks] = useWebViewState<number>('clicks', 0);
const [scrRef, setScrRef] = useSetting('platform.verseRef', defaultScrRef);
const [scrRef, setScrRef] = useWebViewScrollGroupScrRef();
const verseRef = useMemo(
() => new VerseRef(scrRef.bookNum, scrRef.chapterNum, scrRef.verseNum),
[scrRef],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"%webView_platformScriptureEditor_thickBorders%": "Thick Borders",
"%webView_platformScriptureEditor_charactersInventory%": "Inventory: Characters",
"%webView_platformScriptureEditor_repeatedWordsInventory%": "Inventory: Repeated Words",
"%webView_platformScriptureEditor_runBasicChecks%": "Run Basic Checks...",
"%webView_platformScriptureEditor_publisherInfo%": "Publisher Info",
"%webView_platformScriptureEditor_copyrightInfo%": "Copyright Info",
"%platformScriptureEditor_dialog_openResourceViewer_title%": "Open Resource Viewer",
Expand Down
10 changes: 10 additions & 0 deletions extensions/src/platform-scripture-editor/contributions/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
"platformScriptureEditor.inventory": {
"column": "platformScriptureEditor.tools",
"order": 2
},
"platformScriptureEditor.checks": {
"column": "platformScriptureEditor.tools",
"order": 3
}
},
"items": [
Expand Down Expand Up @@ -80,6 +84,12 @@
"order": 2,
"command": "platformScripture.openRepeatedWordsInventory"
},
{
"label": "%webView_platformScriptureEditor_runBasicChecks%",
"group": "platformScriptureEditor.checks",
"order": 1,
"command": "platformScripture.runBasicChecks"
},
{
"label": "%webView_platformScriptureEditor_thickBorders%",
"group": "platformScriptureEditor.layout",
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/platform-scripture-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"zip-build": "^1.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { VerseRef } from '@sillsdev/scripture';
import { JSX, useCallback, useEffect, useMemo, useRef } from 'react';
import type { WebViewProps } from '@papi/core';
import { logger } from '@papi/frontend';
import { useProjectData, useSetting } from '@papi/frontend/react';
import { useProjectData } from '@papi/frontend/react';
import { ScriptureReference, debounce } from 'platform-bible-utils';

/** The offset in pixels from the top of the window to scroll to show the verse number */
Expand All @@ -22,12 +22,6 @@ const VERSE_NUMBER_SCROLL_OFFSET = 80;
*/
const EDITOR_LOAD_DELAY_TIME = 100;

const defaultScrRef: ScriptureReference = {
bookNum: 1,
chapterNum: 1,
verseNum: 1,
};

const usjDocumentDefault: Usj = { type: 'USJ', version: '0.2.1', content: [] };

/**
Expand Down Expand Up @@ -67,14 +61,15 @@ function scrollToScrRef(scrRef: ScriptureReference): HTMLElement | undefined {
globalThis.webViewComponent = function PlatformScriptureEditor({
projectId,
useWebViewState,
useWebViewScrollGroupScrRef,
}: WebViewProps): JSX.Element {
const [isReadOnly] = useWebViewState<boolean>('isReadOnly', true);
const Editor = isReadOnly ? Editorial : Marginal;

// Using react's ref api which uses null, so we must use null
// eslint-disable-next-line no-null/no-null
const editorRef = useRef<EditorRef | MarginalRef | null>(null);
const [scrRef, setScrRefInternal] = useSetting('platform.verseRef', defaultScrRef);
const [scrRef, setScrRefInternal] = useWebViewScrollGroupScrRef();

/**
* Scripture reference we set most recently. Used so we don't scroll on updates to scrRef that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"%mainMenu_toggleIncludeMyParatext9Projects%": "Toggle Include My Paratext 9 Projects",
"%webView_characterInventory_title%": "Character Inventory",
"%webView_repeatedWordsInventory_title%": "Repeated Words Inventory",
"%webView_checkResultsList_title%": "Check Results",
"%webView_inventory_all%": "All items",
"%webView_inventory_approved%": "Approved items",
"%webView_inventory_unapproved%": "Unapproved items",
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/platform-scripture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"zip-build": "^1.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ColumnDef,
Inventory,
ItemData,
Scope,
Status,
inventoryCountColumn,
inventoryItemColumn,
Expand All @@ -20,6 +21,16 @@ const CHARACTER_INVENTORY_STRING_KEYS: LocalizeKey[] = [
'%webView_inventory_table_header_status%',
];

/**
* Function that constructs the column for the inventory component
*
* @param itemLabel Localized label for the item column (e.g. 'Character', 'Repeated Word', etc.)
* @param unicodeValueLabel Localized label for the Unicode Value column
* @param countLabel Localized label for the count column
* @param statusLabel Localized label for the status column
* @param statusChangeHandler Callback function that handles status updates to selected item(s)
* @returns An array of columns that can be passed into the inventory component
*/
const createColumns = (
itemLabel: string,
unicodeValueLabel: string,
Expand Down Expand Up @@ -49,8 +60,8 @@ type CharacterInventoryProps = {
unapprovedItems: string[];
onUnapprovedItemsChange: (items: string[]) => void;
text: string | undefined;
scope: string;
onScopeChange: (scope: string) => void;
scope: Scope;
onScopeChange: (scope: Scope) => void;
};

function CharacterInventory({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.checking-results-list {
height: 500px;
}

.checking-results-list-label {
padding-inline-start: 10px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { WebViewProps } from '@papi/core';
import { Button, Label, ResultsSet, ScriptureResultsViewer } from 'platform-bible-react';
import { useState, useCallback, useEffect, useMemo } from 'react';
import { badLeftoversCheck, engineProblemsCheck } from './testing/test-scripture-checks';

const getLabel = (
projectName: string | undefined,
datetime: string | undefined,
sources: ResultsSet[],
): string => {
let result = '';
if (projectName) {
result = projectName;
}
if (datetime) result += `; ${datetime}`;
if (sources.length > 0) {
result += '; ';
result += sources
.map((s) => s.source.displayName)
.filter(Boolean)
.join(', ');
}
return result;
};

global.webViewComponent = function CheckingResultsListWebView({ useWebViewState }: WebViewProps) {
const [projectName] = useWebViewState('projectName', 'Dummy project');

// This is stub code to get some dummy checking results.
// TODO (#994): Replace this with calls to get actual check results and subscribe to updates.
const onRerun = useCallback(() => {
badLeftoversCheck.reRun();
engineProblemsCheck.reRun();
}, []);

const sources = useMemo(() => [badLeftoversCheck, engineProblemsCheck], []);

const [lastUpdateTimestamp, setLastUpdateTimestamp] = useState<string | undefined>(undefined);
const [currentSources, setCurrentSources] = useState(sources);

useEffect(() => {
setCurrentSources(sources);
}, [sources]);

const handleResultsUpdated = useCallback(() => {
const currentTimestamp = new Date().toLocaleString();
setLastUpdateTimestamp(currentTimestamp);
}, []);

const reRunChecks = useCallback(() => {
if (onRerun) {
onRerun();
// Since onRerun modifies the sources directly, we need to trigger a state update
setCurrentSources([...sources]);
handleResultsUpdated();
}
}, [onRerun, sources, handleResultsUpdated]);

const label = getLabel(projectName, lastUpdateTimestamp, sources);

return (
<div className="checking-results-list">
<Button onClick={reRunChecks}>Rerun</Button>
{label && <Label className="checking-results-list-label">{label}</Label>}
<ScriptureResultsViewer sources={currentSources} />
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import papi, { logger, projectLookup } from '@papi/backend';
import {
GetWebViewOptions,
IWebViewProvider,
SavedWebViewDefinition,
WebViewDefinition,
} from '@papi/core';
import checkingResultsListWebView from './checking-results-list.web-view?inline';
import checkingResultsListStyles from './checking-results-list.web-view.scss?inline';

export const checkResultsListWebViewType = 'platformScripture.checkingResults';

export interface CheckResultsWebViewOptions extends GetWebViewOptions {
projectId: string | undefined;
}

export default class CheckResultsWebViewProvider implements IWebViewProvider {
constructor(public webViewType: string = checkResultsListWebViewType) {}

async getWebView(
savedWebView: SavedWebViewDefinition,
getWebViewOptions: CheckResultsWebViewOptions,
): Promise<WebViewDefinition | undefined> {
if (savedWebView.webViewType !== this.webViewType)
throw new Error(
`${checkResultsListWebViewType} provider received request to provide a ${savedWebView.webViewType} web view`,
);

// We know that the projectId (if present in the state) will be a string.
let projectId =
getWebViewOptions.projectId ||
// eslint-disable-next-line no-type-assertion/no-type-assertion
(savedWebView.state?.projectId as string) ||
undefined;

let title = await papi.localization.getLocalizedString({
localizeKey: '%webView_checkResultsList_title%',
});

let projectName: string | undefined;

if (projectId) {
projectName =
(await (
await papi.projectDataProviders.get('platform.base', projectId)
).getSetting('platform.name')) ?? projectId;

title += ` - ${projectName}`;
}

if (!projectId && globalThis.isNoisyDevModeEnabled) {
logger.debug(`${title} web view did not get a project passed in. Choosing a random one...`);

const projectMetadata = await projectLookup.getMetadataForAllProjects();
if (projectMetadata.length === 0) {
logger.debug('Testing out checks: No projects available');
return undefined;
}
projectId = projectMetadata[0].id;
}

logger.info(`${title} web view opening with ${projectId}`);

return {
title,
...savedWebView,
content: checkingResultsListWebView,
styles: checkingResultsListStyles,
state: {
projectName,
projectId,
...savedWebView.state,
webViewType: this.webViewType,
},
};
}
}
Loading

0 comments on commit 7f57af5

Please sign in to comment.