SlideShare a Scribd company logo
1 of 55
#MDBlocal
Writing a Compass Plugin
Anna Herlihy
Software Engineer on MongoDB
Compass
1. Compass Feature Tour
2. Where can my plugin fit into Compass?
3. How can my plugin fit into Compass?
4. Example
Feature Tour
Where does my plugin fit
visually into Compass?
1. Header.Item
2. Instance.Tab
3. Database.Tab
4. Collection.Tab
5. CollectionHUD.item (Heads Up Display)
Plugin Roles
#MDBlocal
Header.Item
● Purpose:
○ Top-level: display global information (e.g. MongoDB
version, topology)
● UI Considerations:
○ Header space is very small
○ Lengthy information should be hidden until asked for
● Potential Plugins:
○ Current user information
#MDBlocal
Instance.Tab
● Purpose:
○ Large instance-level features (e.g. real time server
stats). Currently have “Databases” and “Performance”.
● Potential Plugins:
○ Cluster Health
○ List of All Users
#MDBlocal
Database.Tab
● Purpose:
○ Large database-level feature. Right now we just have
a list of collections.
● Potential Plugins:
○ System.profile Charts
○ List all users
#MDBlocal
Collection.Tab
● Purpose:
○ Large collection-level features (e.g. CRUD, Explain
Plan, or schema analysis)
● Potential Plugin:
○ Object size histogram of schema sample
#MDBlocal
CollectionHUD.Item
● Purpose:
○ Display statistical information relevant to a collection
● UI Considerations:
○ Should not distract users from the main content of the
collection body
○ Should be text-based
● Potential Plugin:
○ Mongotop / server statistics
What makes up a plugin?
Compass and any plugins are React
applications.
React
React is a framework made up of Stores,
Components, and Actions.
● Stores are “smart”, they keep track of
state information and pass it to the
Components.
● Components are “dumb”, they just
receive data from the store and render it.
● Actions are how components
communicate with the store to trigger
changes.
Actions
● Events triggered when a user performs an action.
● Can be button clicks, link clicks, text entry, etc.
● Actions are sent from Components and listened to by
Stores.
Components
● Components make up the User Interface.
● This is where you use JSX to define what the plugin
should look like.
● Styles are imported from a local .less file with the
same name as the component.
Stores
● Reflux/Redux Stores that hold the application state.
● Each plugin can listen to other stores/have its state
changes listened to by others.
● Flow of data:
○ Actions should be listened to by stores
○ Stores should be subscribed to by components
The AppRegistry
● Holds all Compass + plugin actions, components,
and stores
○ All plugins must register with the AppRegistry.
● Information flows from Compass to plugins and back
through the AppRegistry.
● It is available to all Plugins globally by calling
global.hadronApp.appRegistry.
Lifecycle Hooks
How do Compass and my plugin
become aware of each other?
activate(): Tell Compass about the plugin
● Compass will look in the plugins directory.
○ ~/.mongodb/compass/plugins on OSX
● It will call the activate method in the root index.js.
● The plugin should register its actions, components, and
stores with the AppRegistry in this method.
● This is where you specify what role you want your
plugin to occupy.
whoami/src/index.js
onActivated(appReg): Tell plugin about Compass
● When all plugin registration is completed, the
onActivated method is called on any registered store.
● In this method, the plugin can get and listen to any stores
in Compass or another plugin.
● Guarantees everything has been registered before any
plugin tries to get anything from the registry.
whoami/src/stores/store.js
The AppRegistry will emit events
● data-service-connected
● collection-changed
● database-changed
● query-changed
… or any other events you want to add!
My First Compass Plugin
Who is the current user?
● Since it’s global to the Compass instance, it can take
the role Header.Item
● The connectionStatus DB command lists
authenticated users and their roles.
Final Product
Final Product
Step 0: Get the Template
~/.mongodb/compass/plugins $
> npm install -g khaos
> khaos create mongodb-js/compass-plugin ./whoami
> git init && git add . && git commit -m “init”
> npm install
Compass without plugin
Compass with unchanged plugin
Plugin running standalone
Step 1: The Store
src/stores/store.js:
● We set the initial state to empty.
● onActivated: when the DataService is connected,
we want to run the connectionStatus command.
● When the command returns, we set the state to the
results.
appRegistry.on('data-service-connected', (error, dataService) => {
if (!error) {
dataService.command(
'admin',
{connectionStatus : 1},
(err, res) => {
if (!err && res.authInfo && res.authInfo.authenticatedUsers) {
this.setState({
user: res.authInfo.authenticatedUsers[0].user,
role: res.authInfo.authenticatedUserRoles[0].role
})
} else {
this.setState({user: null, role: null});
}
}
);
}
});
getInitialState() {
return {
user: null, role: null
};
}
Call DB command on activation
Initialize State
Step 2: The Component
src/components/whoami/whoami.jsx
● The store state will be passed to the component as
this.props.user and this.props.role
● Component must render the username and role
● If not provided, render “no user”
static propTypes = {
user: PropTypes.string.isRequired,
role: PropTypes.string.isRequired
};
static defaultProps = {
user: '', role: ''
};
render() {
if (!this.props.user) {
return (
<div className={classnames(styles.root)}>
<FontAwesome name="user-times"/>
No User
</div>
);
}
return (
<div className={classnames(styles.root)}>
<FontAwesome name="user"/>
<i> {this.props.user}:{this.props.role}</i>
</div>
);
}
Define and
Set Default Props
Render Props
Step 3: The Actions
(not used in this plugin)
Step 4: Styles
src/components/whoami/whoami.less
● Every component has a .less file with the same name
located in the same directory
● In this case just want to remove the colors.
.root {
background:
#0e83cd;
color: @pw;
padding: 2.4rem;
}
#MDBlocal
Run It Standalone!
#MDBlocal
Run Compass!
A PLUGIN!
Writing a Plugin is Easy!
● We are here to help!
○ Email team-compass@mongodb.com
● All plugin documentation:
○ https://docs.mongodb.com/compass/master/plugin
s/creating-compass-plugins
● The “whoami” plugin + these slides are on GitHub
○ https://github.com/aherlihy/compass-plugins-talk
Future Plans
● We encourage everyone to share their plugins!
● MongoDB can provide marketing and support
● When there are enough plugins there will be a plugin
marketplace
● Until then, MongoDB can list the plugins the same
way we list community drivers
#MDBlocal
THANK YOU!
#MDBlocal
THANKS FOR COMING!
Anna Herlihy
anna@mongodb.com
@annaisworking

