Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elyra Canvas Documentation using mkdocs #1702

Merged
merged 26 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b19c585
feat: new guide
Paul-Kawalkowski Jul 24, 2023
bd9b570
Merge branch 'main' into new-guide
srikant-ch5 Feb 13, 2024
2131ab8
Merge branch 'main' into new-guide
srikant-ch5 Feb 19, 2024
559de91
#1701 : New Elyra Canvas Documentation using mkdocs setup
srikant-ch5 Feb 19, 2024
5dae51d
Add instructions related to mkdocs setup in Readme
srikant-ch5 Feb 21, 2024
4ab5f66
Merge branch 'main' into new-guide
srikant-ch5 Feb 21, 2024
a129d9b
Update Readme, mkdocs.yml and Styling.md as per feedback
srikant-ch5 Feb 22, 2024
ee740e0
Merge branch 'main' into new-guide
srikant-ch5 Feb 23, 2024
4b0322a
Update new documentation as per comments and include github action fi…
srikant-ch5 Feb 23, 2024
32f0f38
Update username and id in ci.yml for github pages
srikant-ch5 Feb 23, 2024
c6aab84
Update username and id as default
srikant-ch5 Feb 23, 2024
d88a8d7
Update new-guide branch in ci.yml
srikant-ch5 Feb 23, 2024
7252eb7
Test using readthedocs theme
srikant-ch5 Feb 23, 2024
62ed288
Revert theme change
srikant-ch5 Feb 23, 2024
5c85847
Include links js file
srikant-ch5 Feb 23, 2024
e9755ff
Remove awesome-pages to test deployment
srikant-ch5 Feb 26, 2024
8e18c5c
Deploy docs to gh-pages and fix link navigation in docs
srikant-ch5 Feb 26, 2024
5d54fad
Fix Resource def links in docs link navigation
srikant-ch5 Feb 26, 2024
9f64d5a
Add slider info in Common Properties docs
srikant-ch5 Feb 27, 2024
339ec87
Merge branch 'main' into new-guide
srikant-ch5 Feb 28, 2024
a0ed397
Fix link redirection in 2.4.6, 3.1 and 3.2 docs
srikant-ch5 Feb 28, 2024
9df99fd
Merge branch 'main' into new-guide
srikant-ch5 Feb 29, 2024
8da981a
Add Copyrights in docs file and revert links in js files to point to …
srikant-ch5 Feb 29, 2024
547fd65
Check deployment action
srikant-ch5 Mar 1, 2024
41dbda1
Check deployment by removing git credentials from ci.yml
srikant-ch5 Mar 1, 2024
0e589b2
Update branch name in ci.yml
srikant-ch5 Mar 1, 2024
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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ci
on:
push:
branches:
- new-guide
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. Would this mean the guide would only be updated when the branch is new-guide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Matt, this needs to be changed as main when merged, for testing purpose I have kept it as new-guide.

permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you come up with these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matt to deploy the docs using gh-pages I have followed https://squidfunk.github.io/mkdocs-material/publishing-your-site/ resource and able to deploy whenever I push any change in docs to my new-guide branch. It triggers ci to deploy the changes without manually running mkdocs gh-deploy --force
Screenshot 2024-02-29 at 7 12 06 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more wondering about git config user.name github-actions[bot] and git config user.email 41898282+github-actions[bot]@users.noreply.github.com. Do we need these?

git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material
- run: mkdocs gh-deploy --force
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ build/Release
# Dependency directory
node_modules

# Site folder generated by mkdocs-deploy
site

config/app-local.json

