-
Notifications
You must be signed in to change notification settings - Fork 335
/
PreviewDataTab.vue
212 lines (210 loc) · 7.66 KB
/
PreviewDataTab.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<template>
<div class="fill-height">
<div ref="header" class="pb-2 result-header d-flex align-center">
<template v-if="validConn">
<div class="d-flex align-center mr-4">
<b class="mr-1">Table:</b>
<truncate-string
:maxWidth="260"
:nudgeLeft="16"
:text="$typy(getActiveTreeNode, 'id').safeObject"
/>
</div>
<v-tabs
v-model="activeView"
hide-slider
:height="20"
class="tab-navigation--btn-style"
>
<v-tab
:key="SQL_QUERY_MODES.PRVW_DATA"
:href="`#${SQL_QUERY_MODES.PRVW_DATA}`"
class="tab-btn px-3 text-uppercase"
active-class="tab-btn--active font-weight-medium"
>
{{ $t('data') }}
</v-tab>
<v-tab
:key="SQL_QUERY_MODES.PRVW_DATA_DETAILS"
:href="`#${SQL_QUERY_MODES.PRVW_DATA_DETAILS}`"
class="tab-btn px-3 text-uppercase"
active-class="tab-btn--active font-weight-medium"
>
{{ $t('details') }}
</v-tab>
</v-tabs>
<v-spacer />
<keep-alive>
<duration-timer
v-if="activeView"
:key="activeView"
:startTime="getPrvwSentTime(activeView)"
:executionTime="getPrvwExeTime(activeView)"
:totalDuration="getPrvwTotalDuration(activeView)"
/>
</keep-alive>
<v-tooltip
v-if="activeView === SQL_QUERY_MODES.PRVW_DATA"
top
transition="slide-y-transition"
content-class="shadow-drop color text-navigation py-1 px-4"
>
<template v-slot:activator="{ on }">
<div
v-if="!getPrvwDataRes(SQL_QUERY_MODES.PRVW_DATA).complete"
class="ml-4 d-flex align-center"
v-on="on"
>
<v-icon size="16" color="error" class="mr-2">
$vuetify.icons.alertWarning
</v-icon>
{{ $t('incomplete') }}
</div>
</template>
<span> {{ $t('info.queryIncomplete') }}</span>
</v-tooltip>
</template>
<span v-else v-html="$t('prvwTabGuide')" />
</div>
<template v-if="validConn">
<v-skeleton-loader
v-if="isPrwDataLoading"
:loading="isPrwDataLoading"
type="table: table-thead, table-tbody"
:height="dynDim.height - headerHeight"
/>
<template v-else>
<keep-alive>
<result-data-table
v-if="
activeView === SQL_QUERY_MODES.PRVW_DATA ||
activeView === SQL_QUERY_MODES.PRVW_DATA_DETAILS
"
:key="activeView"
:height="dynDim.height - headerHeight"
:width="dynDim.width"
:headers="$typy(getPrvwDataRes(activeView), 'fields').safeArray"
:rows="$typy(getPrvwDataRes(activeView), 'data').safeArray"
/>
</keep-alive>
</template>
</template>
</div>
</template>
<script>
/*
* Copyright (c) 2020 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2025-08-17
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'
import ResultDataTable from './ResultDataTable'
import DurationTimer from './DurationTimer'
export default {
name: 'preview-data-tab',
components: {
ResultDataTable,
DurationTimer,
},
props: {
dynDim: {
type: Object,
validator(obj) {
return 'width' in obj && 'height' in obj
},
required: true,
},
},
data() {
return {
headerHeight: 0,
}
},
computed: {
...mapState({
SQL_QUERY_MODES: state => state.app_config.SQL_QUERY_MODES,
curr_query_mode: state => state.query.curr_query_mode,
curr_cnct_resource: state => state.query.curr_cnct_resource,
}),
...mapGetters({
getPrvwDataRes: 'query/getPrvwDataRes',
getPrvwSentTime: 'query/getPrvwSentTime',
getPrvwExeTime: 'query/getPrvwExeTime',
getPrvwTotalDuration: 'query/getPrvwTotalDuration',
getLoadingPrvw: 'query/getLoadingPrvw',
getActiveTreeNode: 'query/getActiveTreeNode',
}),
validConn() {
return Boolean(this.getActiveTreeNode.id && this.curr_cnct_resource.id)
},
isPrwDataLoading() {
return (
this.getLoadingPrvw(this.SQL_QUERY_MODES.PRVW_DATA) ||
this.getLoadingPrvw(this.SQL_QUERY_MODES.PRVW_DATA_DETAILS)
)
},
activeView: {
get() {
return this.curr_query_mode
},
set(value) {
if (this.curr_query_mode !== this.SQL_QUERY_MODES.QUERY_VIEW)
this.SET_CURR_QUERY_MODE(value)
},
},
},
watch: {
activeView: async function(activeView) {
// Wait until data is fetched
if (!this.isPrwDataLoading && this.validConn) await this.handleFetch(activeView)
},
},
activated() {
this.setHeaderHeight()
},
methods: {
...mapMutations({
SET_CURR_QUERY_MODE: 'query/SET_CURR_QUERY_MODE',
}),
...mapActions({
fetchPrvw: 'query/fetchPrvw',
}),
setHeaderHeight() {
if (!this.$refs.header) return
this.headerHeight = this.$refs.header.clientHeight
},
/**
* This function checks if there is no preview data or details data
* before dispatching action to fetch either preview data or details
* data based on SQL_QUERY_MODE value.
* @param {String} SQL_QUERY_MODE - query mode
*/
async handleFetch(SQL_QUERY_MODE) {
switch (SQL_QUERY_MODE) {
case this.SQL_QUERY_MODES.PRVW_DATA:
case this.SQL_QUERY_MODES.PRVW_DATA_DETAILS:
if (!this.getPrvwDataRes(SQL_QUERY_MODE).fields) {
await this.fetchActiveNodeData(SQL_QUERY_MODE)
}
break
}
},
/**
* @param {String} SQL_QUERY_MODE - query mode
*/
async fetchActiveNodeData(SQL_QUERY_MODE) {
await this.fetchPrvw({
tblId: this.$typy(this.getActiveTreeNode, 'id').safeObject,
prvwMode: SQL_QUERY_MODE,
})
},
},
}
</script>