customViews

Description

Static Custom Views

This allows you to add custom views in a specific location on the dashboard.

Types

export type BaseCustomView = {
  id: string;
};
 
export type StaticCustomView = BaseCustomView & {
  /* The index of the row where the component will be placed. */
  rowIndex: number;
  /* The index of the cell where the component will be placed. */
  cellIndex: number;
  /* The component to render. 
  The component can be a React component or a string.
  */
  Component: (params: CustomViewCallbackParams) => JSX.Element | string;
  /* The options for the component. */
  options?: {
    /* Disable the ability to add a cell to a row where the component is placed. */
    disableAddCell?: boolean;
    /* Removes the Panel that contains the component. */
    raw?: boolean;
  };
  /* The attributes for the component. */
  attributes?: {
    /* The title of the component. */
    displayTitle?: string;
    /* The subject of the component. */
    displaySubject?: string;
  };
};
<Vizzly.Dashboard
  customViews={[
    {
      id: '<< A UNIQUE ID >>',
      Component: () => <div>Custom view</div>,
      rowIndex: 0,
      cellIndex: 0,
    },
  ]}
/>

Selectable Custom Views

These will appear in the Views dropdown in the Editor and can be selected. They can place them anywhere on the dashboard.

It's currently not possible for the end user to add properties to these components.

Types

export type BaseCustomView = {
  id: string;
};
 
export type SelectableCustomView = BaseCustomView & {
  title: string;
  Icon: () => JSX.Element;
  Component: (params: CustomViewCallbackParams) => JSX.Element | string;
};
<Vizzly.Dashboard
  customViews={[
    {
      id: '<< A UNIQUE ID >>',
      Component: () => <div>Custom view</div>,
      title: '<< A TITLE >>',
      Icon: () => <div style={{ width: 20, height: 20 }} />,
    },
  ]}
/>

Using the property with Vizzly Query Engine

The Component in the Custom View makes available dashboardFilters, this contains the selected filters on the dashboard. If you want your component to behave based on what the user has selected you can pass this into your query and it will only return data that matches the filters.

You can use the customViews in conjunction with the query API to build your own custom components.

Types

export type DataSetDashboardFilters = { [dataSetId: string]: QueryAttributes.Filter[][] };
 
export type CustomViewCallbackParams = {
  dashboardFilters: DataSetDashboardFilters;
  attributes?: Component.CustomViewAttributes;
};

Example

Make sure both @vizzly/services and @vizzly/dashboard packages are installed.

import React, { Fragment, useEffect, useState } from 'react';
import { Dashboard } from '@vizzly/dashboard';
import { QueryResponse, Vizzly } from '@vizzly/services';
 
export default () => {
  const [vizzlyLoaded, setVizzlyLoaded] = useState<boolean>(false);
 
  useEffect(() => {
    async function initializeVizzly() {
      try {
        await Vizzly.load({
          queryEngine: 'https://example.vizzly.co/query-engine',
          identity: getIdentity('new_user'),
        });
        const instance = await Vizzly.waitToUse();
        setVizzlyLoaded(!!instance);
      } catch (err) {
        console.error(err);
      }
    }
 
    initializeVizzly();
  }, []);
 
  if (!vizzlyLoaded) {
    return <div>Loading...</div>;
  }
 
  return (
    <Dashboard
      customViews={[
        {
          id: 'string',
          Component: (params: CustomViewCallbackParams) => (
            // In your code, add a component like we have in this example with CustomView.
            <CustomChart dashboardFilters={params?.dashboardFilters} />
          ),
          rowIndex: 1,
          cellIndex: 1,
        },
      ]}
    />
  );
};
 
const CustomChart: FunctionComponent<{ dashboardFilters: DataSetDashboardFilters }> = ({ dashboardFilters }) => {
  const [componentResponse, setComponentResponse] = useState<QueryResponse | null>(null);
 
  useEffect(() => {
    const doSomething = async () => {
      const vizzly = Vizzly.use();
      const response: QueryResponse = await vizzly.query(
        [
          {
            filter: [],
            measure: [
              {
                field: 'fie_1',
                function: 'sum',
              },
            ],
            dimension: [
              {
                field: 'fie_1',
                function: 'none',
                pivot: 'x',
              },
            ],
            timeDimension: null,
            dataSetId: 'data_set_1',
            order: [],
            limit: 5000,
          },
        ],
        // here we pass in the dashboardFilters brought in from the parent component
        // and used in your custom query.
        { dashboardFilters }
      );
      setComponentResponse(response);
    };
 
    doSomething();
  }, [dashboardFilters]);
 
  if (componentResponse === null) return <div>Loading...</div>;
 
  return <div>{JSON.stringify(componentResponse.results)}</div>;
};

