Skip to content

Commit

Permalink
dataset-select contributors separate from keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
eharkins committed Mar 26, 2021
1 parent 782cc0e commit ec257c3
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions static-site/src/components/build-pages/dataset-select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class DatasetSelect extends React.Component {
this.applyFilter = this.applyFilter.bind(this);
this.createFilterBadges = this.createFilterBadges.bind(this);
this.getStyles = this.getStyles.bind(this);
this.getKeyWordArray = this.getKeyWordArray.bind(this);
this.getFilterableValuesFromDataset = this.getFilterableValuesFromDataset.bind(this);
this.makeOptions = this.makeOptions.bind(this);
this.selectionMade = this.selectionMade.bind(this);
this.createIndividualBadge = this.createIndividualBadge.bind(this);
Expand Down Expand Up @@ -215,9 +215,12 @@ class DatasetSelect extends React.Component {
}
};
}
getKeyWordArray = (dataset, filterByContributor) => {
const keywordArray = get(dataset, "filename").replace('.json', '').split("_");
if (filterByContributor) keywordArray.push(dataset.contributor);
getFilterableValuesFromDataset = (dataset, filterByContributor) => {
const keywordArray = get(dataset, "filename")
.replace('.json', '')
.split("_")
.map((v) => ["keyword", v]);
if (filterByContributor) keywordArray.push(["contributor", dataset.contributor]);
return keywordArray;
}
makeOptions = () => {
Expand All @@ -231,15 +234,15 @@ class DatasetSelect extends React.Component {
const filterByContributor = contributorSet.size > 1;
const datasets = this.props.datasets.filter((b) => b.url !== undefined);
const optionsObject = datasets.reduce((accumulator, dataset) => {
const keywordArray = this.getKeyWordArray(dataset, filterByContributor);
keywordArray.forEach((keyword) => {
if (accumulator.seenValues["keyword"]) {
if (accumulator.seenValues["keyword"].has(keyword.toLowerCase())) return;
const filterOptions = this.getFilterableValuesFromDataset(dataset, filterByContributor);
filterOptions.forEach(([filterType, filterValue]) => {
if (accumulator.seenValues[filterType]) {
if (accumulator.seenValues[filterType].has(filterValue.toLowerCase())) return;
} else {
accumulator.seenValues["keyword"] = new Set([]);
accumulator.seenValues[filterType] = new Set([]);
}
accumulator.seenValues["keyword"].add(keyword.toLowerCase());
accumulator.options.push({label: `keyword${keyword}`, value: ["keyword", keyword]});
accumulator.seenValues[filterType].add(filterValue.toLowerCase());
accumulator.options.push({label: `${filterType}${filterValue}`, value: [filterType, filterValue]});
});
return accumulator;
}, {options: [], seenValues: {}});
Expand Down Expand Up @@ -276,11 +279,11 @@ class DatasetSelect extends React.Component {
return this.createIndividualBadge({filterName, item, label, onHoverMessage});
});
}
datasetMatchesFilter(dataset, filterObjects, filterByContributor) {
const keywordArray = this.getKeyWordArray(dataset, filterByContributor);
datasetMatchesFilter(dataset, filterType, filterObjects, filterByContributor) {
const filterableValues = this.getFilterableValuesFromDataset(dataset, filterByContributor);
return filterObjects.every((filter) => {
if (!filter.active) return true; // inactive filter is the same as a match
return keywordArray.includes(filter.value);
return filterableValues.some(([k, v]) => k === filterType && v.includes(filter.value));
});
}
getFilteredDatasets(filterByContributor) {
Expand All @@ -289,7 +292,7 @@ class DatasetSelect extends React.Component {
.filter((b) => b.url !== undefined)
.filter((b) => Object.entries(this.state.filters)
.filter((filterEntry) => filterEntry[1].length)
.every(([filterName, filterValues]) => this.datasetMatchesFilter(b, filterValues, filterByContributor)));
.every(([filterType, filterValues]) => this.datasetMatchesFilter(b, filterType, filterValues, filterByContributor)));
return sortBy(filtered, [(d) => d.filename.toLowerCase()]);
}

Expand Down

0 comments on commit ec257c3

Please sign in to comment.