Skip to content

Commit 58a1ac0

Browse files
committed
add iframe
1 parent 3f33bb3 commit 58a1ac0

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

.tool-versions

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nodejs 16.13.1
2+
ruby 3.3.3

ui/src/data_resources/components/query_tab.vue

+28-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
fix
1818
/>
1919
<div
20-
v-else-if="!data.length"
20+
v-else-if="!data.length && !isIframe"
2121
class="d-flex justify-content-center align-items-center"
2222
style="height: 100%"
2323
>
@@ -35,12 +35,22 @@
3535
:header-border="showVariablesForm"
3636
:preferences="query.preferences"
3737
/>
38+
<div
39+
v-else-if="isIframe"
40+
style="overflow: hidden; height: 100%"
41+
>
42+
<iframe
43+
:src="iframeSrc"
44+
:style="{ height: '100%', border: 0, width: '100%' }"
45+
/>
46+
</div>
3847
</template>
3948
</div>
4049
</template>
4150

4251
<script>
4352
import QueryResult from 'queries/components/result'
53+
import { interpolateForQueryParams } from 'utils/scripts/string'
4454
import VariablesForm from 'queries/components/variables_form'
4555
import api from 'api'
4656
@@ -69,13 +79,17 @@ export default {
6979
errors: [],
7080
data: [],
7181
columns: [],
82+
iframeSrc: '',
7283
query: {}
7384
}
7485
},
7586
computed: {
7687
queryId () {
7788
return this.tab.preferences.query_id
7889
},
90+
isIframe () {
91+
return this.query?.preferences?.visualization === 'iframe'
92+
},
7993
style () {
8094
if (this.isLoadingQuery || !this.showVariablesForm) {
8195
return 'height: 100%'
@@ -91,8 +105,19 @@ export default {
91105
}
92106
},
93107
mounted () {
94-
this.loadQuery()
95-
this.runQuery()
108+
this.loadQuery().then(() => {
109+
if (this.isIframe) {
110+
const [apiPath, queryParams] = interpolateForQueryParams(this.query.preferences.api_path, {
111+
...this.dataVariables,
112+
...this.variables
113+
})
114+
115+
console.log(this.query.preferences.api_path, this.variables)
116+
this.iframeSrc = `${apiPath}?${new URLSearchParams(queryParams).toString()}`
117+
} else {
118+
this.runQuery()
119+
}
120+
})
96121
},
97122
methods: {
98123
loadQuery () {

ui/src/queries/components/settings.vue

+14-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
{{ ' ' }} {{ i18n['stacked_bars'] }}
8282
</Checkbox>
8383
</template>
84-
<template v-if="!['table', 'markdown', 'html', 'value', 'map'].includes(preferences.visualization)">
84+
<template v-if="!['table', 'markdown', 'html', 'value', 'map', 'iframe'].includes(preferences.visualization)">
8585
<p class="fs-4 fw-bold my-1">
8686
Format
8787
</p>
@@ -102,7 +102,7 @@
102102
</Radio>
103103
</RadioGroup>
104104
</template>
105-
<template v-if="!['table', 'markdown', 'html'].includes(preferences.visualization) && preferences.visualization_options.label_format === 'currency'">
105+
<template v-if="!['table', 'markdown', 'html', 'iframe'].includes(preferences.visualization) && preferences.visualization_options.label_format === 'currency'">
106106
<p class="fs-4 fw-bold my-1">
107107
{{ i18n['currency'] }}
108108
</p>
@@ -148,6 +148,11 @@ export default {
148148
required: false,
149149
default: () => []
150150
},
151+
withIframe: {
152+
type: Boolean,
153+
required: false,
154+
default: false
155+
},
151156
withVariablesEditor: {
152157
type: Boolean,
153158
required: false,
@@ -162,7 +167,7 @@ export default {
162167
},
163168
computed: {
164169
visualizationOptions () {
165-
return [
170+
const options = [
166171
{ label: this.i18n.table, value: 'table' },
167172
{ label: this.i18n.value, value: 'value' },
168173
{ label: this.i18n.markdown, value: 'markdown' },
@@ -175,6 +180,12 @@ export default {
175180
{ label: this.i18n.funnel, value: 'funnel' },
176181
{ label: this.i18n.map, value: 'map' }
177182
]
183+
184+
if (this.withIframe) {
185+
options.push({ label: 'Iframe', value: 'iframe' })
186+
}
187+
188+
return options
178189
},
179190
formatOptions () {
180191
return [

ui/src/queries/pages/show.vue

+24-4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
:preferences="dataQuery.preferences"
106106
:columns="columns"
107107
:with-variables-editor="queryType === 'api'"
108+
:with-iframe="queryType === 'api'"
108109
style="height: 100%"
109110
@close="toggleSettings"
110111
/>
@@ -184,7 +185,7 @@
184185
fix
185186
/>
186187
<div
187-
v-else-if="!data.length && !errors.length && !dataHTML"
188+
v-else-if="!data.length && !errors.length && !dataHTML && !isIframe"
188189
class="d-flex justify-content-center align-items-center h-100"
189190
>
190191
{{ i18n['no_data'] }}
@@ -203,6 +204,15 @@
203204
:preferences="dataQuery.preferences"
204205
@settings="toggleSettings"
205206
/>
207+
<div
208+
v-else-if="isIframe"
209+
style="overflow: hidden; height: 100%"
210+
>
211+
<iframe
212+
:src="iframeSrc"
213+
:style="{ height: withFooter ? '100%' : '100%', border: 0, width: '100%' }"
214+
/>
215+
</div>
206216
<div
207217
v-else-if="dataHTML"
208218
class="h-100 overflow-auto"
@@ -304,7 +314,7 @@ import QueryForm from '../components/form'
304314
import Settings from '../components/settings'
305315
import throttle from 'view3/src/utils/throttle'
306316
import VariablesForm from '../components/variables_form'
307-
import { titleize } from 'utils/scripts/string'
317+
import { interpolateForQueryParams, titleize } from 'utils/scripts/string'
308318
import singularize from 'inflected/src/singularize'
309319
import { widthLessThan } from 'utils/scripts/dimensions'
310320
import { modelNameMap } from 'data_resources/scripts/schema'
@@ -359,7 +369,8 @@ export default {
359369
errors: [],
360370
columns: [],
361371
data: [],
362-
dataHTML: ''
372+
dataHTML: '',
373+
iframeSrc: ''
363374
}
364375
},
365376
computed: {
@@ -377,6 +388,9 @@ export default {
377388
showApiUi () {
378389
return this.queryType === 'api' || (!this.isNewPage && this.dataQuery.preferences.api_path)
379390
},
391+
isIframe () {
392+
return this.dataQuery.preferences.visualization === 'iframe'
393+
},
380394
queryTypes () {
381395
return [
382396
{ label: this.i18n.sql, value: 'sql' },
@@ -696,7 +710,13 @@ export default {
696710
loadQueryData () {
697711
this.maybeUpdateVariablesQueryParams()
698712
699-
if (this.queryType === 'api') {
713+
if (this.queryType === 'api' && this.isIframe) {
714+
const [apiPath, queryParams] = interpolateForQueryParams(this.dataQuery.preferences.api_path, this.variablesData)
715+
716+
this.iframeSrc = `${apiPath}?${new URLSearchParams(queryParams).toString()}`
717+
718+
return Promise.resolve({ src: this.iframeSrc })
719+
} else if (this.queryType === 'api') {
700720
return this.runApiQuery()
701721
} else {
702722
if (this.dataQuery.sql_body && (this.isEdited || !this.query.id)) {

0 commit comments

Comments
 (0)