mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 13:06:01 +00:00
filter name optimalization
This commit is contained in:
@@ -34,13 +34,31 @@
|
||||
let expandLimited = false;
|
||||
|
||||
$: matcher = module.createMatcher && module.createMatcher(filter, passProps?.searchSettings);
|
||||
$: childMatcher = module.createChildMatcher && module.createChildMatcher(filter, passProps?.searchSettings);
|
||||
|
||||
$: dataLabeled = _.compact(
|
||||
(list || []).map(data => {
|
||||
const isMatched = !matcher || matcher(data);
|
||||
const isChildMatched =
|
||||
module.disableShowChildrenWithParentMatch && isMatched ? false : !childMatcher || childMatcher(data);
|
||||
const matchResult = matcher ? matcher(data) : true;
|
||||
|
||||
let isMatched = true;
|
||||
let isChildMatched = true;
|
||||
|
||||
if (matchResult == false) {
|
||||
isMatched = false;
|
||||
isChildMatched = false;
|
||||
} else if (matchResult == 'child') {
|
||||
isMatched = true;
|
||||
isChildMatched = true;
|
||||
} else if (matchResult == 'main') {
|
||||
isMatched = true;
|
||||
isChildMatched = false;
|
||||
} else if (matchResult == 'none') {
|
||||
isMatched = false;
|
||||
isChildMatched = false;
|
||||
} else if (matchResult == 'both') {
|
||||
isMatched = true;
|
||||
isChildMatched = !module.disableShowChildrenWithParentMatch;
|
||||
}
|
||||
|
||||
const group = groupFunc ? groupFunc(data) : undefined;
|
||||
return { group, data, isMatched, isChildMatched };
|
||||
})
|
||||
|
||||
@@ -3,13 +3,11 @@
|
||||
export const createMatcher = filter => props => {
|
||||
const { _id, displayName, server } = props;
|
||||
const databases = getLocalStorage(`database_list_${_id}`) || [];
|
||||
return filterName(filter, displayName, server, ...databases.map(x => x.name));
|
||||
};
|
||||
export const createChildMatcher = filter => props => {
|
||||
if (!filter) return false;
|
||||
const { _id } = props;
|
||||
const databases = getLocalStorage(`database_list_${_id}`) || [];
|
||||
return filterName(filter, ...databases.map(x => x.name));
|
||||
return filterNameCompoud(
|
||||
filter,
|
||||
[displayName, server],
|
||||
databases.map(x => x.name)
|
||||
);
|
||||
};
|
||||
export function openConnection(connection, disableExpand = false) {
|
||||
if (connection.singleDatabase) {
|
||||
@@ -106,7 +104,7 @@
|
||||
openedConnections,
|
||||
openedSingleDatabaseConnections,
|
||||
} from '../stores';
|
||||
import { filterName } from 'dbgate-tools';
|
||||
import { filterName, filterNameCompoud } from 'dbgate-tools';
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||
|
||||
@@ -5,42 +5,25 @@
|
||||
export const createMatcher =
|
||||
(filter, cfg = DEFAULT_SEARCH_SETTINGS) =>
|
||||
({ schemaName, pureName, objectComment, tableEngine, columns, objectTypeField, createSql }) => {
|
||||
const filterArgs = [];
|
||||
if (cfg.schemaName) filterArgs.push(schemaName);
|
||||
const mainArgs = [];
|
||||
const childArgs = [];
|
||||
if (cfg.schemaName) mainArgs.push(schemaName);
|
||||
if (objectTypeField == 'tables') {
|
||||
if (cfg.tableName) filterArgs.push(pureName);
|
||||
if (cfg.tableComment) filterArgs.push(objectComment);
|
||||
if (cfg.tableEngine) filterArgs.push(tableEngine);
|
||||
if (cfg.tableName) mainArgs.push(pureName);
|
||||
if (cfg.tableComment) mainArgs.push(objectComment);
|
||||
if (cfg.tableEngine) mainArgs.push(tableEngine);
|
||||
|
||||
for (const column of columns || []) {
|
||||
if (cfg.columnName) filterArgs.push(column.columnName);
|
||||
if (cfg.columnComment) filterArgs.push(column.columnComment);
|
||||
if (cfg.columnDataType) filterArgs.push(column.dataType);
|
||||
if (cfg.columnName) childArgs.push(column.columnName);
|
||||
if (cfg.columnComment) childArgs.push(column.columnComment);
|
||||
if (cfg.columnDataType) childArgs.push(column.dataType);
|
||||
}
|
||||
} else {
|
||||
if (cfg.sqlObjectName) filterArgs.push(pureName);
|
||||
if (cfg.sqlObjectText) filterArgs.push(createSql);
|
||||
if (cfg.sqlObjectName) mainArgs.push(pureName);
|
||||
if (cfg.sqlObjectText) childArgs.push(createSql);
|
||||
}
|
||||
|
||||
const res = filterName(filter, ...filterArgs);
|
||||
return res;
|
||||
};
|
||||
|
||||
export const createChildMatcher =
|
||||
(filter, cfg = DEFAULT_SEARCH_SETTINGS) =>
|
||||
({ columns, objectTypeField, createSql }) => {
|
||||
const filterArgs = [];
|
||||
if (objectTypeField == 'tables') {
|
||||
for (const column of columns || []) {
|
||||
if (cfg.columnName) filterArgs.push(column.columnName);
|
||||
if (cfg.columnComment) filterArgs.push(column.columnComment);
|
||||
if (cfg.columnDataType) filterArgs.push(column.dataType);
|
||||
}
|
||||
} else {
|
||||
if (cfg.sqlObjectText) filterArgs.push(createSql);
|
||||
}
|
||||
|
||||
const res = filterName(filter, ...filterArgs);
|
||||
const res = filterNameCompoud(filter, mainArgs, childArgs);
|
||||
return res;
|
||||
};
|
||||
|
||||
@@ -929,6 +912,7 @@
|
||||
import {
|
||||
extractDbNameFromComposite,
|
||||
filterName,
|
||||
filterNameCompoud,
|
||||
generateDbPairingId,
|
||||
getAlterDatabaseScript,
|
||||
getConnectionLabel,
|
||||
|
||||
@@ -167,7 +167,7 @@ export const DEFAULT_SEARCH_SETTINGS = {
|
||||
tableName: true,
|
||||
viewName: true,
|
||||
columnName: true,
|
||||
columnDataType: true,
|
||||
columnDataType: false,
|
||||
tableComment: true,
|
||||
columnComment: true,
|
||||
sqlObjectName: true,
|
||||
|
||||
Reference in New Issue
Block a user