Skip to content

Commit fbfd247

Browse files
authored
feat: Emit data mask and other missing functions from OSS (#31)
* feat: Emit data mask and other missing functions from OSS * bump version
1 parent 4e82502 commit fbfd247

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@preset-sdk/embedded",
3-
"version": "0.1.12",
3+
"version": "0.1.13",
44
"description": "Frontend SDK for embedding Preset data analytics into your own application",
55
"access": "public",
66
"keywords": [

src/index.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type UiConfigType = {
1717
hideTitle?: boolean
1818
hideTab?: boolean
1919
hideChartControls?: boolean
20+
emitDataMasks?: boolean
2021
filters?: {
2122
[key: string]: boolean | undefined
2223
visible?: boolean
@@ -52,9 +53,22 @@ export type Size = {
5253
width: number, height: number
5354
}
5455

56+
export type ObserveDataMaskCallbackFn = (
57+
dataMask: Record<string, any> & {
58+
crossFiltersChanged: boolean
59+
nativeFiltersChanged: boolean
60+
}
61+
) => void
62+
5563
export type EmbeddedDashboard = {
5664
getScrollSize: () => Promise<Size>
5765
unmount: () => void
66+
getDashboardPermalink: (anchor: string) => Promise<string>
67+
getActiveTabs: () => Promise<string[]>
68+
observeDataMask: (
69+
callbackFn: ObserveDataMaskCallbackFn
70+
) => void
71+
getDataMask: () => Record<string, any>
5872
}
5973

6074
/**
@@ -97,6 +111,9 @@ export async function embedDashboard({
97111
if(dashboardUiConfig.hideChartControls) {
98112
configNumber += 8
99113
}
114+
if (dashboardUiConfig.emitDataMasks) {
115+
configNumber += 16
116+
}
100117
}
101118
return configNumber
102119
}
@@ -169,11 +186,24 @@ export async function embedDashboard({
169186
}
170187

171188
const getScrollSize = () => ourPort.get<Size>('getScrollSize');
172-
189+
const getDashboardPermalink = (anchor: string) =>
190+
ourPort.get<string>('getDashboardPermalink', { anchor })
191+
const getActiveTabs = () => ourPort.get<string[]>('getActiveTabs')
192+
const getDataMask = () => ourPort.get<Record<string, any>>('getDataMask')
193+
const observeDataMask = (
194+
callbackFn: ObserveDataMaskCallbackFn
195+
) => {
196+
ourPort.start()
197+
ourPort.defineMethod('observeDataMask', callbackFn)
198+
}
173199
return {
174200
getScrollSize,
175201
unmount,
176-
};
202+
getDashboardPermalink,
203+
getActiveTabs,
204+
observeDataMask,
205+
getDataMask
206+
}
177207
}
178208

179209
export function _initComms(window: Window, targetOrigin: string, debug = false) {

0 commit comments

Comments
 (0)