From 15ea391dfdd3c87ac62a177ee523918f0cbc0a90 Mon Sep 17 00:00:00 2001 From: PhotoNomad0 Date: Fri, 22 Nov 2024 10:00:34 -0500 Subject: [PATCH] fixes for tsv export and upload, saving settings and invalidated checking --- package.json | 2 +- src/utilities/network.ts | 35 +++++++--- webview-ui/package.json | 4 +- webview-ui/pnpm-lock.yaml | 10 +-- .../components/TranslationCheckingPane.tsx | 68 +++++++++++++++++-- .../components/TranslationCheckingView.tsx | 20 +++++- 6 files changed, 112 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 635be49..523019a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "checking-extension", "displayName": "checking-extension", "description": "A vscode extension to open tn_check and twl_check files for checking verses", - "version": "0.9.8", + "version": "0.9.9", "publisher": "unfoldingWord", "engines": { "vscode": "^1.91.0" diff --git a/src/utilities/network.ts b/src/utilities/network.ts index 2464947..4f7a69c 100644 --- a/src/utilities/network.ts +++ b/src/utilities/network.ts @@ -251,7 +251,7 @@ async function deleteTheBranchAndPR(server: string, owner: string, repo: string, return false } -async function updateFilesInBranch(localFiles: string[], localRepoPath: string, handledFiles: NestedObject, uploadedFiles: NestedObject, server: string, owner: string, repo: string, branch: string, token: string): Promise { +async function updateFilesInBranch(localFiles: string[], localRepoPath: string, unHandledFiles: NestedObject, uploadedFiles: NestedObject, server: string, owner: string, repo: string, branch: string, token: string): Promise { let changedFiles = 0; const importsFolder = path.join(projectsBasePath, 'imports') fs.emptyDirSync(importsFolder) @@ -270,7 +270,7 @@ async function updateFilesInBranch(localFiles: string[], localRepoPath: string, let skip = false; let localChecksum: string = ""; - const remoteFileData = handledFiles[localFile]; + const remoteFileData = unHandledFiles[localFile]; const isOnDcs = !!remoteFileData; if (!isOnDcs) { doUpload = true; @@ -278,7 +278,9 @@ async function updateFilesInBranch(localFiles: string[], localRepoPath: string, localChecksum = await getChecksum(fullFilePath); const lastUploadData = uploadedFiles[localFile]; const lastSha = lastUploadData?.sha; - if ((lastUploadData?.checksum === localChecksum) && (remoteFileData?.sha === lastSha)) { + const checksumUnchanged = lastUploadData?.checksum === localChecksum; + const shaUnchanged = remoteFileData?.sha === lastSha; + if (checksumUnchanged && shaUnchanged) { // if checksum unchanged and sha unchanged, then skip this file skip = true; } @@ -309,7 +311,7 @@ async function updateFilesInBranch(localFiles: string[], localRepoPath: string, delete newFileData["content"]; uploadedFiles[localFile] = newFileData; if (isOnDcs) { - delete handledFiles[localFile]; + delete unHandledFiles[localFile]; changedFiles++ } } else { @@ -319,12 +321,12 @@ async function updateFilesInBranch(localFiles: string[], localRepoPath: string, return results } } else { - delete handledFiles[localFile]; + delete unHandledFiles[localFile]; } } - for (const file of Object.keys(handledFiles)) { - const fileData = handledFiles[file]; + for (const file of Object.keys(unHandledFiles)) { + const fileData = unHandledFiles[file]; const fileType = fileData?.type; if (fileType === "file" || fileType === "blob") { sendUpdateUploadStatus(`updateFilesInBranch`, `deleting ${file}`); @@ -537,7 +539,7 @@ async function updateFilesAndMergeToMaster(localRepoPath: string, server: string const localFiles = getAllFiles(localRepoPath); const results = await getRepoTree(server, owner, repo, branch, token); - const handledFiles: NestedObject = {}; + const unHandledFiles: NestedObject = {}; let uploadedFiles: NestedObject = dcsState?.files || {}; if (state.newRepo) { // if new repo then upload everything uploadedFiles = {}; @@ -545,10 +547,10 @@ async function updateFilesAndMergeToMaster(localRepoPath: string, server: string for (const file of results?.tree || []) { // make object indexed by path // @ts-ignore - handledFiles[file.path] = file; + unHandledFiles[file.path] = file; } - const updateFilesResults = await updateFilesInBranch(localFiles, localRepoPath, handledFiles, uploadedFiles, server, owner, repo, branch, token); + const updateFilesResults = await updateFilesInBranch(localFiles, localRepoPath, unHandledFiles, uploadedFiles, server, owner, repo, branch, token); if (updateFilesResults.error) { return updateFilesResults } @@ -584,6 +586,7 @@ async function updateFilesAndMergeToMaster(localRepoPath: string, server: string sendUpdateUploadStatus(`updateFilesAndMergeToMaster`, `PR #${pr.number} has no changes, deleting PR`) state.mergeComplete = await deleteTheBranchAndPR(server, owner, repo, pr, token, branch); state.noChanges = true; + updateSavedData = true; // need to update in case sha data is out ouf sync } else { sendUpdateUploadStatus(`updateFilesAndMergeToMaster`, `PR #${pr.number} has ${prStatus?.length} changes`) if (!pr.mergeable) { @@ -595,6 +598,7 @@ async function updateFilesAndMergeToMaster(localRepoPath: string, server: string sendUpdateUploadErrorStatus(`updateFilesAndMergeToMaster`, `PR #${pr.number} has already been merged, deleting PR`) state.mergeComplete = await deleteTheBranchAndPR(server, owner, repo, pr, token, branch); state.noChanges = true; + updateSavedData = true; // need to update in case sha data is out ouf sync } else { sendUpdateUploadStatus(`updateFilesAndMergeToMaster`, `merging PR #${pr.number}`) const response = await squashMergePullRequest(server, owner, repo, pr.number, true, token, 2); @@ -610,7 +614,16 @@ async function updateFilesAndMergeToMaster(localRepoPath: string, server: string if (updateSavedData) { console.log(`updateContentOnDCS - updating saved data`); const branch = await getRepoBranch(server, owner, repo, "master", token); - const commit = branch?.commit?.id || null; + const commit = branch?.commit?.id || ''; + const treeResults = await getRepoTree(server, owner, repo, commit, token); + for (const file of treeResults?.tree || []) { + // @ts-ignore + const filePath = file.path; + const uploadedFile = uploadedFiles[filePath]; + if (uploadedFile) { + uploadedFile.sha = file.sha + } + } state.updatedSavedData = true; // save latest upload data const newStatus = { diff --git a/webview-ui/package.json b/webview-ui/package.json index 939190a..5221cd6 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -1,6 +1,6 @@ { "name": "checking-extension-webview", - "version": "0.9.8", + "version": "0.9.9", "private": true, "scripts": { "start": "vite", @@ -17,7 +17,7 @@ "@material-ui/lab": "4.0.0-alpha.61", "@mui/lab": "5.0.0-alpha.89", "@vscode/webview-ui-toolkit": "^1.4.0", - "checking-tool-rcl": "0.9.19", + "checking-tool-rcl": "0.9.20", "deep-equal": "1.0.1", "dompurify": "^3.0.9", "gitea-react-toolkit": "2.4.1", diff --git a/webview-ui/pnpm-lock.yaml b/webview-ui/pnpm-lock.yaml index e1d303b..eb22560 100644 --- a/webview-ui/pnpm-lock.yaml +++ b/webview-ui/pnpm-lock.yaml @@ -27,8 +27,8 @@ importers: specifier: ^1.4.0 version: 1.4.0(react@18.3.1) checking-tool-rcl: - specifier: 0.9.19 - version: 0.9.19(@types/react@18.3.3)(prop-types@15.8.1)(react-dom@18.3.1(react@18.3.1))(react-redux@7.2.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1)(webpack@5.93.0) + specifier: 0.9.20 + version: 0.9.20(@types/react@18.3.3)(prop-types@15.8.1)(react-dom@18.3.1(react@18.3.1))(react-redux@7.2.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1)(webpack@5.93.0) deep-equal: specifier: 1.0.1 version: 1.0.1 @@ -1008,8 +1008,8 @@ packages: charenc@0.0.2: resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==, tarball: https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz} - checking-tool-rcl@0.9.19: - resolution: {integrity: sha512-9xvc0uoBhuR5PQlepLZKEjUbLPrAaaionfrSOmVubgIVEad+qm5zdw4pZLLGyfJOPduif8cOnJ7nlZdkGV+V7w==, tarball: https://registry.npmjs.org/checking-tool-rcl/-/checking-tool-rcl-0.9.19.tgz} + checking-tool-rcl@0.9.20: + resolution: {integrity: sha512-2zpPXPDAq6J8aF4k3CN6LcryYbVYeMXqEpe06+Hk8cENUyP7Dxwmt36avqe4J6UglEhus9W3Wv+Vpw+MgK48Jw==, tarball: https://registry.npmjs.org/checking-tool-rcl/-/checking-tool-rcl-0.9.20.tgz} peerDependencies: prop-types: ^15.x react: 18.3.1 @@ -3219,7 +3219,7 @@ snapshots: charenc@0.0.2: {} - checking-tool-rcl@0.9.19(@types/react@18.3.3)(prop-types@15.8.1)(react-dom@18.3.1(react@18.3.1))(react-redux@7.2.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1)(webpack@5.93.0): + checking-tool-rcl@0.9.20(@types/react@18.3.3)(prop-types@15.8.1)(react-dom@18.3.1(react@18.3.1))(react-redux@7.2.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1)(webpack@5.93.0): dependencies: '@material-ui/core': 4.12.4(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@material-ui/icons': 4.11.3(@material-ui/core@4.12.4(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) diff --git a/webview-ui/src/components/TranslationCheckingPane.tsx b/webview-ui/src/components/TranslationCheckingPane.tsx index 9bc22f6..21662f8 100644 --- a/webview-ui/src/components/TranslationCheckingPane.tsx +++ b/webview-ui/src/components/TranslationCheckingPane.tsx @@ -12,8 +12,17 @@ from 'checking-tool-rcl' import { GeneralObject, ResourcesObject } from "../../../types/index"; import { ALL_BIBLE_BOOKS } from "../../../src/utilities/BooksOfTheBible"; -import { AppBar, IconButton, makeStyles, Toolbar, Typography } from "@material-ui/core"; +import { + AppBar, + CircularProgress, + IconButton, + makeStyles, + Toolbar, + Typography, +} from "@material-ui/core"; import MenuIcon from '@material-ui/icons/Menu' +import ErrorIcon from '@material-ui/icons/Error'; +import DoneOutlineIcon from '@material-ui/icons/DoneOutline'; // @ts-ignore import { APP_NAME, APP_VERSION } from "../common/constants.js"; // @ts-ignore @@ -74,7 +83,7 @@ function hasResourceData(resource:object) { } type saveCheckingDataFunction = (resources: ResourcesObject) => void; -type uploadToDCSFunction = (server: string, owner: string, token: string, dcsUpdate: (status: string) => void) => Promise; +type uploadToDCSFunction = (server: string, owner: string, token: string, dcsUpdate: (update: object) => void) => Promise; type TranslationCheckingProps = { checkingObj: ResourcesObject; @@ -202,8 +211,27 @@ const TranslationCheckingPane: React.FC = ({ function uploadToDCS(server:string, owner: string, token: string) { _showDialogContent({ message: 'Doing Upload to DCS' }) - const dcsUpdateCallback = (status: string) => { - _showDialogContent({ message: status || '' }) + let log: string[] = [] + const dcsUpdateCallback = (update: object) => { + // @ts-ignore + const status = update?.status || ''; + // @ts-ignore + log = update?.log || [] + _showDialogContent({ + message: +
+ Upload is in Process +
+ {`Current Status: ${status}`} +
+ Log:
+ {log.map((item: string) => ( + <> + {item}
+ + ))} +
+ }) } _uploadToDCS(server, owner, token, dcsUpdateCallback).then(results => { console.log(`uploadToDCS completed with results:`, results) @@ -216,7 +244,21 @@ const TranslationCheckingPane: React.FC = ({ const url = `${lastState.server}/${lastState.owner}/${lastState.repo}` message = `${message}. Repo is at ${url}` } - _showDialogContent({ message }); + const dialogContent = ( +
+ Upload Complete Successfully: +
+ {`Current Status: ${message}`} +
+ Log:
+ {log.map((item: string) => ( + <> + {item}
+ + ))} +
+ ) + _showDialogContent({ message: dialogContent }); } else { let message = 'Upload Success' const lastState = results?.lastState; @@ -224,7 +266,21 @@ const TranslationCheckingPane: React.FC = ({ const url = `${lastState.server}/${lastState.owner}/${lastState.repo}` message = `${message} to ${url}` } - _showDialogContent({ message }); + const dialogContent =( +
+ Upload Complete Successfully: +
+ {`Current Status: ${message}`} +
+ Log:
+ {log.map((item: string) => ( + <> + {item}
+ + ))} +
+ ) + _showDialogContent({ message: dialogContent }); } }) } diff --git a/webview-ui/src/components/TranslationCheckingView.tsx b/webview-ui/src/components/TranslationCheckingView.tsx index 8bbb12d..9ec2bf4 100644 --- a/webview-ui/src/components/TranslationCheckingView.tsx +++ b/webview-ui/src/components/TranslationCheckingView.tsx @@ -55,6 +55,15 @@ const useStyles = makeStyles(theme => ({ })) let _callbacks:object = { } // saves callback by key +let uploadProgress: string[] = [] + +function clearUploadProgress() { + uploadProgress = [] +} + +function addToUploadProgress(status: string) { + uploadProgress.push(status) +} function saveCallBack(key: string, callback: any) { // @ts-ignore @@ -162,9 +171,15 @@ function TranslationCheckingView() { // @ts-ignore const key = "uploadToDcsStatusResponse"; const callback = getCallBack(key); + value = value || '' + addToUploadProgress(value) if (callback) { + const update = { + status: value, + log: uploadProgress, + } // @ts-ignore - callback(value); + callback(update); } else { console.error(`No handler for uploadToDcsStatusResponse(${key}) response`) } @@ -219,11 +234,12 @@ function TranslationCheckingView() { return promise } - async function uploadToDCS(server:string, owner: string, token: string, dcsUpdateCallback: (status: string) => void): Promise { + async function uploadToDCS(server:string, owner: string, token: string, dcsUpdateCallback: (update: object) => void): Promise { const _uploadToDCS = (server:string, owner: string, token: string): Promise => { const promise = new Promise((resolve) => { saveCallBack("uploadToDCS", resolve); saveCallBack("uploadToDcsStatusResponse", dcsUpdateCallback); + clearUploadProgress() vscode.postMessage({ command: "uploadToDCS", text: "Upload Repo to DCS",