Examples Gallery

Customised Header Row

Create a header row or action bar using the customViews property. It allows you to match your current design guidelines to create a consistent experience.

<Vizzly.Dashboard
  customViews={[
    {
      id: 'row-header',
      Component: () => (
       <div
          style={{
            display: 'flex',
            alignItems: 'center',
            width: '100%',
            justifyContent: 'space-between',
            borderBottom: '2px solid #cdcfd3',
          }}
        >
          <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
            <span>
              <svg
                width="48px"
                height="48px"
                viewBox="0 0 1024 1024"
                className="icon"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
              >
                <path d="M512 301.2m-10 0a10 10 0 1 0 20 0 10 10 0 1 0-20 0Z" fill="#E73B37" />
                <path
                  d="M400.3 744.5c2.1-0.7 4.1-1.4 6.2-2-2 0.6-4.1 1.3-6.2 2z m0 0c2.1-0.7 4.1-1.4 6.2-2-2 0.6-4.1 1.3-6.2 2z"
                  fill="#39393A"
                />
                <path
                  d="M511.8 256.6c24.4 0 44.2 19.8 44.2 44.2S536.2 345 511.8 345s-44.2-19.8-44.2-44.2 19.9-44.2 44.2-44.2m0-20c-35.5 0-64.2 28.7-64.2 64.2s28.7 64.2 64.2 64.2 64.2-28.7 64.2-64.2-28.7-64.2-64.2-64.2z"
                  fill="#E73B37"
                />
                <path
                  d="M730.7 529.5c0.4-8.7 0.6-17.4 0.6-26.2 0-179.6-86.1-339.1-219.3-439.5-133.1 100.4-219.2 259.9-219.2 439.5 0 8.8 0.2 17.5 0.6 26.1-56 56-90.6 133.3-90.6 218.7 0 61.7 18 119.1 49.1 167.3 30.3-49.8 74.7-90.1 127.7-115.3 39-18.6 82.7-29 128.8-29 48.3 0 93.9 11.4 134.3 31.7 52.5 26.3 96.3 67.7 125.6 118.4 33.4-49.4 52.9-108.9 52.9-173.1 0-85.4-34.6-162.6-90.5-218.6zM351.1 383.4c9.2-37.9 22.9-74.7 40.6-109.5a502.1 502.1 0 0 1 63.6-95.9c17.4-20.6 36.4-39.9 56.8-57.5 20.4 17.6 39.4 36.9 56.8 57.5 24.8 29.5 46.2 61.8 63.6 95.9 17.7 34.8 31.4 71.6 40.6 109.5 8.7 35.8 13.5 72.7 14.2 109.9C637.4 459 577 438.9 512 438.9c-65 0-125.3 20.1-175.1 54.4 0.7-37.2 5.5-74.1 14.2-109.9z m-90.6 449.2c-9.1-27-13.7-55.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 20.8 103.2 0 31-5.3 61.3-15.7 90z"
                  fill="#39393A"
                />
                <path
                  d="M512 819.3c8.7 0 24.7 22.9 24.7 60.4s-16 60.4-24.7 60.4-24.7-22.9-24.7-60.4 16-60.4 24.7-60.4m0-20c-24.7 0-44.7 36-44.7 80.4 0 44.4 20 80.4 44.7 80.4s44.7-36 44.7-80.4c0-44.4-20-80.4-44.7-80.4z"
                  fill="#E73B37"
                />
              </svg>
            </span>
            <h3>
              Custom Row
            </h3>
          </div>
          <div>
            <button>Custom Action</button>
          </div>
        </div>
      ),
      rowIndex: 5,
      cellIndex: 0,
      options: {
        disableAddCell: true,
        raw: true,
      },
    },
  ]}
/>