Skip to content

Commit

Permalink
fixes cart links not removing profile cut
Browse files Browse the repository at this point in the history
  • Loading branch information
davelandry committed Mar 15, 2019
1 parent de161a6 commit b89ff11
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/mortarRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ module.exports = function(app) {
returnObject.image = image;
returnObject.sections.forEach(section => {
section.topics.forEach(topic => {
topic.profile = section.profile.slug;
topic.section = section.slug;
});
});
Expand Down Expand Up @@ -322,6 +323,7 @@ module.exports = function(app) {
const topics = resp[2].map(t => t.toJSON());
let topic = topics.find(t => t.section.profile.slug === slug);
topic = varSwapRecursive(topic, formatterFunctions, variables, req.query);
topic.profile = topic.section.profile.slug;
topic.section = topic.section.slug;
if (topic.subtitles) topic.subtitles.sort(sorter);
if (topic.selectors) topic.selectors.sort(sorter);
Expand Down
27 changes: 24 additions & 3 deletions app/components/Viz/Options.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ const geographyLevels = {
"795": "PUMA"
};

const slugMap = {
cip: "CIP",
geo: "Geography",
naics: "PUMS Industry",
napcs: "NAPCS",
soc: "PUMS Occupation",
university: "University"
};

const children = id => {
const prefix = id.slice(0, 3);
return prefix === "010" ? "State"
Expand Down Expand Up @@ -84,14 +93,14 @@ class Options extends Component {

async onCart() {

const {addToCart, cart, removeFromCart, slug} = this.props;
const {addToCart, cart, removeFromCart, slug, topic} = this.props;
const inCart = cart.data.find(c => c.slug === slug);

if (!inCart) {

const {config, data, dataFormat, title} = this.props;
const {list, stripHTML} = this.context.formatters;

console.log(topic);
console.log(slug);
console.log(data);
console.log(config);
Expand All @@ -117,6 +126,17 @@ class Options extends Component {
let slices = [];
if (!params.drilldowns) params.drilldowns = [];

if (params[slugMap[topic.profile]] && topic.variables.hierarchy) {
delete params[slugMap[topic.profile]];
params.drilldowns.push(topic.variables.hierarchy);
}

// params.drilldowns = params.drilldowns
// .filter((d, i, arr) => {
// if (d === "Sector" && arr.includes("University")) return false;
// return true;
// });

const groupBy = config.groupBy instanceof Array ? config.groupBy : [config.groupBy];
for (let i = 0; i < groupBy.length; i++) {
const group = groupBy[i];
Expand Down Expand Up @@ -156,6 +176,7 @@ class Options extends Component {

const urls = [];
const drilldowns = params.drilldowns.concat(slices);

if (slices.length) {
slices.forEach(slice => {
params.drilldowns.push(slice);
Expand All @@ -176,7 +197,7 @@ class Options extends Component {
const cartTitle = `${stripHTML(title)}${drilldowns ? ` by ${list(drilldowns)}` : ""}`;
console.log(cartTitle);

addToCart({urls, format, slug, title: cartTitle});
// addToCart({urls, format, slug, title: cartTitle});

}
else {
Expand Down

0 comments on commit b89ff11

Please sign in to comment.