query history with search

This commit is contained in:
Jan Prochazka
2021-06-03 15:52:46 +02:00
parent f6c8588573
commit 6362e2137b
3 changed files with 28 additions and 4 deletions

View File

@@ -14,7 +14,7 @@ function readCore(reader, skip, limit, filter) {
if (!line && !line.trim()) return;
try {
const json = JSON.parse(line);
if (filterName(filter, json.sql)) {
if (filterName(filter, json.sql, json.database)) {
if (!skip || readed >= skip) {
res.push(json);
}

View File

@@ -39,6 +39,12 @@ export function filterName(filter: string, ...names: string[]) {
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
const tokens = filter.split(' ').map(x => x.trim());
return !!_compact(names).find(name => !tokens.find(token => !name.toUpperCase().includes(token.toUpperCase())));
// return name.toUpperCase().includes(filter.toUpperCase());
const namesCompacted = _compact(names);
for (const token of tokens) {
const tokenUpper = token.toUpperCase();
const found = namesCompacted.find(name => name.toUpperCase().includes(tokenUpper));
if (!found) return false;
}
return true;
}

View File

@@ -9,6 +9,7 @@
import { onMount } from 'svelte';
import socket from '../utility/socket';
import axiosInstance from '../utility/axiosInstance';
import openNewTab from '../utility/openNewTab';
let filter = '';
let search = '';
@@ -50,7 +51,24 @@
</SearchBoxWrapper>
<WidgetsInnerContainer>
{#each historyItems as item}
<div class="wrapper" title={item.sql}>
<div
class="wrapper"
title={item.sql}
on:click={() => {
openNewTab(
{
title: 'Query #',
icon: 'icon sql-file',
tabComponent: 'QueryTab',
props: {
conid: item.conid,
database: item.database,
},
},
{ editor: item.sql }
);
}}
>
<div class="sql">
<FontIcon icon="icon sql-file" />
{item.sql}