Home App

Overview

The @interopio/home-ui-react library offers React hooks and components that enable you to create and customize a Home App for your io.Connect Browser projects. The Home App is meant to act as a Main app in your project.

Currently, the only supported option is to build a Home App that's also a Workspaces App.

Use the Home App template in GitHub as a startup skeleton to create and customize your own Home App.

Installation

To use the @interopio/home-ui-react library in your project, execute the following command:

npm install @interopio/home-ui-react

Using the Components

All default components can be reused and composed with custom code. If usage of such component has been detected, its default behavior will be applied. For instance, if you use the <SlidePanel /> component, it will automatically open the panel it contains when the user clicks on its icon, without the need of custom code to induce this behavior.

Home Component

Available since io.Connect Browser 3.2

The <IOConnectHome /> component is the root component for building a Home App. Its config property is the main customization point for the Home App. It accepts all required and optional settings for initializing and configuring the Home App as the Main app of your io.Connect Browser project, for configuring the authentication mechanism and the first-time user setup flow, and also for customizing the Workspaces App and the Launchpad.

The config object of the <IOConnectHome /> component has the following properties:

Property Type Description
getIOConnectConfig function Required. Accepts a function that will be called when initializing the Main app. It must return valid configuration for initializing the @interopio/react-hooks library. When called, the function will receive as an argument an object containing the user ID, password, authentication token, and more, depending on the configured authentication mechanism. You can use this object to extract the necessary authentication details for initializing the Main app (e.g., if your Main app is connected to io.Manager).
launchpad object Settings for the Launchpad used in the Home App.
login object Settings for the user authentication process.
setupFlow object Settings for the first-time user setup flow for requesting the necessary browser permissions.
workspaces object Settings for the Workspace App.

⚠️ Note that currently the only supported option is to build a Home App that's also a Workspaces App, so you must configure your Main app as a Workspaces App.

The following example demonstrates a basic configuration for the <IOConnectHome /> component. The configuration provides:

import { IOConnectHome } from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";

const getConfig = (user) => {
    // Platform configuration.
    const platformConfig = {
        browserPlatform: {
            factory: IOBrowserPlatform,
            config: {
                // Required license key.
                licenseKey: "my-license-key",
                // Workspaces App configuration.
                workspaces: {
                    src: "/",
                    isFrame: true
                },
                // Connection to io.Manager using Basic authentication.
                manager: {
                    url: "https://my-io-manager.com:4242/api",
                    auth: {
                        basic: {
                            // Extracting the user details from the `user` argument.
                            username: user.username,
                            password: user.password
                        }
                    },
                    critical: true
                }
            }
        }
    };

    return platformConfig;
};

