[Reporting] Post URL: track layoutID in state

This commit is contained in:
Timothy Sullivan 2019-02-04 18:21:12 -07:00
parent 53a60b9f0f
commit b87d5687d7
2 changed files with 16 additions and 4 deletions

View file

@ -19,6 +19,7 @@ import { reportingClient } from '../lib/reporting_client';
interface Props {
reportType: string;
layoutId: string;
objectId?: string;
objectType: string;
getJobParams: () => any;
@ -31,6 +32,7 @@ interface Props {
interface State {
isStale: boolean;
absoluteUrl: string;
layoutId: string;
}
class ReportingPanelContentUi extends Component<Props, State> {
@ -42,6 +44,7 @@ class ReportingPanelContentUi extends Component<Props, State> {
this.state = {
isStale: false,
absoluteUrl: '',
layoutId: '',
};
}
@ -54,12 +57,18 @@ class ReportingPanelContentUi extends Component<Props, State> {
public componentDidMount() {
this.mounted = true;
this.setAbsoluteReportGenerationUrl();
window.addEventListener('hashchange', this.markAsStale, false);
window.addEventListener('resize', this.setAbsoluteReportGenerationUrl);
}
public getDerivedStateFromProps(newProps: Props) {
if (newProps.layoutId !== this.state.layoutId) {
this.setAbsoluteReportGenerationUrl(); // changes state.absoluteUrl
}
return this.state;
}
public render() {
if (this.isNotSaved() || this.props.isDirty || this.state.isStale) {
return (

View file

@ -11,6 +11,7 @@ import { ReportingPanelContent } from './reporting_panel_content';
interface Props {
reportType: string;
layoutId: string;
objectId?: string;
objectType: string;
getJobParams: () => any;
@ -35,6 +36,7 @@ export class ScreenCapturePanelContent extends Component<Props, State> {
return (
<ReportingPanelContent
reportType={this.props.reportType}
layoutId={this.getLayout().id}
objectType={this.props.objectType}
objectId={this.props.objectId}
getJobParams={this.getJobParams}
@ -103,8 +105,9 @@ export class ScreenCapturePanelContent extends Component<Props, State> {
};
private getJobParams = () => {
const jobParams = this.props.getJobParams();
jobParams.layout = this.getLayout();
return jobParams;
return {
...this.props.getJobParams(),
layout: this.getLayout(),
};
};
}