Skip to content

Commit 4d1b419

Browse files
Merge pull request #280 from agrifooddatacanada/agreeable-mushroom
Dec 16 prod deployment
2 parents d23facb + 367e789 commit 4d1b419

File tree

2 files changed

+71
-71
lines changed

2 files changed

+71
-71
lines changed

src/ViewSchema/useExportLogic.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,25 @@ const useExportLogic = () => {
8585
OCADataArray.push(OCADescriptionData);
8686

8787
// CAPTURE ATTRIBUTE SHEET DATA
88-
languages.forEach((language) => {
89-
const rowData = [];
90-
91-
attributesList.forEach((item, index) => {
92-
const rowObject = {};
93-
rowObject.Attribute = item;
94-
rowObject.Flagged = attributeRowData[index]?.Flagged ? "Y" : "";
95-
rowObject.Unit = attributeRowData[index]?.Unit;
96-
rowObject.Type = attributeRowData[index]?.Type;
97-
rowObject.Label = lanAttributeRowData[language][index]?.Label;
98-
rowObject.Description = lanAttributeRowData[language][index]?.Description;
99-
rowObject.List = lanAttributeRowData[language][index]?.List;
100-
rowObject.Language = language;
101-
rowData.push(rowObject);
88+
if (Object.keys(lanAttributeRowData).length > 0) {
89+
languages.forEach((language) => {
90+
const rowData = [];
91+
92+
attributesList.forEach((item, index) => {
93+
const rowObject = {};
94+
rowObject.Attribute = item;
95+
rowObject.Flagged = attributeRowData[index]?.Flagged ? "Y" : "";
96+
rowObject.Unit = attributeRowData[index]?.Unit;
97+
rowObject.Type = attributeRowData[index]?.Type;
98+
rowObject.Label = lanAttributeRowData[language][index]?.Label;
99+
rowObject.Description = lanAttributeRowData[language][index]?.Description;
100+
rowObject.List = lanAttributeRowData[language][index]?.List;
101+
rowObject.Language = language;
102+
rowData.push(rowObject);
103+
});
104+
OCADataArray.push(rowData);
102105
});
103-
OCADataArray.push(rowData);
104-
});
106+
}
105107

106108
const handleOCAExport = (dataArray) => {
107109
const workbook = new ExcelJS.Workbook();

src/ViewSchema/useExportLogicV2.js

+53-55
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const useExportLogicV2 = () => {
1919
cardinalityData
2020
} = useContext(Context);
2121

22-
//CAPTURE SHEET DESCRIPTIONS DATA
22+
// CAPTURE SHEET DESCRIPTIONS DATA
2323
const OCADescriptionData = [];
2424
const OCADataArray = [];
2525
const languagesWithCode = [];
@@ -40,21 +40,19 @@ const useExportLogicV2 = () => {
4040
rowObject.Description = schemaDescription[language].description;
4141
OCADescriptionData.push(rowObject);
4242

43-
4443
const languageObject = {};
4544
languageObject.language = language;
4645
languageObject.code =
47-
languageCodesObject[language.toLowerCase()] ||
48-
customIsos[language.toLowerCase()];
46+
languageCodesObject[language.toLowerCase()] || customIsos[language.toLowerCase()];
4947
if (!languageObject.code) {
5048
languageObject.code = "unknown";
5149
}
5250
if (allLanguageCodes.includes(languageObject.code)) {
5351
let number = 2;
54-
let newCode = languageObject.code + "_" + number;
52+
let newCode = `${languageObject.code}_${number}`;
5553
while (allLanguageCodes.includes(newCode)) {
5654
number++;
57-
newCode = languageObject.code + "_" + number;
55+
newCode = `${languageObject.code}_${number}`;
5856
}
5957
languageObject.code = newCode;
6058
}
@@ -63,7 +61,7 @@ const useExportLogicV2 = () => {
6361
});
6462
OCADataArray.push(OCADescriptionData);
6563

66-
//CAPTURE ATTRIBUTE SHEET DATA
64+
// CAPTURE ATTRIBUTE SHEET DATA
6765
languages.forEach((language) => {
6866
const rowData = [];
6967
attributesList.forEach((item, index) => {
@@ -105,7 +103,7 @@ const useExportLogicV2 = () => {
105103
const buildMetaText = () => {
106104
let buildText = "# Add meta overlay";
107105

108-
languagesWithCode.forEach((language, _) => {
106+
languagesWithCode.forEach((language) => {
109107
const languageIndex = OCADataArray[0].findIndex(
110108
(obj) => obj.Language === language.language
111109
);
@@ -115,21 +113,21 @@ const useExportLogicV2 = () => {
115113
buildText += ` description="${OCADataArray[0][languageIndex].Description}"`;
116114
});
117115

118-
buildText += `\n`;
116+
buildText += "\n";
119117
return buildText;
120118
};
121119

122120
const buildFormatText = () => {
123121
let buildText = "# Add Format Overlay\n";
124122

125-
let tempText = '';
123+
let tempText = "";
126124
formatRuleRowData.forEach((item, index) => {
127-
if (item['FormatText']) {
128-
tempText += ` ${attributesList[index]}="${item['FormatText']}"`;
125+
if (item.FormatText) {
126+
tempText += ` ${attributesList[index]}="${item.FormatText}"`;
129127
}
130128
});
131129

132-
if (tempText !== '') {
130+
if (tempText !== "") {
133131
buildText += "ADD Format ATTRS";
134132
buildText += tempText;
135133
buildText += "\n";
@@ -140,14 +138,14 @@ const useExportLogicV2 = () => {
140138

141139
const buildConformanceText = () => {
142140
let buildText = "# Add Conformance Overlay\n";
143-
let conformanceText = '';
141+
let conformanceText = "";
144142

145143
attributesList.forEach((item, index) => {
146144
if (overlay["Make selected entries required"].selected) {
147-
conformanceText += ` ${item}=${characterEncodingRowData[index]['Make selected entries required'] ? "M" : "O"}`;
145+
conformanceText += ` ${item}=${characterEncodingRowData[index]["Make selected entries required"] ? "M" : "O"}`;
148146
}
149147
});
150-
if (conformanceText !== '') {
148+
if (conformanceText !== "") {
151149
buildText += `ADD CONFORMANCE ATTRS${conformanceText}\n`;
152150
}
153151
return buildText;
@@ -156,16 +154,14 @@ const useExportLogicV2 = () => {
156154
const buildLabelText = (data) => {
157155
let buildText = "# Add label overlay";
158156

159-
languagesWithCode.forEach((language, _) => {
157+
languagesWithCode.forEach((language) => {
160158
let labelText = "";
161159
attributesList.forEach((item, index) => {
162160
const languageIndex =
163161
data
164162
.slice(1)
165-
.findIndex(
166-
(element) => element[0].Language === language.language
167-
) + 1;
168-
if (data[languageIndex][index].Label && data[languageIndex][index].Label !== '') {
163+
.findIndex((element) => element[0].Language === language.language) + 1;
164+
if (data[languageIndex][index].Label && data[languageIndex][index].Label !== "") {
169165
labelText += ` ${item}="${data[languageIndex][index].Label}"`;
170166
}
171167
});
@@ -174,24 +170,24 @@ const useExportLogicV2 = () => {
174170
}
175171
});
176172

177-
buildText += `\n`;
173+
buildText += "\n";
178174
return buildText;
179175
};
180176

181177
const buildInformationText = (data) => {
182178
let buildText = "# Add information overlay";
183179

184-
languagesWithCode.forEach((language, _) => {
180+
languagesWithCode.forEach((language) => {
185181
let infoText = "";
186182
attributesList.forEach((item, index) => {
187183
const languageIndex =
188184
data
189185
.slice(1)
190-
.findIndex(
191-
(element) => element[0].Language === language.language
192-
) + 1;
193-
if (data[languageIndex][index].Description && data[languageIndex][index].Description !== '') {
194-
186+
.findIndex((element) => element[0].Language === language.language) + 1;
187+
if (
188+
data[languageIndex][index].Description &&
189+
data[languageIndex][index].Description !== ""
190+
) {
195191
infoText += ` ${item}="${data[languageIndex][index].Description}"`;
196192
}
197193
});
@@ -200,35 +196,35 @@ const useExportLogicV2 = () => {
200196
}
201197
});
202198

203-
buildText += `\n`;
199+
buildText += "\n";
204200
return buildText;
205201
};
206202

207203
const buildEntryCodeText = () => {
208204
let buildText = "# Add entry code overlay\n";
209205
// buildText += "ADD ENTRY_CODE ATTRS";
210206

211-
let entryCodesText = '';
212-
attributesList.forEach((item, _) => {
213-
let entryCodes = '';
207+
let entryCodesText = "";
208+
attributesList.forEach((item) => {
209+
let entryCodes = "";
214210
if (savedEntryCodes[item]) {
215211
for (const entry of savedEntryCodes[item]) {
216-
entryCodes += (', "' + entry.Code + '"');
212+
entryCodes += `, "${entry.Code}"`;
217213
}
218214
entryCodesText += ` ${item}=[${entryCodes.slice(2)}]`;
219215
}
220216
});
221217

222-
if (entryCodesText !== '') {
218+
if (entryCodesText !== "") {
223219
buildText += `ADD ENTRY_CODE ATTRS${entryCodesText}\n`;
224220

225-
languagesWithCode.forEach((language, _) => {
221+
languagesWithCode.forEach((language) => {
226222
buildText += `ADD ENTRY ${language.code} ATTRS`;
227-
attributesList.forEach((item, _) => {
223+
attributesList.forEach((item) => {
228224
if (savedEntryCodes[item]) {
229-
let entryString = '';
225+
let entryString = "";
230226
for (const entry of savedEntryCodes[item]) {
231-
entryString += (', "' + entry.Code + '": "' + entry[language.language] + '"');
227+
entryString += `, "${entry.Code}": "${entry[language.language]}"`;
232228
}
233229
buildText += ` ${item}={${entryString.slice(2)}}`;
234230
}
@@ -248,7 +244,7 @@ const useExportLogicV2 = () => {
248244
buildText += ` ${item}=${data[1][index].Unit}`;
249245
});
250246

251-
buildText += `\n`;
247+
buildText += "\n";
252248
return buildText;
253249
};
254250

@@ -257,29 +253,32 @@ const useExportLogicV2 = () => {
257253
buildText += "ADD CHARACTER_ENCODING ATTRS";
258254

259255
attributesList.forEach((item, index) => {
260-
if (characterEncodingRowData?.[index] && characterEncodingRowData?.[index]?.['Character Encoding']) {
261-
buildText += ` ${item}="${characterEncodingRowData[index]['Character Encoding']}"`;
256+
if (
257+
characterEncodingRowData?.[index] &&
258+
characterEncodingRowData?.[index]?.["Character Encoding"]
259+
) {
260+
buildText += ` ${item}="${characterEncodingRowData[index]["Character Encoding"]}"`;
262261
} else {
263-
buildText += ` ${item}="${(data[1][index].Type === 'Array[Binary]' || data[1][index].Type === 'Binary') ? 'base64' : 'utf-8'}"`;
264-
};
262+
buildText += ` ${item}="${data[1][index].Type === "Array[Binary]" || data[1][index].Type === "Binary" ? "base64" : "utf-8"}"`;
263+
}
265264
});
266265

267-
buildText += `\n`;
266+
buildText += "\n";
268267
return buildText;
269268
};
270269

271270
const buildCardinalityText = () => {
272271
let buildText = "# Add cardinality overlay\n";
273272

274-
if (overlay["Cardinality"].selected) {
273+
if (overlay.Cardinality.selected) {
275274
let isAdd = false;
276-
let buildNewText = '';
275+
let buildNewText = "";
277276

278277
if (cardinalityData.length > 0) {
279-
cardinalityData.forEach((item, _) => {
280-
if (item['EntryLimit'] && item['EntryLimit'] !== '') {
278+
cardinalityData.forEach((item) => {
279+
if (item.EntryLimit && item.EntryLimit !== "") {
281280
isAdd = true;
282-
buildNewText += ` ${item['Attribute']}="${item['EntryLimit']}"`;
281+
buildNewText += ` ${item.Attribute}="${item.EntryLimit}"`;
283282
}
284283
});
285284
}
@@ -291,7 +290,6 @@ const useExportLogicV2 = () => {
291290
}
292291
}
293292

294-
295293
return buildText;
296294
};
297295

@@ -307,7 +305,7 @@ const useExportLogicV2 = () => {
307305
buildBodyText += buildInformationText(data);
308306
buildBodyText += buildEntryCodeText();
309307
buildBodyText += buildCardinalityText();
310-
// buildBodyText += buildUnitsText(data);
308+
buildBodyText += buildUnitsText(data);
311309
buildBodyText += buildCharacterEncodingText(data);
312310

313311
return buildBodyText;
@@ -316,13 +314,13 @@ const useExportLogicV2 = () => {
316314
const exportData = async () => {
317315
const data = buildOCAText(OCADataArray);
318316

319-
const blob = new Blob([data], { type: 'text/plain' });
317+
const blob = new Blob([data], { type: "text/plain" });
320318

321319
const url = URL.createObjectURL(blob);
322320

323-
const a = document.createElement('a');
321+
const a = document.createElement("a");
324322
a.href = url;
325-
a.download = 'ocafile.txt';
323+
a.download = "ocafile.txt";
326324
document.body.appendChild(a);
327325
a.click();
328326

@@ -335,4 +333,4 @@ const useExportLogicV2 = () => {
335333
};
336334
};
337335

338-
export default useExportLogicV2;
336+
export default useExportLogicV2;

0 commit comments

Comments
 (0)