Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions backend/mpt_extension_python_template/routers/plugs/portal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from mpt_extension_sdk.routing import PlugRouter
from mpt_extension_sdk.routing.plugs import NavigationPlug, Plug

from mpt_extension_python_template.routers.plugs.common import add_plug, plug_id, plug_name
from mpt_extension_python_template.routers.plugs.common import plug_id, plug_name

portal_router = PlugRouter()

Expand All @@ -13,6 +13,7 @@ def portal_plugs() -> list[Plug | NavigationPlug]:
id=plug_id("learn-extensions"),
name=plug_name("Learn extensions"),
description="Guides and examples for extensions development.",
icon="help",
socket="portal",
)
return [
Expand All @@ -31,5 +32,12 @@ def portal_plugs() -> list[Plug | NavigationPlug]:
socket=learn_extensions.nested_socket,
href="/static/guide/index.js",
),
add_plug("portal"),
Plug(
id=plug_id("add-portal"),
name=plug_name("Plug here"),
description="Showcase: add your extension plug on this socket.",
socket="portal",
href="/static/add-portal/index.js",
icon="no_existing_icon", # no error; the Portal shows no icon
),
]
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requires-python = ">=3.12,<4"
license = { text = "Apache-2.0 license" }
dependencies = [
"mpt-extension-contrib-order-status==1.0.*",
"mpt-extension-sdk==6.9.*",
"mpt-extension-sdk==6.11.*",
"mpt-tool==6.0.*",
]

Expand Down
7 changes: 7 additions & 0 deletions backend/tests/routers/test_showcase_plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_learn_extensions_container_registered():

assert result["learn-extensions-ext-1111-1111"]["socket"] == "portal"
assert result["learn-extensions-ext-1111-1111"]["href"] is None
assert result["learn-extensions-ext-1111-1111"]["icon"] == "help"


def test_portal_showcase_plugs_registered():
Expand All @@ -41,6 +42,12 @@ def test_portal_showcase_plugs_registered():
assert result["guide-ext-1111-1111"]["href"] == "/static/guide/index.js"


def test_portal_add_plug_keeps_unknown_icon():
result = {plug.id: plug.model_dump() for plug in ext_app.to_meta_config().plugs}

assert result["add-portal-ext-1111-1111"]["icon"] == "no_existing_icon"


def test_add_showcase_plugs_registered():
declared = map(add_plug, ADD_SOCKETS)
expected = {plug.id: (plug.socket, plug.href) for plug in declared}
Expand Down
1,405 changes: 758 additions & 647 deletions backend/uv.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ agreements `add` plug in [`agreements.py`](../backend/mpt_extension_python_templ
| `guide-<extension-id>` — `portal.learn-extensions-<extension-id>` | [`modules/guide/`](../frontend/src/modules/guide/) | Rendering bundled Markdown with `InlineMarkdown` (esbuild `.md` text loader) |
| `add-<socket>-<extension-id>` (one per socket) | [`modules/add-*/`](../frontend/src/modules/) | A "plug here" scaffold shown on every remaining Portal socket, so the full set of sockets is covered |

The `learn-extensions` group sets `icon="help"`, which the Portal shows next to
its menu entry. An icon is the code name of an icon in the
[SoftwareOne design system icon library](https://design.platform.softwareone.com/1233aa9e6/p/27bce1-icons),
not a file under `static/`: the Portal renders no custom icons or image files.
The top-level `add` plug sets `icon="no_existing_icon"` on purpose, to show that
a name missing from the library raises no error and the Portal shows no icon for
it. The other `add` plugs set no icon.

The `add-*` plugs cover many near-identical sockets without duplicating logic:
each is a thin module directory whose `index.tsx` mounts the shared
[`AddPlugShowcase`](../frontend/src/shared/components/AddPlugShowcase.tsx)
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/shared/components/AddPlugShowcase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ jest.mock('@softwareone-platform/sdk-react-ui-v0/divider', () => {

jest.mock('@softwareone-platform/sdk-react-ui-v0/input', () => {
const React = jest.requireActual<typeof import('react')>('react');
return { Input: ({ label }: { label?: string }) => React.createElement('label', null, label) };
return {
Input: ({ label }: { label?: string }) =>
React.createElement('input', { type: 'text', 'aria-label': label, readOnly: true }),
};
});

jest.mock('@softwareone-platform/sdk-react-ui-v0/switcher', () => {
Expand All @@ -53,6 +56,12 @@ describe('AddPlugShowcase', () => {
expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
});

it('renders an optional icon field', () => {
render(<AddPlugShowcase socket="portal" />);

expect(screen.getByRole('textbox', { name: 'Icon' })).toBeInTheDocument();
});

it('renders inside a card on the top-level portal socket', () => {
render(<AddPlugShowcase socket="portal" />);

Expand Down
16 changes: 14 additions & 2 deletions frontend/src/shared/components/AddPlugShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface PlugConfig {
name: string;
description: string;
href: string;
icon: string;
condition: string;
}

Expand All @@ -29,6 +30,7 @@ function toYaml(plug: PlugConfig, socket: string): string {
if (plug.name) lines.push(` name: ${plug.name}`);
if (plug.description) lines.push(` description: ${plug.description}`);
if (plug.href) lines.push(` href: ${plug.href}`);
if (plug.icon) lines.push(` icon: ${plug.icon}`);
if (plug.condition) lines.push(` condition: "${plug.condition}"`);
return lines.join('\n');
}
Expand All @@ -38,6 +40,7 @@ function toJson(plug: PlugConfig, socket: string): string {
if (plug.name) obj.name = plug.name;
if (plug.description) obj.description = plug.description;
if (plug.href) obj.href = plug.href;
if (plug.icon) obj.icon = plug.icon;
if (plug.condition) obj.condition = plug.condition;
return JSON.stringify(obj, null, 2);
}
Expand All @@ -57,6 +60,7 @@ export function AddPlugShowcase({ socket }: { socket: string }) {
name: '',
description: '',
href: '/static/',
icon: '',
condition: '',
});

Expand All @@ -72,8 +76,8 @@ export function AddPlugShowcase({ socket }: { socket: string }) {
Fill in the fields below to generate plug configuration. In this template plugs are declared
in Python via a <code>PlugRouter</code> — but the same fields (<code>id</code>,{' '}
<code>name</code>, <code>description</code>, <code>socket</code>, <code>href</code>,{' '}
<code>condition</code>) map one-to-one, so you can use this as a scratchpad. Then build a JS
bundle at the <code>href</code> path you specified.
<code>icon</code>, <code>condition</code>) map one-to-one, so you can use this as a
scratchpad. Then build a JS bundle at the <code>href</code> path you specified.
</p>

<div className="add-plug__form">
Expand Down Expand Up @@ -107,6 +111,14 @@ export function AddPlugShowcase({ socket }: { socket: string }) {
onChange={update('href')}
description="Relative path to the JS bundle"
/>
<Input
name="icon"
label="Icon"
placeholder="extension"
value={plug.icon}
onChange={update('icon')}
description="Optional design system icon name, not a file"
/>
<Input
name="condition"
label="Condition (RQL)"
Expand Down
Loading