/public/build/*
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ npm install -g grunt-cli sass
```
In your application's package.json replace
```
"@elyra/canvas": "<verson>"
"@elyra/canvas": "<version>"
```
with
```
Expand All @@ -50,3 +50,19 @@ Delete @elyra/canvas from node_modules of your application
# Run npm install to get local copy of common-canvas and/or common-properties
npm install
```

### Contribute to the Elyra Canvas documentation (mkdocs)
1. Python v3 needs to be available.
nmgokhale marked this conversation as resolved.
Show resolved Hide resolved
2. Go to canvas directory.

3. Install required mkdocs packages using pip3.
```
pip3 install -r requirements.txt`
```

4. Run below command to start mkdocs server.
```
mkdocs serve
```

5. When complete, open the browser: http://127.0.0.1:8000/
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const portsHorizontalDefaultLayout = {
labelAllowReturnKey: false, // true allows line feed to be inserted into label, "save" to make the return key save the label.

// An array of decorations to be applied to the node. For details see:
// https://github.com/elyra-ai/canvas/wiki/2.4.2-Decoration-Specification
// https://github.com/elyra-ai/canvas/tree/main/guide/2.4.2-Decoration-Specification.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all these links be github pages links? Also, I don't this guide is the folder anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matt, I have reverted the docs links to point to existing elyra canvas docs once the new one is deployed I will change these urls pointing to new docs.

// These are added to the node at run time and will not be saved into
// the pipeline flow.
decorations: [],
Expand Down Expand Up @@ -488,7 +488,7 @@ const portsVerticalDefaultLayout = {
labelAllowReturnKey: false, // true allows line feed to be inserted into label, "save" to make the return key save the label.

// An array of decorations to be applied to the node. For details see:
// https://github.com/elyra-ai/canvas/wiki/2.4.2-Decoration-Specification
// https://github.com/elyra-ai/canvas/tree/main/guide/2.4.2-Decoration-Specification.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Have a look at all the links.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matt, I have reverted the docs links to point to existing elyra canvas docs once the new one is deployed I will change these urls pointing to new docs.

// These are added to the node at run time and will not be saved into
// the pipeline flow.
decorations: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class CommonPropertiesComponents extends React.Component {
to <span className="harness-highlight">Custom</span> and <span className="harness-highlight">rightFlyout</span> set to true.
Below is the minimum specifications to render CommonProperties. More options and details are listed in the&nbsp;
<a className="harness-properties-documentation-page-intro-link"
href={"https://github.com/elyra-ai/canvas/wiki/3.0-Common-properties-documentation"}
href={"https://github.com/elyra-ai/canvas/tree/main/guide/3.0-Common-properties-documentation.md"}
>
Common Properties wiki
</a>.
Expand All @@ -548,7 +548,7 @@ class CommonPropertiesComponents extends React.Component {
</pre>
<p>For more information with using CommonCanvas right-flyout for the properties editor, refer to the documentation in the&nbsp;
<a className="harness-properties-documentation-page-intro-link"
href={"https://github.com/elyra-ai/canvas/wiki/3.0-Common-properties-documentation" +
href={"https://github.com/elyra-ai/canvas/tree/main/guide/3.0-Common-properties-documentation.md" +
"#using-commonproperties-documentation-in-commoncanvas-right-flyout-panel"}
>
Common Properties wiki
Expand Down Expand Up @@ -2123,7 +2123,7 @@ class CommonPropertiesComponents extends React.Component {
to <span className="harness-highlight">More than ten fields...</span> This placeholder text can be configured through
&nbsp;
<a className="harness-properties-documentation-page-intro-link"
href="https://github.com/elyra-ai/canvas/wiki/3.0-Common-Properties-documentation#step-3--display-the-properties-editor"
href="https://github.com/elyra-ai/canvas/tree/main/guide/3.0-Common-Properties-documentation#step-3--display-the-properties-editor.md"
>custom labels</a>.
</p>
<div className="harness-section-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export default class SidePanelAPI extends React.Component {

if (this.state.appendLink) {
messageLink = (<div>
<a href="https://github.com/elyra-ai/canvas/wiki/2.0-Common-Canvas-Documentation" target="_blank">Visit Common Canvas Wiki!</a>
<a href="https://github.com/elyra-ai/canvas/tree/main/guide/2.0-Common-Canvas-Documentation.md" target="_blank">Visit Common Canvas Wiki!</a>
</div>);
}

Expand Down
241 changes: 241 additions & 0 deletions docs/2.0-Common-Canvas-Documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
## Introduction
Common canvas displays a flow of data operations as nodes and links which the user can create and edit to get the flow they want. These visual flows of data operations are translated into data processing steps performed by a back-end server. Common canvas provides functionality for the visual display of flows in the browser and leaves persistence and execution of data flows to the application.
Within common canvas the user can perform operations such as:

* Create a new node by dragging a node definition from a palette onto the canvas.
* Create a new node by dragging a node from outside the canvas onto the canvas (you'll have to do some programming to get this to work).
* Delete a node by clicking a context menu option.
* Create a link by dragging a line from one node to another.
* Delete a link by clicking a context menu option.
* Add a comment to the canvas and draw a link from it to one or more nodes.
* Edit a comment.
* Move nodes and comments around in the canvas to get the desired arrangement.
* And more! ...

# Architecture

## Common Canvas react object
Common-canvas is a react component that can be used in your react application to display a fully-functional canvas user interface including the function mentioned above. The `<CommonCanvas>` component is displayed in a `<div>` provided by your application.

Common-canvas has these constituent parts that are visible to the user:

* [Canvas editor](2.0.1-Canvas-Editor.md) - the main area of the UI where the flow is displayed and edited
* [Palette](2.0.2-Palette.md) - a set of node templates that can be dragged to the canvas to create new nodes
* [Context menu](2.0.3-Context-Menu.md) - a menu of options for nodes, comments, etc
* [Context toolbar](2.0.4-Context-Toolbar.md) - a menu of options for nodes, comments, etc presented as a small toolbar
* Toolbar - a set of tools across the top of the UI
* Notification panel - a panel for displaying runtime and other messages to your user
* Right side flyout - a panel, often used to display node properties
* Top panel - a panel which can be used to display other app related information
* Bottom panel - a panel which can be used to display other app related information

and it handles:

1. the visual display of the flow of operations;
2. any user gestures on the canvas;
3. display of context menus;
4. display and handling of the palette.
5. provision of callbacks to tell your code what operations the user is performing on the canvas
6. and much much more.

## Canvas Controller

The only mandatory parameter for the `<CommonCanvas>` component is a regular JavaScript object called the [CanvasController](2.4-Canvas-Controller-API.md).

The CanvasController routes handles calls from the host application and actions performed by the user. It then updates the internal object model which stores:

1. the data that describes the flow of nodes, links and comments (called a pipelineFlow);
2. the data that describes the definition of the palette which contains node templates that can dragged to add nodes to the canvas;
3. the set of currently selected objects.
4. notification messages
5. breadcrumbs that indicate which sub-flow is being viewed
6. layout information

The [CanvasController](2.4-Canvas-Controller-API.md) provides an API which allows your code to:

1. set a new pipelineFlow;
2. get the current pipelineFlow (after the user has edited it);
3. update and edit objects in the canvas (for example, add node, delete link etc.);
4. set the node definition data (for display of nodes in the palette)

# Getting started with common canvas programming

## Hello Canvas!
You can start by looking at these two 'hello world' examples for using common canvas:

* This first one called [app-tiny.js](https://github.com/elyra-ai/canvas/blob/master/canvas_modules/harness/src/client/app-tiny.js) has the bare minimum necessary to get a fully functioning common-canvas to appear including all the basic functionality, a palette and a flow of nodes and links.
* The second, called [app-small.js](https://github.com/elyra-ai/canvas/blob/master/canvas_modules/harness/src/client/app-small.js), shows many of the options available to a common-canvas developer such as configurations and callback handlers.

You can also look at the [App.js](https://github.com/elyra-ai/canvas/blob/49ed634e3353d8f5c58eb8409ed8e1009f19c87a/canvas_modules/harness/src/client/App.js) file in the test harness section of this repo to see examples of code that uses the common canvas component.

Now let's walk through the different steps to get common-canvas working:


## Step 1 : Install Elyra Canvas NPM module

Enter:
```
npm install @elyra/canvas
```

## Step 2 : Import Common-canvas

To use common canvas in your react application you need to do the following. First import the CommonCanvas react component and CanvasController class from the Elyra Canvas library. Elyra Canvas produces both `esm` and `cjs` outputs. By default `esm` will be used when webpack is used to build the consuming application.

**All Components**
```js
import { CommonCanvas, CanvasController } from "@elyra/canvas";
```
**Canvas only**

To import only canvas functionality in `cjs` format use:
```js
import { CommonCanvas, CanvasController } from "@elyra/canvas/dist/lib/canvas";
```

In addition you'll need to import `<IntlProvider>` from the `react-intl` library.
```js
import { IntlProvider } from "react-intl";
```


## Step 3 : Create an instance of the canvas controller
To control the canvas you'll need an instance of the canvas controller so create an instance of it like this (probably in the constructor of your object).
```js
this.canvasController = new CanvasController();
```
## Step 4 : Set the palette data
Next you'll need to populate the palette data. This will specify the nodes (split into categories) that will appear in the palette. The user can drag them from the palette to build their flow. This is done by calling CanvasController with:
```js
this.canvasController.setPipelineFlowPalette(pipelineFlowPalette);
```
The pipelineFlowPalette object should conform to the JSON schema found here:
https://github.com/elyra-ai/pipeline-schemas/tree/master/common-canvas/palette

Some examples of palette JSON files can be found here:
https://github.com/elyra-ai/canvas/tree/master/canvas_modules/harness/test_resources/palettes

## Step 5 : (Optional) Set the flow data
This is an optional step. If you want a previously saved flow to be shown in the canvas editor so the user can start to edit it, you will need to call the CanvasController with:
```js
this.canvasController.setPipelineFlow(pipelineFlow);
```

The pipelineFlow object should conform to the JSON schema found here:
https://github.com/elyra-ai/pipeline-schemas/tree/master/common-pipeline/pipeline-flow

Some examples of pipeline flow JSON files can be found here:
https://github.com/elyra-ai/canvas/tree/master/canvas_modules/harness/test_resources/diagrams

## Step 6 : Pull in the CSS
Check this section to find info on what CSS to include in your application's CSS. [Styling](4.0-Styling.md).

## Step 7 : Display the canvas

Finally you'll need to display the canvas object inside an `<IntlProvider>` object. Inside your render code, add the following:
```html
<div>
<IntlProvider>
<CommonCanvas canvasController={this.canvasController} />
</IntlProvider>
</div>
```
The div should have the dimensions you want for your canvas to display in your page. For the canvasController property, pass the instance of canvas controller you created earlier. This is the only mandatory property. After providing this and running your code you will have a fully functioning canvas including: a palette; default toolbar; context menus; direct manipulation (move and resize) etc. To customize these behaviors and presentation continue with the sections below.

## Common Canvas customization
If you want to customize the behavior of common canvas you can specify any combination of the following optional settings:
```html
<div>
<CommonCanvas
canvasController={this.canvasController}

config={this.commonCanvasConfig}
toolbarConfig={this.toolbarConfig}
notificationConfig={this.notificationConfig}
contextMenuConfig={this.contextMenuConfig}
keyboardConfig={this.keyboardConfig}

contextMenuHandler={this.contextMenuHandler}
beforeEditActionHandler={this.beforeEditActionHandler}
editActionHandler={this.editActionHandler}
clickActionHandler={this.clickActionHandler}
decorationActionHandler={this.decorationActionHandler}
layoutHandler={this.layoutHandler}
tipHandler={this.tipHandler}
idGeneratorHandler={this.idGeneratorHandler}
selectionChangeHandler={this.selectionChangeHandler}
actionLabelHandler={this.actionLabelHandler}

showRightFlyout={showRightFlyout}
rightFlyoutContent={rightFlyoutContent}

showBottomPanel={showBottomPanel}
bottomPanelContent={bottomPanelContent}

showTopPanel={showTopPanel}
topPanelContent={topPanelContent}
>
</CommonCanvas>
</div>
```

### Config objects
Common canvas has five **optional** configuration objects: config, toolbarConfig, notificationConfig, contextMenuConfig and keyboardConfig.
They are documented here:
[Config Objects](2.1-Config-Objects.md)

### Handlers
There are several **optional** handlers implemented as callback functions. They are contextMenuHandler, editActionHandler, beforeEditActionHandler, clickActionHandler, decorationActionHandler, layoutHandler, tipHandler, idGeneratorHandler, selectionChangeHandler and actionLabelHandler. They are documented here:
[Common Canvas Callback](2.2-Common-Canvas-callbacks.md)

### Right-flyout panel parameters
The right flyout panel appears on the right of the canvas area. You can add whatever content you like to this panel. Typically, it is used to display properties of nodes on the canvas. There are two **optional** parameters to let you manage the right flyout panel These are:

- showRightFlyout: This can be true or false to indicate whether the flyout panel is shown or not. The default is false.
- rightFlyoutContent: content to display in the right flyout which is a JSX object. Nothing is displayed by default.

### Bottom panel parameters
The bottom panel appears below the canvas area and between the palette and the right flyout panel. You can add whatever content you like to this panel. There are two **optional** parameters to let you manage the bottom panel. These are:

- showBottomPanel: This can be true or false to indicate whether the bottom panel is shown or not. The default is false.
- bottomPanelContent: content to display in the bottom panel which is a JSX object. Nothing is displayed by default.

### Top panel parameters
The top panel appears below the toolbar and between the palette and the right flyout panel. You can add whatever content you like to this panel. There are two **optional** parameters to let you manage the top panel. These are:

- showTopPanel: This can be true or false to indicate whether the top panel is shown or not. The default is false.
- topPanelContent: content to display in the top panel which is a JSX object. Nothing is displayed by default.

### Localization
You can customize `<CommonCanvas>` using the `<IntlProvider>` object to [display translated test](#localization)

## Creating nodes on the canvas

Nodes can be created on the canvas by the user in two ways:

* By dragging a node from the palette onto the canvas background
* By dragging a node from outside the canvas

The first technique is provided by Common canvas. The second requires some development work which is documented here:
[Enabling node creation from external object](2.3-Enabling-node-creation-from-external-object.md)


## Keyboard support

Common canvas supports a number of keyboard interactions as follows:

|Keyboard Shortcut|Action|Description|
|---|---|---|
|Ctrl/Cmnd + a|selectAll|Select All objects
|delete|deleteSelectedObjects|Delete currently selected objects|
|Ctrl/Cmnd + x|cut|Cut selected objects to the clipboard|
|Ctrl/Cmnd + c|copy|Copy selected objects to the clipboard|
|Ctrl/Cmnd + v|paste|Paste objects from the clipboard. If the mouse cursor is over <br>the canvas, objects will be pasted at the cursor position or, <br>if not, at a default position|
|Ctrl/Cmnd + z|undo|Undo last command|
|Ctrl/Cmnd + Shift + z|redo|Redo last undone command|
|Ctrl/Cmnd + y|redo|Redo last undone command|


Your application can disable any or all of these actions by providing the [keyboard config object](2.1-Config-Objects.md#keyboard-config-object) to the CommonCanvas react component.

When any of the shortcut keys are pressed the common-canvas object model will be updated and then the [editActionHandler](2.2-Common-Canvas-callbacks.md#editactionhandler) callback will be called with the `data.editType` parameter set to the action above and the `data.editSource` parameter set to "keyboard".
11 changes: 11 additions & 0 deletions docs/2.0.1-Canvas-Editor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The Canvas Editor displays the flow to the user and allows the user to interact with the flow using the mouse/trackpad and the keyboard.

The editor displays the following object types which the user can interact with:

## Nodes
## Links
## Comments
## The Canvas background


[Still under construction]
1 change: 1 addition & 0 deletions docs/2.0.1.1-Nodes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Under construction]
Loading
Loading