Skip to content

Commit

Permalink
Merge pull request #28 from livechat/feature/DPS-4294
Browse files Browse the repository at this point in the history
Enable page_data event for fullscreen app widget
  • Loading branch information
arturfracala authored Oct 28, 2024
2 parents 67928fb + bc6623a commit 86d6634
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-pets-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livechat/agent-app-sdk": minor
---

[DPS-4294] extend `page_data` event for Fullscreen apps
14 changes: 13 additions & 1 deletion packages/agent-app-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,15 @@ Gets the customer profile recorded most recently. Returns the `ICustomerProfile`

### Events

This widget currently does not support any events.
#### `page_data`

Emitted when widget in initialized. The handler will get the main window page data object as an argument:

```ts
interface IPageData {
queryParams: object;
}
```

### Methods

Expand All @@ -255,6 +263,10 @@ Navigates LiveChat Agent App to given pathname.

Updates "Reports" section filters to given `filters` object.

#### `getPageData(): IPageData | null`

Gets the main window page data recorded most recently. Returns the `IPageData` object, which is identical to the one emitted by the `page_data` event or `null` (if no data were registered).

## Settings widget (`ISettingsWidget`)

### Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ jest.mock('@livechat/widget-core-sdk', () => {
};
});

jest.mock('../shared/page-data', () => {
return {
withPageData: jest.fn().mockImplementation(widget => ({
...widget,
getPageData: jest.fn()
}))
};
});

describe('FullscreenWidget', () => {
it('has a `setNotificationBadge` method', () => {
const connection = createMockConnection();
Expand Down Expand Up @@ -108,12 +117,13 @@ describe('createFullscreenWidget', () => {
});

it('returns the correct object with correct properties', async () => {
expect.assertions(4);
expect.assertions(5);

const widget = await createFullscreenWidget();
expect(widget).toHaveProperty('setNotificationBadge');
expect(widget).toHaveProperty('on');
expect(widget).toHaveProperty('off');
expect(widget).toHaveProperty('sendMessage');
expect(widget).toHaveProperty('getPageData');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IFullscreenWidgetEvents,
ReportsFilters
} from './interfaces';
import { withPageData } from '../shared/page-data';

export { ReportsFilters } from './interfaces';

Expand All @@ -35,13 +36,17 @@ export function FullscreenWidget(
}
}
);
return withAmplitude(base);
return withAmplitude(withPageData(base));
}

export type IFullscreenWidget = ReturnType<typeof FullscreenWidget>;

export default function createFullscreenWidget(): Promise<IFullscreenWidget> {
return createConnection<IFullscreenWidgetEvents>().then(connection =>
FullscreenWidget(connection)
);
let widget: IFullscreenWidget;
return createConnection<IFullscreenWidgetEvents>()
.then(connection => {
widget = FullscreenWidget(connection);
return connection.sendMessage('plugin_inited');
})
.then(() => widget);
}

0 comments on commit 86d6634

Please sign in to comment.