ActiveUI

ActiveUI

  • User Guide
  • Developer Documentation

›Getting Started

About

  • Introduction
  • Changelog

Getting Started

  • Step by Step
  • Development Environment
  • Artifacts
  • ActiveUI Application
  • Usage as an npm Dependency
  • Initialization
  • Project Architecture

Guides

  • Adding KaTex fonts
  • Adding Servers
  • Authentication
  • Bookmark favorites
  • Charts
  • Configuring Widget Handlers and Actions
  • Container
  • Custom UI components with Ant Design
  • Data manipulation
  • Debugging
  • Deployment
  • Internationalization
  • MDX Manipulation
  • Plugins
  • Reporting
  • Settings
  • Tabular View and Pivot Tables
  • Testing

Reference

  • API Reference
  • Default Widget Bookmarks
  • Plugins
  • Settings

Advanced

  • Content Server Setup
  • Experimental Features
  • Maven Integration
  • Offline Installation
  • Script-based Integration

Project Architecture

It is important to take care with the architecture of your project, to keep it maintainable and easily testable.

We strongly advise against exporting an instance of ActiveUI and importing it directly. This is a singleton pattern and it will prevent you from writing tests in isolation.

Instead you should use the <ActiveUIProvider /> component, and the useActiveUI hook:

// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {createActiveUI, ActiveUIProvider} from '@activeviam/activeui-sdk';
import {App} from './App';

const activeUI = createActiveUI();

ReactDOM.render(
  <ActiveUIProvider activeUI={activeUI}>
    <App />
  </ActiveUIProvider>,
  document.getElementById('root'),
);
// App.js
import React from 'react';
import {useActiveUI} from '@activeviam/activeui-sdk';

export function App() {
  const activeUI = useActiveUI();
  return <span>{activeUI.settings.get('global.locale')}</span>;
}

By using useActiveUI instead of importing activeUI directly our component is not tied to a specific instance of ActiveUI.

To further decouple your components, you could separate App into App and AppContainer, where AppContainer is concerned with getting props from activeUI.

// App.js
import React from 'react';

export function App(props) {
  return <span>{props.locale}</span>;
}
// AppContainer.js
import React from 'react';
import {App} from './App';
import {useActiveUI} from '@activeviam/activeui-sdk';

export function AppContainer() {
  const activeUI = useActiveUI();
  return <App locale={activeUI.settings.get('global.locale')} />;
}

This way <App /> can be tested on its own, without having to create and provide an instance of ActiveUI.

There are other ways of getting access to ActiveUI from React context if you need them:

  • ActiveUIConsumer
    • Can be used inside JSX.
  • ActiveUIContext
    • Can be used with contextType or React.useContext.
  • See React's context docs for more information.
← InitializationAdding KaTex fonts →
Copyright © 2023 ActiveViam