Skip to content

Commit

Permalink
fixes for tsv export and upload, saving settings and invalidated chec…
Browse files Browse the repository at this point in the history
…king
  • Loading branch information
PhotoNomad0 committed Nov 22, 2024
1 parent 964dcc2 commit 15ea391
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 24 additions & 11 deletions src/utilities/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeneralObject> {
async function updateFilesInBranch(localFiles: string[], localRepoPath: string, unHandledFiles: NestedObject, uploadedFiles: NestedObject, server: string, owner: string, repo: string, branch: string, token: string): Promise<GeneralObject> {
let changedFiles = 0;
const importsFolder = path.join(projectsBasePath, 'imports')
fs.emptyDirSync(importsFolder)
Expand All @@ -270,15 +270,17 @@ 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;
} else {
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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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}`);
Expand Down Expand Up @@ -537,18 +539,18 @@ 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 = {};
}

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
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions webview-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "checking-extension-webview",
"version": "0.9.8",
"version": "0.9.9",
"private": true,
"scripts": {
"start": "vite",
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions webview-ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 62 additions & 6 deletions webview-ui/src/components/TranslationCheckingPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<GeneralObject>;
type uploadToDCSFunction = (server: string, owner: string, token: string, dcsUpdate: (update: object) => void) => Promise<GeneralObject>;

type TranslationCheckingProps = {
checkingObj: ResourcesObject;
Expand Down Expand Up @@ -202,8 +211,27 @@ const TranslationCheckingPane: React.FC<TranslationCheckingProps> = ({

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:
<div>
<CircularProgress /> <b>Upload is in Process</b>
<br />
<span><b>{`Current Status: ${status}`}</b></span>
<hr />
<b>Log:</b><br />
{log.map((item: string) => (
<>
<span>{item}</span><br />
</>
))}
</div>
})
}
_uploadToDCS(server, owner, token, dcsUpdateCallback).then(results => {
console.log(`uploadToDCS completed with results:`, results)
Expand All @@ -216,15 +244,43 @@ const TranslationCheckingPane: React.FC<TranslationCheckingProps> = ({
const url = `${lastState.server}/${lastState.owner}/${lastState.repo}`
message = `${message}. Repo is at ${url}`
}
_showDialogContent({ message });
const dialogContent = (
<div>
<ErrorIcon /> <b>Upload Complete Successfully:</b>
<br />
<span>{`Current Status: ${message}`}</span>
<hr />
<b>Log:</b><br />
{log.map((item: string) => (
<>
<span>{item}</span><br />
</>
))}
</div>
)
_showDialogContent({ message: dialogContent });
} else {
let message = 'Upload Success'
const lastState = results?.lastState;
if (lastState) {
const url = `${lastState.server}/${lastState.owner}/${lastState.repo}`
message = `${message} to ${url}`
}
_showDialogContent({ message });
const dialogContent =(
<div>
<DoneOutlineIcon /> <b>Upload Complete Successfully:</b>
<br />
<span>{`Current Status: ${message}`}</span>
<hr />
<b>Log:</b><br />
{log.map((item: string) => (
<>
<span>{item}</span><br />
</>
))}
</div>
)
_showDialogContent({ message: dialogContent });
}
})
}
Expand Down
20 changes: 18 additions & 2 deletions webview-ui/src/components/TranslationCheckingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`)
}
Expand Down Expand Up @@ -219,11 +234,12 @@ function TranslationCheckingView() {
return promise
}

async function uploadToDCS(server:string, owner: string, token: string, dcsUpdateCallback: (status: string) => void): Promise<GeneralObject> {
async function uploadToDCS(server:string, owner: string, token: string, dcsUpdateCallback: (update: object) => void): Promise<GeneralObject> {
const _uploadToDCS = (server:string, owner: string, token: string): Promise<GeneralObject> => {
const promise = new Promise<object>((resolve) => {
saveCallBack("uploadToDCS", resolve);
saveCallBack("uploadToDcsStatusResponse", dcsUpdateCallback);
clearUploadProgress()
vscode.postMessage({
command: "uploadToDCS",
text: "Upload Repo to DCS",
Expand Down

0 comments on commit 15ea391

Please sign in to comment.