Skip to content

Commit

Permalink
hides button on save, adds vizes to end of render
Browse files Browse the repository at this point in the history
  • Loading branch information
jhmullen committed Jul 23, 2020
1 parent 76b39c9 commit 42eb19f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/cms/src/api/pdfRoute.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const puppeteer = require("puppeteer");

const pdfOptions = {
format: "A4",
printBackground: true
};

const generate = async path => {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto(path, {waitUntil: "networkidle2"});
page.emulateMediaType("print");
const pdf = await page.pdf(pdfOptions);
await browser.close();
return pdf;
Expand Down
32 changes: 30 additions & 2 deletions packages/cms/src/components/ProfileRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import libs from "../utils/libs";
import Hero from "./sections/Hero";
import Section from "./sections/Section";
import Related from "./sections/Related";
import Viz from "./Viz/Viz";
import SectionGrouping from "./sections/components/SectionGrouping";
import Subnav from "./sections/components/Subnav";
import Mirror from "./Viz/Mirror";
Expand Down Expand Up @@ -174,6 +175,7 @@ class ProfileRenderer extends Component {
hideHero, // strip out the hero section
hideSubnav // strip out the subnav
} = this.props;
const {print} = this.context;

if (!this.state.profile) return null;
if (this.state.profile.error) return <div>{this.state.profile.error}</div>;
Expand All @@ -195,6 +197,11 @@ class ProfileRenderer extends Component {
const innerGroupedSections = []; // array for sections to be accumulated into
let groupedSections = [];

let printTables = [];
if (print) {
printTables = sections.reduce((acc, d) => acc.concat(d.visualizations), []);
}

// make sure there are sections to loop through (issue #700)
if (sections.length) {
// reduce sections into a nested array of groupedSections
Expand Down Expand Up @@ -282,9 +289,29 @@ class ProfileRenderer extends Component {
)}
</div>
)}
{!hideHero && relatedProfiles && relatedProfiles.length > 0 &&
{!hideHero && !print && relatedProfiles && relatedProfiles.length > 0 &&
<Related profiles={relatedProfiles} />
}
{
printTables.length > 0 && <div>
<h1>LOOK</h1>
{printTables.map(d =>
<Viz
config={d}
key={d.id}
dataOnly={true}

/*
section={this}
headingLevel={vizHeadingLevel}
sectionTitle={title}
slug={slug}
hideOptions={hideOptions}
*/
/>
)}
</div>
}
</main>

{/* modal sections */}
Expand Down Expand Up @@ -317,7 +344,8 @@ class ProfileRenderer extends Component {
}

ProfileRenderer.contextTypes = {
router: PropTypes.object
router: PropTypes.object,
print: PropTypes.bool
};

ProfileRenderer.childContextTypes = {
Expand Down
12 changes: 12 additions & 0 deletions packages/cms/src/components/Viz/Viz.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Viz extends Component {
config,
configOverride,
className,
dataOnly,
debug,
headingLevel,
hideOptions,
Expand Down Expand Up @@ -107,6 +108,17 @@ class Viz extends Component {
// whether to show the title and/or visualization options
const showHeader = (title && showTitle || !hideOptions) && type !== "Graphic" && type !== "HTML";

if (dataOnly) {
return <Options
key="option-key"
component={{section, viz: this}}
data={vizConfig.data}
dataFormat={vizProps.dataFormat}
slug={slug }
title={title || sectionTitle || slug}
/>;
}

return <SizeMe render={({size}) =>
<div
className={`${namespace}-viz-container${
Expand Down
6 changes: 6 additions & 0 deletions packages/cms/src/components/sections/Hero.css
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,9 @@
height: 75vh;
}
}

@media print {
.cp-hero-pdf {
display: none;
}
}

0 comments on commit 42eb19f

Please sign in to comment.