diff --git a/site/gatsby-site/gatsby-node.js b/site/gatsby-site/gatsby-node.js index a24c0455b7..cffa7e5dee 100644 --- a/site/gatsby-site/gatsby-node.js +++ b/site/gatsby-site/gatsby-node.js @@ -34,6 +34,8 @@ const createBlogPages = require('./page-creators/createBlogPages'); const createDocPages = require('./page-creators/createDocPages'); +const createDiscoverPage = require('./page-creators/createDiscoverPage'); + const algoliasearch = require('algoliasearch'); const Translator = require('./src/utils/Translator'); @@ -75,6 +77,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => { }); for (const pageCreator of [ + createDiscoverPage, createBlogPages, createCitationPages, createWordCountsPages, diff --git a/site/gatsby-site/page-creators/createDiscoverPage.js b/site/gatsby-site/page-creators/createDiscoverPage.js new file mode 100644 index 0000000000..b7cdc49e55 --- /dev/null +++ b/site/gatsby-site/page-creators/createDiscoverPage.js @@ -0,0 +1,43 @@ +const path = require('path'); + +const createDiscoverPage = async (graphql, createPage) => { + const pageQuery = await graphql(` + query DiscoverPageQuery { + reports: allMongodbAiidprodReports { + nodes { + report_number + date_published + } + } + } + `); + + const reports = pageQuery.data.reports?.nodes; + + const numBins = 16; + + const histogramBins = new Array(numBins).fill().map(() => 0); + + const publishDates = reports.map((report) => new Date(report.date_published)); + + const latestPublishDate = Math.max(...publishDates); + + const earliestPublishDate = Math.min(...publishDates); + + for (const publishDate of publishDates) { + const position = + (publishDate - earliestPublishDate) / (latestPublishDate - earliestPublishDate); + + const index = Math.round(position * (histogramBins.length - 1)); + + histogramBins[index] += 1; + } + + createPage({ + path: '/apps/discover/', + component: path.resolve('./src/templates/discover.js'), + context: { histogramBins }, + }); +}; + +module.exports = createDiscoverPage; diff --git a/site/gatsby-site/playwright/e2e/discover.spec.ts b/site/gatsby-site/playwright/e2e/discover.spec.ts index 79ffb09705..c58ecd37d2 100644 --- a/site/gatsby-site/playwright/e2e/discover.spec.ts +++ b/site/gatsby-site/playwright/e2e/discover.spec.ts @@ -10,7 +10,7 @@ import config from '../../config'; test.describe('The Discover app', () => { const url = '/apps/discover'; - + test('Successfully loads', async ({ page }) => { await page.goto(url); }); @@ -503,4 +503,20 @@ test.describe('The Discover app', () => { await expect(count).toBeGreaterThanOrEqual(0); }).toPass(); }); + + test('Should select date range', async ({ page }) => { + await page.goto(url); + + await page.locator('[data-cy="epoch_date_published"]').first().click(); + + const rangeKnobSelector = '[data-cy="epoch_date_published"] [data-cy="range-knob"]'; + + await page.locator(rangeKnobSelector).first().focus(); + + await page.locator(rangeKnobSelector).first().press('ArrowRight'); + + await page.locator(rangeKnobSelector).first().press('ArrowRight'); + + await expect(page).toHaveURL(/.*epoch_date_published_min.*/g); + }); }); diff --git a/site/gatsby-site/src/components/discover/Controls.js b/site/gatsby-site/src/components/discover/Controls.js index fc2c2ecf0f..110c3c3d7d 100644 --- a/site/gatsby-site/src/components/discover/Controls.js +++ b/site/gatsby-site/src/components/discover/Controls.js @@ -12,7 +12,7 @@ import { Trans } from 'react-i18next'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCaretDown, faCaretRight } from '@fortawesome/free-solid-svg-icons'; -const Controls = () => { +const Controls = ({ histogramBins }) => { const { indexUiState } = useInstantSearch(); const [expandFilters, setExpandFilters] = useState(false); @@ -75,7 +75,7 @@ const Controls = () => {
-