Skip to content

Commit

Permalink
Merge pull request #3 from gofynd/breadcrumb-support
Browse files Browse the repository at this point in the history
breadcrumbs support added
  • Loading branch information
vishu3011 committed Sep 6, 2021
2 parents 9961eff + 0f773dd commit e24d9d4
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ context.dispatch();
```
<img src="https://github.com/gofynd/fdk-extension-bridge-javascript/blob/master/demo/context_item.png" alt="Context Item"><hr>

## For Including Breadcrumb

```javascript
let breadCrumbs = new components.Breadcrumb(EXT, {
displayText: "Export Data",
});
breadCrumbs.dispatch();
```
<img src="https://github.com/gofynd/fdk-extension-bridge-javascript/blob/breadcrumb-support/demo/breadcrumb.png" alt="Breadcrumb"><hr>

## For resetting extesnion bridge

```javascript
Expand Down
16 changes: 16 additions & 0 deletions components/base.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ class Component {
}
});
}

setState(config = {}, id, payload){
let namespace = `${this.type}/${this.eventName}`;
let dispatchPayload = {
target: this.type,
id: `${namespace}:${id}`,
action: this.eventName, // click,register,change
data: {
config
}
}
if(payload) {
dispatchPayload.data.payload = payload
}
this.extension.transport.dispatch(dispatchPayload)
}
}

module.exports = Component;
54 changes: 54 additions & 0 deletions components/breadcrumb.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const Component = require("./base.component");

const c_type = 'Breadcrumb';
const Actions = {
SHOW: 'show'
};

class Breadcrumb extends Component{

/**
*
* @param {*} extension
* @param {*} config
*
* {
* "displayText": "",
* }
*/
constructor(extension, config) {
super(extension, c_type, config.id);
this.displayText = config.displayText || 'Settings';
this.config = {
displayText: this.displayText
}
}

// subscribe(eventName, callback) {
// if(eventName !== Actions.SHOW) {
// return "" // throw error
// }
// return super.subscribe(eventName, callback);
// }

// unsubscribe(listnerId) {
// return super.unsubscribe(listnerId);
// }

dispatch(payload = null){
return super.dispatch(this.config, payload);
}


setState() {
// to set state of a component
}
}

Breadcrumb.Actions = Actions;
Breadcrumb.component_type = c_type;

module.exports = Breadcrumb;

2 changes: 1 addition & 1 deletion components/button.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Button extends Component{


setState({label,disabled,buttonType}) {
// ignore this
// to set state of a component
if(label){
this.label = label
Expand All @@ -60,7 +61,6 @@ class Button extends Component{
if(type){
this.buttonType = buttonType
}
this.dispatch()
}
}

Expand Down
4 changes: 3 additions & 1 deletion components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
const Button = require("./button.component");
const ToggleButton = require("./toggle_button.component");
const ContextMenuItem = require("./context_menu_item.component");
const Breadcrumb = require("./breadcrumb.component");

module.exports = {
Button,
ToggleButton,
ContextMenuItem
ContextMenuItem,
Breadcrumb
}
5 changes: 4 additions & 1 deletion components/toggle_button.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ class ToggleButton extends Component{
}


setState() {
setState(payload = null) {
// to set state of a component
if(payload){
return super.setState(this.config, this.id, payload);
}
}
}

Expand Down
Binary file added demo/breadcrumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e24d9d4

Please sign in to comment.