fix: ensure processing of locally returned json data
This commit is contained in:
parent
92df420819
commit
9674c195d1
@ -1,5 +1,6 @@
|
|||||||
window.appState = {
|
window.appState = {
|
||||||
currentData: null,
|
currentData: null,
|
||||||
|
originalData: null, // Store original unprocessed data
|
||||||
outputFormat: 'json',
|
outputFormat: 'json',
|
||||||
tutorialDismissed: false,
|
tutorialDismissed: false,
|
||||||
};
|
};
|
||||||
@ -255,6 +256,8 @@ async function fetchData(endpoint, requestData) {
|
|||||||
} else if (data.status === 'error') {
|
} else if (data.status === 'error') {
|
||||||
window.uiAPI.displayError(data.message || 'An error occurred');
|
window.uiAPI.displayError(data.message || 'An error occurred');
|
||||||
} else {
|
} else {
|
||||||
|
// Store both original and current data
|
||||||
|
window.appState.originalData = structuredClone(data);
|
||||||
window.appState.currentData = data;
|
window.appState.currentData = data;
|
||||||
window.uiAPI.displayResults(data);
|
window.uiAPI.displayResults(data);
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,18 @@ function displayResults(data) {
|
|||||||
const replaceKeys = document.getElementById('replaceKeysOption').checked;
|
const replaceKeys = document.getElementById('replaceKeysOption').checked;
|
||||||
let displayData = data;
|
let displayData = data;
|
||||||
|
|
||||||
|
// Use the original data stored in appState for processing
|
||||||
if (convertTime || replaceKeys) {
|
if (convertTime || replaceKeys) {
|
||||||
const timezone = document.getElementById('timezoneSelect').value;
|
const timezone = document.getElementById('timezoneSelect').value;
|
||||||
|
// Use the original unprocessed data for processing
|
||||||
|
const sourceData = window.appState.originalData || data;
|
||||||
displayData = window.backendAPI.processTimestamps(
|
displayData = window.backendAPI.processTimestamps(
|
||||||
structuredClone(data),
|
structuredClone(sourceData),
|
||||||
timezone
|
timezone
|
||||||
); // Use structured clone API instead of JSON.parse/stringify
|
);
|
||||||
// displayData = window.backendAPI.processTimestamps(JSON.parse(JSON.stringify(data)), timezone);
|
} else if (window.appState.originalData) {
|
||||||
|
// If no processing is selected, use original data
|
||||||
|
displayData = structuredClone(window.appState.originalData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the data
|
// Format the data
|
||||||
@ -313,10 +318,8 @@ function setupProcessingOptions() {
|
|||||||
.getElementById('sanitizeOption')
|
.getElementById('sanitizeOption')
|
||||||
.addEventListener('change', function () {
|
.addEventListener('change', function () {
|
||||||
if (window.appState.currentData) {
|
if (window.appState.currentData) {
|
||||||
// Call window.appState
|
// Process current data without re-fetching
|
||||||
// Re-fetch with new options
|
displayResults(window.appState.currentData);
|
||||||
document.querySelector('.tab.active').getAttribute('data-tab');
|
|
||||||
triggerActiveTabButton();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -324,9 +327,8 @@ function setupProcessingOptions() {
|
|||||||
.getElementById('replaceKeysOption')
|
.getElementById('replaceKeysOption')
|
||||||
.addEventListener('change', function () {
|
.addEventListener('change', function () {
|
||||||
if (window.appState.currentData) {
|
if (window.appState.currentData) {
|
||||||
// Re-fetch with new options
|
// Process current data without re-fetching
|
||||||
document.querySelector('.tab.active').getAttribute('data-tab');
|
displayResults(window.appState.currentData);
|
||||||
triggerActiveTabButton();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user