mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 04:16:00 +00:00
toggle dynamic structure
This commit is contained in:
@@ -13,10 +13,23 @@
|
||||
testEnabled: () => getCurrentEditor() != null,
|
||||
onClick: () => getCurrentEditor().save(),
|
||||
});
|
||||
|
||||
registerCommand({
|
||||
id: 'freeTable.toggleDynamicStructure',
|
||||
category: 'Table data',
|
||||
name: 'Toggle dynamic structure',
|
||||
testEnabled: () => getCurrentEditor() != null,
|
||||
onClick: () => getCurrentEditor().toggleDynamicStructure(),
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { createFreeTableModel, FreeTableGridDisplay, runMacro } from 'dbgate-datalib';
|
||||
import {
|
||||
analyseCollectionDisplayColumns,
|
||||
createFreeTableModel,
|
||||
FreeTableGridDisplay,
|
||||
runMacro,
|
||||
} from 'dbgate-datalib';
|
||||
import { setContext } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import registerCommand from '../commands/registerCommand';
|
||||
@@ -86,7 +99,33 @@
|
||||
const collapsedLeftColumnStore = writable(false);
|
||||
setContext('collapsedLeftColumnStore', collapsedLeftColumnStore);
|
||||
|
||||
registerMenu({ command: 'freeTable.save', tag: 'save' });
|
||||
export function toggleDynamicStructure() {
|
||||
let structure = $modelState.value.structure;
|
||||
structure = { ...structure, __isDynamicStructure: !structure.__isDynamicStructure };
|
||||
if (!structure.__isDynamicStructure) {
|
||||
const columns = analyseCollectionDisplayColumns($modelState.value.rows, display);
|
||||
structure = {
|
||||
...structure,
|
||||
columns: columns
|
||||
.filter(col => col.uniquePath.length == 1)
|
||||
.map(col => ({
|
||||
columnName: col.uniqueName,
|
||||
})),
|
||||
};
|
||||
}
|
||||
dispatchModel({
|
||||
type: 'set',
|
||||
value: {
|
||||
...$modelState.value,
|
||||
structure,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
registerMenu(
|
||||
{ command: 'freeTable.save', tag: 'save' },
|
||||
{ command: 'freeTable.toggleDynamicStructure', tag: 'export' }
|
||||
);
|
||||
|
||||
// display is overridden in FreeTableGridCore, this is because of column manager
|
||||
$: display = new FreeTableGridDisplay($modelState.value, $config, config.update, null, null);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import { getContext, setContext } from 'svelte';
|
||||
import invalidateCommands from '../commands/invalidateCommands';
|
||||
import { currentDropDownMenu } from '../stores';
|
||||
import getAsArray from './getAsArray';
|
||||
|
||||
@@ -9,9 +10,12 @@ export function registerMenu(...items) {
|
||||
}
|
||||
|
||||
export default function contextMenu(node, items = []) {
|
||||
const handleContextMenu = e => {
|
||||
const handleContextMenu = async e => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
await invalidateCommands();
|
||||
|
||||
if (items) {
|
||||
const left = e.pageX;
|
||||
const top = e.pageY;
|
||||
|
||||
Reference in New Issue
Block a user