Skip to content

Commit 78e385e

Browse files
feat: improve Map and Set logging display in console
- Remove size property from Map and Set displays - Display Set values at top level with numeric indices (0, 1, 2, ...) - Display Map entries at top level with => notation (key =>: value) - Remove [[Set]] and [[Map]] wrapper properties for cleaner display - Collapse Maps and Sets by default in console (matching Postman behavior) - Add 'Map' and 'Set' type labels to clearly identify object types - Maintain expandable/collapsible UI for easy inspection of contents
1 parent aa06aea commit 78e385e

File tree

1 file changed

+47
-19
lines changed
  • packages/bruno-app/src/components/Devtools/Console

1 file changed

+47
-19
lines changed

packages/bruno-app/src/components/Devtools/Console/index.js

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,62 +67,90 @@ const LogMessage = ({ message, args }) => {
6767
const { displayedTheme } = useTheme();
6868

6969
// Helper function to transform Bruno special types back to readable format
70-
const transformBrunoTypes = obj => {
70+
// Returns { data, metadata } where metadata contains type information
71+
const transformBrunoTypes = (obj, returnMetadata = false) => {
7172
if (typeof obj !== 'object' || obj === null) {
72-
return obj;
73+
return returnMetadata ? { data: obj, metadata: {} } : obj;
7374
}
7475

7576
// Handle Bruno special types
7677
if (obj.__brunoType) {
7778
switch (obj.__brunoType) {
7879
case 'Set':
79-
return {
80-
'[[Set]]': obj.__brunoValue,
81-
'size': obj.__brunoValue.length,
82-
};
80+
// Transform Set to display values at top level with numeric indices
81+
// Convert array of values to object with numeric keys (0, 1, 2, ...)
82+
const setEntries = {};
83+
if (Array.isArray(obj.__brunoValue)) {
84+
obj.__brunoValue.forEach((value, index) => {
85+
setEntries[index] = transformBrunoTypes(value, false);
86+
});
87+
}
88+
return returnMetadata ? { data: setEntries, metadata: { type: 'Set' } } : setEntries;
8389
case 'Map':
84-
return {
85-
'[[Map]]': obj.__brunoValue,
86-
'size': obj.__brunoValue.length,
87-
};
90+
// Transform Map to display entries at top level with => notation
91+
// Convert array of [key, value] pairs to object with "key => value" format
92+
const mapEntries = {};
93+
if (Array.isArray(obj.__brunoValue)) {
94+
obj.__brunoValue.forEach(([key, value]) => {
95+
// Use => notation to clearly indicate Map entries
96+
const displayKey = `${String(key)} =>`;
97+
mapEntries[displayKey] = transformBrunoTypes(value, false);
98+
});
99+
}
100+
return returnMetadata ? { data: mapEntries, metadata: { type: 'Map' } } : mapEntries;
88101
case 'Function':
89-
return `[Function: ${obj.__brunoValue.split('\n')[0].substring(0, 50)}...]`;
102+
const funcData = `[Function: ${obj.__brunoValue.split('\n')[0].substring(0, 50)}...]`;
103+
return returnMetadata ? { data: funcData, metadata: {} } : funcData;
90104
case 'undefined':
91-
return 'undefined';
105+
return returnMetadata ? { data: 'undefined', metadata: {} } : 'undefined';
92106
default:
93-
return obj;
107+
return returnMetadata ? { data: obj, metadata: {} } : obj;
94108
}
95109
}
96110

97111
// Recursively transform nested objects
98112
if (Array.isArray(obj)) {
99-
return obj.map(transformBrunoTypes);
113+
const transformed = obj.map((item) => transformBrunoTypes(item, false));
114+
return returnMetadata ? { data: transformed, metadata: {} } : transformed;
100115
}
101116

102117
const transformed = {};
103118
for (const [key, value] of Object.entries(obj)) {
104-
transformed[key] = transformBrunoTypes(value);
119+
transformed[key] = transformBrunoTypes(value, false);
105120
}
106-
return transformed;
121+
return returnMetadata ? { data: transformed, metadata: {} } : transformed;
107122
};
108123

109124
const formatMessage = (msg, originalArgs) => {
110125
if (originalArgs && originalArgs.length > 0) {
111126
return originalArgs.map((arg, index) => {
112127
if (typeof arg === 'object' && arg !== null) {
113-
const transformedArg = transformBrunoTypes(arg);
128+
const { data: transformedArg, metadata } = transformBrunoTypes(arg, true);
129+
130+
// Determine the name to display based on the type
131+
let displayName = false;
132+
let shouldCollapse = 1; // Default: collapse at depth 1 for regular objects
133+
134+
if (metadata.type === 'Map') {
135+
displayName = 'Map';
136+
shouldCollapse = true; // Fully collapse Maps by default
137+
} else if (metadata.type === 'Set') {
138+
displayName = 'Set';
139+
shouldCollapse = true; // Fully collapse Sets by default
140+
}
141+
114142
return (
115143
<div key={index} className="log-object">
116144
<ReactJson
117145
src={transformedArg}
118146
theme={displayedTheme === 'light' ? 'rjv-default' : 'monokai'}
119147
iconStyle="triangle"
120148
indentWidth={2}
121-
collapsed={1}
149+
collapsed={shouldCollapse}
122150
displayDataTypes={false}
123151
displayObjectSize={false}
124152
enableClipboard={false}
125-
name={false}
153+
name={displayName}
126154
style={{
127155
backgroundColor: 'transparent',
128156
fontSize: '12px',

0 commit comments

Comments
 (0)