Skip to content

Commit

Permalink
converts appendix to true sections
Browse files Browse the repository at this point in the history
  • Loading branch information
jhmullen committed Aug 6, 2020
1 parent 2c580e8 commit 9303edd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
62 changes: 37 additions & 25 deletions packages/cms/src/components/ProfileRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ class ProfileRenderer extends Component {
const innerGroupedSections = []; // array for sections to be accumulated into
let groupedSections = [];

let printSections = [];
if (print) {
printSections = sections.filter(d => d.visualizations.length > 0);
}

// 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 @@ -249,6 +244,43 @@ class ProfileRenderer extends Component {
}, []);
}

let printSections = [];
if (print) {
const index = sections.length + 1;
const groupingStubSection = {
allowed: "always",
descriptions: [],
icon: "",
id: "printGroup",
ordering: index,
position: "default",
profile_id: 1,
selectors: [],
short: "",
slug: "labels",
stats: [],
subtitles: [],
title: "<p>Appendix</p>",
type: "Grouping",
visualizations: []
};
printSections = sections
.filter(d => d.visualizations.length > 0)
.map(d => [{
...d,
id: `print-${d.id}`,
ordering: index,
descriptions: [],
selectors: [],
stats: [],
subtitles: [],
position: "default",
type: "Default",
configOverride: {type: "Table", showPagination: false, minRows: 0}
}]);
groupedSections.push([[groupingStubSection], ...printSections]);
}

const modalSection = modalSlug ? profile.sections.find(s => s.slug === modalSlug) : null;

// To prevent a "loading flicker" when users call setVariables, normal Sections don't show a "Loading"
Expand Down Expand Up @@ -311,26 +343,6 @@ class ProfileRenderer extends Component {
{!hideHero && !print && relatedProfiles && relatedProfiles.length > 0 &&
<Related profiles={relatedProfiles} />
}
{
printSections.length > 0 && <div>
<h1>APPENDIX</h1>
{printSections.map(section =>
<div key={section.id}>
<h3>{stripHTML(section.title)}</h3>
<p>source will go here</p>
{section.visualizations.map((viz, i) =>
<Viz
config={viz}
configOverride={{type: "Table"}}
key={viz.id}
hideOptions={true}
slug={`Visualization ${i + 1} (${stripHTML(section.title)})`}
/>
)}
</div>
)}
</div>
}
</main>

{/* modal sections */}
Expand Down
11 changes: 0 additions & 11 deletions packages/cms/src/components/Viz/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,6 @@ class Table extends Component {
const {d3plus} = this.context;
config.data = data;

console.log("data", data);

/*
// check that we have a valid columns object
const columns = config.columns &&
// it it's array, use it as-is; otherwise, make it an array
Array.isArray(config.columns) ? config.columns : [config.columns] ||
// otherwise, make an array from all available columns
Object.keys(data.length ? data[0] : {});
*/

let columns = [];
if (config.columns) {
columns = Array.isArray(config.columns) ? config.columns : [config.columns];
Expand Down
3 changes: 2 additions & 1 deletion packages/cms/src/components/sections/Default.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "./Default.css";

export default class Default extends Component {
render() {
const {slug, heading, hideOptions, title, paragraphs, loading, filters, resetButton, stats, sources, visualizations, vizHeadingLevel} = this.props;
const {slug, heading, hideOptions, title, paragraphs, configOverride, loading, filters, resetButton, stats, sources, visualizations, vizHeadingLevel} = this.props;

return (
<div
Expand Down Expand Up @@ -36,6 +36,7 @@ export default class Default extends Component {
sectionTitle={title}
slug={slug}
hideOptions={hideOptions}
configOverride={configOverride}
key={ii}
/>
)}
Expand Down
4 changes: 3 additions & 1 deletion packages/cms/src/components/sections/Section.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class Section extends Component {
render() {
const {contents, sources, isStickyIE, height, showReset} = this.state;
const {headingLevel, hideAnchor, hideOptions, isModal, loading, t} = this.props;
const {configOverride} = contents;

// remap old section names
const layout = contents.type;
Expand Down Expand Up @@ -272,7 +273,8 @@ class Section extends Component {
vizHeadingLevel: `h${parseInt(headingLevel.replace("h", ""), 10) + 1}`,
hideOptions,
loading,
contents
contents,
configOverride
};

return (
Expand Down

0 comments on commit 9303edd

Please sign in to comment.