Skip to content

Commit

Permalink
Fix the bug that causes the same field to be displayed twice #1798
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Aug 19, 2024
1 parent f253e9a commit e49ead5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
20 changes: 14 additions & 6 deletions dataedit/static/peer_review/opr_contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ function renderSummaryPageFields() {
const missingFields = [];
const emptyFields = [];

const processedFields = new Set();

if (state_dict && Object.keys(state_dict).length > 0) {
const fields = document.querySelectorAll('.field');
for (let field of fields) {
Expand All @@ -359,10 +361,13 @@ function renderSummaryPageFields() {
const fieldState = getFieldState(field_id);
const fieldCategory = field.getAttribute('data-category');
const fieldName = field_id.split('.').pop();
const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`;
if (isEmptyValue(fieldValue)) {
emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" });
processedFields.add(uniqueFieldIdentifier);
} else if (fieldState === 'ok') {
acceptedFields.push({ fieldName, fieldValue, fieldCategory });
processedFields.add(uniqueFieldIdentifier);
}
}
}
Expand All @@ -374,6 +379,12 @@ function renderSummaryPageFields() {
const isRejected = review.fieldReview.some((fieldReview) => fieldReview.state === 'rejected');
const fieldCategory = review.category;
const fieldName = review.key.split('.').pop();
const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`;

if (processedFields.has(uniqueFieldIdentifier)) {
continue; // Skipp fields that have already been processed from state_dict
}


if (isEmptyValue(fieldValue)) {
emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" });
Expand All @@ -400,11 +411,13 @@ function renderSummaryPageFields() {
const fieldState = getFieldState(field_id);
const fieldCategory = field.getAttribute('data-category');
const fieldName = field_id.split('.').pop();
const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`;

if (isEmptyValue(fieldValue)) {
if (isEmptyValue(fieldValue) && !processedFields.has(uniqueFieldIdentifier)) {
emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" });
} else if (!found && fieldState !== 'ok') {
missingFields.push({ fieldName, fieldValue, fieldCategory });
processedFields.add(uniqueFieldIdentifier);
}
}
}
Expand Down Expand Up @@ -742,8 +755,6 @@ window.addEventListener('DOMContentLoaded', updateTabClasses);
/**
* Hide and show revier controles once the user clicks the summary tab
*/
console.log('Script is running...');

document.addEventListener('DOMContentLoaded', function() {
// console.log('DOM fully loaded and parsed');

Expand All @@ -756,9 +767,6 @@ document.addEventListener('DOMContentLoaded', function() {
];
const reviewContent = document.querySelector(".review__content");

console.log('Summary Tab:', summaryTab);
console.log('Other Tabs:', otherTabs);
console.log('Review Content:', reviewContent);

if (summaryTab && reviewContent) {
summaryTab.addEventListener('click', function() {
Expand Down
36 changes: 23 additions & 13 deletions dataedit/static/peer_review/opr_reviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ function renderSummaryPageFields() {
const missingFields = [];
const emptyFields = [];

const processedFields = new Set();

if (state_dict && Object.keys(state_dict).length > 0) {
const fields = document.querySelectorAll('.field');
for (let field of fields) {
Expand All @@ -432,15 +434,16 @@ function renderSummaryPageFields() {
const fieldState = getFieldState(field_id);
const fieldCategory = field.getAttribute('data-category');
const fieldName = field_id.split('.').pop();
const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`;

if (isEmptyValue(fieldValue)) {
emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" });
} else if (fieldState === 'ok') {
acceptedFields.push({ fieldName, fieldValue, fieldCategory });
} else if (fieldState === 'suggestion') {
suggestingFields.push({ fieldName, fieldValue, fieldCategory });
} else if (fieldState === 'rejected') {
rejectedFields.push({ fieldName, fieldValue, fieldCategory });
processedFields.add(uniqueFieldIdentifier);
} else {
missingFields.push({ fieldName, fieldValue, fieldCategory });
processedFields.add(uniqueFieldIdentifier);
}
}
}
Expand All @@ -451,7 +454,11 @@ function renderSummaryPageFields() {
const fieldState = review.fieldReview.state;
const fieldCategory = review.category;
const fieldName = review.key.split('.').pop();
const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`;

if (processedFields.has(uniqueFieldIdentifier)) {
continue; // Skipp fields that have already been processed from state_dict
}

if (isEmptyValue(fieldValue)) {
emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" });
Expand Down Expand Up @@ -480,13 +487,15 @@ function renderSummaryPageFields() {
const fieldState = getFieldState(field_id);
const fieldCategory = field.getAttribute('data-category');
const fieldName = field_id.split('.').pop();
if (!found && fieldState !== 'ok' && !isEmptyValue(fieldValue)) {
const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`;

if (!found && fieldState !== 'ok' && !isEmptyValue(fieldValue) && !processedFields.has(uniqueFieldIdentifier)) {
missingFields.push({ fieldName, fieldValue, fieldCategory });
processedFields.add(uniqueFieldIdentifier);
}
}
}


// Display fields on the Summary page
const summaryContainer = document.getElementById("summary");

Expand All @@ -495,6 +504,7 @@ function renderSummaryPageFields() {
summaryContainer.firstChild.remove();
}
}

function generateTable(data) {
let table = document.createElement('table');
table.className = 'table review-summary';
Expand Down Expand Up @@ -539,15 +549,14 @@ function renderSummaryPageFields() {
return table;
}


function updateSummaryTable() {
function updateSummaryTable() {
clearSummaryTable();
let allData = [];
allData.push(...missingFields.map((item) => ({...item, fieldStatus: 'Missing'})));
allData.push(...acceptedFields.map((item) => ({...item, fieldStatus: 'Accepted'})));
allData.push(...suggestingFields.map((item) => ({...item, fieldStatus: 'Suggested'})));
allData.push(...rejectedFields.map((item) => ({...item, fieldStatus: 'Rejected'})));
allData.push(...emptyFields.map((item) => ({...item, fieldStatus: 'Empty'})));
allData.push(...missingFields.map((item) => ({ ...item, fieldStatus: 'Missing' })));
allData.push(...acceptedFields.map((item) => ({ ...item, fieldStatus: 'Accepted' })));
allData.push(...suggestingFields.map((item) => ({ ...item, fieldStatus: 'Suggested' })));
allData.push(...rejectedFields.map((item) => ({ ...item, fieldStatus: 'Rejected' })));
allData.push(...emptyFields.map((item) => ({ ...item, fieldStatus: 'Empty' })));

let table = generateTable(allData);
summaryContainer.appendChild(table);
Expand All @@ -557,6 +566,7 @@ function renderSummaryPageFields() {
updateTabProgressIndicatorClasses();
}


/**
* Creates an HTML list of fields with their categories
* @param {Array} fields Array of field objects
Expand Down

0 comments on commit e49ead5

Please sign in to comment.