Skip to content

Commit

Permalink
updated labels to deal undefined. (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: smizero <[email protected]>
  • Loading branch information
Steven-Mugisha and smizero authored Mar 11, 2024
1 parent 4ef24e9 commit ffb7f44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 46 deletions.
36 changes: 13 additions & 23 deletions src/Landing/generateDataEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,27 @@ export function generateDataEntry(acceptedFiles, setLoading) {
const attrLength = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes).length;
const labelsLength = Object.keys(jsonData.find(o => o.type && o.type.includes('/label/')).attribute_labels).length;

if (labelsLength !== attrLength) {
if (labelsLength === attrLength) {
const labelValues = Object.values(jsonData.find(o => o.type && o.type.includes('/label/')).attribute_labels);
const attrKeys = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes);
sheet2.getRow(1).values = attrKeys;

// format using the formatDataHeader function
attrKeys.forEach((_attrName, index) => {
const labelsFilled = labelValues.map((label, index) => label ? label : attrKeys[index]);
sheet2.getRow(1).values = labelsFilled;
labelsFilled.forEach((_label, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
}
} else {
sheet2.getRow(1).values = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes);
Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes).forEach((_attrName, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
sheet2.getRow(1).values = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes);
Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes).forEach((_attrName, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
} catch (error) {
throw new WorkbookError('.. Error assigning head names to sheet2 (Data Entry) ...');
throw new WorkbookError('.. Error assigning head names to sheet2 (Data Entry) ...');
};



const sheet3 = workbook.addWorksheet('Schema conformant data');

const attributesIndex = {};
Expand Down Expand Up @@ -548,14 +546,6 @@ export function generateDataEntry(acceptedFiles, setLoading) {
if (rowIndex) {
sheet1.getCell(shift + rowIndex, i + 3 - skipped).value = label;
};

const labelValue = Object.values(attr_labels);
sheet2.getRow(1).values = labelValue;

labelValue.forEach((_label, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
} catch (error) {
throw new WorkbookError('.. Error in formatting labels code column (header and rows) ...');
Expand Down
36 changes: 13 additions & 23 deletions src/Landing/generateDataEntryV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,29 +253,27 @@ export function generateDataEntryV2(acceptedFiles, setLoading) {
const attrLength = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes).length;
const labelsLength = Object.keys(jsonData.find(o => o.type && o.type.includes('/label/')).attribute_labels).length;

if (labelsLength !== attrLength) {
if (labelsLength === attrLength) {
const labelValues = Object.values(jsonData.find(o => o.type && o.type.includes('/label/')).attribute_labels);
const attrKeys = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes);
sheet2.getRow(1).values = attrKeys;

// format using the formatDataHeader function
attrKeys.forEach((_attrName, index) => {
const labelsFilled = labelValues.map((label, index) => label ? label : attrKeys[index]);
sheet2.getRow(1).values = labelsFilled;
labelsFilled.forEach((_label, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
}
} else {
sheet2.getRow(1).values = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes);
Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes).forEach((_attrName, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
sheet2.getRow(1).values = Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes);
Object.keys(jsonData.find(o => o.type && o.type.includes('/capture_base/')).attributes).forEach((_attrName, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
} catch (error) {
throw new WorkbookError('.. Error assigning head names to sheet2 (Data Entry) ...');
throw new WorkbookError('.. Error assigning head names to sheet2 (Data Entry) ...');
};



const sheet3 = workbook.addWorksheet('Schema conformant data');

const attributesIndex = {};
Expand Down Expand Up @@ -562,14 +560,6 @@ export function generateDataEntryV2(acceptedFiles, setLoading) {
if (rowIndex) {
sheet1.getCell(shift + rowIndex, i + 3 - skipped).value = label;
};

const labelValue = Object.values(attr_labels);
sheet2.getRow(1).values = labelValue;

labelValue.forEach((_label, index) => {
const cell = sheet2.getCell(1, index + 1);
formatDataHeader(cell);
});
};
} catch (error) {
throw new WorkbookError('.. Error in formatting labels code column (header and rows) ...');
Expand Down

0 comments on commit ffb7f44

Please sign in to comment.