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

Add a custom workflow panel component. #3

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"prettier": "^2.6.1",
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"terriajs": "8.1.26",
"terriajs": "8.2.3",
"tslib": "^2.3.1",
"typescript": "^3.9.4"
}
Expand Down
25 changes: 25 additions & 0 deletions src/TestTool.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { observer } from "mobx-react";
import React from "react";
import { Icon, ViewState } from "terriajs-plugin-api";
import WorkflowPanel from "terriajs/lib/ReactViews/Workflow/WorkflowPanel";

interface PropsType {
viewState: ViewState;
}

// Note: we need to wrap this in observer() right now or else it results in a render loop.
// Will have to debug that later.
const TestTool: React.FC<PropsType> = observer((props: PropsType) => {
return (
<WorkflowPanel
viewState={props.viewState}
title="Test tool"
icon={Icon.GLYPHS.cube}
closeButtonText="Close"
onClose={() => {props.viewState.closeTool()}}>
<p>Hello, world</p>
</WorkflowPanel>
);
});

export default TestTool;
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Workbench
} from "terriajs-plugin-api";
import BoxDrawingCatalogItem from "./BoxDrawingCatalogItem";
import TestTool from "./TestTool";

const plugin: TerriaPlugin = {
name: "Sample plugin",
Expand All @@ -22,11 +23,16 @@ const plugin: TerriaPlugin = {
icon: Icon.GLYPHS.cube,
text: "Draw a 3D box",
onUserEnterMode: () => {
userDrawing = createUserRectangleDrawing(terria, rectangle => {
create3dBoxItemFromRectangle(terria, workbench, rectangle);
drawModeButton.closeMode();
// userDrawing = createUserRectangleDrawing(terria, rectangle => {
// create3dBoxItemFromRectangle(terria, workbench, rectangle);
// drawModeButton.closeMode();
// });
// userDrawing.enterDrawMode();
viewState.openTool({
toolName: "My Tool",
getToolComponent: () => TestTool,
showCloseButton: false
});
userDrawing.enterDrawMode();
},
onUserCloseMode: () => {
userDrawing?.endDrawing();
Expand Down