Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-131266: Update FG project details #774

Merged
merged 1 commit into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions tools/floodgate/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getHelixAdminApiUrl,
readProjectFile,
} from '../../loc/project.js';
import { getFilesData } from '../../loc/sharepoint.js';
import { getSpFiles } from '../../loc/sharepoint.js';
import { getDocPathFromUrl, getFloodgateUrl } from './utils.js';

let project;
Expand All @@ -22,27 +22,25 @@ const PROJECT_STATUS = {
/**
* Makes the sharepoint file data part of `projectDetail` per URL.
*/
function injectSharepointData(projectUrls, filePaths, docPaths, spFiles, isFloodgate) {
for (let i = 0; i < spFiles.length; i += 1) {
let fileBody = {};
let status = 404;
if (!spFiles[i].error) {
fileBody = spFiles[i];
status = 200;
}
const filePath = docPaths[i];
const urls = filePaths.get(filePath);
urls.forEach((key) => {
const urlObjVal = projectUrls.get(key);
if (isFloodgate) {
urlObjVal.doc.fg.sp = fileBody;
urlObjVal.doc.fg.sp.status = status;
} else {
urlObjVal.doc.sp = fileBody;
urlObjVal.doc.sp.status = status;
}
function injectSharepointData(projectUrls, filePaths, docPaths, spBatchFiles, isFloodgate) {
spBatchFiles.forEach((spFiles) => {
if (!spFiles?.responses) return;
spFiles.responses.forEach(({ id, status, body }) => {
const filePath = docPaths[id];
const fileBody = status === 200 ? body : {};
const urls = filePaths.get(filePath);
urls.forEach((key) => {
const urlObjVal = projectUrls.get(key);
if (isFloodgate) {
urlObjVal.doc.fg.sp = fileBody;
urlObjVal.doc.fg.sp.status = status;
} else {
urlObjVal.doc.sp = fileBody;
urlObjVal.doc.sp.status = status;
}
});
});
}
});
}

async function updateProjectWithDocs(projectDetail) {
Expand All @@ -51,10 +49,10 @@ async function updateProjectWithDocs(projectDetail) {
}
const { filePaths } = projectDetail;
const docPaths = [...filePaths.keys()];
const spFiles = await getFilesData(docPaths);
injectSharepointData(projectDetail.urls, filePaths, docPaths, spFiles);
const fgSpFiles = await getFilesData(docPaths, true);
injectSharepointData(projectDetail.urls, filePaths, docPaths, fgSpFiles, true);
const spBatchFiles = await getSpFiles(docPaths);
injectSharepointData(projectDetail.urls, filePaths, docPaths, spBatchFiles);
const fgSpBatchFiles = await getSpFiles(docPaths, true);
injectSharepointData(projectDetail.urls, filePaths, docPaths, fgSpBatchFiles, true);
}

async function initProject() {
Expand Down