This package has been deprecated

Author message:

Package has been deprecated in favor of @cumul.io/react-native-cumulio-dashboard

react-native-cumulio
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

React Component Library

This is a React native library for embedding Cumul.io dashboards in your react native application.

Install

npm i react-native-cumulio

OR

yarn add react-native-cumulio

Extra things to do for react native

This library has a peer dependency on react-native-webview to render the dashboards.

Example

An example version can be found on https://snack.expo.io/@sandergo90/react-native-cumulio. You can play with it and try out the example on iOS or Android.

Usage

Add higher order context provider

This library makes use of the React state and context functionality.

More info about React context can be found here

Therefore all components that want to access the cumulio data and use the external actions, need to be wrapped in this context. All children in the App component will now have access to Cumulio data.

import React, { useReducer } from "react";
import {
    CumulioContext,
    initialState,
    reducer
} from "react-native-cumulio";

const [state, dispatch] = useReducer(reducer, initialState);

<CumulioContext.Provider value={{ state, dispatch }}>
    <App />
</CumulioContext.Provider>

Use component

Render dashboard

The component can now be used and the state can be accessed. Include the component by:

<CumulioComponent
    dashboardId="dashboardId"
    language="en"
/>

OR render a single chart

<CumulioComponent
    dashboardId="dashboardId"
    chartId="chartId"
    language="en"
/>

Available Inputs
Below a list of available input options you can pass to the component. If you like, you can always take a look at the typescript definitions in the cumulio-model.ts file

dashboardId: string;                // The id of the Cumul.io dashboard you wish to embed.
chartId: string;                    // The id of the Cumul.io chart you wish to embed (Default: null)
authKey: string;                    // Authorization key generated via Cumul.io API (Default: null)
authToken: string;                  // Authorization token generated via Cumul.io API (Default: null)
language: string;                   // Sets the language of errors and loader, eg. 'en' (Default: 'auto')
screenmode: string;                 // Sets the screenmode of your dashboard: 'mobile', 'tablet', 'desktop', 'largeScreen', 'fixed' (Default: 'auto'). There is a ScreenMode enum available that can be used to simplify your code.
switchScreenmodeOnResize: boolean;  // true: the embedded dashboard can switch screenmodes on resize of the container , false: Dashboard will keep the same screenmode (Default: true)
loaderBackground: string;           // Background color of the loader element (Default: '#f9f9f9')
loaderFontColor: string;            // Font color of the text of the loaders (Default: '#5a5a5a')
loaderSpinnerColor: string;         // Spinner color of the loader (Default: 'rgba(255, 165, 0, 0.7)')
loaderSpinnerBackground: string;    // Background color of the spinner (Default: 'rgba(169, 169, 169, 0.14)')
loaderLogoColor: string;    // Background color of the spinner (Default: 'orange')
chartDimensions: Object;            // (optional) The desired dimensions of the single chart you want to embed; can be set when 'chartId' is set, chartDimensions : { width: 100, height: 200 }. (Default: { width: 'auto', height: 'auto' }) 

Examples

A dashboard with a gray loader background

<CumulioComponent
    dashboardId="035c0304-0bfe-4b7c-8c10-a4acb8eb9d76"
    loaderBackground="rgb(238,243,246)"
/>

A dashboard with a purple spinner color of the loader with screenmode mobile and switchScreenmodeOnResize on false, so that the dashboard will stay in mobile mode

import {
    ScreenMode,
} from "react-native-cumulio";

<CumulioComponent
    dashboardId="55cfb99c-d602-492b-b192-6c15277fdb9a"
    loaderSpinnerColor="purple"
    screenMode={ScreenMode.MOBILE}
    switchScreenmodeOnResize={false}
/>

Public methods that can be dispatched

There are a few methods that can be dispatched using the React state. This actions will execute a specific method on cumul.io. You can use the useCumulio() hook provided by the package. This hook will give you access to:

const { state, dispatch } = useCumulio();

The dispatch method allows a action to be passed.

const { state, dispatch } = useCumulio();

dispatch(getDataAction(
    {
        chartId: "eb626f65-7c67-4cde-b365-d73c00bee0b7",
        dashboard: {
            dashboardId: "763177aa-9b93-4ae7-903e-3cb07dc593d8"
        }
    }
));

Dispatch the action and the data will be available inside the state variable.

The following state variables can be accessed.

dashboards: CumulioDashboard[];   // Returns an array of all the visible dashboards on a page with their information
filters: IDashboardFilters[];     // Returns an array of all visible dashboards with their active filters
data: object[];                   // Array with processed chart data

Possible actions and their parameters:

1. getDataAction

Returns an array the data of a chart of a certain dashboard by adding the dashboardId or the container of the iframe.

Properties that can be passed to the action.

interface IGetDataPayload {
    chartId: string;
    dashboard?: {
        dashboardId?: string;
        container?: string;
    };
}

2. refreshDataAction

Refreshes the data of a specific chart when the id of that chart is supplied. Without a chartId this refreshes the data in all charts.

Properties that can be passed to the action.

interface IRefreshDataPayload {
    id?: string;
}

3. setAuthorizationAction

Changes the authorization of all or one dashboard and refreshes the data of those dashboards

Properties that can be passed to the action.

interface ISetAuthorizationPayload {
    authKey: string;
    authToken: string;
    dashboard?: {
        dashboardId?: string;
        container?: string;
    };
}

4. reloadDashboardAction

Reloads the dashboard. (useful when the authorization is changed, and dashboard needs to be reloaded without reloading the iFrame).

Quick links

Cumul.io |

Package Sidebar

Install

npm i react-native-cumulio

Weekly Downloads

1

Version

1.0.1

License

none

Unpacked Size

493 kB

Total Files

41

Last publish

Collaborators

  • luzmoteam
  • cumul.io_team