Working with default category values from store if none are provided in config

This commit is contained in:
efarooqui
2021-05-24 22:00:51 -07:00
parent 5c3fffd99e
commit 09d82b4da5
3 changed files with 15 additions and 17 deletions

View File

@@ -120,7 +120,7 @@ export function fetchDomain() {
);
}
dispatch(toggleFetchingDomain());
// dispatch(setInitialCategories(result.associations));
dispatch(setInitialCategories(result.associations));
dispatch(setInitialShapes(result.shapes));
return result;
})

View File

@@ -534,8 +534,8 @@ export function mapStyleByShape(shapes, activeShapes) {
return styledShapes;
}
export function mapCategoriesToPaths(categories) {
const categoryMap = categories.reduce((acc, cat) => {
export function mapCategoriesToPaths(categories, panelCategories) {
const mappedCats = categories.reduce((acc, cat) => {
const type = cat.filter_paths[0];
if (!(type in acc)) {
acc[type] = [];
@@ -543,6 +543,9 @@ export function mapCategoriesToPaths(categories) {
acc[type].push(cat);
return acc;
}, {});
const categoryMap =
panelCategories.length > 1 ? mappedCats : { default: categories };
return categoryMap;
}
@@ -550,7 +553,7 @@ export function getCategoryIdxs(panelCategories, startingIdx) {
let idxCounter = startingIdx;
// If there are specified categories from the config, filter out the default value; else, leave the default value
const catTypes =
panelCategories.length > 1 && panelCategories.includes("default")
panelCategories.length > 1
? panelCategories.filter((val) => val !== "default")
: panelCategories;
return catTypes.reduce((set, val) => {
@@ -568,5 +571,5 @@ export function getFilterIdx(
if (narrativesExist && !categoriesExist) return 1;
else if (!narrativesExist && categoriesExist) return numCategoryPanels;
else if (narrativesExist && categoriesExist) return numCategoryPanels + 1;
else return;
else return 0;
}

View File

@@ -114,8 +114,11 @@ class Toolbar extends React.Component {
renderToolbarCategoriesPanel() {
const { categories: panelCategories } = this.props.toolbarCopy.panels;
const catMap = mapCategoriesToPaths(this.props.categories);
console.info(catMap);
const catMap = mapCategoriesToPaths(
this.props.categories,
Object.keys(panelCategories)
);
return (
<div>
{Object.keys(catMap).map((type) => {
@@ -127,16 +130,8 @@ class Toolbar extends React.Component {
activeCategories={this.props.activeCategories}
onCategoryFilter={this.props.methods.onCategoryFilter}
language={this.props.language}
title={
panelCategories[type]
? panelCategories[type].label
: panelCategories.default.label
}
description={
panelCategories[type]
? panelCategories[type].description
: panelCategories.default.description
}
title={panelCategories[type].label}
description={panelCategories[type].description}
/>
</TabPanel>
);