-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: install applications via plugins (#275)
- Loading branch information
1 parent
84ecfe9
commit d0a5f59
Showing
24 changed files
with
275 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"project_name": "My Cool Application", | ||
"__project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}" | ||
} |
28 changes: 28 additions & 0 deletions
28
..._cli/templates/plugins/application/{{ cookiecutter.__project_slug }}/CANVAS_MANIFEST.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"sdk_version": "0.1.4", | ||
"plugin_version": "0.0.1", | ||
"name": "{{ cookiecutter.__project_slug }}", | ||
"description": "Edit the description in CANVAS_MANIFEST.json", | ||
"components": { | ||
"applications": [ | ||
{ | ||
"class": "{{ cookiecutter.__project_slug }}.applications.my_application:MyApplication", | ||
"name": "My Application", | ||
"description": "An Application that does xyz...", | ||
"scope": "global", | ||
"icon": "assets/python-logo.png", | ||
"origins": [] | ||
} | ||
], | ||
"commands": [], | ||
"content": [], | ||
"effects": [], | ||
"views": [] | ||
}, | ||
"secrets": [], | ||
"tags": {}, | ||
"references": [], | ||
"license": "", | ||
"diagram": false, | ||
"readme": "./README.md" | ||
} |
11 changes: 11 additions & 0 deletions
11
...s_cli/templates/plugins/application/{{ cookiecutter.__project_slug }}/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ cookiecutter.__project_slug }} | ||
{% for _ in cookiecutter.__project_slug %}={% endfor %} | ||
|
||
## Description | ||
|
||
A description of this plugin | ||
|
||
### Important Note! | ||
|
||
The CANVAS_MANIFEST.json is used when installing your plugin. Please ensure it | ||
gets updated if you add, remove, or rename protocols. |
Empty file.
12 changes: 12 additions & 0 deletions
12
...ates/plugins/application/{{ cookiecutter.__project_slug }}/applications/my_application.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from canvas_sdk.effects import Effect | ||
from canvas_sdk.effects.launch_modal import LaunchModalEffect | ||
from canvas_sdk.handlers.application import Application | ||
|
||
|
||
class MyApplication(Application): | ||
"""An embeddable application that can be registered to Canvas.""" | ||
|
||
def on_open(self) -> Effect: | ||
"""Handle the on_open event.""" | ||
# Implement this method to handle the application on_open event. | ||
return LaunchModalEffect(url="", target=LaunchModalEffect.TargetType.DEFAULT_MODAL).apply() |
Binary file added
BIN
+20.2 KB
...es/plugins/application/{{ cookiecutter.__project_slug }}/assets/python-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from canvas_generated.messages.effects_pb2 import Effect, EffectType | ||
|
||
__all__ = ("Effect", "EffectType") | ||
from .base import _BaseEffect | ||
|
||
__all__ = ("Effect", "EffectType", "_BaseEffect") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from enum import StrEnum | ||
from typing import Any | ||
|
||
from canvas_sdk.effects import EffectType, _BaseEffect | ||
|
||
|
||
class LaunchModalEffect(_BaseEffect): | ||
"""An Effect that will launch a modal.""" | ||
|
||
class Meta: | ||
effect_type = EffectType.LAUNCH_MODAL | ||
|
||
class TargetType(StrEnum): | ||
DEFAULT_MODAL = "default_modal" | ||
NEW_WINDOW = "new_window" | ||
RIGHT_CHART_PANE = "right_chart_pane" | ||
|
||
url: str | ||
target: TargetType = TargetType.DEFAULT_MODAL | ||
|
||
@property | ||
def values(self) -> dict[str, Any]: | ||
"""The LaunchModalEffect values.""" | ||
return {"url": self.url, "target": self.target.value} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from canvas_sdk.effects import Effect | ||
from canvas_sdk.events import EventType | ||
from canvas_sdk.handlers import BaseHandler | ||
|
||
|
||
class Application(BaseHandler, ABC): | ||
"""An embeddable application that can be registered to Canvas.""" | ||
|
||
RESPONDS_TO = [EventType.Name(EventType.APPLICATION__ON_OPEN)] | ||
|
||
def compute(self) -> list[Effect]: | ||
"""Handle the application events.""" | ||
match self.event.type: | ||
case EventType.APPLICATION__ON_OPEN: | ||
return [self.on_open()] if self.target == self.identifier else [] | ||
case _: | ||
return [] | ||
|
||
@abstractmethod | ||
def on_open(self) -> Effect: | ||
"""Handle the application open event.""" | ||
... | ||
|
||
@property | ||
def identifier(self) -> str: | ||
"""The application identifier.""" | ||
return f"{self.__class__.__module__}:{self.__class__.__qualname__}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.