embed-dossier-mstr-react
Version:
A production-ready React library for embedding MicroStrategy Dossiers, Reports, and Bot Consumption pages with full TypeScript support.
428 lines (347 loc) โข 11.5 kB
Markdown
# embed-dossier-mstr-react
[](https://www.npmjs.com/package/embed-dossier-mstr-react)
[](https://opensource.org/licenses/MIT)
[](https://www.typescriptlang.org/)
[](https://vitest.dev/)
> A production-ready React library for embedding MicroStrategy Dossiers, Reports, and Bot Consumption pages with full TypeScript support and comprehensive testing.
## ๐ Features
- **๐ฏ Type-Safe**: Full TypeScript support with 40+ interfaces and type definitions
- **โก Performance Optimized**: Lazy SDK loading, error boundaries, and efficient re-render prevention
- **๐งช Well-Tested**: Comprehensive unit tests with Vitest and React Testing Library
- **๐ฆ Multiple Integration Patterns**: Components, hooks, and authenticated variants
- **๐จ Highly Customizable**: 20+ configuration options for UI, navigation, and features
- **๐ Comprehensive Documentation**: 23+ API reference pages with examples
- **๐ Authentication Support**: Built-in authentication handling with custom token support
- **๐ Event-Driven**: 22 event handlers for complete lifecycle control
## ๐ Table of Contents
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Architecture](#architecture)
- [Advanced Usage](#advanced-usage)
- [API Reference](#api-reference)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)
## ๐ฏ Use Cases
This library is ideal for:
- Embedding interactive MicroStrategy dashboards in React applications
- Building custom analytics portals with MicroStrategy integration
- Creating white-labeled BI solutions
- Integrating MicroStrategy reports into existing React ecosystems
## ๐ฆ Installation
```bash
npm install embed-dossier-mstr-react
```
or
```bash
yarn add embed-dossier-mstr-react
```
or
```bash
pnpm add embed-dossier-mstr-react
```
**Requirements:**
- React 18.2.0 or higher
- TypeScript 5.5+ (for TypeScript projects)
- Modern browser with ES6+ support
## ๐๏ธ Architecture
This library is built with modern development practices:
```
embed-dossier-mstr-react/
โโโ src/
โ โโโ components/ # React components
โ โ โโโ DashboardEmbed
โ โ โโโ DashboardEmbedWithAuth
โ โ โโโ BotConsumptionPage
โ โ โโโ LibraryPageEmbed
โ โโโ hooks/ # Custom React hooks
โ โ โโโ useCreateDashboard
โ โ โโโ useCreateDashboardWithAuth
โ โ โโโ useCreateBotConsumptionPage
โ โ โโโ useLoadMstrSDK
โ โโโ types/ # TypeScript definitions (40+ interfaces)
โ โ โโโ index.ts # Core types
โ โ โโโ events.ts # Event handlers (22 types)
โ โ โโโ filter.ts # Filter configurations
โ โ โโโ navigation.ts # Navigation interfaces
โ โ โโโ settings.ts # Settings & customization
โ โโโ tests/ # Comprehensive test suite
โ โโโ utils.ts # Helper functions
โโโ vitest.config.ts # Test configuration
โโโ tsconfig.json # TypeScript configuration
```
**Key Technical Decisions:**
- **Monorepo Architecture**: Uses Turborepo for efficient build orchestration
- **Lazy Loading**: MicroStrategy SDK loaded on-demand to optimize initial bundle size
- **Error Boundaries**: Graceful error handling with fallback UI
- **Event-Driven Design**: 22 event handlers for complete application lifecycle control
- **Type Safety**: Comprehensive TypeScript definitions prevent runtime errors
## โก Quick Start
### Basic Usage
The simplest way to embed a MicroStrategy Dossier:
```tsx
import { DashboardEmbed } from "embed-dossier-mstr-react";
const MinimalTemplateEmbed = () => {
return (
<DashboardEmbed
dossierUrl="https://demo.microstrategy.com/MicroStrategyLibrary/app/B7CA92F04B9FAE8D941C3E9B7E0CD754/27D332AC6D43352E0928B9A1FCAF4AB0"
style={{
width: "1000px",
height: "1200px",
}}
/>
);
};
export default MinimalTemplateEmbed;
```
That's it! You have successfully embedded a dashboard with automatic SDK loading and error handling.
## ๐ง Advanced Usage
### Customized Configuration
For production applications, you'll want granular control over features and UI:
```tsx {6-79} showLineNumbers
import {
DashboardEmbed,
MicroStrategyDossierConfig,
} from "embed-dossier-mstr-react";
const dossierConfig: Omit<MicroStrategyDossierConfig, "placeholder" | "url"> = {
customUi: {},
disableNotification: true,
dockedComment: {
dockedPosition: "left",
canClose: true,
dockChangeable: false,
isDocked: false,
},
dockedFilter: {
dockedPosition: "left",
canClose: true,
dockChangeable: false,
isDocked: false,
},
dossierFeature: {
readonly: false,
},
enableCollaboration: true,
enableCustomAuthentication: false,
enableResponsive: true,
filterFeature: {
enabled: true,
edit: true,
summary: true,
},
filters: [],
navigationBar: {
enabled: true,
gotoLibrary: true,
title: true,
toc: true,
reset: true,
reprompt: true,
share: true,
comment: true,
notification: true,
filter: true,
options: true,
bookmark: true,
edit: false,
},
optionsFeature: {
enabled: true,
help: false,
logout: true,
manage: false,
showTutorials: false,
},
shareFeature: {
enabled: true,
invite: false,
link: true,
email: false,
export: true,
download: false,
shareDossier: false,
subscribe: false,
},
smartBanner: false,
tocFeature: {
enabled: true,
},
uiMessage: {
enabled: true,
addToLibrary: false,
},
visibleTutorials: {
library: true,
welcome: false,
dossier: true,
notification: false,
},
};
const SimpleDashboardEmbed = () => {
return (
<DashboardEmbed
dossierUrl="https://demo.microstrategy.com/MicroStrategyLibrary/app/B7CA92F04B9FAE8D941C3E9B7E0CD754/27D332AC6D43352E0928B9A1FCAF4AB0"
config={dossierConfig}
style={{
width: "1000px",
height: "1200px",
}}
/>
);
};
export default SimpleDashboardEmbed;
```
**Key Configuration Options:**
- **Navigation Bar**: Control visibility of 14+ UI elements (share, filter, bookmark, etc.)
- **Docked Panels**: Configure comment and filter panel behavior
- **Features**: Enable/disable collaboration, responsive design, tutorials
- **Sharing**: Granular control over export, download, and sharing capabilities
## ๐ฃ Hook-Based Integration
For maximum flexibility and control over the dashboard lifecycle:
```tsx
import cn from "classnames";
import {
getInfoFromUrl,
MicroStrategyDossierConfig,
useCreateDashboard,
} from "embed-dossier-mstr-react";
interface EmbedWithHooksProps {
dossierUrl: string; // https://{env-url}/{libraryName}/app/{projectId}/{dossierId}
className?: string;
style?: React.CSSProperties;
config?: Omit<MicroStrategyDossierConfig, "placeholder" | "url">;
}
const EmbedWithHooks = ({
dossierUrl,
className,
style,
config,
}: EmbedWithHooksProps) => {
let serverUrlLibrary = "";
try {
const urlInfo = getInfoFromUrl(dossierUrl);
serverUrlLibrary = urlInfo.serverUrlLibrary;
} catch (error) {
console.error("Failed to parse dossier URL:", error);
}
const { dashboard, containerRef, isSdkLoaded, isDashboardError } =
useCreateDashboard({
serverUrlLibrary,
config: {
url: dossierUrl,
...config,
},
});
if (isDashboardError) {
return <div>Failed to load dashboard</div>;
}
if (!isSdkLoaded) {
return <div>Loading...</div>;
}
if (dashboard) {
console.log("Dashboard instance created:", dashboard);
// Access dashboard methods:
// - dashboard.getCurrentPageVisualization()
// - dashboard.setFilterState()
// - dashboard.refresh()
}
return <div ref={containerRef} className={cn(className)} style={style} />;
};
export { EmbedWithHooks };
```
**Hook Benefits:**
- Access to dashboard instance for programmatic control
- Custom loading and error states
- Fine-grained lifecycle management
- Integration with existing state management
### Authentication Support
For applications requiring secure access:
```tsx
import { DashboardEmbedWithAuth } from "embed-dossier-mstr-react";
const SecureDashboard = () => {
return (
<DashboardEmbedWithAuth
dossierUrl="https://your-server.com/MicroStrategyLibrary/app/{projectId}/{dossierId}"
authToken="your-auth-token"
style={{ width: "100%", height: "800px" }}
/>
);
};
```
## ๐ API Reference
This library provides comprehensive TypeScript definitions:
### Components
- `DashboardEmbed` - Basic dossier embedding
- `DashboardEmbedWithAuth` - Authenticated dossier embedding
- `BotConsumptionPage` - Bot consumption page embedding
- `LibraryPageEmbed` - MicroStrategy library page
### Hooks
- `useCreateDashboard` - Create dashboard instance
- `useCreateDashboardWithAuth` - Create authenticated dashboard
- `useCreateBotConsumptionPage` - Create bot consumption page
- `useLoadMstrSDK` - Load MicroStrategy SDK
### Types & Interfaces
Over 40 TypeScript interfaces including:
- `MicroStrategyDossierConfig` - Main configuration interface
- `EventHandlers` - 22 event handler types
- `NavigationBar` - Navigation customization
- `CustomUi` - UI customization options
- `FilterTypeInfo` - Filter configurations
- And many more...
[๐ View Full API Documentation](https://your-docs-url.com)
## ๐งช Testing & Quality Assurance
This library maintains high code quality standards:
```bash
# Run unit tests
pnpm test
# Run tests with UI
pnpm test:ui
# Generate coverage report
pnpm coverage
```
**Testing Stack:**
- **Vitest**: Fast unit test runner
- **React Testing Library**: Component testing
- **jsdom**: DOM simulation
- **Coverage**: V8 coverage reporting
**Test Coverage:**
- โ
All components tested
- โ
All hooks tested
- โ
Edge cases covered (error handling, network failures)
- โ
Integration tests for authentication flow
## ๐ ๏ธ Development
```bash
# Install dependencies
pnpm install
# Development mode with hot reload
pnpm dev
# Build for production
pnpm build
# Lint code
pnpm lint
# Fix linting issues
pnpm lint:fix
```
## ๐๏ธ Project Structure
This is part of a monorepo built with:
- **Turborepo**: Build system optimization
- **TypeScript**: Type safety
- **Vitest**: Testing framework
- **Changesets**: Version management
- **pnpm**: Fast, efficient package manager
## ๐ค Contributing
Contributions are welcome! This project demonstrates:
1. Clean code architecture
2. Comprehensive testing
3. Type-safe development
4. Modern React patterns
5. Performance optimization
## ๐ License
MIT ยฉ [Your Name]
## ๐ Links
- [Documentation](https://your-docs-url.com)
- [npm Package](https://www.npmjs.com/package/embed-dossier-mstr-react)
- [GitHub Repository](https://github.com/Ibrairsyad17/embed-dossier-mstr)
- [Issue Tracker](https://github.com/Ibrairsyad17/embed-dossier-mstr/issues)
**Built with โค๏ธ using React, TypeScript, and modern development practices**