feat(plugins): open plugin workbench from context menu
This commit is contained in:
1 parent
05a72de255
commit
4c1eaa6b16
10 files changed
+494
-69
No files matched your search
@@ -72,8 +72,9 @@ import { useSavedSqlStore } from "@/stores/savedSqlStore";
|
||||
import { savedSqlErrorMessage } from "@/lib/savedSql/savedSqlErrors";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin";
|
||||
import { buildPluginTableContextMenuInvocation } from "@/lib/plugins/pluginContext";
|
||||
import type { InstalledPlugin } from "@/types/database";
|
||||
import { activatePluginContextMenuItem, buildPluginConnectionContextMenuInvocation, buildPluginTableContextMenuInvocation } from "@/lib/plugins/pluginContext";
|
||||
import type { PluginContextMenuInvocation } from "@/lib/plugins/pluginContext";
|
||||
import type { InstalledPlugin, PluginContextMenuContribution } from "@/types/database";
|
||||
import { useDatabaseOptions } from "@/composables/useDatabaseOptions";
|
||||
import type { ColumnInfo, ConnectionConfig, DatabaseType, TreeNode, TreeNodeType } from "@/types/database";
|
||||
import * as api from "@/lib/backend/api";
|
||||
@@ -6732,6 +6733,15 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
return items;
|
||||
}
|
||||
|
||||
function activateSidebarPluginContextMenuItem(pluginId: string, contribution: PluginContextMenuContribution, invocation: PluginContextMenuInvocation) {
|
||||
void activatePluginContextMenuItem(pluginId, contribution, invocation, {
|
||||
findWorkbench: (ownerPluginId, workbenchId) => !!sidebarPluginRegistry.value.findWorkbench(ownerPluginId, workbenchId),
|
||||
openWorkbench: (ownerPluginId, workbenchId, options) => queryStore.openPluginWorkbench(ownerPluginId, workbenchId, options),
|
||||
invokePlugin: (ownerPluginId, method, params) => api.invokePlugin(ownerPluginId, method, params),
|
||||
toast,
|
||||
});
|
||||
}
|
||||
|
||||
/** Plugin-contributed native menu entries for saved connections. */
|
||||
function appendPluginConnectionMenuItems(items: ContextMenuItem[], node: TreeNode) {
|
||||
if (node.type !== "connection") return;
|
||||
@@ -6739,26 +6749,19 @@ function appendPluginConnectionMenuItems(items: ContextMenuItem[], node: TreeNod
|
||||
if (pluginItems.length === 0) return;
|
||||
const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;
|
||||
if (!config) return;
|
||||
items.push({ label: "", separator: true });
|
||||
for (const { plugin, contribution } of pluginItems) {
|
||||
items.push({
|
||||
label: contribution.label,
|
||||
icon: PlugZap,
|
||||
action: () => {
|
||||
api
|
||||
.invokePlugin(plugin.manifest.id, `contextMenu/${contribution.id}`, {
|
||||
connection: { id: config.id, dbType: config.db_type, name: config.name, database: config.database || "" },
|
||||
})
|
||||
.then((result) => {
|
||||
const message = (result as { message?: unknown } | null | undefined)?.message;
|
||||
if (typeof message === "string" && message.trim()) toast(message, 4000);
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
toast(String((error as Error)?.message || error), 5000);
|
||||
});
|
||||
const menuItems = pluginItems.flatMap(({ plugin, contribution }) => {
|
||||
const invocation = buildPluginConnectionContextMenuInvocation(contribution.id, config);
|
||||
if (!invocation) return [];
|
||||
return [
|
||||
{
|
||||
label: contribution.label,
|
||||
icon: PlugZap,
|
||||
action: () => activateSidebarPluginContextMenuItem(plugin.manifest.id, contribution, invocation),
|
||||
},
|
||||
});
|
||||
}
|
||||
];
|
||||
});
|
||||
if (menuItems.length === 0) return;
|
||||
items.push({ label: "", separator: true }, ...menuItems);
|
||||
}
|
||||
|
||||
/** Plugin-contributed native menu entries for canonical table nodes. */
|
||||
@@ -6774,17 +6777,7 @@ function appendPluginTableMenuItems(items: ContextMenuItem[], node: TreeNode) {
|
||||
tableItems.push({
|
||||
label: contribution.label,
|
||||
icon: PlugZap,
|
||||
action: () => {
|
||||
api
|
||||
.invokePlugin(plugin.manifest.id, invocation.method, invocation.params)
|
||||
.then((result) => {
|
||||
const message = (result as { message?: unknown } | null | undefined)?.message;
|
||||
if (typeof message === "string" && message.trim()) toast(message, 4000);
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
toast(String((error as Error)?.message || error), 5000);
|
||||
});
|
||||
},
|
||||
action: () => activateSidebarPluginContextMenuItem(plugin.manifest.id, contribution, invocation),
|
||||
});
|
||||
}
|
||||
if (tableItems.length === 0) return;
|
||||
|
||||
Reference in new issue
Block a user