mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 17:06:01 +00:00
search settings
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
export let showPinnedInsteadOfUnpin = false;
|
||||
export let indentLevel = 0;
|
||||
export let disableBoldScroll = false;
|
||||
export let filter = null;
|
||||
|
||||
$: isChecked =
|
||||
checkedObjectsStore && $checkedObjectsStore.find(x => module?.extractKey(data) == module?.extractKey(x));
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
$: filtered = !groupFunc
|
||||
? list.filter(data => {
|
||||
const matcher = module.createMatcher && module.createMatcher(data);
|
||||
const matcher = module.createMatcher && module.createMatcher(data, passProps?.searchSettings);
|
||||
if (matcher && !matcher(filter)) return false;
|
||||
return true;
|
||||
})
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
$: childrenMatched = !groupFunc
|
||||
? list.filter(data => {
|
||||
const matcher = module.createChildMatcher && module.createChildMatcher(data);
|
||||
const matcher = module.createChildMatcher && module.createChildMatcher(data, passProps?.searchSettings);
|
||||
if (matcher && !matcher(filter)) return false;
|
||||
return true;
|
||||
})
|
||||
@@ -62,7 +62,7 @@
|
||||
$: listGrouped = groupFunc
|
||||
? _.compact(
|
||||
(list || []).map(data => {
|
||||
const matcher = module.createMatcher && module.createMatcher(data);
|
||||
const matcher = module.createMatcher && module.createMatcher(data, passProps?.searchSettings);
|
||||
const isMatched = matcher && !matcher(filter) ? false : true;
|
||||
const group = groupFunc(data);
|
||||
return { group, data, isMatched };
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
{module}
|
||||
{disableContextMenu}
|
||||
{passProps}
|
||||
{filter}
|
||||
/>
|
||||
|
||||
{#if (isExpanded || isExpandedBySearch) && subItemsComponent}
|
||||
|
||||
@@ -3,14 +3,30 @@
|
||||
|
||||
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
||||
export const createMatcher =
|
||||
({ schemaName, pureName, columns }) =>
|
||||
filter =>
|
||||
filterName(
|
||||
filter,
|
||||
pureName,
|
||||
schemaName,
|
||||
...(columns?.map(({ columnName }) => ({ childName: columnName })) || [])
|
||||
);
|
||||
(
|
||||
{ schemaName, pureName, objectComment, tableEngine, columns, objectTypeField, createSql },
|
||||
cfg = DEFAULT_SEARCH_SETTINGS
|
||||
) =>
|
||||
filter => {
|
||||
const filterArgs = [];
|
||||
if (cfg.schemaName) filterArgs.push(schemaName);
|
||||
if (objectTypeField == 'tables') {
|
||||
if (cfg.tableName) filterArgs.push(pureName);
|
||||
if (cfg.tableComment) filterArgs.push(objectComment);
|
||||
if (cfg.tableEngine) filterArgs.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);
|
||||
}
|
||||
} else {
|
||||
if (cfg.sqlObjectName) filterArgs.push(pureName);
|
||||
if (cfg.sqlObjectText) filterArgs.push(createSql);
|
||||
}
|
||||
|
||||
return filterName(filter, ...filterArgs);
|
||||
};
|
||||
export const createTitle = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
||||
|
||||
export const databaseObjectIcons = {
|
||||
@@ -877,9 +893,11 @@
|
||||
import AppObjectCore from './AppObjectCore.svelte';
|
||||
import {
|
||||
currentDatabase,
|
||||
DEFAULT_SEARCH_SETTINGS,
|
||||
extensions,
|
||||
getActiveTab,
|
||||
getCurrentSettings,
|
||||
getDatabaseObjectAppObjectSearchSettings,
|
||||
getExtensions,
|
||||
getLastUsedDefaultActions,
|
||||
lastUsedDefaultActions,
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
let submenuItem;
|
||||
let submenuOffset;
|
||||
|
||||
let switchIndex = 0;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
let closeHandlers = [];
|
||||
|
||||
@@ -80,6 +82,14 @@
|
||||
submenuOffset = hoverOffset;
|
||||
return;
|
||||
}
|
||||
if (item.switchStore) {
|
||||
item.switchStore.update(x => ({
|
||||
...x,
|
||||
[item.switchValue]: !x[item.switchValue],
|
||||
}));
|
||||
switchIndex++;
|
||||
return;
|
||||
}
|
||||
dispatchClose();
|
||||
if (onCloseParent) onCloseParent();
|
||||
if (item.onClick) item.onClick();
|
||||
@@ -131,7 +141,18 @@
|
||||
}}
|
||||
>
|
||||
<a on:click={e => handleClick(e, item)} class:disabled={item.disabled} class:bold={item.isBold}>
|
||||
{item.text || item.label}
|
||||
<span>
|
||||
{#if item.switchStoreGetter}
|
||||
{#key switchIndex}
|
||||
{#if item.switchStoreGetter()[item.switchValue]}
|
||||
<FontIcon icon="icon checkbox-marked" padRight />
|
||||
{:else}
|
||||
<FontIcon icon="icon checkbox-blank" padRight />
|
||||
{/if}
|
||||
{/key}
|
||||
{/if}
|
||||
{item.text || item.label}
|
||||
</span>
|
||||
{#if item.keyText}
|
||||
<span class="keyText">{formatKeyText(item.keyText)}</span>
|
||||
{/if}
|
||||
@@ -179,6 +200,7 @@
|
||||
white-space: nowrap;
|
||||
overflow-y: auto;
|
||||
max-height: calc(100% - 20px);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.keyText {
|
||||
|
||||
@@ -161,6 +161,25 @@ export const lastUsedDefaultActions = writableWithStorage({}, 'lastUsedDefaultAc
|
||||
export const selectedDatabaseObjectAppObject = writable(null);
|
||||
export const focusedConnectionOrDatabase = writable<{ conid: string; database?: string; connection: any }>(null);
|
||||
|
||||
export const DEFAULT_SEARCH_SETTINGS = {
|
||||
collectionName: true,
|
||||
schemaName: false,
|
||||
tableName: true,
|
||||
viewName: true,
|
||||
columnName: true,
|
||||
columnDataType: true,
|
||||
tableComment: true,
|
||||
columnComment: true,
|
||||
sqlObjectName: true,
|
||||
sqlObjectText: true,
|
||||
tableEngine: false,
|
||||
};
|
||||
|
||||
export const databaseObjectAppObjectSearchSettings = writableWithStorage(
|
||||
DEFAULT_SEARCH_SETTINGS,
|
||||
'databaseObjectAppObjectSearchSettings'
|
||||
);
|
||||
|
||||
export const currentThemeDefinition = derived([currentTheme, extensions], ([$currentTheme, $extensions]) =>
|
||||
$extensions.themes.find(x => x.themeClassName == $currentTheme)
|
||||
);
|
||||
@@ -358,4 +377,12 @@ let lastUsedDefaultActionsValue = {};
|
||||
lastUsedDefaultActions.subscribe(value => {
|
||||
lastUsedDefaultActionsValue = value;
|
||||
});
|
||||
export const getLastUsedDefaultActions = () => lastUsedDefaultActionsValue;
|
||||
export const getLastUsedDefaultActions = () => lastUsedDefaultActionsValue;
|
||||
|
||||
let databaseObjectAppObjectSearchSettingsValue: typeof DEFAULT_SEARCH_SETTINGS = {
|
||||
...DEFAULT_SEARCH_SETTINGS,
|
||||
};
|
||||
databaseObjectAppObjectSearchSettings.subscribe(value => {
|
||||
databaseObjectAppObjectSearchSettingsValue = value;
|
||||
});
|
||||
export const getDatabaseObjectAppObjectSearchSettings = () => databaseObjectAppObjectSearchSettingsValue;
|
||||
|
||||
@@ -38,8 +38,10 @@
|
||||
import { extractDbNameFromComposite, findEngineDriver } from 'dbgate-tools';
|
||||
import {
|
||||
currentDatabase,
|
||||
databaseObjectAppObjectSearchSettings,
|
||||
extensions,
|
||||
focusedConnectionOrDatabase,
|
||||
getDatabaseObjectAppObjectSearchSettings,
|
||||
getSelectedDatabaseObjectAppObject,
|
||||
selectedDatabaseObjectAppObject,
|
||||
} from '../stores';
|
||||
@@ -124,8 +126,32 @@
|
||||
return res;
|
||||
}
|
||||
|
||||
function createSearchMenu() {
|
||||
const res = [];
|
||||
if (driver?.databaseEngineTypes?.includes('document')) {
|
||||
res.push({ label: 'Collection names' });
|
||||
}
|
||||
if (driver?.databaseEngineTypes?.includes('sql')) {
|
||||
res.push({ label: 'Schema name', switchValue: 'schemaName' });
|
||||
res.push({ label: 'Table name', switchValue: 'tableName' });
|
||||
res.push({ label: 'View name', switchValue: 'viewName' });
|
||||
res.push({ label: 'Column name', switchValue: 'columnName' });
|
||||
res.push({ label: 'Column data type', switchValue: 'columnType' });
|
||||
res.push({ label: 'Table comment', switchValue: 'tableComment' });
|
||||
res.push({ label: 'Column comment', switchValue: 'columnComment' });
|
||||
res.push({ label: 'Procedure/function/trigger name', switchValue: 'sqlObjectName' });
|
||||
res.push({ label: 'Procedure/function/trigger text', switchValue: 'sqlObjectText' });
|
||||
res.push({ label: 'Table engine', switchValue: 'tableEngine' });
|
||||
}
|
||||
return res.map(item => ({
|
||||
...item,
|
||||
switchStore: databaseObjectAppObjectSearchSettings,
|
||||
switchStoreGetter: getDatabaseObjectAppObjectSearchSettings,
|
||||
}));
|
||||
}
|
||||
|
||||
$: flatFilteredList = objectList.filter(data => {
|
||||
const matcher = databaseObjectAppObject.createMatcher(data);
|
||||
const matcher = databaseObjectAppObject.createMatcher(data, $databaseObjectAppObjectSearchSettings);
|
||||
if (matcher && !matcher(filter)) return false;
|
||||
return true;
|
||||
});
|
||||
@@ -184,7 +210,7 @@
|
||||
{:else}
|
||||
<SearchBoxWrapper>
|
||||
<SearchInput
|
||||
placeholder="Search in tables, objects, # prefix in columns"
|
||||
placeholder="Search in tables, views, procedures"
|
||||
bind:value={filter}
|
||||
bind:this={domFilter}
|
||||
onFocusFilteredList={() => {
|
||||
@@ -192,7 +218,12 @@
|
||||
}}
|
||||
/>
|
||||
<CloseSearchButton bind:filter />
|
||||
<DropDownButton icon="icon plus-thick" menu={createAddMenu} />
|
||||
{#if filter}
|
||||
<DropDownButton icon="icon filter" menu={createSearchMenu} />
|
||||
{/if}
|
||||
{#if !filter}
|
||||
<DropDownButton icon="icon plus-thick" menu={createAddMenu} />
|
||||
{/if}
|
||||
<InlineButton on:click={handleRefreshDatabase} title="Refresh database connection and object list" square>
|
||||
<FontIcon icon="icon refresh" />
|
||||
</InlineButton>
|
||||
@@ -256,6 +287,7 @@
|
||||
showPinnedInsteadOfUnpin: true,
|
||||
connection: $connection,
|
||||
hideSchemaName: !!$appliedCurrentSchema,
|
||||
searchSettings: $databaseObjectAppObjectSearchSettings,
|
||||
}}
|
||||
getIsExpanded={data =>
|
||||
expandedObjects.includes(`${data.objectTypeField}||${data.schemaName}||${data.pureName}`)}
|
||||
|
||||
Reference in New Issue
Block a user