Skip to content

Commit e8bc37f

Browse files
fix: Json prune of empty keys (#229)
* feat: Mock module for extra datasource * fix: Show boolean as string in logtable * fix: prune empty keys for better support of new data sources af04cc1
1 parent 88556fe commit e8bc37f

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/CloudLogging.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// src/CloudLogging.js
22
import { useState, useEffect } from "react";
33
import { GoogleOAuthProvider, useGoogleLogin } from "@react-oauth/google";
4+
import ExtraDataSource from "./ExtraDataSource";
45
import { log } from "./Utils";
56
import { toast, ToastContainer } from "react-toastify";
67
import "react-toastify/dist/ReactToastify.css";
@@ -375,6 +376,8 @@ const CloudLoggingForm = ({ onLogsReceived, onFileUpload }) => {
375376
</div>
376377
)}
377378
<div className="cloud-logging-buttons">
379+
{ExtraDataSource.isAvailable() && ExtraDataSource.renderButton(onLogsReceived)}
380+
378381
<button
379382
type="button"
380383
onClick={handleFetch}

src/ExtraDataSource.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// src/ExtraDataSource.js - mock implementation
2+
export default {
3+
isAvailable: () => false,
4+
};

src/LogTable.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ function LogTable(props) {
285285
return column.solutionTypes.indexOf(props.logData.solutionType) !== -1;
286286
}
287287
);
288-
289288
// Add dynamic columns
290289
_.map(props.extraColumns, (dotPath) => {
291290
const elems = dotPath.split(".");
@@ -294,6 +293,11 @@ function LogTable(props) {
294293
accessor: dotPath === ".error" ? "error" : dotPath,
295294
width: columnRegularWidth,
296295
className: "logtable-cell",
296+
Cell: ({ cell }) => {
297+
const value = cell.value;
298+
if (value === undefined || value === null) return null;
299+
return typeof value === "boolean" ? String(value) : value;
300+
},
297301
});
298302
});
299303
const headers = [

src/localStorage.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ export function parseJsonContent(content) {
145145
if (Array.isArray(obj)) return obj.map(processJsonObject);
146146

147147
return Object.keys(obj).reduce((result, key) => {
148-
const newKey = key.replace(/_/g, "");
149148
let value = obj[key];
150149

150+
if (value === null || value === undefined) {
151+
return result;
152+
}
153+
154+
const newKey = key.replace(/_/g, "");
155+
151156
// Check if this is a value object with only a 'value' property and flatten
152157
if (
153158
value !== null &&
@@ -157,9 +162,18 @@ export function parseJsonContent(content) {
157162
"value" in value
158163
) {
159164
value = value.value;
165+
166+
if (value === null || value === undefined) {
167+
return result;
168+
}
160169
} else if (typeof value === "object" && value !== null) {
161170
// Recursively process nested objects
162171
value = processJsonObject(value);
172+
173+
// Skip empty objects (those with no properties after processing)
174+
if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) {
175+
return result;
176+
}
163177
}
164178

165179
result[newKey] = value;
@@ -170,7 +184,7 @@ export function parseJsonContent(content) {
170184
try {
171185
const parsed = JSON.parse(content);
172186
const processedData = processJsonObject(parsed);
173-
log("Processed JSON data: removed underscores and flattened value objects");
187+
log("Processed JSON data: removed underscores, flattened value objects, and pruned null/undefined fields");
174188
return sortObjectKeys(processedData);
175189
} catch (error) {
176190
log("Initial JSON parsing failed, attempting to wrap in array");

0 commit comments

Comments
 (0)