villebro commented on code in PR #38346:
URL: https://github.com/apache/superset/pull/38346#discussion_r2874813623
##########
docs/developer_docs/extensions/contribution-types.md:
##########
@@ -28,100 +28,83 @@ To facilitate the development of extensions, we define a
set of well-defined con
## Frontend
-Frontend contribution types allow extensions to extend Superset's user
interface with new views, commands, and menu items.
+Frontend contribution types allow extensions to extend Superset's user
interface with new views, commands, and menu items. Frontend contributions are
registered directly in code from your extension's `index.tsx` entry point —
they do not need to be declared in `extension.json`.
### Views
-Extensions can add new views or panels to the host application, such as custom
SQL Lab panels, dashboards, or other UI components. Each view is registered
with a unique ID and can be activated or deactivated as needed. Contribution
areas are uniquely identified (e.g., `sqllab.panels` for SQL Lab panels),
enabling seamless integration into specific parts of the application.
+Extensions can add new views or panels to the host application, such as custom
SQL Lab panels, dashboards, or other UI components. Contribution areas are
uniquely identified (e.g., `sqllab.panels` for SQL Lab panels), enabling
seamless integration into specific parts of the application.
-```json
-"frontend": {
- "contributions": {
- "views": {
- "sqllab": {
- "panels": [
- {
- "id": "my_extension.main",
- "name": "My Panel Name"
- }
- ]
- }
- }
- }
-}
+```tsx
+import React from 'react';
+import { views } from '@apache-superset/core';
+import MyPanel from './MyPanel';
+
+views.registerView(
+ { id: 'my-extension.main', name: 'My Panel Name' },
+ 'sqllab.panels',
+ () => <MyPanel />,
+);
```
### Commands
-Extensions can define custom commands that can be executed within the host
application, such as context-aware actions or menu options. Each command can
specify properties like a unique command identifier, an icon, a title, and a
description. These commands can be invoked by users through menus, keyboard
shortcuts, or other UI elements, enabling extensions to add rich, interactive
functionality to Superset.
-
-```json
-"frontend": {
- "contributions": {
- "commands": [
- {
- "command": "my_extension.copy_query",
- "icon": "CopyOutlined",
- "title": "Copy Query",
- "description": "Copy the current query to clipboard"
- }
- ]
- }
-}
+Extensions can define custom commands that can be executed within the host
application, such as context-aware actions or menu options. Each command
specifies a unique identifier, a title, an optional icon, and a description.
Commands can be invoked by users through menus, keyboard shortcuts, or other UI
elements.
+
+```typescript
+import { commands } from '@apache-superset/core';
+
+commands.registerCommand(
+ {
+ id: 'my-extension.copy-query',
+ title: 'Copy Query',
+ icon: 'CopyOutlined',
+ description: 'Copy the current query to clipboard',
+ },
+ () => {
+ // Command implementation
+ },
+);
```
### Menus
-Extensions can contribute new menu items or context menus to the host
application, providing users with additional actions and options. Each menu
item can specify properties such as the target view, the command to execute,
its placement (primary, secondary, or context), and conditions for when it
should be displayed. Menu contribution areas are uniquely identified (e.g.,
`sqllab.editor` for the SQL Lab editor), allowing extensions to seamlessly
integrate their functionality into specific menus and workflows within Superset.
+Extensions can contribute new menu items or context menus to the host
application, providing users with additional actions and options. Each menu
item specifies the target area, the command to execute, and its placement
(primary, secondary, or context). Menu contribution areas are uniquely
identified (e.g., `sqllab.editor` for the SQL Lab editor).
-```json
-"frontend": {
- "contributions": {
- "menus": {
- "sqllab": {
- "editor": {
- "primary": [
- {
- "view": "builtin.editor",
- "command": "my_extension.copy_query"
- }
- ],
- "secondary": [
- {
- "view": "builtin.editor",
- "command": "my_extension.prettify"
- }
- ],
- "context": [
- {
- "view": "builtin.editor",
- "command": "my_extension.clear"
- }
- ]
- }
- }
- }
- }
-}
+```typescript
+import { menus } from '@apache-superset/core';
+
+menus.addMenuItem('sqllab.editor', {
+ placement: 'primary',
+ command: 'my-extension.copy-query',
+});
+
+menus.addMenuItem('sqllab.editor', {
+ placement: 'secondary',
+ command: 'my-extension.prettify',
+});
+
+menus.addMenuItem('sqllab.editor', {
+ placement: 'context',
+ command: 'my-extension.clear',
+});
```
### Editors
-Extensions can replace Superset's default text editors with custom
implementations. This enables enhanced editing experiences using alternative
editor frameworks like Monaco, CodeMirror, or custom solutions. When an
extension registers an editor for a language, it replaces the default Ace
editor in all locations that use that language (SQL Lab, Dashboard Properties,
CSS editors, etc.).
+Extensions can replace Superset's default text editors with custom
implementations. This enables enhanced editing experiences using alternative
editor frameworks like Monaco, CodeMirror, or custom solutions. When an
extension registers an editor for a language, it replaces the default editor in
all locations that use that language (SQL Lab, Dashboard Properties, CSS
editors, etc.).
-```json
-"frontend": {
- "contributions": {
- "editors": [
- {
- "id": "my_extension.monaco_sql",
- "name": "Monaco SQL Editor",
- "languages": ["sql"],
- "description": "Monaco-based SQL editor with IntelliSense"
- }
- ]
- }
-}
+```typescript
+import { editors } from '@apache-superset/core';
+import MonacoSQLEditor from './MonacoSQLEditor';
+
+editors.registerEditor(
+ {
+ id: 'my-extension.monaco-sql',
+ name: 'Monaco SQL Editor',
+ languages: ['sql'],
+ },
Review Comment:
Are we missing description here?
```suggestion
{
id: 'my-extension.monaco-sql',
name: 'Monaco SQL Editor',
languages: ['sql'],
description: 'Monaco-based SQL editor with IntelliSense',
},
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]