stevegreatrex / birst-react-embed Goto Github PK
View Code? Open in Web Editor NEWEmbed React-generated content in Birst dashboards
License: MIT License
Embed React-generated content in Birst dashboards
License: MIT License
The way we currently 'Drill Down' to a dashboard in playerGrid
is by passing in a property on IProfileGridParameters
like so:
drillDown: {
dashboard: 'Collection',
page: 'React Embed Child Dashboard'
}
... where dashboard
is the Collection that contains the child dashboard and page
is the child dashboard that you wish to drill down to. (Collection
rather than dashboard
and childDashboard
instead of page
would make more sense in hindsight ๐ ).
This gets mapped to IProfileCardGridProps
which is available on each ProfileCard
and finally we use the following function onClick : drillDownHandler()
to send the operation to the window:
const drilldownHandler = (props: IProfileCardProps) => {
if(!props.drillDown)
return;
//Add a filter to the parent window
const parentWindow = window.parent as IBirstParentWindow;
parentWindow.filters = { drillDownFilter: props.playerName};
//Drill Down to the child dashboard
window.parent.postMessage( { operation: 'drillToDashboard', dashboard: props.drillDown.dashboard, page: props.drillDown.page }, '*' );
};
Sharoon and I feel that it would make sense for it to go on the birst-react-embed
library in a reusable function to make life easier and as you put it "reduce the amount of WTF".
The real general idea would still pass in the collection
and page
properties into createConnectedGrid
and then using a applyDrillDown
function that transforms the IBQLComponent
into an component with a drillDown
(I'm not sure I explained that very well.) Then the drillDown is available on each component and fillters would be optional.
We wrote some pseudo code to demonstrate how it could work:
const createConnectedGrid = (parameters: IProfileGridParameters) => {
const bqlComponent = createQuery(parameters);
if (parameters.drillDown) {
bqlComponent = applyDrilldown(bqlComponent, parameters.drillDown);
}
const Connected = connectToBirst(bqlComponent)(ProfileCardGrid);
return <Connected {...parameters} />;
};
function applyDrilldown<TBirstComponent>(component: TBirstComponent, drillDownParameters: IDrillDownParameters) {
function createDrillDownComponent<TDrillDownComponent extends TBirstComponent>(component: TBirstComponent, drillDownParameters: IDrillDownParameters){
// Set drilldown on params.
// return new component with drill down
}
}
I hope that makes some sense. Here's our current implementation for reference
Hey Steve, hope things are well.
I'm currently trying to port the Bodymap into a reusesable birst widget, and I'm having an issue when I try and use connectToBirst(createQuery(parameters))(BodyMapComponent)
.
If BodyMapComponent
is a stateless component it works fine but I'm getting to a point where I think need to be able to deal with state and when I make it into a class I get the following error:
ERROR in [at-loader] ./src/BodyMap/createConnectedBodyMap.tsx:38:60
TS2345: Argument of type 'typeof BodyMapContainer' is not assignable to parameter of type 'ComponentType<{ bodyParts: IBodyPart[]; } & { applyDrillDown(drillDown: IDrillDown): any; }>'.
Type 'typeof BodyMapContainer' is not assignable to type 'StatelessComponent<{ bodyParts: IBodyPart[]; } & { applyDrillDown(drillDown: IDrillDown): any; }>'.
Type 'typeof BodyMapContainer' provides no match for the signature '(props: { bodyParts: IBodyPart[]; } & { applyDrillDown(drillDown: IDrillDown): any; } & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.
webpack: Failed to compile.
A quick get around is to replace BodyMapComponent
with a stateless component wrapping BodyMapComponent
and this passes down the props, but obviously that feels a little wrong and I think this might be causing some issues with trying to pass through other HTMLparameters.
Here's my BodyMapContainer
component just in case I'm doing anything obvious:
import * as React from 'react';
import { IBodyPart } from '../IBodyPart';
import { BodyPart } from './BodyPart';
import { BodyMap } from './BodyMap';
import { Thumbnail } from './Thumbnail';
const css = require('../bodyMap.less');
export interface IBodyMapContainerProps {
bodyParts: IBodyPart[];
imageUrls: string;
};
interface IBodyMapContainerState {
backgroundImage: string;
}
export class BodyMapContainer extends React.Component<IBodyMapContainerProps, IBodyMapContainerState> {
constructor(props: IBodyMapContainerProps) {
super(props);
}
updateImage = (backgroundImage: string) => {
//Does something
};
render() {
return (
<div className='image-map-container'>
<div className='thumbnails'>
<Thumbnail onChange = { this.updateImage } backgroundImage = './Images/body-map-front.png'/>
<Thumbnail onChange = { this.updateImage } backgroundImage = './Images/body-map-back.png'/>
</div>
<svg className='image-map-svg' >
<BodyMap
{...this.props}
>
</BodyMap>
</svg>
</div>
)
}
}
export default BodyMapContainer;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.