More Related Content

What's hot

Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 DreamLab
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHPAndru Weir
 
첫 리액트 경험기
첫 리액트 경험기첫 리액트 경험기
첫 리액트 경험기석진 고
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsNeil Crookes
 
Cake fest 2012 create a restful api
Cake fest 2012 create a restful apiCake fest 2012 create a restful api
Cake fest 2012 create a restful apiceeram
 
Grails Simple Login
Grails Simple LoginGrails Simple Login
Grails Simple Loginmoniguna
 
Migration from Rails2 to Rails3
Migration from Rails2 to Rails3Migration from Rails2 to Rails3
Migration from Rails2 to Rails3Umair Amjad
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJSAll Things Open
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max PetruckMaksym Petruk
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsMihail Gaberov
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxCommit University
 
Asyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-sagaAsyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-sagaPedro Solá
 
CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsanthony_putignano
 
Up and Running with ReactJS
Up and Running with ReactJSUp and Running with ReactJS
Up and Running with ReactJSLoc Nguyen
 
React: High level overview for backend developers
React: High level overview for backend developersReact: High level overview for backend developers
React: High level overview for backend developersBonnie DiPasquale
 

What's hot (20)

Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHP
 
첫 리액트 경험기
첫 리액트 경험기첫 리액트 경험기
첫 리액트 경험기
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIs
 
Cake fest 2012 create a restful api
Cake fest 2012 create a restful apiCake fest 2012 create a restful api
Cake fest 2012 create a restful api
 
Grails Simple Login
Grails Simple LoginGrails Simple Login
Grails Simple Login
 
Migration from Rails2 to Rails3
Migration from Rails2 to Rails3Migration from Rails2 to Rails3
Migration from Rails2 to Rails3
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
React outbox
React outboxReact outbox
React outbox
 
getSIDUsers
getSIDUsersgetSIDUsers
getSIDUsers
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's Redux
 
