Skip to content

Commit 12afc38

Browse files
committed
refactor: optimize Monaco editor integration and improve JSON handling
- Updated nuxt.config.ts to conditionally set animations based on the development environment. - Modified useDebug composable to disable the minimap in the Monaco editor. - Replaced JSON.stringify calls with a new stringifyForEditor method across multiple components to enhance performance and caching of JSON data. - Introduced an editorJsonCache to store serialized JSON for improved efficiency in rendering editor content.
1 parent 528cf1d commit 12afc38

File tree

6 files changed

+96
-8
lines changed

6 files changed

+96
-8
lines changed

apps/web/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export default defineNuxtConfig({
198198
},
199199
},
200200
extras: {
201-
animations: 'all',
201+
animations: IS_DEV ? 'all' : [],
202202
},
203203
},
204204
monacoEditor: {

apps/web/src/composables/useDebug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function useDebug() {
6161
theme: $q.dark.isActive ? 'vs-dark' : 'vs-light',
6262
readOnly: true,
6363
minimap: {
64-
enabled: true,
64+
enabled: false,
6565
},
6666
largeFileOptimizations: true,
6767
scrollBeyondLastColumn: 0,

apps/web/src/pages/identities/table/[_id]/jobs.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ div
6161
q-separator(v-if="tabs[keyCompute + '_' + key]")
6262
q-tab-panels.overflow-auto(v-model="tabs[keyCompute + '_' + key]")
6363
q-tab-panel(name="params")
64-
MonacoEditor(style="height: 45vh; width: 100%" :model-value="JSON.stringify(job.params, null, 2)" :options="monacoOptions" lang="json")
64+
MonacoEditor(style="height: 45vh; width: 100%" :model-value="stringifyForEditor(job.params)" :options="monacoOptions" lang="json")
6565
q-tab-panel(name="result")
66-
MonacoEditor(style="height: 45vh; width: 100%;" :model-value="JSON.stringify(job.result, null, 2)" :options="monacoOptions" lang="json")
66+
MonacoEditor(style="height: 45vh; width: 100%;" :model-value="stringifyForEditor(job.result)" :options="monacoOptions" lang="json")
6767
q-timeline-entry.text-h5(v-if='empty' icon='mdi-flag-off' title='Fin de la liste...' color="red")
6868
</template>
6969

@@ -73,6 +73,7 @@ export default defineNuxtComponent({
7373
data() {
7474
return {
7575
tabs: {},
76+
editorJsonCache: new WeakMap<object, string>(),
7677
jobsByOptions: [
7778
{ label: 'Jour', value: 'DD/MM/YYYY' },
7879
{ label: 'Mois', value: 'MM/YYYY' },
@@ -161,6 +162,27 @@ export default defineNuxtComponent({
161162
return 'mdi-help'
162163
}
163164
},
165+
stringifyForEditor(payload: unknown): string {
166+
if (payload && typeof payload === 'object') {
167+
const cached = this.editorJsonCache.get(payload as object)
168+
if (cached) {
169+
return cached
170+
}
171+
}
172+
173+
let value = ''
174+
try {
175+
value = JSON.stringify(payload ?? null, null, 2) ?? 'null'
176+
} catch {
177+
value = String(payload)
178+
}
179+
180+
if (payload && typeof payload === 'object') {
181+
this.editorJsonCache.set(payload as object, value)
182+
}
183+
184+
return value
185+
},
164186
},
165187
})
166188
</script>

apps/web/src/pages/jobs/details.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ div
5757
q-separator(v-if="tabs[keyCompute + '_' + key]")
5858
q-tab-panels.overflow-auto(v-model="tabs[keyCompute + '_' + key]")
5959
q-tab-panel(name="params")
60-
MonacoEditor(style="height: 45vh; width: 100%" :model-value="JSON.stringify(job.params, null, 2)" :options="monacoOptions" lang="json")
60+
MonacoEditor(style="height: 45vh; width: 100%" :model-value="stringifyForEditor(job.params)" :options="monacoOptions" lang="json")
6161
q-tab-panel(name="result")
62-
MonacoEditor(style="height: 45vh; width: 100%;" :model-value="JSON.stringify(job.result, null, 2)" :options="monacoOptions" lang="json")
62+
MonacoEditor(style="height: 45vh; width: 100%;" :model-value="stringifyForEditor(job.result)" :options="monacoOptions" lang="json")
6363
q-timeline-entry.text-h5(v-if='empty' icon='mdi-flag-off' title='Fin de la liste...' color="red")
6464
</template>
6565

@@ -69,6 +69,7 @@ export default defineComponent({
6969
data() {
7070
return {
7171
tabs: {},
72+
editorJsonCache: new WeakMap<object, string>(),
7273
jobsByOptions: [
7374
{ label: 'Jour', value: 'DD/MM/YYYY' },
7475
{ label: 'Mois', value: 'MM/YYYY' },
@@ -157,6 +158,27 @@ export default defineComponent({
157158
return 'mdi-help'
158159
}
159160
},
161+
stringifyForEditor(payload: unknown): string {
162+
if (payload && typeof payload === 'object') {
163+
const cached = this.editorJsonCache.get(payload as object)
164+
if (cached) {
165+
return cached
166+
}
167+
}
168+
169+
let value = ''
170+
try {
171+
value = JSON.stringify(payload ?? null, null, 2) ?? 'null'
172+
} catch {
173+
value = String(payload)
174+
}
175+
176+
if (payload && typeof payload === 'object') {
177+
this.editorJsonCache.set(payload as object, value)
178+
}
179+
180+
return value
181+
},
160182
},
161183
})
162184
</script>

apps/web/src/pages/jobs/table.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ q-page.container.q-pa-sm
110110
q-td(colspan="100%" style="padding: 0")
111111
MonacoEditor(
112112
style="height: 45vh; width: 100%"
113-
:model-value="JSON.stringify(props.row?.result, null, 2)"
113+
:model-value="stringifyForEditor(props.row?.result)"
114114
:options="monacoOptions"
115115
lang="json"
116116
)
@@ -123,6 +123,7 @@ export default defineComponent({
123123
data() {
124124
return {
125125
expanded: [] as string[],
126+
editorJsonCache: new WeakMap<object, string>(),
126127
foptions: [
127128
{ label: 'Ok', value: '9' },
128129
{ label: 'En erreur', value: '-1' },
@@ -288,6 +289,27 @@ export default defineComponent({
288289
open(path): void {
289290
window.open(path, '_blank')
290291
},
292+
stringifyForEditor(payload: unknown): string {
293+
if (payload && typeof payload === 'object') {
294+
const cached = this.editorJsonCache.get(payload as object)
295+
if (cached) {
296+
return cached
297+
}
298+
}
299+
300+
let value = ''
301+
try {
302+
value = JSON.stringify(payload ?? null, null, 2) ?? 'null'
303+
} catch {
304+
value = String(payload)
305+
}
306+
307+
if (payload && typeof payload === 'object') {
308+
this.editorJsonCache.set(payload as object, value)
309+
}
310+
311+
return value
312+
},
291313
expandRow(props): void {
292314
this.expanded = this.expanded.includes(props.row.jobId) ? [] : [props.row.jobId]
293315
},

apps/web/src/pages/lifecycles/table.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
q-tr(v-if="props.expand" :props="props")
9797
q-td(colspan="100%" style="padding: 0;")
9898
MonacoEditor(
99-
:model-value="JSON.stringify(props.row, null, 2)"
99+
:model-value="stringifyForEditor(props.row)"
100100
lang="json"
101101
:options="monacoOptions"
102102
style="height: 35vh; width: 100%"
@@ -111,6 +111,7 @@ export default defineComponent({
111111
return {
112112
filter: ref(''),
113113
expanded: ref<any[]>([]),
114+
editorJsonCache: new WeakMap<object, string>(),
114115
}
115116
},
116117
async setup() {
@@ -234,6 +235,27 @@ export default defineComponent({
234235
expandRow(props) {
235236
this.expanded = this.expanded.includes(props.row._id) ? [] : [props.row._id]
236237
},
238+
stringifyForEditor(payload: unknown): string {
239+
if (payload && typeof payload === 'object') {
240+
const cached = this.editorJsonCache.get(payload as object)
241+
if (cached) {
242+
return cached
243+
}
244+
}
245+
246+
let value = ''
247+
try {
248+
value = JSON.stringify(payload ?? null, null, 2) ?? 'null'
249+
} catch {
250+
value = String(payload)
251+
}
252+
253+
if (payload && typeof payload === 'object') {
254+
this.editorJsonCache.set(payload as object, value)
255+
}
256+
257+
return value
258+
},
237259
open(path) {
238260
window.open(path, '_blank')
239261
},

0 commit comments

Comments
 (0)