Skip to content

Commit

Permalink
Sky-box-addin action-click (#66)
Browse files Browse the repository at this point in the history
* sky-box-addin action-click

* package and change log

* review comment version bump

---------

Co-authored-by: Akash Mehra <[email protected]>
  • Loading branch information
blackbaud-akashmehra and Akash Mehra authored Aug 22, 2024
1 parent 467a3ce commit 07597ff
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.4.0 (2024-08-21)
- Added a `actionClick` callback for Box Add-ins to allow developers to take action when actions are clicked.
- Added `AddinBoxConfig` interface for defining configuration options for `Box add-ins`.

# 1.3.0 (2024-06-18)
- Added `AddinClientConfig` interface to allow additional host origins to be supplied by an `AddinClient`.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blackbaud/sky-addin-client",
"version": "1.3.0",
"version": "1.4.0",
"description": "SKY add-in client",
"main": "dist/bundles/sky-addin-client.umd.js",
"module": "index.ts",
Expand Down
51 changes: 51 additions & 0 deletions src/addin/addin-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,57 @@ describe('AddinClient ', () => {

});

describe('action-click', () => {

it('should call the "actionClick" callback.',
() => {
let actionClickCalled = false;

const client = new AddinClient({
callbacks: {
init: () => { return; },
actionClick: () => { actionClickCalled = true; }
}
});

initializeHost();

const msg: AddinHostMessageEventData = {
message: {},
messageType: 'action-click',
source: 'bb-addin-host'
};

postMessageFromHost(msg);
client.destroy();

expect(actionClickCalled).toBe(true);
});

it('should tolerate the "actionClick" callback being undefined.',
() => {
const client = new AddinClient({
callbacks: {
init: () => { return; }
}
});

initializeHost();

const msg: AddinHostMessageEventData = {
message: {},
messageType: 'action-click',
source: 'bb-addin-host'
};

postMessageFromHost(msg);
client.destroy();

// No assertion. Just don't fail.
});

});

describe('help-click', () => {

it('should call the "helpClick" callback.',
Expand Down
5 changes: 5 additions & 0 deletions src/addin/addin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ export class AddinClient {
} else if (this.isFromValidOrigin(event)) {
/* tslint:disable-next-line switch-default */
switch (data.messageType) {
case 'action-click':
if (this.args.callbacks.actionClick) {
this.args.callbacks.actionClick(data.message.reason);
}
break;
case 'auth-token':
case 'auth-token-fail':
this.handleAuthTokenMessage(data);
Expand Down
16 changes: 16 additions & 0 deletions src/addin/client-interfaces/addin-box-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AddinBoxControl } from './addin-box-control';

/**
* Interface for defining configuration options for Box add-ins
*/
export interface AddinBoxConfig {
/**
* The controls to use for the box context menu
*/
controls: AddinBoxControl[] | undefined;

/**
* The help key to open when the Help icon is clicked
*/
helpKey?: string | undefined;
}
14 changes: 14 additions & 0 deletions src/addin/client-interfaces/addin-box-control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Interface for defining a control for Box add-ins
*/
export interface AddinBoxControl {
/**
* The display name of the control
*/
name: string;

/**
* The action of the control
*/
action: string;
}
5 changes: 5 additions & 0 deletions src/addin/client-interfaces/addin-client-callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export interface AddinClientCallbacks {
*/
init: (args: AddinClientInitArgs) => void;

/**
* Callback raised for box add-ins indicating that a control action was clicked.
*/
actionClick?: (action: string) => void;

/**
* Callback raised for button add-ins indicating that the button was clicked.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/addin/client-interfaces/addin-client-ready-args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AddinActionButtonConfig } from './addin-action-button-config';
import { AddinBoxConfig } from './addin-box-config';
import { AddinButtonConfig } from './addin-button-config';
import { AddinModalConfig } from './addin-modal-config';
import { AddinTabConfig } from './addin-tab-config';
Expand Down Expand Up @@ -44,4 +45,9 @@ export interface AddinClientReadyArgs {
* Provides additional configuration for Tab add-ins
*/
tabConfig?: AddinTabConfig;

/**
* Provides additional configuration for Box add-ins
*/
boxConfig?: AddinBoxConfig;
}
2 changes: 2 additions & 0 deletions src/addin/client-interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './addin-box-config';
export * from './addin-box-control';
export * from './addin-button-config';
export * from './addin-button-style';
export * from './addin-client-args';
Expand Down

0 comments on commit 07597ff

Please sign in to comment.