mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 18:45:59 +00:00
focused DB UX
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import {
|
import {
|
||||||
currentDatabase,
|
currentDatabase,
|
||||||
|
focusedConnectionOrDatabase,
|
||||||
getActiveTab,
|
getActiveTab,
|
||||||
getCurrentDatabase,
|
getCurrentDatabase,
|
||||||
getLockedDatabaseMode,
|
getLockedDatabaseMode,
|
||||||
@@ -78,6 +79,16 @@ export async function handleAfterTabClick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentDatabase.subscribe(currentDb => {
|
currentDatabase.subscribe(currentDb => {
|
||||||
|
if (currentDb) {
|
||||||
|
focusedConnectionOrDatabase.set({
|
||||||
|
conid: currentDb.connection?._id,
|
||||||
|
database: currentDb.name,
|
||||||
|
connection: currentDb.connection,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
focusedConnectionOrDatabase.set(null);
|
||||||
|
}
|
||||||
|
|
||||||
if (!getLockedDatabaseMode()) return;
|
if (!getLockedDatabaseMode()) return;
|
||||||
if (!currentDb && !getAppLoaded()) return;
|
if (!currentDb && !getAppLoaded()) return;
|
||||||
openedTabs.update(tabs => {
|
openedTabs.update(tabs => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import keycodes from '../utility/keycodes';
|
import keycodes from '../utility/keycodes';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { sleep } from '../utility/common';
|
||||||
|
|
||||||
export let list;
|
export let list;
|
||||||
export let selectedObjectStore;
|
export let selectedObjectStore;
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
|
|
||||||
export let onScrollTop = null;
|
export let onScrollTop = null;
|
||||||
export let onFocusFilterBox = null;
|
export let onFocusFilterBox = null;
|
||||||
|
export let getDefaultFocusedItem = null;
|
||||||
|
|
||||||
let isListFocused = false;
|
let isListFocused = false;
|
||||||
let domDiv = null;
|
let domDiv = null;
|
||||||
@@ -106,12 +108,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFocus() {
|
async function handleFocus() {
|
||||||
isListFocused = true;
|
isListFocused = true;
|
||||||
|
// await tick();
|
||||||
|
await sleep(100);
|
||||||
|
// console.log('ON FOCUS AFTER SLEEP');
|
||||||
const listInstance = _.isFunction(list) ? list() : list;
|
const listInstance = _.isFunction(list) ? list() : list;
|
||||||
const selected = getSelectedObject();
|
const selected = getSelectedObject();
|
||||||
const index = _.findIndex(listInstance, x => selectedObjectMatcher(x, selected));
|
const index = _.findIndex(listInstance, x => selectedObjectMatcher(x, selected));
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
|
const focused = getDefaultFocusedItem?.();
|
||||||
|
if (focused) {
|
||||||
|
const index2 = _.findIndex(listInstance, x => selectedObjectMatcher(x, focused));
|
||||||
|
if (index2 >= 0) {
|
||||||
|
selectedObjectStore.set(focused);
|
||||||
|
handleObjectClick?.(focused, { tabPreviewMode: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
focusFirst();
|
focusFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
collapsedConnectionGroupNames,
|
collapsedConnectionGroupNames,
|
||||||
focusedConnectionOrDatabase,
|
focusedConnectionOrDatabase,
|
||||||
getFocusedConnectionOrDatabase,
|
getFocusedConnectionOrDatabase,
|
||||||
|
currentDatabase,
|
||||||
} from '../stores';
|
} from '../stores';
|
||||||
import runCommand from '../commands/runCommand';
|
import runCommand from '../commands/runCommand';
|
||||||
import { filterName, getConnectionLabel } from 'dbgate-tools';
|
import { filterName, getConnectionLabel } from 'dbgate-tools';
|
||||||
@@ -200,6 +201,14 @@
|
|||||||
selectedObjectStore={focusedConnectionOrDatabase}
|
selectedObjectStore={focusedConnectionOrDatabase}
|
||||||
getSelectedObject={getFocusedConnectionOrDatabase}
|
getSelectedObject={getFocusedConnectionOrDatabase}
|
||||||
selectedObjectMatcher={(o1, o2) => o1?.conid == o2?.conid && o1?.database == o2?.database}
|
selectedObjectMatcher={(o1, o2) => o1?.conid == o2?.conid && o1?.database == o2?.database}
|
||||||
|
getDefaultFocusedItem={() =>
|
||||||
|
$currentDatabase
|
||||||
|
? {
|
||||||
|
conid: $currentDatabase?.connection?._id,
|
||||||
|
database: $currentDatabase?.name,
|
||||||
|
connection: $currentDatabase?.connection,
|
||||||
|
}
|
||||||
|
: null}
|
||||||
onScrollTop={() => {
|
onScrollTop={() => {
|
||||||
domContainer?.scrollTop();
|
domContainer?.scrollTop();
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -212,6 +212,17 @@
|
|||||||
name: $focusedConnectionOrDatabase?.database,
|
name: $focusedConnectionOrDatabase?.database,
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
|
<FormStyledButton
|
||||||
|
value={`Show ${database}`}
|
||||||
|
skipWidth
|
||||||
|
on:click={() => {
|
||||||
|
$focusedConnectionOrDatabase = {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
connection: $connection,
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user