Skip to content

Commit

Permalink
feat: show query results in success message
Browse files Browse the repository at this point in the history
  • Loading branch information
ZonaHex committed Nov 17, 2023
1 parent a08bb42 commit 34d2ae8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
19 changes: 12 additions & 7 deletions src/assets/style/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,31 @@ body {
border-radius: 6px;

.arco-message-content {
display: -webkit-box;
overflow: hidden;
color: var(--main-font-color);
font-size: 14px;
line-height: 22px;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
line-clamp: 2;
-webkit-box-orient: vertical;
}
}

.arco-message-success {
background-color: var(--success-bg-color);
border-color: var(--success-color);

.arco-message-content {
white-space: pre;
}
}

.arco-message-error {
background-color: var(--danger-bg-color);
border-color: var(--danger-color);

.arco-message-content {
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
}

.arco-tooltip-content {
Expand Down
27 changes: 19 additions & 8 deletions src/store/modules/code-run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ const useCodeRunStore = defineStore('codeRun', () => {
// TODO: try something better
let oneResult = {} as ResultType
const res: HttpResponse = await API_MAP[type](codeInfo)
Message.success({
content: i18n.global.t('dashboard.runSuccess'),
duration: 2 * 1000,
})

const resultsInLog: Array<ResultInLog> = []
res.output.forEach((oneRes: OutputType) => {
if (Reflect.has(oneRes, 'records')) {
const rowLength = oneRes.records.rows.length
resultsInLog.push({
records: rowLength,
type: 'select',
rowCount: rowLength,
})
if (rowLength >= 0) {
const pageType = CODE_TO_PAGE[type]
Expand Down Expand Up @@ -91,15 +89,28 @@ const useCodeRunStore = defineStore('codeRun', () => {
}
if (Reflect.has(oneRes, 'affectedrows')) {
resultsInLog.push({
affectedRows: oneRes.affectedrows,
type: 'affect',
rowCount: oneRes.affectedrows,
})
}
})

const message = resultsInLog
.map((result: ResultInLog) => {
return i18n.global.tc(`dashboard.${result.type}`, result.rowCount, { rowCount: result.rowCount })
})
.join(`;\n`)

Message.success({
content: message,
duration: 2 * 1000,
})

const oneLog: Log = {
type,
...res,
codeInfo,
results: resultsInLog,
message,
}
if (type === 'promql') {
oneLog.promInfo = {
Expand All @@ -109,7 +120,7 @@ const useCodeRunStore = defineStore('codeRun', () => {
Query: codeInfo,
}
}
// TODO: try something better

return {
log: oneLog,
lastResult: oneResult,
Expand Down
11 changes: 7 additions & 4 deletions src/store/modules/log/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export interface ResultInLog {
type: string
rowCount: number
}

export interface Log {
results?: ResultInLog[]
sql?: string
error?: string
name?: string
type: string
promInfo?: {}
promInfo?: object
codeInfo: string
message: string
}

export interface ResultInLog {}
4 changes: 2 additions & 2 deletions src/views/dashboard/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export default {
'dashboard.yType': 'Y-Axis Types',
'dashboard.xType': 'X-Axis Type',
'dashboard.groupBy': 'Group By',
'dashboard.select': 'Select {records} row | Select {records} rows',
'dashboard.select': 'Selected {rowCount} row | Selected {rowCount} rows',
'dashboard.pleaseSelect': 'Please select...',
'dashboard.draw': 'Draw',
'dashboard.error': 'Error',
'dashboard.affected': 'Affected {record} row | Affected {record} rows',
'dashboard.affect': 'Affected {rowCount} row | Affected {rowCount} rows',
'dashboard.executeTime': 'Execute: {time} ms',
'dashboard.executed': 'Executed {length} statement | Executed {length} statements',
'dashboard.network': 'Network: {time} ms',
Expand Down
4 changes: 1 addition & 3 deletions src/views/dashboard/modules/log.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ a-list-item.smaller-divider
.start-time
| {{ log.startTime }}
a-space.result(v-if="!log.error" fill :size="4")
a-space(v-if="hasExecutionTime" :size="0")
template(#split) ;
span(v-for="(oneResult, index) of log.results" :key="index") {{ oneResult.records >= 0 ? $tc('dashboard.select', oneResult.records, { records: oneResult.records }) : $tc('dashboard.affected', oneResult.affectedRows, { record: oneResult.affectedRows }) }}
span(v-if="hasExecutionTime") {{ log.message }}
.total-time(v-if="hasExecutionTime")
a-popover(content-class="total-time-popover")
template(#content)
Expand Down

0 comments on commit 34d2ae8

Please sign in to comment.