perspective ctx menu

This commit is contained in:
Jan Prochazka
2022-08-05 19:55:14 +02:00
parent 7dc7af0cdb
commit 25d2c129cd
6 changed files with 96 additions and 49 deletions

View File

@@ -4,9 +4,10 @@
export let value;
export let rowSpan;
export let rowData;
export let columnIndex;
</script>
<td rowspan={rowSpan}>
<td rowspan={rowSpan} data-column={columnIndex}>
{#if value !== undefined}
<CellValue {rowData} {value} />
{/if}

View File

@@ -74,6 +74,7 @@
<th
rowspan={column.rowSpan}
class="columnHeader"
data-column={column.columnIndex}
on:mouseenter={() => (mouseIn = true)}
on:mouseleave={() => (mouseIn = false)}
>

View File

@@ -7,6 +7,7 @@
import { showModal } from '../modals/modalTools';
import contextMenu from '../utility/contextMenu';
import CustomJoinModal from './CustomJoinModal.svelte';
import { getPerspectiveNodeMenu } from './perspectiveMenu';
export let conid;
export let database;
@@ -16,41 +17,14 @@
export let setConfig: ChangePerspectiveConfigFunc;
function createMenu() {
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,
}),
},
];
return getPerspectiveNodeMenu({
conid,
database,
node,
root,
config,
setConfig,
});
}
</script>

View File

@@ -29,6 +29,7 @@
import PerspectiveLoadingIndicator from './PerspectiveLoadingIndicator.svelte';
import PerspectiveHeaderControl from './PerspectiveHeaderControl.svelte';
import createRef from '../utility/createRef';
import { getPerspectiveNodeMenu } from './perspectiveMenu';
const dbg = debug('dbgate:PerspectivaTable');
export const activator = createActivator('PerspectiveTable', true);
@@ -37,6 +38,8 @@
export let loadedCounts;
export let config;
export let setConfig;
export let conid;
export let database;
let dataRows;
let domWrapper;
@@ -151,18 +154,34 @@
checkLoadAdditionalData();
}
function buildMenu() {
return [
{
command: 'perspective.refresh',
},
{
command: 'perspective.openJson',
},
{
command: 'perspective.customJoin',
},
];
function buildMenu({ targetElement }) {
const res = [];
const td = targetElement.closest('td') || targetElement.closest('th');
if (td) {
const columnIndex = td.getAttribute('data-column');
const column = display?.columns?.[columnIndex];
if (column)
res.push(
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() {
@@ -301,6 +320,7 @@
{#each display.columns as column}
{#if !row.rowCellSkips[column.columnIndex]}
<PerspectiveCell
columnIndex={column.columnIndex}
value={row.rowData[column.columnIndex]}
rowSpan={row.rowSpans[column.columnIndex]}
rowData={row.rowData}

View File

@@ -124,7 +124,7 @@
</div>
<svelte:fragment slot="2">
<PerspectiveTable {root} {loadedCounts} {config} {setConfig} />
<PerspectiveTable {root} {loadedCounts} {config} {setConfig} {conid} {database} />
</svelte:fragment>
</HorizontalSplitter>

View 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,
}),
},
];
}