AboutSupportDeveloper GuideVersion 19.1.23

Type alias WorkspacePlatformOverrideCallback

WorkspacePlatformOverrideCallback: OpenFin.OverrideCallback<WorkspacePlatformProvider>

Extend or replace default functionality in order to customize behavior of a Workspace Platform Provider.

To implement your own handlers for Workspace Platform behavior, extend the provided class and override any methods you'd like to alter.

import * as WorkspacePlatform from '@openfin/workspace-platform';
import { UpdateSavedPageRequest } from '@client-platform/shapes';

const overrideCallback: WorkspacePlatform.WorkspacePlatformOverrideCallback = async (
WorkspacePlatformProvider
) => {
class Override extends WorkspacePlatformProvider {
// Override the default behavior of updateSavedPage
updateSavedPage = async (req: UpdateSavedPageRequest): Promise<void> => {
console.log(`saving page ${req.page.pageId}`);
// calling custom function to the save page here
};

// add a custom menu item in Global Context Menu
openGlobalContextMenu(req: WorkspacePlatform.OpenGlobalContextMenuPayload, callerIdentity: any) {
return super.openGlobalContextMenu(
{
...req,
template: [
...req.template,
{
label: 'Sample custom global option',
data: {
type: GlobalContextMenuOptionType.Custom,
action: {
// This action needs to be registered in customActions property in the call WorkspacePlatform.init
id: 'sample-custom-global-menu-action'
}
}
}
]
},
callerIdentity
);
}

// add a custom menu item in View Tab Context Menu
openViewTabContextMenu = async (payload: OpenViewTabContextMenuPayload, callerIdentity) => {
const viewsInfo = await Promise.all(payload.selectedViews.map(async (v) => fin.View.wrapSync(v).getInfo()));

const enableBack = viewsInfo.every((viewInfo) => viewInfo.canNavigateBack === true);
const enableForward = viewsInfo.every((viewInfo) => viewInfo.canNavigateForward === true);

return super.openViewTabContextMenu({
...payload,
template: [
{
label: 'Sample View Tab Context Menu',
data: {
type: ViewTabMenuOptionType.Custom,
action: {
// This action needs to be registered in customActions property in the call WorkspacePlatform.init
id: 'sample-viewtab-action',
customData: 'Custom View Tab Action'
}
}
},
{
type: 'normal',
label: 'Back',
data: {
type: ViewTabMenuOptionType.Back
},
enabled: enableBack
},
{
type: 'normal',
label: 'Forward',
data: {
type: ViewTabMenuOptionType.Forward
},
enabled: enableForward
},
...payload.template
]
}, callerIdentity);
};

// add a custom menu item in Save Context Menu
openSaveButtonContextMenu = (req: WorkspacePlatform.OpenSaveButtonContextMenuPayload, callerIdentity: OpenFin.Identity) => {
return super.openSaveButtonContextMenu(
{
...req,
template: [
...req.template,
{
label: 'Save custom option',
data: {
type: SaveButtonContextMenuOptionType.Custom,
action: {
id: 'sample-custom-action-name',
customData: {
someProp: 'Save Button task'
}
}
}
}
]
},
callerIdentity
);
}
}
return new Override();
};

await WorkspacePlatform.init({
browser: {
title: "My Workspace Platform"
}
overrideCallback,
customActions: {
'sample-custom-global-menu-action': (payload: CustomActionPayload) => {
alert('This custom action works ' + JSON.stringify(payload));
return 'someresponse';
},
'sample-viewtab-action': (payload: ViewTabCustomActionPayload) => {
alert('This custom action works ' + JSON.stringify(payload));
return 'someresponse';
}
}
});