mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 12:03:58 +00:00
search in columns
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
import _compact from 'lodash/compact';
|
import _compact from 'lodash/compact';
|
||||||
|
import _isString from 'lodash/isString';
|
||||||
|
|
||||||
|
export interface FilterNameDefinition {
|
||||||
|
childName: string;
|
||||||
|
}
|
||||||
|
|
||||||
// original C# variant
|
// original C# variant
|
||||||
// public bool Match(string value)
|
// public bool Match(string value)
|
||||||
@@ -54,17 +59,29 @@ function fuzzysearch(needle, haystack) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function filterName(filter: string, ...names: string[]) {
|
export function filterName(filter: string, ...names: (string | FilterNameDefinition)[]) {
|
||||||
if (!filter) return true;
|
if (!filter) return true;
|
||||||
|
|
||||||
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
|
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
|
||||||
const tokens = filter.split(' ').map(x => x.trim());
|
const tokens = filter.split(' ').map(x => x.trim());
|
||||||
|
|
||||||
const namesCompacted = _compact(names);
|
const namesCompacted = _compact(names);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const namesOwn: string[] = namesCompacted.filter(x => _isString(x));
|
||||||
|
// @ts-ignore
|
||||||
|
const namesChild: string[] = namesCompacted.filter(x => x.childName).map(x => x.childName);
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
const tokenUpper = token.toUpperCase();
|
const tokenUpper = token.toUpperCase();
|
||||||
const found = namesCompacted.find(name => fuzzysearch(tokenUpper, name.toUpperCase()));
|
if (tokenUpper.startsWith('#')) {
|
||||||
if (!found) return false;
|
const tokenUpperSub = tokenUpper.substring(1);
|
||||||
|
const found = namesChild.find(name => fuzzysearch(tokenUpperSub, name.toUpperCase()));
|
||||||
|
if (!found) return false;
|
||||||
|
} else {
|
||||||
|
const found = namesOwn.find(name => fuzzysearch(tokenUpper, name.toUpperCase()));
|
||||||
|
if (!found) return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
||||||
export const createMatcher = ({ schemaName, pureName }) => filter => filterName(filter, pureName, schemaName);
|
export const createMatcher = ({ schemaName, pureName, columns }) => filter =>
|
||||||
|
filterName(filter, pureName, schemaName, ...columns?.map(({ columnName }) => ({ childName: columnName })));
|
||||||
export const createTitle = ({ pureName }) => pureName;
|
export const createTitle = ({ pureName }) => pureName;
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@
|
|||||||
</WidgetsInnerContainer>
|
</WidgetsInnerContainer>
|
||||||
{:else}
|
{:else}
|
||||||
<SearchBoxWrapper>
|
<SearchBoxWrapper>
|
||||||
<SearchInput placeholder="Search tables or objects" bind:value={filter} />
|
<SearchInput placeholder="Search in tables, objects, # prefix in columns" bind:value={filter} />
|
||||||
<CloseSearchButton bind:filter />
|
<CloseSearchButton bind:filter />
|
||||||
<DropDownButton icon="icon plus-thick" menu={createAddMenu} />
|
<DropDownButton icon="icon plus-thick" menu={createAddMenu} />
|
||||||
<InlineButton on:click={handleRefreshDatabase} title="Refresh database connection and object list">
|
<InlineButton on:click={handleRefreshDatabase} title="Refresh database connection and object list">
|
||||||
|
|||||||
Reference in New Issue
Block a user