// Configuration for the `<IOConnectHome />` component.
const config = {
    // Retrieve the platform configuration.
    getIOConnectConfig: getConfig,
    // Login settings.
    login: {
        type: "simple",
        onLogin: async (username, password) => {
            // Custom validation logic.
            await validateUser(username, password);

            const user = { id: username, username, password };

            return user;
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Login

The Home App provides two authentication mechanisms - simple and Auth0. The simple login consists of a form for the user credentials (username and password). You must provide a callback with your custom logic for validating the user credentials. The Auth0 login uses @auth0/auth0-react internally. It's required to provide the domain and the client ID for Auth0 authentication. You can also perform additional user validation after a successful Auth0 login, and based on the returned result, the user will be either authenticated, or automatically logged out of Auth0 and returned to the login screen. It's possible to customize the login pages for both types of login.

The following sections demonstrate how to provide configuration settings for the supported authentication mechanisms by using the config property of the <IOConnectHome /> component.

Simple Login

The following example demonstrates basic configuration for simple authentication:

import { IOConnectHome } from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    // Settings for simple login.
    login: {
        // Type must be set to `"simple"`.
        type: "simple",
        // Asynchronous callback for user validation.
        onLogin: async (username, password) => {
            // Custom validation logic.
            await validateUser(username, password);
            // Must return a `User` object.
            const user = { id: username, username, password };

            return user;
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

The login object for simple login accepts the following properties:

Property Type Description
components object Components for customizing the login page.
onLogin function Required. Asynchronous callback for user validation. Must return a User object.
onLogout function Callback for handling the user logout.
type "simple" Required. Type of the login. Must be set to "simple".
userInputName string This will modify the placeholder for the input field of the login form.

The callback supplied in the onLogin property must resolve with a User object with the following properties:

Property Type Description
avatarUrl string URL pointing to an image that will be used as a user avatar.
email string User email.
firstName string First name of the user.
id string Required. User ID.
lastName string Last name of the user.
password string Password for authentication.
token string Authentication token.
username string Username for authentication.

Auth0 Login

The following example demonstrates basic configuration for Auth0 authentication:

import { IOConnectHome } from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    // Settings for Auth0 login.
    login: {
        // Type must be set to `"auth0"`.
        type: "auth0",
        // Required settings for connecting to the Auth0 authentication provider.
        providerOptions: {
            domain: "my-domain.auth0.com",
            clientId: "my-client-id"
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

The login object for Auth0 login accepts the following properties:

Property Type Description
components object Components for customizing the login page.
loginType "popup" | "redirect" Type of the Auth0 login.
providerOptions object Required. Auth0ProviderOptions for connecting to the Auth0 authentication provider. The domain and clientId properties are required.
type "auth0" Required. Type of the login. Must be set to "auth0".
validateUser function Callback for additional user validation after a successful Auth0 login. If the the validation fails, the user will be automatically logged out of Auth0 and returned to the login screen.

The callback supplied in the validateUser property must return a result in one of the following shapes:

type ValidationResult = { ok: true } | { ok: false; message: string };

The specified error message will be shown to the user in case of an unsuccessful validation.

Customizing the Login Page

For both types of login, you can use the components property in the configuration object to provide custom components for the login page.

The components object has the following properties:

Property Type Description
Heading React.ComponentType Component for the heading displayed in the login page.
Logo React.ComponentType Component for the logo displayed in the login page.

The following example demonstrates providing custom logo and heading for the simple login page:

import { IOConnectHome } from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";
import logo from "./logo.png";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    login: {
        type: "simple",
        onLogin: async (username, password) => {
            // Custom validation logic.
        },
        // Custom components for the login page.
        components: {
            Logo: () => <img src={logo} />,
            Heading: () => <div>My Custom Heading</div>
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Custom Login Page

Setup Flow

To customize the first-time user setup flow of the Home App, use the setupFlow property of the config object for the <IOConnectHome /> component.

The setupFlow object has the following properties:

Property Type Description
components object Components for customizing the setup page. Currently, only a logo for the setup flow page can be specified.
enabled boolean If true (default), will enable the first-time user setup flow for requesting the necessary browser permissions.
settings object Settings for the setup process. Currently, only the edgeNotificationsPermissionTimeout property is available that specifies an interval in milliseconds to wait for the notifications permission prompt when using Microsoft Edge as a browser.

The following example demonstrates how to provide a custom logo for the setup flow page:

import { IOConnectHome } from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";
import logo from "./logo.png";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    // Setup flow settings.
    setupFlow: {
        // Custom logo for the setup flow page.
        components: {
            Logo: () => <img src={logo} />
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Custom Setup Page

Workspaces

To customize the Workspaces App of the Home App, use the workspaces property of the config object for the <IOConnectHome /> component.

The workspaces object has the following properties:

Property Type Description
components object Components for the <Workspaces /> component of the Workspaces App. For details on customizing the <Workspaces /> component, see the Windows > Workspaces > Workspaces App section.
HeaderLogoArea React.ComponentType Component for the header area of the Workspaces App. This component contains the icon that opens the Launchpad. You can use it to change this icon or to add additional icons and buttons inside the component that will provide other functionalities for your Home App (e.g., you can add an icon that opens the Notification Panel outside the Launchpad).

The following example demonstrates customizing the Launchpad icon and reusing the default <LaunchpadAccess /> component:

import { IOConnectHome, LaunchpadAccess } from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";
import icon from "./icon.png";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    // Customizing the Workspaces App with an icon for the Launchpad.
    workspaces: {
        HeaderLogoArea: () => <LaunchpadAccess icon={<img src={icon} />} />
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Custom Launchpad Icon

You can use the component provided to the HeaderLogoArea property to add more icons and buttons in the header area of the Workspaces App. The following example demonstrates reusing the default <NotificationsIcon />, <NotificationsPanel /> and the <SlidePanel /> components to display the Notification Panel outside the Launchpad, after the default Launchpad icon:

import {
    IOConnectHome,
    LaunchpadAccess,
    SlidePanel,
    NotificationsIcon,
    NotificationsPanel
} from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    // Extracting the Notification Panel outside the Launchpad.
    workspaces: {
        HeaderLogoArea: () => {
            return (
                <>
                    <LaunchpadAccess />
                    <SlidePanel icon={<NotificationsIcon />}>
                        {() => <NotificationsPanel />}
                    </SlidePanel>
                </>
            );
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Custom Notification Panel

Launchpad

To customize the Launchpad of the Home App, use the launchpad property of the config object for the <IOConnectHome /> component.

The launchpad object has the following properties:

Property Type Description
components object Components for the Launchpad.

The components object has the following properties:

Property Type Description
NotificationsPanel React.ComponentType | null Component for the Notification Panel of the Launchpad. Set to null to remove the Notification Panel from the Launchpad.
Sections React.ComponentType Component containing default or custom sections to be displayed in the Launchpad.
UserPanel React.ComponentType | null Component for the User Panel of the Launchpad. Set to null to remove the User Panel from the Launchpad.

The following example demonstrates removing the Notification Panel and providing a custom component for the User Panel in the Launchpad:

import { IOConnectHome } from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";
import MyCustomUserPanel from "./MyCustomUserPanel";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    // Customizing the Launchpad.
    launchpad: {
        components: {
            // Removing the Notification Panel.
            NotificationsPanel: null,
            // Providing a custom User Panel.
            UserPanel: MyCustomUserPanel
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Default Sections

The <FavoritesSection />, <WorkspacesSection /> and <ApplicationsSection /> components are the default sections of the Launchpad. You can reuse them, rearrange them and modify their behavior by passing them to the Sections property of the components object in the Launchpad configuration. Each of these components has the following properties:

Property Type Description
displayCount number The number of items to display at a time in the section. The rest of the items will be hidden and a "More" button will be displayed in the section. When the user clicks the "More" button, another set of items with equal to the number set for displayCount will be displayed.
isSectionCollapsible boolean If true, the section will be collapsible.
showAllItems boolean If true, all items in the section will be displayed.
sortOrder "ascending" | "descending" | "disabled" Specifies the order in which items in the section will be sorted (alphabetically for the "Applications" and "Workspaces" section, and by most recently added for the "Favorites" section). If set to "disabled", the items will be displayed in the order they are passed to the section.

The following example demonstrates rearranging the default sections, making the "Workspaces" and "Applications" sections collapsible, configuring the "Applications" section to show all items, and sorting the items in the "Favorites" section in a reverse order:

import {
    IOConnectHome,
    FavoritesSection,
    ApplicationsSection,
    WorkspacesSection
} from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

const config = {
    getIOConnectConfig: getConfig,
    launchpad: {
        components: {
            // Customizing the default sections.
            Sections: () => {
                return (
                    <>
                        <FavoritesSection sortOrder="descending" />
                        <ApplicationsSection isSectionCollapsible={true} showAllItems={true} />
                        <WorkspacesSection isSectionCollapsible={true} />
                    </>
                );
            }
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Custom Sections

The Sections property of the components object in the Launchpad configuration allows you to add your own custom sections to the Launchpad. You can reuse the default <Section /> component, or provide an entirely customized one.

The <Section /> component has the following properties:

Property Type Description
config object Required. Configuration for the section.
onItemClick function Callback for handling clicks on items in the section.

The config object has the following properties:

Property Type Description
displayCount number The number of items to display at a time in the section. The rest if the items will be hidden and a "More" button will be displayed in the section. When the user clicks the "More" button, another set of items with equal to the number set for displayCount will be displayed.
iconName string Name of an icon from the default io.Connect theme to be used for the section. Can be used instead of iconSrc.
iconSrc string URL pointing to the location of an icon to be used for the section.
id string Required. ID for the section.
isCollapsible boolean If true, the section will be collapsible.
items object[] Required. List of items or other sections to be displayed within the current section.
showAllItems boolean If true, all items in the section will be displayed.
title string Required. Title for the section.

The items array accept a list of objects each describing a section (as described above), or an item with the following properties:

Property Type Description
contextMenuActions object[] List of objects describing context menu actions that will be shown in the context menu for the item. Each object has a required name property and optional displayName and disabled properties. You can handle these actions in the callback provided to the onItemClick property of the section configuration.
description string Description for the icon.
icon string Name of an icon from the default io.Connect theme to be used for the section. Can be used instead of iconSrc.
iconSrc string URL pointing to the location of an icon to be used for the item.
id string Required. ID for the item.
isOpen boolean If true, will display an "Opened" label for the item, indicating that it is currently open (e.g., if an app is already running, or a Workspace is already opened).
title string Required. Title for the item.
type string Required. Type that can be used in search operations by the Search Bar.

The callback provided to the onItemClick property of the config object for the <Section /> component will receive as an argument an object with the following properties:

Property Type Description
item object Required. Object describing the clicked section item. This is the same object passed in the items array of the section configuration.
modifier string | null Required. Keyboard key used as a modifier when the action was clicked.
selectedContextMenuActionName string Name of the clicked context menu action.

The following example demonstrates rearranging the default sections, making the "Applications" section collapsible, and adding a custom collapsible section with several items in it. Clicking on an item in the custom section will perform a predefined action:

import {
    IOConnectHome,
    FavoritesSection,
    ApplicationsSection,
    WorkspacesSection,
    Section
} from "@interopio/home-ui-react";
import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/src/index.css";
import icon from "./icon.png";

const getConfig = (user) => {
    // Define and return the required platform configuration.
};

// Items for the custom section in the Launchpad.
const items = [
    {
        id: "custom-item",
        title: "Custom Item",
        type: "custom-type"
    },
    {
        id: "another-custom-item",
        title: "Another Custom Item",
        type: "custom-type"
    }
];

const config = {
    getIOConnectConfig: getConfig,
    launchpad: {
        components: {
            // Rearranging the default sections, making the "Applications" section collapsible,
            // and adding a custom section with items.
            Sections: () => {
                return (
                    <>
                        <FavoritesSection />
                        <ApplicationsSection isSectionCollapsible={true} />
                        <WorkspacesSection />
                        <Section
                            config={{
                                id: "my-section-id",
                                title: "Custom Section",
                                items,
                                iconSrc: icon,
                                isCollapsible: true
                            }}
                            onItemClick={({ item }) => alert(`Clicked "${item.title}".`)}
                        />
                    </>
                );
            }
        }
    }
};

const App = () => {
    return <IOConnectHome config={config} />
};

export default App;

Custom Launchpad Sections

Styles

To use the default styles for your custom Home App, import the following CSS files:

import "@interopio/workspaces-ui-react/dist/styles/workspaces.css";
import "@interopio/home-ui-react/index.css";

To use custom styles for the Home App, simply import your CSS file after the default CSS imports to override them. Two default themes are available - "Day" and "Night" - and the trigger for switching between them is the class property of the <html> element - "light" for the "Day" theme and "dark" for the "Night" theme:

<!-- Day theme -->
<html class="light">

<!-- Night theme -->
<html class="dark">

Hooks

The following lists the available hooks exported by the library:

Hook Description
useIsBrowserSupported() Checks whether the current browser is supported. The Home App requires support for the browser Window Management API.

The useIsBrowserSupported() hook returns a Boolean value that determines whether the browser is supported:

const isBrowserSupported = useIsBrowserSupported();

if (!isBrowserSupported) {
    return <div>Browser Not Supported</div>;
};

Components

The following lists the more important main components for building a Home App:

Component Description
<BrowserNotSupported /> Component showing a page when the current browser isn't supported.
<IOConnectHome /> The main component for building a Home App.

The following lists the more important components for building a Home App that's also a Workspaces App:

Component Description
<HomeAppWorkspace /> The main component for building a Home App that's also a Workspaces App.
<LaunchpadAccess /> Component containing an icon for the Launchpad in the header area of the Home App when the Home App is also a Workspaces App.

The following lists the more important components comprising the Launchpad:

Component Description
<ApplicationsSection /> Component containing a section in the Launchpad with the available io.Connect apps.
<FavoritesSection /> Component containing a section in the Launchpad with favorite items.
<Launchpad /> The main component containing the Launchpad.
<LaunchpadSlidePanel /> Wrapper component around the <Launchpad /> component allowing it to open as a sliding panel.
<LayoutsPanel /> Component containing a section in the Launchpad with Global Layout settings.
<Logo /> Default io.Connect logo for the Launchpad.
<NotificationsIcon /> Icon displayed in the Launchpad for opening the Notification Panel.
<NotificationsPanel /> Component containing the Notification Panel displayed when the user clicks on the notifications icon in the Launchpad.
<SearchBar /> Component containing a search bar.
<SearchResults /> Component containing the search results displayed when the user starts typing in the search bar.
<Section /> Component that can be used for creating custom sections in the Launchpad.
<SlidePanel /> Sliding panel that can be used to show icons and panels outside the Launchpad.
<UserPanel /> Component containing user details and settings displayed when the user clicks on the User Panel icon.
<UserPanelIcon /> Icon displayed in the Launchpad for opening the User Panel.
<WorkspacesSection /> Component containing a section in the Launchpad with Workspace Layouts.