Skip to content

Commit a68bcf7

Browse files
committed
Make req Parms in the records view consistent with the Request view
Fixes #882
1 parent babc017 commit a68bcf7

File tree

4 files changed

+58
-22
lines changed

4 files changed

+58
-22
lines changed

web-client/src/components/SrParmsFormatTabs.vue

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,24 @@ hljs.registerLanguage('json', json)
2626
hljs.registerLanguage('python', python)
2727
hljs.registerLanguage('lua', lua)
2828
29-
const props = defineProps<{
30-
rcvdParms: object | string | null
31-
sentParms?: object | string | null
32-
endpoint?: string
33-
}>()
29+
const props = withDefaults(
30+
defineProps<{
31+
rcvdParms: object | string | null
32+
sentParms?: object | string | null
33+
endpoint?: string
34+
mode?: 'received' | 'sending'
35+
}>(),
36+
{
37+
mode: 'received'
38+
}
39+
)
40+
41+
// Tooltip text based on mode
42+
const tooltipPrefix = computed(() =>
43+
props.mode === 'sending'
44+
? 'Request parameters that will be sent to server formatted in'
45+
: 'Request parameters used by the server to create this record formatted in'
46+
)
3447
3548
const activeTab = ref('0')
3649
@@ -377,9 +390,9 @@ watch(parsedData, () => {
377390
<template>
378391
<Tabs v-model:value="activeTab">
379392
<TabList>
380-
<Tab value="0" title="Request parameters used by the server formatted in JSON">JSON</Tab>
381-
<Tab value="1" title="Request parameters used by the server formatted in Python">Python</Tab>
382-
<Tab value="2" title="Request parameters used by the server formatted in Lua">Lua</Tab>
393+
<Tab value="0" :title="`${tooltipPrefix} JSON`">JSON</Tab>
394+
<Tab value="1" :title="`${tooltipPrefix} Python`">Python</Tab>
395+
<Tab value="2" :title="`${tooltipPrefix} Lua`">Lua</Tab>
383396
<Tab value="3" title="Request parameters used in a python code example">Python Code</Tab>
384397
<Tab v-if="hasDiff" value="4" title="The exact parameters sent by this web client">Sent</Tab>
385398
<Tab
@@ -406,7 +419,7 @@ watch(parsedData, () => {
406419
<div class="tab-content">
407420
<div class="button-row">
408421
<Button
409-
label="Copy"
422+
label="Copy Python"
410423
size="small"
411424
icon="pi pi-copy"
412425
@click="copyPythonSnippetToClipboard"

web-client/src/components/SrRecIdReqDisplay.vue

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</template>
2424

2525
<script setup lang="ts">
26-
import { ref, onMounted } from 'vue'
26+
import { ref, onMounted, watch } from 'vue'
2727
import Button from 'primevue/button'
2828
import { db } from '@/db/SlideRuleDb'
2929
import SrReqParmsDisplayDlg from './SrReqParmsDisplayDlg.vue'
@@ -55,15 +55,31 @@ const reqParms = ref<string>('')
5555
const curAPI = ref<string>('')
5656
const tooltipRef = ref()
5757
58-
onMounted(async () => {
59-
if (props.reqId) {
60-
curAPI.value = await db.getFunc(props.reqId)
61-
const p = await db.getReqParams(props.reqId)
58+
async function loadReqParams(reqId: number) {
59+
if (reqId) {
60+
curAPI.value = await db.getFunc(reqId)
61+
// Get the full request record to access rcvd_parms
62+
const request = await db.table('requests').get(reqId)
63+
// Use rcvd_parms (what server used) if available, fall back to parameters (what was sent)
64+
const p = request?.rcvd_parms || request?.parameters || {}
6265
reqParms.value = JSON.stringify(p, null, 2)
6366
} else {
64-
logger.debug('onMounted: no reqId')
67+
logger.debug('loadReqParams: no reqId')
68+
reqParms.value = ''
69+
curAPI.value = ''
6570
}
71+
}
72+
73+
onMounted(() => {
74+
void loadReqParams(props.reqId)
6675
})
76+
77+
watch(
78+
() => props.reqId,
79+
(newReqId) => {
80+
void loadReqParams(newReqId)
81+
}
82+
)
6783
// Open the Parms dialog
6884
function openParmsDialog(params: string | object) {
6985
if (typeof params === 'object') {

web-client/src/components/SrReqDisplay.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
:title="`endpoint = ${curAPI}`"
1919
:endpoint="curAPI"
2020
width="80vw"
21+
mode="sending"
2122
/>
2223
</div>
2324
</template>

web-client/src/components/SrReqParmsDisplayDlg.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
import Dialog from 'primevue/dialog'
33
import SrParmsFormatTabs from './SrParmsFormatTabs.vue'
44
5-
const props = defineProps<{
6-
rcvdParms: object | string | null
7-
width?: string
8-
title?: string
9-
endpoint?: string
10-
}>()
5+
const props = withDefaults(
6+
defineProps<{
7+
rcvdParms: object | string | null
8+
width?: string
9+
title?: string
10+
endpoint?: string
11+
mode?: 'received' | 'sending'
12+
}>(),
13+
{
14+
mode: 'received'
15+
}
16+
)
1117
1218
const modelValue = defineModel<boolean>({ default: false })
1319
</script>
@@ -25,7 +31,7 @@ const modelValue = defineModel<boolean>({ default: false })
2531
</div>
2632
</template>
2733

28-
<SrParmsFormatTabs :rcvdParms="props.rcvdParms" :endpoint="props.endpoint" />
34+
<SrParmsFormatTabs :rcvdParms="props.rcvdParms" :endpoint="props.endpoint" :mode="props.mode" />
2935
</Dialog>
3036
</template>
3137

0 commit comments

Comments
 (0)