mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 14:03:57 +00:00
perspective ctx menu
This commit is contained in:
@@ -4,9 +4,10 @@
|
|||||||
export let value;
|
export let value;
|
||||||
export let rowSpan;
|
export let rowSpan;
|
||||||
export let rowData;
|
export let rowData;
|
||||||
|
export let columnIndex;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<td rowspan={rowSpan}>
|
<td rowspan={rowSpan} data-column={columnIndex}>
|
||||||
{#if value !== undefined}
|
{#if value !== undefined}
|
||||||
<CellValue {rowData} {value} />
|
<CellValue {rowData} {value} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
<th
|
<th
|
||||||
rowspan={column.rowSpan}
|
rowspan={column.rowSpan}
|
||||||
class="columnHeader"
|
class="columnHeader"
|
||||||
|
data-column={column.columnIndex}
|
||||||
on:mouseenter={() => (mouseIn = true)}
|
on:mouseenter={() => (mouseIn = true)}
|
||||||
on:mouseleave={() => (mouseIn = false)}
|
on:mouseleave={() => (mouseIn = false)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
import contextMenu from '../utility/contextMenu';
|
import contextMenu from '../utility/contextMenu';
|
||||||
import CustomJoinModal from './CustomJoinModal.svelte';
|
import CustomJoinModal from './CustomJoinModal.svelte';
|
||||||
|
import { getPerspectiveNodeMenu } from './perspectiveMenu';
|
||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
@@ -16,41 +17,14 @@
|
|||||||
export let setConfig: ChangePerspectiveConfigFunc;
|
export let setConfig: ChangePerspectiveConfigFunc;
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
const customJoin = node.customJoinConfig;
|
return getPerspectiveNodeMenu({
|
||||||
const filterInfo = node.filterInfo;
|
conid,
|
||||||
return [
|
database,
|
||||||
filterInfo && {
|
node,
|
||||||
text: 'Add to filter',
|
root,
|
||||||
onClick: () =>
|
config,
|
||||||
setConfig(cfg => ({
|
setConfig,
|
||||||
...cfg,
|
});
|
||||||
filterInfos: {
|
|
||||||
...cfg.filterInfos,
|
|
||||||
[node.uniqueName]: filterInfo,
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
customJoin && {
|
|
||||||
text: 'Remove custom join',
|
|
||||||
onClick: () =>
|
|
||||||
setConfig(cfg => ({
|
|
||||||
...cfg,
|
|
||||||
customJoins: (cfg.customJoins || []).filter(x => x.joinid != customJoin.joinid),
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
customJoin && {
|
|
||||||
text: 'Edit custom join',
|
|
||||||
onClick: () =>
|
|
||||||
showModal(CustomJoinModal, {
|
|
||||||
config,
|
|
||||||
setConfig,
|
|
||||||
conid,
|
|
||||||
database,
|
|
||||||
root,
|
|
||||||
editValue: customJoin,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
import PerspectiveLoadingIndicator from './PerspectiveLoadingIndicator.svelte';
|
import PerspectiveLoadingIndicator from './PerspectiveLoadingIndicator.svelte';
|
||||||
import PerspectiveHeaderControl from './PerspectiveHeaderControl.svelte';
|
import PerspectiveHeaderControl from './PerspectiveHeaderControl.svelte';
|
||||||
import createRef from '../utility/createRef';
|
import createRef from '../utility/createRef';
|
||||||
|
import { getPerspectiveNodeMenu } from './perspectiveMenu';
|
||||||
|
|
||||||
const dbg = debug('dbgate:PerspectivaTable');
|
const dbg = debug('dbgate:PerspectivaTable');
|
||||||
export const activator = createActivator('PerspectiveTable', true);
|
export const activator = createActivator('PerspectiveTable', true);
|
||||||
@@ -37,6 +38,8 @@
|
|||||||
export let loadedCounts;
|
export let loadedCounts;
|
||||||
export let config;
|
export let config;
|
||||||
export let setConfig;
|
export let setConfig;
|
||||||
|
export let conid;
|
||||||
|
export let database;
|
||||||
|
|
||||||
let dataRows;
|
let dataRows;
|
||||||
let domWrapper;
|
let domWrapper;
|
||||||
@@ -151,18 +154,34 @@
|
|||||||
checkLoadAdditionalData();
|
checkLoadAdditionalData();
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMenu() {
|
function buildMenu({ targetElement }) {
|
||||||
return [
|
const res = [];
|
||||||
{
|
const td = targetElement.closest('td') || targetElement.closest('th');
|
||||||
command: 'perspective.refresh',
|
|
||||||
},
|
if (td) {
|
||||||
{
|
const columnIndex = td.getAttribute('data-column');
|
||||||
command: 'perspective.openJson',
|
const column = display?.columns?.[columnIndex];
|
||||||
},
|
if (column)
|
||||||
{
|
res.push(
|
||||||
command: 'perspective.customJoin',
|
getPerspectiveNodeMenu({
|
||||||
},
|
config,
|
||||||
];
|
conid,
|
||||||
|
database,
|
||||||
|
node: column.dataNode,
|
||||||
|
root,
|
||||||
|
setConfig,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.push([
|
||||||
|
{ divider: true },
|
||||||
|
{ command: 'perspective.refresh' },
|
||||||
|
{ command: 'perspective.openJson' },
|
||||||
|
{ command: 'perspective.customJoin' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLastVisibleRowIndex() {
|
function getLastVisibleRowIndex() {
|
||||||
@@ -301,6 +320,7 @@
|
|||||||
{#each display.columns as column}
|
{#each display.columns as column}
|
||||||
{#if !row.rowCellSkips[column.columnIndex]}
|
{#if !row.rowCellSkips[column.columnIndex]}
|
||||||
<PerspectiveCell
|
<PerspectiveCell
|
||||||
|
columnIndex={column.columnIndex}
|
||||||
value={row.rowData[column.columnIndex]}
|
value={row.rowData[column.columnIndex]}
|
||||||
rowSpan={row.rowSpans[column.columnIndex]}
|
rowSpan={row.rowSpans[column.columnIndex]}
|
||||||
rowData={row.rowData}
|
rowData={row.rowData}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<svelte:fragment slot="2">
|
<svelte:fragment slot="2">
|
||||||
<PerspectiveTable {root} {loadedCounts} {config} {setConfig} />
|
<PerspectiveTable {root} {loadedCounts} {config} {setConfig} {conid} {database} />
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</HorizontalSplitter>
|
</HorizontalSplitter>
|
||||||
|
|
||||||
|
|||||||
51
packages/web/src/perspectives/perspectiveMenu.ts
Normal file
51
packages/web/src/perspectives/perspectiveMenu.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { ChangePerspectiveConfigFunc, PerspectiveConfig, PerspectiveTreeNode } from 'dbgate-datalib';
|
||||||
|
import { showModal } from '../modals/modalTools';
|
||||||
|
import CustomJoinModal from './CustomJoinModal.svelte';
|
||||||
|
|
||||||
|
interface PerspectiveNodeMenuProps {
|
||||||
|
node: PerspectiveTreeNode;
|
||||||
|
conid: string;
|
||||||
|
database: string;
|
||||||
|
root: PerspectiveTreeNode;
|
||||||
|
config: PerspectiveConfig;
|
||||||
|
setConfig: ChangePerspectiveConfigFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPerspectiveNodeMenu(props: PerspectiveNodeMenuProps) {
|
||||||
|
const { node, conid, database, root, config, setConfig } = props;
|
||||||
|
const customJoin = node.customJoinConfig;
|
||||||
|
const filterInfo = node.filterInfo;
|
||||||
|
return [
|
||||||
|
filterInfo && {
|
||||||
|
text: 'Add to filter',
|
||||||
|
onClick: () =>
|
||||||
|
setConfig(cfg => ({
|
||||||
|
...cfg,
|
||||||
|
filterInfos: {
|
||||||
|
...cfg.filterInfos,
|
||||||
|
[node.uniqueName]: filterInfo,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
customJoin && {
|
||||||
|
text: 'Remove custom join',
|
||||||
|
onClick: () =>
|
||||||
|
setConfig(cfg => ({
|
||||||
|
...cfg,
|
||||||
|
customJoins: (cfg.customJoins || []).filter(x => x.joinid != customJoin.joinid),
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
customJoin && {
|
||||||
|
text: 'Edit custom join',
|
||||||
|
onClick: () =>
|
||||||
|
showModal(CustomJoinModal, {
|
||||||
|
config,
|
||||||
|
setConfig,
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
root,
|
||||||
|
editValue: customJoin,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user