mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 11:03:57 +00:00
reorder pinned tables #227
This commit is contained in:
@@ -722,4 +722,8 @@
|
|||||||
on:click={() => handleClick()}
|
on:click={() => handleClick()}
|
||||||
on:middleclick={() => handleClick(true)}
|
on:middleclick={() => handleClick(true)}
|
||||||
on:expand
|
on:expand
|
||||||
|
on:dragstart
|
||||||
|
on:dragenter
|
||||||
|
on:dragend
|
||||||
|
on:drop
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,19 +10,43 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function dragExchange(dragged, data, pinned, setPinned, compare) {
|
function dragExchange(dragged, data, pinned, setPinned, compare) {
|
||||||
|
if (!compare(dragged, data)) {
|
||||||
|
const i1 = _.findIndex(pinned, x => compare(x, dragged));
|
||||||
|
const i2 = _.findIndex(pinned, x => compare(x, data));
|
||||||
|
const newPinned = [...pinned];
|
||||||
|
const tmp = newPinned[i1];
|
||||||
|
newPinned[i1] = newPinned[i2];
|
||||||
|
newPinned[i2] = tmp;
|
||||||
|
setPinned(newPinned);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _, { values } from 'lodash';
|
||||||
import { draggedPinnedObject, pinnedDatabases } from '../stores';
|
import { draggedPinnedObject, pinnedDatabases, pinnedTables } from '../stores';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if data.objectTypeField}
|
{#if data.objectTypeField}
|
||||||
<DatabaseObjectAppObject {...$$props}
|
<DatabaseObjectAppObject
|
||||||
|
{...$$props}
|
||||||
|
on:dragstart={() => {
|
||||||
|
$draggedPinnedObject = data;
|
||||||
|
}}
|
||||||
|
on:dragenter={e => {
|
||||||
|
dragExchange(
|
||||||
|
$draggedPinnedObject,
|
||||||
|
data,
|
||||||
|
$pinnedTables,
|
||||||
|
value => ($pinnedTables = value),
|
||||||
|
(a, b) => a?.pureName == b?.pureName && a?.schemaName == b?.schemaName
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
on:dragend={() => {
|
||||||
|
$draggedPinnedObject = null;
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<DatabaseAppObject
|
<DatabaseAppObject
|
||||||
@@ -31,17 +55,13 @@
|
|||||||
$draggedPinnedObject = data;
|
$draggedPinnedObject = data;
|
||||||
}}
|
}}
|
||||||
on:dragenter={e => {
|
on:dragenter={e => {
|
||||||
const dragged = $draggedPinnedObject;
|
dragExchange(
|
||||||
if (dragged?.connection?._id != data?.connection?._id || dragged?.name != data?.name) {
|
$draggedPinnedObject,
|
||||||
const dbs = $pinnedDatabases;
|
data,
|
||||||
const i1 = _.findIndex(dbs, x => x?.name == dragged?.name && x?.connection?._id == dragged?.connection?._id);
|
$pinnedDatabases,
|
||||||
const i2 = _.findIndex(dbs, x => x?.name == data?.name && x?.connection?._id == data?.connection?._id);
|
value => ($pinnedDatabases = value),
|
||||||
const newDbs = [...dbs];
|
(a, b) => a?.name == b?.name && a?.connection?._id == b?.connection?._id
|
||||||
const tmp = newDbs[i1];
|
);
|
||||||
newDbs[i1] = newDbs[i2];
|
|
||||||
newDbs[i2] = tmp;
|
|
||||||
$pinnedDatabases = newDbs;
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
on:dragend={() => {
|
on:dragend={() => {
|
||||||
$draggedPinnedObject = null;
|
$draggedPinnedObject = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user