React redux
React reduxReact redux
React redux
 
Asyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-sagaAsyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-saga
 
Controller
ControllerController
Controller
 
CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIs
 
Up and Running with ReactJS
Up and Running with ReactJSUp and Running with ReactJS
Up and Running with ReactJS
 
React: High level overview for backend developers
React: High level overview for backend developersReact: High level overview for backend developers
React: High level overview for backend developers
 

Similar to SH 1 - SES 6 - compass-tel-aviv-slides.pptx

JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJSFestUA
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first designKyrylo Reznykov
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleCreating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleSean Chittenden
 
Nancy CLI. Automated Database Experiments
Nancy CLI. Automated Database ExperimentsNancy CLI. Automated Database Experiments
Nancy CLI. Automated Database ExperimentsNikolay Samokhvalov
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
Android app performance
Android app performanceAndroid app performance
Android app performanceSaksham Keshri
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAndrei Sebastian Cîmpean
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Katy Slemon
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobXDarko Kukovec
 
Murach : How to work with session state and cookies
Murach : How to work with session state and cookiesMurach : How to work with session state and cookies
Murach : How to work with session state and cookiesMahmoudOHassouna
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendVlad Fedosov
 

Similar to SH 1 - SES 6 - compass-tel-aviv-slides.pptx (20)

JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleCreating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at Scale
 
Nancy CLI. Automated Database Experiments
Nancy CLI. Automated Database ExperimentsNancy CLI. Automated Database Experiments
Nancy CLI. Automated Database Experiments
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
pio_present
pio_presentpio_present
pio_present
 
Redux
ReduxRedux
Redux
 
Android app performance
Android app performanceAndroid app performance
Android app performance
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
 
Simple React Todo List
Simple React Todo ListSimple React Todo List
Simple React Todo List
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobX
 
Murach : How to work with session state and cookies
Murach : How to work with session state and cookiesMurach : How to work with session state and cookies
Murach : How to work with session state and cookies
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
AutoDOPandRest
AutoDOPandRestAutoDOPandRest
AutoDOPandRest
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 

More from MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump StartMongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB
 

More from MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

