Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby/www): Tried to unbox an edge but it is already a node #21927

Merged
merged 3 commits into from
Mar 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 24 additions & 32 deletions www/src/views/starter-library/filtered-starters.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ export default class FilteredStarterLibrary extends Component {
)

// stopgap for missing gh data (#8763)
let starters = data.allStartersYaml.nodes.filter(
let starterNodes = data.allStartersYaml.nodes.filter(
starter => starter.fields && starter.fields.starterShowcase
)

if (urlState.s.length > 0) {
starters = starters.filter(starter =>
starterNodes = starterNodes.filter(starter =>
JSON.stringify(starter.node)
.toLowerCase()
.includes(urlState.s.toLowerCase())
)
}

if (filtersCategory.size > 0) {
starters = filterByCategories(starters, filtersCategory)
starterNodes = filterByCategories(starterNodes, filtersCategory)
}
if (filtersDependency.size > 0) {
starters = filterByDependencies(starters, filtersDependency)
starterNodes = filterByDependencies(starterNodes, filtersDependency)
}

if (filtersVersion.size > 0) {
starters = filterByVersions(starters, filtersVersion)
starterNodes = filterByVersions(starterNodes, filtersVersion)
}

return (
Expand All @@ -115,7 +115,7 @@ export default class FilteredStarterLibrary extends Component {
heading="Gatsby Version"
data={Array.from(
count(
starters.map(
starterNodes.map(
node =>
node.fields &&
node.fields.starterShowcase.gatsbyMajorVersion.map(
Expand All @@ -129,7 +129,9 @@ export default class FilteredStarterLibrary extends Component {
/>
<LHSFilter
heading="Categories"
data={Array.from(count(starters.map(starter => starter.tags)))}
data={Array.from(
count(starterNodes.map(starter => starter.tags))
)}
filters={filtersCategory}
setFilters={setFiltersCategory}
sortRecent={urlState.sort === `recent`}
Expand All @@ -138,7 +140,7 @@ export default class FilteredStarterLibrary extends Component {
heading="Gatsby Dependencies"
data={Array.from(
count(
starters.map(
starterNodes.map(
starter =>
starter.fields &&
starter.fields.starterShowcase.gatsbyDependencies.map(
Expand Down Expand Up @@ -168,8 +170,8 @@ export default class FilteredStarterLibrary extends Component {
search={urlState.s}
filters={filters}
label="Gatsby Starter"
items={starters}
nodes={starters}
items={starterNodes}
nodes={starterNodes}
what="size"
/>
<div
Expand Down Expand Up @@ -233,15 +235,15 @@ export default class FilteredStarterLibrary extends Component {
<StarterList
urlState={urlState}
sortRecent={urlState.sort === `recent`}
starters={starters}
starters={starterNodes}
count={this.state.sitesToShow}
/>
{this.state.sitesToShow < starters.length && (
{this.state.sitesToShow < starterNodes.length && (
<Button
variant="large"
tag="button"
overrideCSS={loadMoreButton}
onClick={() => this.showMoreSites(starters)}
onClick={() => this.showMoreSites(starterNodes)}
icon={<MdArrowDownward />}
>
Load More
Expand Down Expand Up @@ -274,40 +276,30 @@ function count(arrays) {
return counts
}

function filterByCategories(list, categories) {
let starters = list
starters = starters.filter(starter =>
isSuperset(starter.tags, categories)
)
return starters
function filterByCategories(nodes, categories) {
return nodes.filter(node => isSuperset(node.tags, categories))
}
function filterByDependencies(list, categories) {
let starters = list

starters = starters.filter(
({ node: starter }) =>
starter.fields &&
function filterByDependencies(nodes, categories) {
return nodes.filter(
({ fields }) =>
fields &&
isSuperset(
starter.fields.starterShowcase.gatsbyDependencies.map(c => c[0]),
fields.starterShowcase.gatsbyDependencies.map(c => c[0]),
categories
)
)

return starters
}

function filterByVersions(list, versions) {
let starters = list

starters = starters.filter(
function filterByVersions(nodes, versions) {
return nodes.filter(
({ fields }) =>
fields &&
isSuperset(
fields.starterShowcase.gatsbyMajorVersion.map(c => c[1]),
versions
)
)
return starters
}

function isSuperset(set, subset) {
Expand Down