@openfin/workspace
    TypeScript icon, indicating that this package has built-in type declarations

    4.0.0 • Public • Published

    Workspace Client API

    The Workspace Client APIs enable custom integrations with OpenFin Workspace. They can be used in any and only OpenFin apps.

    The Storefront API is the first Client API created.

    This API is experimental.

    Installation

    Run npm i -E @openfin/workspace.

    Storefront API documentation

    Code examples

    Vanilla JS

    import { Storefront, launchApp } from '@openfin/workspace';
    import { fetchMyApps, fetchMyLandingPage, fetchMyNavigation, fetchMyFooter } from './my-storefront-provider';
    
    Storefront.register({
        id: 'my-storefront',
        title: 'My Storefront',
        getApps: fetchMyApps,
        getLandingPage: fetchMyLandingPage,
        getNavigation: fetchMyNavigation,
        getFooter: fetchMyFooter,
        launchApp: launchApp // OpenFin's default implementation of launchApp, you can also define your own
    });
    
    document.getElementById('show-btn').addEventListener('click', () => {
        Storefront.show();
    });
    
    document.getElementById('hide-btn').addEventListener('click', () => {
        Storefront.hide();
    });

    React

    import { Storefront, launchApp } from '@openfin/workspace';
    import { fetchMyApps, fetchMyLandingPage, fetchMyNavigation, fetchMyFooter } from './my-storefront-provider';
    import React, { useEffect } from 'react';
    
    const App = () => {
        useEffect(() => {
            Storefront.register({
                id: 'my-storefront',
                title: 'My Storefront',
                getApps: fetchMyApps,
                getLandingPage: fetchMyLandingPage,
                getNavigation: fetchMyNavigation,
                getFooter: fetchMyFooter,
                launchApp: launchApp // OpenFin's default implementation of launchApp, you can also define your own
            });
        }, []);
    
        return (
            <>
                <button onClick={Storefront.show}>Show Store</button>
                <button onClick={Storefront.hide}>Hide Store</button>
            </>
        );
    };

    Home API

    API Reference: https://cdn.openfin.co/workspace/api/docs/interfaces/HomeAPI.html

    register(provider: HomeProvider): Promise<void>

    Registers a Home provider. Upon registering a provider, the search results from your provider will be rendered inside Home. See API reference for details which view each topic maps too. Throws an error if provider with provider.id already exists. See reference for definition of HomeProvider interface.

    Vanilla JS Example

    import { Home, HomeActionName, HomeSearchTemplate } from '@openfin/workspace';
    import { fetchMyLongRunningQueryResults, executeMyAction } from './my-provider';
    
    const onUserInput = ({ query, context }) => {
        // If the current search was triggered from the user selecting a suggestion, execute a expensive query.
        if (context.isSuggestion) {
            return { results: fetchMyLongRunningQueryResults() };
        }
    
        // Otherwise, return a cheap suggestion.
        // You can use the `Suggestion` action that is built into the Home UI.
        return {
            results: [
                {
                    key: '0',
                    template: HomeSearchTemplate.Plain,
                    title: `Search my home provider for ${query}`,
                    actions: [{ name: HomeActionName.Suggestion, query }]
                }
            ]
        };
    };
    
    /**
     * Optional method for executing actions that are specific to your Home provider.
     */
    const onResultDispatch = (res) => {
        if (res.action === 'execute-my-action') {
            return executeMyAction(res.data);
        }
    };
    
    Home.register({
        id: 'my-home-provider',
        title: 'My Home Provider',
        onUserInput,
        onResultDispatch
    });

    Keywords

    Install

    npm i @openfin/workspace

    DownloadsWeekly Downloads

    120

    Version

    4.0.0

    License

    MIT

    Unpacked Size

    147 kB

    Total Files

    59

    Last publish

    Collaborators

    • arvidh97
    • manamiueda
    • sakibahmad
    • shahossain
    • daveashton
    • openfinbrandon
    • richardgutan
    • pierrebaize
    • noyangunday
    • michaelmcoates
    • johnmandia-openfin
    • rdepena
    • tgoc99
    • wenjunche
    • harsimran.openfin.singh
    • luiemilio
    • patopenfin
    • tarsillon1
    • licui3936
    • rp-openfin
    • ljopenfin
    • connormccafferty
    • adam.saland
    • openfin-ci
    • chrishobsonexpero
    • vacunafin
    • richbrowne-openfin
    • nedwardsof
    • lomteslie
    • philvogt
    • doomsauce
    • azizyok
    • openfin-gavin
    • themetaterran
    • dewin.pena
    • oblarg
    • yongji.chen
    • tony.fong