Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contentful): add support for tags (#31746)
Co-authored-by: axe312ger <opensource@axe312.dev>
- Loading branch information
Showing
17 changed files
with
382 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
describe(`tags`, () => { | ||
beforeEach(() => { | ||
cy.visit("/tags").waitForRouteChange() | ||
}) | ||
it(`Tag list`, () => { | ||
cy.get('[data-cy-id="tag-numberDecimal"] [data-cy-name]').should( | ||
"have.text", | ||
"Number: Decimal" | ||
) | ||
cy.get('[data-cy-id="tag-numberDecimal"] [data-cy-id]').should( | ||
"have.text", | ||
"numberDecimal" | ||
) | ||
cy.get('[data-cy-id="tag-numberInteger"] [data-cy-name]').should( | ||
"have.text", | ||
"Number: Integer" | ||
) | ||
cy.get('[data-cy-id="tag-numberInteger"] [data-cy-id]').should( | ||
"have.text", | ||
"numberInteger" | ||
) | ||
cy.get('[data-cy-id^="tag-"]').should("have.length", 2) | ||
}) | ||
it(`Filtered Entries`, () => { | ||
cy.get('[data-cy-integers] [data-cy-id="number-integer"]').should( | ||
"have.length", | ||
1 | ||
) | ||
cy.get( | ||
'[data-cy-integers] [data-cy-id="number-integer"] [data-cy-value]' | ||
).should("have.text", 42) | ||
|
||
cy.get('[data-cy-decimals] [data-cy-id="number-decimal"]').should( | ||
"have.length", | ||
1 | ||
) | ||
cy.get( | ||
'[data-cy-decimals] [data-cy-id="number-decimal"] [data-cy-value]' | ||
).should("have.text", 4.2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { graphql } from "gatsby" | ||
import * as React from "react" | ||
import slugify from "slugify" | ||
|
||
import Layout from "../components/layout" | ||
|
||
const TagsPage = ({ data }) => { | ||
const tags = data.tags.nodes | ||
const integers = data.integers.nodes | ||
const decimals = data.decimals.nodes | ||
|
||
return ( | ||
<Layout> | ||
<h1>Tag Listing:</h1> | ||
{tags.map(tag => { | ||
return ( | ||
<div data-cy-id={`tag-${tag.contentful_id}`} key={tag.contentful_id}> | ||
<h2 data-cy-name>{tag.name}</h2> | ||
<p> | ||
ID: <span data-cy-id>{tag.contentful_id}</span> | ||
</p> | ||
</div> | ||
) | ||
})} | ||
<hr /> | ||
<h1>Filtered Entries:</h1> | ||
<h2>Integers:</h2> | ||
<div data-cy-integers> | ||
{integers.map(({ title, integer }) => { | ||
const slug = slugify(title, { strict: true, lower: true }) | ||
return ( | ||
<div data-cy-id={slug} key={slug}> | ||
<h3>{title}</h3> | ||
<p data-cy-value>{integer}</p> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
<h2>Decimals:</h2> | ||
<div data-cy-decimals> | ||
{decimals.map(({ title, decimal }) => { | ||
const slug = slugify(title, { strict: true, lower: true }) | ||
return ( | ||
<div data-cy-id={slug} key={slug}> | ||
<h3>{title}</h3> | ||
<p data-cy-value>{decimal}</p> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</Layout> | ||
) | ||
} | ||
|
||
export default TagsPage | ||
|
||
export const pageQuery = graphql` | ||
query TagsQuery { | ||
tags: allContentfulTag(sort: { fields: contentful_id }) { | ||
nodes { | ||
name | ||
contentful_id | ||
} | ||
} | ||
integers: allContentfulNumber( | ||
sort: { fields: contentful_id } | ||
filter: { | ||
metadata: { | ||
tags: { elemMatch: { contentful_id: { eq: "numberInteger" } } } | ||
} | ||
node_locale: { eq: "en-US" } | ||
} | ||
) { | ||
nodes { | ||
title | ||
integer | ||
} | ||
} | ||
decimals: allContentfulNumber( | ||
sort: { fields: contentful_id } | ||
filter: { | ||
metadata: { | ||
tags: { elemMatch: { contentful_id: { eq: "numberDecimal" } } } | ||
} | ||
node_locale: { eq: "en-US" } | ||
} | ||
) { | ||
nodes { | ||
title | ||
decimal | ||
} | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,5 +74,6 @@ exports.initialSync = () => { | |
}, | ||
], | ||
}, | ||
tagItems: [], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.