SH 1 - SES 6 - compass-tel-aviv-slides.pptx

  • 1. #MDBlocal Writing a Compass Plugin Anna Herlihy Software Engineer on MongoDB Compass
  • 2. 1. Compass Feature Tour 2. Where can my plugin fit into Compass? 3. How can my plugin fit into Compass? 4. Example
  • 4. Where does my plugin fit visually into Compass?
  • 5. 1. Header.Item 2. Instance.Tab 3. Database.Tab 4. Collection.Tab 5. CollectionHUD.item (Heads Up Display) Plugin Roles
  • 7. Header.Item ● Purpose: ○ Top-level: display global information (e.g. MongoDB version, topology) ● UI Considerations: ○ Header space is very small ○ Lengthy information should be hidden until asked for ● Potential Plugins: ○ Current user information
  • 9. Instance.Tab ● Purpose: ○ Large instance-level features (e.g. real time server stats). Currently have “Databases” and “Performance”. ● Potential Plugins: ○ Cluster Health ○ List of All Users
  • 11. Database.Tab ● Purpose: ○ Large database-level feature. Right now we just have a list of collections. ● Potential Plugins: ○ System.profile Charts ○ List all users
  • 13. Collection.Tab ● Purpose: ○ Large collection-level features (e.g. CRUD, Explain Plan, or schema analysis) ● Potential Plugin: ○ Object size histogram of schema sample
  • 15. CollectionHUD.Item ● Purpose: ○ Display statistical information relevant to a collection ● UI Considerations: ○ Should not distract users from the main content of the collection body ○ Should be text-based ● Potential Plugin: ○ Mongotop / server statistics
  • 16. What makes up a plugin? Compass and any plugins are React applications.
  • 17. React React is a framework made up of Stores, Components, and Actions. ● Stores are “smart”, they keep track of state information and pass it to the Components. ● Components are “dumb”, they just receive data from the store and render it. ● Actions are how components communicate with the store to trigger changes.
  • 18. Actions ● Events triggered when a user performs an action. ● Can be button clicks, link clicks, text entry, etc. ● Actions are sent from Components and listened to by Stores.
  • 19. Components ● Components make up the User Interface. ● This is where you use JSX to define what the plugin should look like. ● Styles are imported from a local .less file with the same name as the component.
  • 20. Stores ● Reflux/Redux Stores that hold the application state. ● Each plugin can listen to other stores/have its state changes listened to by others. ● Flow of data: ○ Actions should be listened to by stores ○ Stores should be subscribed to by components
  • 21. The AppRegistry ● Holds all Compass + plugin actions, components, and stores ○ All plugins must register with the AppRegistry. ● Information flows from Compass to plugins and back through the AppRegistry. ● It is available to all Plugins globally by calling global.hadronApp.appRegistry.
  • 22. Lifecycle Hooks How do Compass and my plugin become aware of each other?
  • 23. activate(): Tell Compass about the plugin ● Compass will look in the plugins directory. ○ ~/.mongodb/compass/plugins on OSX ● It will call the activate method in the root index.js. ● The plugin should register its actions, components, and stores with the AppRegistry in this method. ● This is where you specify what role you want your plugin to occupy.
  • 25. onActivated(appReg): Tell plugin about Compass ● When all plugin registration is completed, the onActivated method is called on any registered store. ● In this method, the plugin can get and listen to any stores in Compass or another plugin. ● Guarantees everything has been registered before any plugin tries to get anything from the registry.
  • 27. The AppRegistry will emit events ● data-service-connected ● collection-changed ● database-changed ● query-changed … or any other events you want to add!
  • 29. Who is the current user? ● Since it’s global to the Compass instance, it can take the role Header.Item ● The connectionStatus DB command lists authenticated users and their roles.
  • 32. Step 0: Get the Template
  • 33. ~/.mongodb/compass/plugins $ > npm install -g khaos > khaos create mongodb-js/compass-plugin ./whoami > git init && git add . && git commit -m “init” > npm install
  • 34.
  • 38. Step 1: The Store
  • 39. src/stores/store.js: ● We set the initial state to empty. ● onActivated: when the DataService is connected, we want to run the connectionStatus command. ● When the command returns, we set the state to the results.
  • 40. appRegistry.on('data-service-connected', (error, dataService) => { if (!error) { dataService.command( 'admin', {connectionStatus : 1}, (err, res) => { if (!err && res.authInfo && res.authInfo.authenticatedUsers) { this.setState({ user: res.authInfo.authenticatedUsers[0].user, role: res.authInfo.authenticatedUserRoles[0].role }) } else { this.setState({user: null, role: null}); } } ); } }); getInitialState() { return { user: null, role: null }; } Call DB command on activation Initialize State
  • 41. Step 2: The Component
  • 42. src/components/whoami/whoami.jsx ● The store state will be passed to the component as this.props.user and this.props.role ● Component must render the username and role ● If not provided, render “no user”
  • 43. static propTypes = { user: PropTypes.string.isRequired, role: PropTypes.string.isRequired }; static defaultProps = { user: '', role: '' }; render() { if (!this.props.user) { return ( <div className={classnames(styles.root)}> <FontAwesome name="user-times"/> No User </div> ); } return ( <div className={classnames(styles.root)}> <FontAwesome name="user"/> <i> {this.props.user}:{this.props.role}</i> </div> ); } Define and Set Default Props Render Props
  • 44. Step 3: The Actions (not used in this plugin)
  • 46. src/components/whoami/whoami.less ● Every component has a .less file with the same name located in the same directory ● In this case just want to remove the colors. .root { background: #0e83cd; color: @pw; padding: 2.4rem; }
  • 48.
  • 50.
  • 52. Writing a Plugin is Easy! ● We are here to help! ○ Email team-compass@mongodb.com ● All plugin documentation: ○ https://docs.mongodb.com/compass/master/plugin s/creating-compass-plugins ● The “whoami” plugin + these slides are on GitHub ○ https://github.com/aherlihy/compass-plugins-talk
  • 53. Future Plans ● We encourage everyone to share their plugins! ● MongoDB can provide marketing and support ● When there are enough plugins there will be a plugin marketplace ● Until then, MongoDB can list the plugins the same way we list community drivers
  • 55. #MDBlocal THANKS FOR COMING! Anna Herlihy anna@mongodb.com @annaisworking