Skip to content

Commit

Permalink
fix(Query): utf decode in result table [#533]
Browse files Browse the repository at this point in the history
  • Loading branch information
SimbiozizV committed Jun 5, 2024
1 parent 5282fb7 commit 7cadb62
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/ui/src/ui/pages/query-tracker/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,30 @@ export const CompletedStates = [
QueryStatus.FAILED,
];

const secureDecoding = (value: string) => {
try {
return unipika.decode(value);
} catch (e) {
return value;
}
};

const JSONParser = {
JSONSerializer: {
stringify(data: unknown) {
return JSON.stringify(data);
},
parse(data: string) {
return JSON.parse(data, (_, value) => {
if (typeof value === 'string') {
try {
return unipika.decode(value);
} catch (e) {
return value;
}
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
return Object.keys(value).reduce<Record<any, any>>((acc, k) => {
acc[secureDecoding(k)] =
typeof value[k] === 'string' ? secureDecoding(value[k]) : value[k];

return acc;
}, {});
}

return value;
});
},
Expand Down Expand Up @@ -382,7 +392,7 @@ export function readQueryResults(
},
},
},
setup: getQTApiSetup(),
setup: {...getQTApiSetup(), ...JSONParser},
})) as QueryResult;
return {...result, rows: mapQueryRowNames(result.rows)};
};
Expand Down

0 comments on commit 7cadb62

Please # to comment.