From 8c6217853ad0f3f063aa6c45fac9322e8d3460ba Mon Sep 17 00:00:00 2001 From: Aaron Couch Date: Tue, 14 May 2024 15:39:15 -0400 Subject: [PATCH 01/21] Update internal_task.yml --- .github/ISSUE_TEMPLATE/internal_task.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/internal_task.yml b/.github/ISSUE_TEMPLATE/internal_task.yml index f41909b36..27765e6f8 100644 --- a/.github/ISSUE_TEMPLATE/internal_task.yml +++ b/.github/ISSUE_TEMPLATE/internal_task.yml @@ -1,7 +1,6 @@ name: Internal - Task description: Describes an individual task that needs to be completed title: "[Task]: " -labels: ["project: grants.gov"] assignees: - octocat body: From 90d14d68e7ee66fdfc840889b41b1d32ac69b2e6 Mon Sep 17 00:00:00 2001 From: Aaron Couch Date: Tue, 14 May 2024 15:40:09 -0400 Subject: [PATCH 02/21] Delete .github/ISSUE_TEMPLATE/internal_30k.md --- .github/ISSUE_TEMPLATE/internal_30k.md | 27 -------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/internal_30k.md diff --git a/.github/ISSUE_TEMPLATE/internal_30k.md b/.github/ISSUE_TEMPLATE/internal_30k.md deleted file mode 100644 index 4fe2ceaf5..000000000 --- a/.github/ISSUE_TEMPLATE/internal_30k.md +++ /dev/null @@ -1,27 +0,0 @@ ---- - -name: Internal - 30k deliverable -about: Describe a new deliverable at a 30,000 ft view -title: "[30k]: " -labels: - - "deliverable: 30k ft" -assignees: "" - ---- - -### Key links - -- Deliverable specification -- [Simpler Grants.gov full roadmap](https://github.com/orgs/HHS/projects/12) -- 10k milestones - -### Description - -- **What:** {1-2 sentence summary of what should be delivered} -- **Why:** {1-2 sentence summary of why this deliverable is important} -- **Who** - - {Audience for this deliverable} - - {Audience for this deliverable} - -> [!NOTE] -> For more information about this deliverable, please refer to the deliverable specification linked above. From a9ea8b6bbf879bc3e3ac8a6913060d77111d29f9 Mon Sep 17 00:00:00 2001 From: Aaron Couch Date: Tue, 14 May 2024 15:40:25 -0400 Subject: [PATCH 03/21] Delete .github/ISSUE_TEMPLATE/internal_adr.yml --- .github/ISSUE_TEMPLATE/internal_adr.yml | 56 ------------------------- 1 file changed, 56 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/internal_adr.yml diff --git a/.github/ISSUE_TEMPLATE/internal_adr.yml b/.github/ISSUE_TEMPLATE/internal_adr.yml deleted file mode 100644 index 8bb41ad7d..000000000 --- a/.github/ISSUE_TEMPLATE/internal_adr.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Internal - ADR -description: Outline an architectural decision that needs to be recorded -title: "[ADR]: " -labels: ["project: grants.gov", "docs: adr"] -assignees: - - octocat -body: - - type: markdown - attributes: - value: | - Describe an architectural decision that needs to be recorded - - type: markdown - attributes: - value: | - **Example** [Wiki ADR](https://github.com/HHS/simpler-grants-gov/issues/30) - - type: textarea - id: description - attributes: - label: Description - description: 1-2 sentence summary of the decision that needs to be made - validations: - required: true - - type: textarea - id: approvers - attributes: - label: Approvers - description: List individuals or groups that must approve this decision before the ADR is accepted - validations: - required: false - - type: textarea - id: options - attributes: - label: Options - description: List of options to evaluate - validations: - required: false - - type: textarea - id: decision-criteria - attributes: - label: Decision Criteria - description: List of decision criteria to evaluate - validations: - required: false - - type: checkboxes - id: definition-of-done - attributes: - label: Definition of Done - description: Leave the following acceptance criteria unchecked when the ticket is created then mark them as completed as you meet each criterion with the ADR - options: - - label: The approvers for this decision have been identified (ideally before work on the ADR starts) - - label: The ADR is created and stored in `documentation/decisions/adr` with status "Accepted" - - label: The ADR has been reviewed and approved by the approvers listed above - - label: The ADR satisfies requirements that are outlined in the ADR template - - label: Any follow-up tickets have been created (if necessary) - validations: - required: true From 6bfd75e9aaec0991a4012120295b4f063fee484d Mon Sep 17 00:00:00 2001 From: Ryan Lewis <93001277+rylew1@users.noreply.github.com> Date: Tue, 14 May 2024 12:50:29 -0700 Subject: [PATCH 04/21] [Issue #1757]: setup e2e tests for search (#1) ## Summary Fixes #1757 ## Changes proposed - Add e2e tests for search page - Add e2e test (with FE and API) to its own CI job (`ci-frontend-ci.yml`) - invokes shell script to wait until API is loaded --- .github/workflows/ci-frontend-e2e.yml | 61 +++++++ .github/workflows/ci-frontend.yml | 15 +- api/.gitignore | 3 + api/bin/wait-for-api.sh | 30 ++++ frontend/.eslintrc.js | 2 + frontend/.gitignore | 6 + frontend/package-lock.json | 24 +-- frontend/package.json | 2 +- .../SearchFilterCheckbox.tsx | 2 +- frontend/tests/e2e/search/search.spec.ts | 170 ++++++++++++++++++ frontend/tests/e2e/search/searchUtil.ts | 132 ++++++++++++++ frontend/tests/playwright.config.ts | 2 + 12 files changed, 421 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/ci-frontend-e2e.yml create mode 100755 api/bin/wait-for-api.sh create mode 100644 frontend/tests/e2e/search/search.spec.ts create mode 100644 frontend/tests/e2e/search/searchUtil.ts diff --git a/.github/workflows/ci-frontend-e2e.yml b/.github/workflows/ci-frontend-e2e.yml new file mode 100644 index 000000000..1a1712993 --- /dev/null +++ b/.github/workflows/ci-frontend-e2e.yml @@ -0,0 +1,61 @@ +name: Frontend E2E Tests + +on: + workflow_call: + pull_request: + paths: + - frontend/** + - .github/workflows/ci-frontend-e2e.yml + +defaults: + run: + working-directory: ./frontend + +env: + NODE_VERSION: 18 + LOCKFILE_PATH: ./frontend/package-lock.json + PACKAGE_MANAGER: npm + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + e2e-tests: + name: Run E2E Tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: ${{ env.PACKAGE_MANAGER }} + cache-dependency-path: ${{ env.LOCKFILE_PATH }} + + - run: npm ci + + - name: Install Playwright Browsers + run: npx playwright install --with-deps + + - name: Start API Server for e2e tests + run: | + cd ../api + make init db-seed-local start & + cd ../frontend + # Ensure the API wait script is executable + chmod +x ../api/bin/wait-for-api.sh + ../api/bin/wait-for-api.sh + shell: bash + + - name: Run E2E Tests + run: npm run test:e2e + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: ./frontend/playwright-report/ + retention-days: 30 diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml index a1e299d8c..67766d706 100644 --- a/.github/workflows/ci-frontend.yml +++ b/.github/workflows/ci-frontend.yml @@ -1,4 +1,4 @@ -name: Front-end Checks +name: Frontend Checks on: workflow_call: @@ -34,9 +34,6 @@ jobs: cache: ${{ env.PACKAGE_MANAGER }} - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps - - name: Run lint run: npm run lint @@ -58,16 +55,6 @@ jobs: skip-step: none output: comment - - name: Run e2e tests - run: npm run test:e2e - - - uses: actions/upload-artifact@v3 - if: always() - with: - name: playwright-report - path: ./frontend/playwright-report/ - retention-days: 30 - # Confirms the front end still builds successfully check-frontend-builds: name: FE Build Check diff --git a/api/.gitignore b/api/.gitignore index ff0117b53..2b1784734 100644 --- a/api/.gitignore +++ b/api/.gitignore @@ -26,3 +26,6 @@ coverage.* # VSCode Workspace *.code-workspace .vscode + +#e2e +/test-results/ diff --git a/api/bin/wait-for-api.sh b/api/bin/wait-for-api.sh new file mode 100755 index 000000000..f68a9b13d --- /dev/null +++ b/api/bin/wait-for-api.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# wait-for-api.sh + +set -e + +# Color formatting for readability +GREEN='\033[0;32m' +RED='\033[0;31m' +NO_COLOR='\033[0m' + +MAX_WAIT_TIME=800 # seconds, adjust as necessary +WAIT_TIME=0 + +echo "Waiting for API server to become ready..." + +# Use curl to check the API server health endpoint +until curl --output /dev/null --silent --head --fail http://localhost:8080/health; +do + printf '.' + sleep 5 + + WAIT_TIME=$(($WAIT_TIME + 5)) + if [ $WAIT_TIME -gt $MAX_WAIT_TIME ] + then + echo -e "${RED}ERROR: API server did not become ready within ${MAX_WAIT_TIME} seconds.${NO_COLOR}" + exit 1 + fi +done + +echo -e "${GREEN}API server is ready after ~${WAIT_TIME} seconds.${NO_COLOR}" diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index 023b61c5f..280ce11e3 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -49,6 +49,8 @@ module.exports = { "@typescript-eslint/no-unused-vars": "error", // The usage of `any` defeats the purpose of typescript. Consider using `unknown` type instead instead. "@typescript-eslint/no-explicit-any": "error", + // Just warn since playwright tests may not use screen the way jest would + "testing-library/prefer-screen-queries": "warn", }, }, ], diff --git a/frontend/.gitignore b/frontend/.gitignore index 41bd6facb..f38f90c87 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -45,3 +45,9 @@ npm-debug.log* # uswds assets /public/uswds + +# playwright e2e +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2477fba54..68a0052ab 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -28,7 +28,7 @@ }, "devDependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.0.2", - "@playwright/test": "^1.42.0", + "@playwright/test": "^1.44.0", "@storybook/addon-designs": "^7.0.1", "@storybook/addon-essentials": "^7.1.0", "@storybook/nextjs": "^7.1.0", @@ -5139,12 +5139,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.43.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.43.0.tgz", - "integrity": "sha512-Ebw0+MCqoYflop7wVKj711ccbNlrwTBCtjY5rlbiY9kHL2bCYxq+qltK6uPsVBGGAOb033H2VO0YobcQVxoW7Q==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.44.0.tgz", + "integrity": "sha512-rNX5lbNidamSUorBhB4XZ9SQTjAqfe5M+p37Z8ic0jPFBMo5iCtQz1kRWkEMg+rYOKSlVycpQmpqjSFq7LXOfg==", "dev": true, "dependencies": { - "playwright": "1.43.0" + "playwright": "1.44.0" }, "bin": { "playwright": "cli.js" @@ -20767,12 +20767,12 @@ } }, "node_modules/playwright": { - "version": "1.43.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.43.0.tgz", - "integrity": "sha512-SiOKHbVjTSf6wHuGCbqrEyzlm6qvXcv7mENP+OZon1I07brfZLGdfWV0l/efAzVx7TF3Z45ov1gPEkku9q25YQ==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.44.0.tgz", + "integrity": "sha512-F9b3GUCLQ3Nffrfb6dunPOkE5Mh68tR7zN32L4jCk4FjQamgesGay7/dAAe1WaMEGV04DkdJfcJzjoCKygUaRQ==", "dev": true, "dependencies": { - "playwright-core": "1.43.0" + "playwright-core": "1.44.0" }, "bin": { "playwright": "cli.js" @@ -20785,9 +20785,9 @@ } }, "node_modules/playwright-core": { - "version": "1.43.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.43.0.tgz", - "integrity": "sha512-iWFjyBUH97+pUFiyTqSLd8cDMMOS0r2ZYz2qEsPjH8/bX++sbIJT35MSwKnp1r/OQBAqC5XO99xFbJ9XClhf4w==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.44.0.tgz", + "integrity": "sha512-ZTbkNpFfYcGWohvTTl+xewITm7EOuqIqex0c7dNZ+aXsbrLj0qI8XlGKfPpipjm0Wny/4Lt4CJsWJk1stVS5qQ==", "dev": true, "bin": { "playwright-core": "cli.js" diff --git a/frontend/package.json b/frontend/package.json index f97eb31f5..048464bb1 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -43,7 +43,7 @@ }, "devDependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.0.2", - "@playwright/test": "^1.42.0", + "@playwright/test": "^1.44.0", "@storybook/addon-designs": "^7.0.1", "@storybook/addon-essentials": "^7.1.0", "@storybook/nextjs": "^7.1.0", diff --git a/frontend/src/components/search/SearchFilterAccordion/SearchFilterCheckbox.tsx b/frontend/src/components/search/SearchFilterAccordion/SearchFilterCheckbox.tsx index 4304bf2a7..027cf8864 100644 --- a/frontend/src/components/search/SearchFilterAccordion/SearchFilterCheckbox.tsx +++ b/frontend/src/components/search/SearchFilterAccordion/SearchFilterCheckbox.tsx @@ -37,7 +37,7 @@ const SearchFilterCheckbox: React.FC = ({ onChange={handleChange} disabled={!mounted} checked={option.isChecked === true} - // value={option.id} // TODO: consider poassing explicit value + // value={option.id} // TODO: consider passing explicit value /> ); }; diff --git a/frontend/tests/e2e/search/search.spec.ts b/frontend/tests/e2e/search/search.spec.ts new file mode 100644 index 000000000..99d046961 --- /dev/null +++ b/frontend/tests/e2e/search/search.spec.ts @@ -0,0 +1,170 @@ +import { + clickAccordionWithTitle, + clickMobileNavMenu, + clickSearchNavLink, + expectCheckboxIDIsChecked, + expectSortBy, + expectURLContainsQueryParam, + fillSearchInputAndSubmit, + getMobileMenuButton, + getSearchInput, + hasMobileMenu, + refreshPageWithCurrentURL, + selectSortBy, + toggleCheckboxes, + waitForSearchResultsLoaded, +} from "./searchUtil"; +import { expect, test } from "@playwright/test"; + +test("should navigate from index to search page", async ({ page }) => { + // Start from the index page with feature flag set + await page.goto("/?_ff=showSearchV0:true"); + + // Mobile chrome must first click the menu button + if (await hasMobileMenu(page)) { + const menuButton = getMobileMenuButton(page); + await clickMobileNavMenu(menuButton); + } + + await clickSearchNavLink(page); + + // Verify that the new URL is correct + expectURLContainsQueryParam(page, "status", "forecasted,posted"); + + // Verify the presence of "Search" content on the page + await expect(page.locator("h1")).toContainText( + "Search funding opportunities", + ); + + // Verify that the 'forecasted' and 'posted' are checked + await expectCheckboxIDIsChecked(page, "#status-forecasted"); + await expectCheckboxIDIsChecked(page, "#status-posted"); +}); + +test.describe("Search page tests", () => { + test.beforeEach(async ({ page }) => { + // Navigate to the search page with the feature flag set + await page.goto("/search?_ff=showSearchV0:true"); + }); + + test("should return 0 results when searching for obscure term", async ({ + page, + browserName, + }) => { + // TODO (Issue #2005): fix test for webkit + test.skip( + browserName === "webkit", + "Skipping test for WebKit due to a query param issue.", + ); + + const searchTerm = "0resultearch"; + + await fillSearchInputAndSubmit(searchTerm, page); + + expectURLContainsQueryParam(page, "query", searchTerm); + + const resultsHeading = page.getByRole("heading", { + name: /0 Opportunities/i, + }); + await expect(resultsHeading).toBeVisible(); + + await expect(page.locator("div.usa-prose h2")).toHaveText( + "Your search did not return any results.", + ); + }); + + test("should show and hide loading state", async ({ page, browserName }) => { + // TODO (Issue #2005): fix test for webkit + test.skip( + browserName === "webkit", + "Skipping test for WebKit due to a query param issue.", + ); + const searchTerm = "advanced"; + await fillSearchInputAndSubmit(searchTerm, page); + + const loadingIndicator = page.locator("text='Loading results...'"); + await expect(loadingIndicator).toBeVisible(); + await expect(loadingIndicator).toBeHidden(); + + const searchTerm2 = "agency"; + await fillSearchInputAndSubmit(searchTerm2, page); + await expect(loadingIndicator).toBeVisible(); + await expect(loadingIndicator).toBeHidden(); + }); + test("should retain filters in a new tab", async ({ page }) => { + // Set all inputs, then refresh the page. Those same inputs should be + // set from query params. + const searchTerm = "education"; + const statusCheckboxes = { + "status-forecasted": "forecasted", + "status-posted": "posted", + }; + const fundingInstrumentCheckboxes = { + "funding-instrument-cooperative_agreement": "cooperative_agreement", + "funding-instrument-grant": "grant", + }; + + const eligibilityCheckboxes = { + "eligibility-state_governments": "state_governments", + "eligibility-county_governments": "county_governments", + }; + const agencyCheckboxes = { + ARPAH: "ARPAH", + AC: "AC", + }; + const categoryCheckboxes = { + "category-recovery_act": "recovery_act", + "category-agriculture": "agriculture", + }; + + await selectSortBy(page, "agencyDesc"); + + await waitForSearchResultsLoaded(page); + await fillSearchInputAndSubmit(searchTerm, page); + await toggleCheckboxes(page, statusCheckboxes, "status"); + + await clickAccordionWithTitle(page, "Funding instrument"); + await toggleCheckboxes( + page, + fundingInstrumentCheckboxes, + "fundingInstrument", + ); + + await clickAccordionWithTitle(page, "Eligibility"); + await toggleCheckboxes(page, eligibilityCheckboxes, "eligibility"); + + await clickAccordionWithTitle(page, "Agency"); + await toggleCheckboxes(page, agencyCheckboxes, "agency"); + + await clickAccordionWithTitle(page, "Category"); + await toggleCheckboxes(page, categoryCheckboxes, "category"); + + /***********************************************************/ + /* Page refreshed should have all the same inputs selected + /***********************************************************/ + + await refreshPageWithCurrentURL(page); + + // Expect search inputs are retained in the new tab + await expectSortBy(page, "agencyDesc"); + const searchInput = getSearchInput(page); + await expect(searchInput).toHaveValue(searchTerm); + + for (const [checkboxID] of Object.entries(statusCheckboxes)) { + await expectCheckboxIDIsChecked(page, `#${checkboxID}`); + } + + for (const [checkboxID] of Object.entries(fundingInstrumentCheckboxes)) { + await expectCheckboxIDIsChecked(page, `#${checkboxID}`); + } + for (const [checkboxID] of Object.entries(eligibilityCheckboxes)) { + await expectCheckboxIDIsChecked(page, `#${checkboxID}`); + } + for (const [checkboxID] of Object.entries(agencyCheckboxes)) { + await expectCheckboxIDIsChecked(page, `#${checkboxID}`); + } + for (const [checkboxID] of Object.entries(categoryCheckboxes)) { + await expectCheckboxIDIsChecked(page, `#${checkboxID}`); + } + }); +}); diff --git a/frontend/tests/e2e/search/searchUtil.ts b/frontend/tests/e2e/search/searchUtil.ts new file mode 100644 index 000000000..87d066533 --- /dev/null +++ b/frontend/tests/e2e/search/searchUtil.ts @@ -0,0 +1,132 @@ +// ========================= +// Test Helper Functions +// ========================= + +import { Locator, Page, expect } from "@playwright/test"; + +export function getSearchInput(page: Page) { + return page.locator("#query"); +} + +export async function fillSearchInputAndSubmit(term: string, page: Page) { + const searchInput = getSearchInput(page); + await searchInput.fill(term); + await page.click(".usa-search >> button[type='submit']"); + expectURLContainsQueryParam(page, "query", term); +} + +export function expectURLContainsQueryParam( + page: Page, + queryParamName: string, + queryParamValue: string, +) { + const currentURL = page.url(); + expect(currentURL).toContain(`${queryParamName}=${queryParamValue}`); +} + +export async function waitForURLContainsQueryParam( + page: Page, + queryParamName: string, + queryParamValue: string, + timeout = 30000, // query params get set after a debounce period +) { + const endTime = Date.now() + timeout; + + while (Date.now() < endTime) { + const url = new URL(page.url()); + const params = new URLSearchParams(url.search); + const actualValue = params.get(queryParamName); + + if (actualValue === queryParamValue) { + return; + } + + await page.waitForTimeout(500); + } + + throw new Error( + `URL did not contain query parameter ${queryParamName}=${queryParamValue} within ${timeout}ms`, + ); +} + +export async function clickSearchNavLink(page: Page) { + await page.click("nav >> text=Search"); +} + +export function getMobileMenuButton(page: Page) { + return page.locator("button >> text=MENU"); +} + +export async function hasMobileMenu(page: Page) { + const menuButton = getMobileMenuButton(page); + return await menuButton.isVisible(); +} + +export async function clickMobileNavMenu(menuButton: Locator) { + await menuButton.click(); +} + +export async function expectCheckboxIDIsChecked( + page: Page, + idWithHash: string, +) { + const checkbox: Locator = page.locator(idWithHash); + await expect(checkbox).toBeChecked(); +} + +export async function toggleCheckboxes( + page: Page, + checkboxObject: Record, + queryParamName: string, +) { + let runningQueryParams = ""; + for (const [checkboxID, queryParamValue] of Object.entries(checkboxObject)) { + await toggleCheckbox(page, checkboxID); + runningQueryParams += runningQueryParams + ? `,${queryParamValue}` + : queryParamValue; + await waitForURLContainsQueryParam( + page, + queryParamName, + runningQueryParams, + ); + } +} + +export async function toggleCheckbox(page: Page, idWithoutHash: string) { + const checkBox = page.locator(`label[for=${idWithoutHash}]`); + await checkBox.isEnabled(); + await checkBox.click(); +} + +export async function refreshPageWithCurrentURL(page: Page) { + const currentURL = page.url(); + await page.goto(currentURL); // go to new url in same tab + return page; +} + +export async function selectSortBy(page: Page, sortByValue: string) { + await page.locator("#search-sort-by-select").selectOption(sortByValue); +} + +export async function expectSortBy(page: Page, value: string) { + const selectedValue = await page + .locator('select[name="search-sort-by"]') + .inputValue(); + expect(selectedValue).toBe(value); +} + +export async function waitForSearchResultsLoaded(page: Page) { + // Wait for number of opportunities to show + const resultsHeading = page.locator('h2:has-text("Opportunities")'); + await resultsHeading.waitFor({ state: "visible", timeout: 60000 }); +} + +export async function clickAccordionWithTitle( + page: Page, + accordionTitle: string, +) { + await page + .locator(`button.usa-accordion__button:has-text("${accordionTitle}")`) + .click(); +} diff --git a/frontend/tests/playwright.config.ts b/frontend/tests/playwright.config.ts index ecf694eae..9d7ddb4c0 100644 --- a/frontend/tests/playwright.config.ts +++ b/frontend/tests/playwright.config.ts @@ -28,6 +28,8 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", + screenshot: "on", + video: "on-first-retry", }, /* Configure projects for major browsers */ From 493fb4e65096a86facdd5e2e2f8593db5f463d5e Mon Sep 17 00:00:00 2001 From: Ryan Lewis <93001277+rylew1@users.noreply.github.com> Date: Wed, 22 May 2024 10:39:57 -0700 Subject: [PATCH 05/21] [Issue #37]: finish e2e tests (#38) ## Summary Fixes #37 ## Changes proposed - add some of the relevant tests from bug bash --- frontend/README.md | 4 +- frontend/tests/e2e/search/search.spec.ts | 79 ++++++++++++++++++- .../{searchUtil.ts => searchSpecUtil.ts} | 79 ++++++++++++++++++- 3 files changed, 155 insertions(+), 7 deletions(-) rename frontend/tests/e2e/search/{searchUtil.ts => searchSpecUtil.ts} (59%) diff --git a/frontend/README.md b/frontend/README.md index 587ce3460..2238207f7 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -144,7 +144,9 @@ To run E2E tests using VS Code: 1. Download the VS Code extension described in these [Playwright docs](https://playwright.dev/docs/running-tests#run-tests-in-vs-code) 2. Follow the [instructions](https://playwright.dev/docs/getting-started-vscode#running-tests) Playwright provides -In CI, the "Front-end Checks" workflow (`.github/workflows/ci-frontend.yml`) summary will include an "Artifacts" section where there is an attached "playwright-report". [Playwright docs](https://playwright.dev/docs/ci-intro#html-report) describe how to view HTML Report in more detail. +Playwright E2E tests run "local-to-local", requiring both the frontend and the API to be running for the tests to pass - and for the database to be seeded with data. + +In CI, the "Front-end Checks" workflow (`.github/workflows/ci-frontend-e2e.yml`) summary will include an "Artifacts" section where there is an attached "playwright-report". [Playwright docs](https://playwright.dev/docs/ci-intro#html-report) describe how to view HTML Report in more detail. ## 🤖 Type checking, linting, and formatting diff --git a/frontend/tests/e2e/search/search.spec.ts b/frontend/tests/e2e/search/search.spec.ts index 99d046961..85904bc6a 100644 --- a/frontend/tests/e2e/search/search.spec.ts +++ b/frontend/tests/e2e/search/search.spec.ts @@ -1,19 +1,25 @@ import { clickAccordionWithTitle, + clickLastPaginationPage, clickMobileNavMenu, + clickPaginationPageNumber, clickSearchNavLink, expectCheckboxIDIsChecked, expectSortBy, expectURLContainsQueryParam, fillSearchInputAndSubmit, + getFirstSearchResultTitle, + getLastSearchResultTitle, getMobileMenuButton, + getNumberOfOpportunitySearchResults, getSearchInput, hasMobileMenu, refreshPageWithCurrentURL, + selectOppositeSortOption, selectSortBy, toggleCheckboxes, - waitForSearchResultsLoaded, -} from "./searchUtil"; + waitForSearchResultsInitialLoad, +} from "./searchSpecUtil"; import { expect, test } from "@playwright/test"; test("should navigate from index to search page", async ({ page }) => { @@ -63,6 +69,7 @@ test.describe("Search page tests", () => { expectURLContainsQueryParam(page, "query", searchTerm); + // eslint-disable-next-line testing-library/prefer-screen-queries const resultsHeading = page.getByRole("heading", { name: /0 Opportunities/i, }); @@ -91,7 +98,7 @@ test.describe("Search page tests", () => { await expect(loadingIndicator).toBeVisible(); await expect(loadingIndicator).toBeHidden(); }); - test("should retain filters in a new tab", async ({ page }) => { + test("should refresh and retain filters in a new tab", async ({ page }) => { // Set all inputs, then refresh the page. Those same inputs should be // set from query params. const searchTerm = "education"; @@ -119,7 +126,7 @@ test.describe("Search page tests", () => { await selectSortBy(page, "agencyDesc"); - await waitForSearchResultsLoaded(page); + await waitForSearchResultsInitialLoad(page); await fillSearchInputAndSubmit(searchTerm, page); await toggleCheckboxes(page, statusCheckboxes, "status"); @@ -167,4 +174,68 @@ test.describe("Search page tests", () => { await expectCheckboxIDIsChecked(page, `#${checkboxID}`); } }); + + test("resets page back to 1 when choosing a filter", async ({ page }) => { + await clickPaginationPageNumber(page, 2); + + // Verify that page 1 is highlighted + let currentPageButton = page.locator(".usa-pagination__button.usa-current"); + await expect(currentPageButton).toHaveAttribute("aria-label", "Page 2"); + + // Select the 'Closed' checkbox under 'Opportunity status' + const statusCheckboxes = { + "status-closed": "closed", + }; + await toggleCheckboxes(page, statusCheckboxes, "status"); + + // Wait for the page to reload + await waitForSearchResultsInitialLoad(page); + + // Verify that page 1 is highlighted + currentPageButton = page.locator(".usa-pagination__button.usa-current"); + await expect(currentPageButton).toHaveAttribute("aria-label", "Page 1"); + + // It should not have a page query param set + expectURLContainsQueryParam(page, "page", "1", false); + }); + + test("last result becomes first result when flipping sort order", async ({ + page, + }) => { + await clickLastPaginationPage(page); + + await waitForSearchResultsInitialLoad(page); + + const lastSearchResultTitle = await getLastSearchResultTitle(page); + + await selectOppositeSortOption(page); + + const firstSearchResultTitle = await getFirstSearchResultTitle(page); + + expect(firstSearchResultTitle).toBe(lastSearchResultTitle); + }); + + test("number of results is the same with none or all opportunity status checked", async ({ + page, + }) => { + const initialNumberOfOpportunityResults = + await getNumberOfOpportunitySearchResults(page); + + // check all 4 boxes + const statusCheckboxes = { + "status-forecasted": "forecasted", + "status-posted": "posted", + "status-closed": "closed", + "status-archived": "archived", + }; + + await toggleCheckboxes(page, statusCheckboxes, "status"); + + const updatedNumberOfOpportunityResults = + await getNumberOfOpportunitySearchResults(page); + + expect(initialNumberOfOpportunityResults).toBe( + updatedNumberOfOpportunityResults, + ); + }); }); diff --git a/frontend/tests/e2e/search/searchUtil.ts b/frontend/tests/e2e/search/searchSpecUtil.ts similarity index 59% rename from frontend/tests/e2e/search/searchUtil.ts rename to frontend/tests/e2e/search/searchSpecUtil.ts index 87d066533..f54d32b15 100644 --- a/frontend/tests/e2e/search/searchUtil.ts +++ b/frontend/tests/e2e/search/searchSpecUtil.ts @@ -19,9 +19,16 @@ export function expectURLContainsQueryParam( page: Page, queryParamName: string, queryParamValue: string, + shouldContain = true, ) { const currentURL = page.url(); - expect(currentURL).toContain(`${queryParamName}=${queryParamValue}`); + const queryParam = `${queryParamName}=${queryParamValue}`; + + if (shouldContain) { + expect(currentURL).toContain(queryParam); + } else { + expect(currentURL).not.toContain(queryParam); + } } export async function waitForURLContainsQueryParam( @@ -116,7 +123,7 @@ export async function expectSortBy(page: Page, value: string) { expect(selectedValue).toBe(value); } -export async function waitForSearchResultsLoaded(page: Page) { +export async function waitForSearchResultsInitialLoad(page: Page) { // Wait for number of opportunities to show const resultsHeading = page.locator('h2:has-text("Opportunities")'); await resultsHeading.waitFor({ state: "visible", timeout: 60000 }); @@ -130,3 +137,71 @@ export async function clickAccordionWithTitle( .locator(`button.usa-accordion__button:has-text("${accordionTitle}")`) .click(); } + +export async function clickPaginationPageNumber( + page: Page, + pageNumber: number, +) { + const paginationButton = page.locator( + `button[data-testid="pagination-page-number"][aria-label="Page ${pageNumber}"]`, + ); + await paginationButton.first().click(); +} + +export async function clickLastPaginationPage(page: Page) { + const paginationButtons = page.locator("li > button"); + const count = await paginationButtons.count(); + + // must be more than 1 page + if (count > 2) { + await paginationButtons.nth(count - 2).click(); + } +} + +export async function getFirstSearchResultTitle(page: Page) { + const firstResultSelector = page.locator( + ".usa-list--unstyled > li:first-child h2 a", + ); + return await firstResultSelector.textContent(); +} + +export async function getLastSearchResultTitle(page: Page) { + const lastResultSelector = page.locator( + ".usa-list--unstyled > li:last-child h2 a", + ); + return await lastResultSelector.textContent(); +} + +// If descending, select the ascending variant +export async function selectOppositeSortOption(page: Page) { + const sortByDropdown = page.locator("#search-sort-by-select"); + const currentValue = await sortByDropdown.inputValue(); + let oppositeValue; + + if (currentValue.includes("Asc")) { + oppositeValue = currentValue.replace("Asc", "Desc"); + } else if (currentValue.includes("Desc")) { + oppositeValue = currentValue.replace("Desc", "Asc"); + } else { + throw new Error(`Unexpected sort value: ${currentValue}`); + } + + await sortByDropdown.selectOption(oppositeValue); +} + +export async function waitForLoaderToBeHidden(page: Page) { + await page.waitForSelector( + ".display-flex.flex-align-center.flex-justify-center.margin-bottom-15.margin-top-15", + { state: "hidden" }, + ); +} + +export async function getNumberOfOpportunitySearchResults(page: Page) { + await waitForLoaderToBeHidden(page); + const opportunitiesText = await page + .locator("h2.tablet-lg\\:grid-col-fill") + .textContent(); + return opportunitiesText + ? parseInt(opportunitiesText.replace(/\D/g, ""), 10) + : 0; +} From cd18a47fb821c2d1bb56fb779149d8d172ee4a48 Mon Sep 17 00:00:00 2001 From: Ryan Lewis <93001277+rylew1@users.noreply.github.com> Date: Wed, 22 May 2024 10:48:20 -0700 Subject: [PATCH 06/21] [Issue #1957]: sortby posted date desc default (#4) ## Summary Fixes #1957 ## Changes proposed - Update sortby labels and ordering --- frontend/src/app/api/SearchOpportunityAPI.ts | 10 ++++++---- .../src/components/search/SearchSortBy.tsx | 20 +++++++++---------- .../src/types/search/searchRequestTypes.ts | 8 +++++++- .../components/search/SearchSortBy.test.tsx | 6 +++--- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/api/SearchOpportunityAPI.ts b/frontend/src/app/api/SearchOpportunityAPI.ts index c515bb7bc..36fdb31ac 100644 --- a/frontend/src/app/api/SearchOpportunityAPI.ts +++ b/frontend/src/app/api/SearchOpportunityAPI.ts @@ -109,7 +109,7 @@ export default class SearchOpportunityAPI extends BaseApi { closeDate: "close_date", }; - let order_by: PaginationOrderBy = "opportunity_id"; + let order_by: PaginationOrderBy = "post_date"; if (sortby) { for (const [key, value] of Object.entries(orderByFieldLookup)) { if (sortby.startsWith(key)) { @@ -119,9 +119,11 @@ export default class SearchOpportunityAPI extends BaseApi { } } - const sort_direction: PaginationSortDirection = sortby?.endsWith("Desc") - ? "descending" - : "ascending"; + // default to descending + let sort_direction: PaginationSortDirection = "descending"; + if (sortby) { + sort_direction = sortby?.endsWith("Desc") ? "descending" : "ascending"; + } return { order_by, diff --git a/frontend/src/components/search/SearchSortBy.tsx b/frontend/src/components/search/SearchSortBy.tsx index ebd706898..5c5475534 100644 --- a/frontend/src/components/search/SearchSortBy.tsx +++ b/frontend/src/components/search/SearchSortBy.tsx @@ -7,16 +7,16 @@ type SortOption = { }; const SORT_OPTIONS: SortOption[] = [ - { label: "Opportunity Number (Ascending)", value: "opportunityNumberAsc" }, - { label: "Opportunity Number (Descending)", value: "opportunityNumberDesc" }, - { label: "Opportunity Title (Ascending)", value: "opportunityTitleAsc" }, - { label: "Opportunity Title (Descending)", value: "opportunityTitleDesc" }, - { label: "Agency (Ascending)", value: "agencyAsc" }, - { label: "Agency (Descending)", value: "agencyDesc" }, - { label: "Posted Date (Ascending)", value: "postedDateAsc" }, - { label: "Posted Date (Descending)", value: "postedDateDesc" }, - { label: "Close Date (Ascending)", value: "closeDateAsc" }, - { label: "Close Date (Descending)", value: "closeDateDesc" }, + { label: "Posted Date (newest)", value: "postedDateDesc" }, + { label: "Posted Date (oldest)", value: "postedDateAsc" }, + { label: "Close Date (newest)", value: "closeDateDesc" }, + { label: "Close Date (oldest)", value: "closeDateAsc" }, + { label: "Opportunity Title (A to Z)", value: "opportunityTitleAsc" }, + { label: "Opportunity Title (Z to A)", value: "opportunityTitleDesc" }, + { label: "Agency (A to Z)", value: "agencyAsc" }, + { label: "Agency (Z to A)", value: "agencyDesc" }, + { label: "Opportunity Number (descending)", value: "opportunityNumberDesc" }, + { label: "Opportunity Number (ascending)", value: "opportunityNumberAsc" }, ]; interface SearchSortByProps { diff --git a/frontend/src/types/search/searchRequestTypes.ts b/frontend/src/types/search/searchRequestTypes.ts index 83afcad5c..94e78635f 100644 --- a/frontend/src/types/search/searchRequestTypes.ts +++ b/frontend/src/types/search/searchRequestTypes.ts @@ -6,7 +6,13 @@ export interface SearchFilterRequestBody { funding_category?: { one_of: string[] }; } -export type PaginationOrderBy = "opportunity_id" | "opportunity_number"; +export type PaginationOrderBy = + | "opportunity_id" + | "opportunity_number" + | "opportunity_title" + | "agency_code" + | "post_date" + | "close_date"; export type PaginationSortDirection = "ascending" | "descending"; export interface PaginationRequestBody { order_by: PaginationOrderBy; diff --git a/frontend/tests/components/search/SearchSortBy.test.tsx b/frontend/tests/components/search/SearchSortBy.test.tsx index 3dff473bd..17b6f732e 100644 --- a/frontend/tests/components/search/SearchSortBy.test.tsx +++ b/frontend/tests/components/search/SearchSortBy.test.tsx @@ -12,7 +12,7 @@ jest.mock("../../../src/hooks/useSearchParamUpdater", () => ({ })); describe("SearchSortBy", () => { - const initialQueryParams = "opportunityNumberAsc"; + const initialQueryParams = "postedDateDesc"; const mockFormRef = React.createRef(); it("should not have basic accessibility issues", async () => { @@ -36,7 +36,7 @@ describe("SearchSortBy", () => { ); expect( - screen.getByDisplayValue("Opportunity Number (Ascending)"), + screen.getByDisplayValue("Posted Date (newest)"), ).toBeInTheDocument(); }); @@ -57,7 +57,7 @@ describe("SearchSortBy", () => { }); expect( - screen.getByDisplayValue("Opportunity Title (Descending)"), + screen.getByDisplayValue("Opportunity Title (Z to A)"), ).toBeInTheDocument(); expect(requestSubmitMock).toHaveBeenCalled(); From 16f708e17e6716ec852da07116d370acfd43245b Mon Sep 17 00:00:00 2001 From: Michael Chouinard <46358556+chouinar@users.noreply.github.com> Date: Wed, 22 May 2024 13:48:48 -0400 Subject: [PATCH 07/21] Upgrade dependencies for API (May 21, 2024) (#48) ### Time to review: __1 mins__ ## Changes proposed Needed to upgrade dependencies for the API for grype issue: https://github.com/navapbc/simpler-grants-gov/actions/runs/9180615894/job/25245519194?pr=47 ## Additional information As usual, just ran `poetry update` --- api/poetry.lock | 53 ++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/api/poetry.lock b/api/poetry.lock index 2b372c21e..5fe4fa9e1 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -21,13 +21,13 @@ tz = ["backports.zoneinfo"] [[package]] name = "annotated-types" -version = "0.6.0" +version = "0.7.0" description = "Reusable constraint types to use with typing.Annotated" optional = false python-versions = ">=3.8" files = [ - {file = "annotated_types-0.6.0-py3-none-any.whl", hash = "sha256:0641064de18ba7a25dee8f96403ebc39113d0cb953a01429249d5c7564666a43"}, - {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, + {file = "annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53"}, + {file = "annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89"}, ] [[package]] @@ -156,17 +156,17 @@ files = [ [[package]] name = "boto3" -version = "1.34.103" +version = "1.34.110" description = "The AWS SDK for Python" optional = false python-versions = ">=3.8" files = [ - {file = "boto3-1.34.103-py3-none-any.whl", hash = "sha256:59b6499f1bb423dd99de6566a20d0a7cf1a5476824be3a792290fd86600e8365"}, - {file = "boto3-1.34.103.tar.gz", hash = "sha256:58d097241f3895c4a4c80c9e606689c6e06d77f55f9f53a4cc02dee7e03938b9"}, + {file = "boto3-1.34.110-py3-none-any.whl", hash = "sha256:2fc871b4a5090716c7a71af52c462e539529227f4d4888fd04896d5028f9cedc"}, + {file = "boto3-1.34.110.tar.gz", hash = "sha256:83ffe2273da7bdfdb480d85b0705f04e95bd110e9741f23328b7c76c03e6d53c"}, ] [package.dependencies] -botocore = ">=1.34.103,<1.35.0" +botocore = ">=1.34.110,<1.35.0" jmespath = ">=0.7.1,<2.0.0" s3transfer = ">=0.10.0,<0.11.0" @@ -175,13 +175,13 @@ crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] [[package]] name = "botocore" -version = "1.34.103" +version = "1.34.110" description = "Low-level, data-driven core of boto 3." optional = false python-versions = ">=3.8" files = [ - {file = "botocore-1.34.103-py3-none-any.whl", hash = "sha256:0330d139f18f78d38127e65361859e24ebd6a8bcba184f903c01bb999a3fa431"}, - {file = "botocore-1.34.103.tar.gz", hash = "sha256:5f07e2c7302c0a9f469dcd08b4ddac152e9f5888b12220242c20056255010939"}, + {file = "botocore-1.34.110-py3-none-any.whl", hash = "sha256:1edf3a825ec0a5edf238b2d42ad23305de11d5a71bb27d6f9a58b7e8862df1b6"}, + {file = "botocore-1.34.110.tar.gz", hash = "sha256:b2c98c40ecf0b1facb9e61ceb7dfa28e61ae2456490554a16c8dbf99f20d6a18"}, ] [package.dependencies] @@ -836,13 +836,13 @@ files = [ [[package]] name = "mako" -version = "1.3.3" +version = "1.3.5" description = "A super-fast templating language that borrows the best ideas from the existing templating languages." optional = false python-versions = ">=3.8" files = [ - {file = "Mako-1.3.3-py3-none-any.whl", hash = "sha256:5324b88089a8978bf76d1629774fcc2f1c07b82acdf00f4c5dd8ceadfffc4b40"}, - {file = "Mako-1.3.3.tar.gz", hash = "sha256:e16c01d9ab9c11f7290eef1cfefc093fb5a45ee4a3da09e2fec2e4d1bae54e73"}, + {file = "Mako-1.3.5-py3-none-any.whl", hash = "sha256:260f1dbc3a519453a9c856dedfe4beb4e50bd5a26d96386cb6c80856556bb91a"}, + {file = "Mako-1.3.5.tar.gz", hash = "sha256:48dbc20568c1d276a2698b36d968fa76161bf127194907ea6fc594fa81f943bc"}, ] [package.dependencies] @@ -978,7 +978,7 @@ files = [ [package.dependencies] marshmallow = [ - {version = ">=3.13.0,<4.0"}, + {version = ">=3.13.0,<4.0", optional = true, markers = "python_version < \"3.7\" or extra != \"enum\""}, {version = ">=3.18.0,<4.0", optional = true, markers = "python_version >= \"3.7\" and extra == \"enum\""}, ] typeguard = {version = ">=2.4.1,<4.0.0", optional = true, markers = "extra == \"union\""} @@ -1141,13 +1141,13 @@ files = [ [[package]] name = "platformdirs" -version = "4.2.1" +version = "4.2.2" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`." optional = false python-versions = ">=3.8" files = [ - {file = "platformdirs-4.2.1-py3-none-any.whl", hash = "sha256:17d5a1161b3fd67b390023cb2d3b026bbd40abde6fdb052dfbd3a29c3ba22ee1"}, - {file = "platformdirs-4.2.1.tar.gz", hash = "sha256:031cd18d4ec63ec53e82dceaac0417d218a6863f7745dfcc9efe7793b7039bdf"}, + {file = "platformdirs-4.2.2-py3-none-any.whl", hash = "sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee"}, + {file = "platformdirs-4.2.2.tar.gz", hash = "sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3"}, ] [package.extras] @@ -1563,7 +1563,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -1571,16 +1570,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -1597,7 +1588,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -1605,7 +1595,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -1613,13 +1602,13 @@ files = [ [[package]] name = "requests" -version = "2.31.0" +version = "2.32.2" description = "Python HTTP for Humans." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, - {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, + {file = "requests-2.32.2-py3-none-any.whl", hash = "sha256:fc06670dd0ed212426dfeb94fc1b983d917c4f9847c863f313c9dfaaffb7c23c"}, + {file = "requests-2.32.2.tar.gz", hash = "sha256:dd951ff5ecf3e3b3aa26b40703ba77495dab41da839ae72ef3c8e5d8e2433289"}, ] [package.dependencies] From 25b0295506439ff8dacfded16269ecc21d9edc4a Mon Sep 17 00:00:00 2001 From: Michael Chouinard <46358556+chouinar@users.noreply.github.com> Date: Wed, 22 May 2024 13:58:12 -0400 Subject: [PATCH 08/21] [Issue #9] Setup opensearch locally (#39) ## Summary Fixes #9 ### Time to review: __10 mins__ ## Changes proposed Setup a search index to run locally via Docker Updated makefile to automatically initialize the index + added a script to wait for the index to start up before proceeding. Setup a very basic client for connecting to the search index (will be expanded more in subsequent PRs) Basic test / test utils to verify it is working (also will be expanded) ## Context for reviewers This is the first step in getting the search index working locally. This actually gets it running, and the client works, we just aren't doing anything meaningful with it yet besides tests. ## Additional information This doesn't yet create an index that we can use, except in the test. However, if you want to test out a search index, you can go to http://localhost:5601/app/dev_tools#/console (after running `make init`) to run some queries against the (one node) cluster. https://opensearch.org/docs/latest/getting-started/communicate/#sending-requests-in-dev-tools provides some examples of how to create + use indexes that you can follow. --- api/Makefile | 15 ++++- api/bin/wait-for-local-opensearch.sh | 31 +++++++++ api/docker-compose.yml | 37 +++++++++++ api/local.env | 9 +++ api/poetry.lock | 66 ++++++++++++++++--- api/pyproject.toml | 7 ++ api/src/adapters/search/__init__.py | 4 ++ api/src/adapters/search/opensearch_client.py | 36 ++++++++++ api/src/adapters/search/opensearch_config.py | 33 ++++++++++ api/tests/conftest.py | 29 ++++++++ api/tests/src/adapters/search/__init__.py | 0 .../src/adapters/search/test_opensearch.py | 58 ++++++++++++++++ 12 files changed, 315 insertions(+), 10 deletions(-) create mode 100755 api/bin/wait-for-local-opensearch.sh create mode 100644 api/src/adapters/search/__init__.py create mode 100644 api/src/adapters/search/opensearch_client.py create mode 100644 api/src/adapters/search/opensearch_config.py create mode 100644 api/tests/src/adapters/search/__init__.py create mode 100644 api/tests/src/adapters/search/test_opensearch.py diff --git a/api/Makefile b/api/Makefile index f2774d3a7..d5daab1d2 100644 --- a/api/Makefile +++ b/api/Makefile @@ -100,7 +100,7 @@ start-debug: run-logs: start docker-compose logs --follow --no-color $(APP_NAME) -init: build init-db +init: build init-db init-opensearch clean-volumes: ## Remove project docker volumes (which includes the DB state) docker-compose down --volumes @@ -179,6 +179,19 @@ create-erds: # Create ERD diagrams for our DB schema setup-postgres-db: ## Does any initial setup necessary for our local database to work $(PY_RUN_CMD) setup-postgres-db +################################################## +# Opensearch +################################################## + +init-opensearch: start-opensearch +# TODO - in subsequent PRs, we'll add more to this command to setup the search index locally + +start-opensearch: + docker-compose up --detach opensearch-node + docker-compose up --detach opensearch-dashboards + ./bin/wait-for-local-opensearch.sh + + ################################################## # Testing diff --git a/api/bin/wait-for-local-opensearch.sh b/api/bin/wait-for-local-opensearch.sh new file mode 100755 index 000000000..a14af8048 --- /dev/null +++ b/api/bin/wait-for-local-opensearch.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# wait-for-local-opensearch + +set -e + +# Color formatting +RED='\033[0;31m' +NO_COLOR='\033[0m' + +MAX_WAIT_TIME=30 # seconds +WAIT_TIME=0 + +# Curl the healthcheck endpoint of the local opensearch +# until it returns a success response +until curl --output /dev/null --silent http://localhost:9200/_cluster/health; +do + echo "waiting on OpenSearch to initialize..." + sleep 3 + + WAIT_TIME=$(($WAIT_TIME+3)) + if [ $WAIT_TIME -gt $MAX_WAIT_TIME ] + then + echo -e "${RED}ERROR: OpenSearch appears to not be starting up, running \"docker logs opensearch-node\" to troubleshoot.${NO_COLOR}" + docker logs opensearch-node + exit 1 + fi +done + +echo "OpenSearch is ready after ~${WAIT_TIME} seconds" + + diff --git a/api/docker-compose.yml b/api/docker-compose.yml index a364c74c3..9ec206214 100644 --- a/api/docker-compose.yml +++ b/api/docker-compose.yml @@ -12,6 +12,41 @@ services: volumes: - grantsdbdata:/var/lib/postgresql/data + opensearch-node: + image: opensearchproject/opensearch:latest + container_name: opensearch-node + environment: + - cluster.name=opensearch-cluster # Name the cluster + - node.name=opensearch-node # Name the node that will run in this container + - discovery.type=single-node # Nodes to look for when discovering the cluster + - bootstrap.memory_lock=true # Disable JVM heap memory swapping + - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM + - DISABLE_INSTALL_DEMO_CONFIG=true # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch + - DISABLE_SECURITY_PLUGIN=true # Disables Security plugin + ulimits: + memlock: + soft: -1 # Set memlock to unlimited (no soft or hard limit) + hard: -1 + nofile: + soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536 + hard: 65536 + volumes: + - opensearch-data:/usr/share/opensearch/data # Creates volume called opensearch-data and mounts it to the container + ports: + - 9200:9200 # REST API + - 9600:9600 # Performance Analyzer + + opensearch-dashboards: + image: opensearchproject/opensearch-dashboards:latest + container_name: opensearch-dashboards + ports: + - 5601:5601 # Map host port 5601 to container port 5601 + expose: + - "5601" # Expose port 5601 for web access to OpenSearch Dashboards + environment: + - 'OPENSEARCH_HOSTS=["http://opensearch-node:9200"]' + - DISABLE_SECURITY_DASHBOARDS_PLUGIN=true # disables security dashboards plugin in OpenSearch Dashboards + grants-api: build: context: . @@ -28,6 +63,8 @@ services: - .:/api depends_on: - grants-db + - opensearch-node volumes: grantsdbdata: + opensearch-data: diff --git a/api/local.env b/api/local.env index fc1c1c1a4..4ca4c86b5 100644 --- a/api/local.env +++ b/api/local.env @@ -59,6 +59,15 @@ DB_SSL_MODE=allow # could contain sensitive information. HIDE_SQL_PARAMETER_LOGS=TRUE +############################ +# Opensearch Environment Variables +############################ + +OPENSEARCH_HOST=opensearch-node +OPENSEARCH_PORT=9200 +OPENSEARCH_USE_SSL=FALSE +OPENSEARCH_VERIFY_CERTS=FALSE + ############################ # AWS Defaults ############################ diff --git a/api/poetry.lock b/api/poetry.lock index 5fe4fa9e1..017f1460e 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -1106,6 +1106,30 @@ files = [ {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, ] +[[package]] +name = "opensearch-py" +version = "2.5.0" +description = "Python client for OpenSearch" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,<4,>=2.7" +files = [ + {file = "opensearch-py-2.5.0.tar.gz", hash = "sha256:0dde4ac7158a717d92a8cd81964cb99705a4b80bcf9258ba195b9a9f23f5226d"}, + {file = "opensearch_py-2.5.0-py2.py3-none-any.whl", hash = "sha256:cf093a40e272b60663f20417fc1264ac724dcf1e03c1a4542a6b44835b1e6c49"}, +] + +[package.dependencies] +certifi = ">=2022.12.07" +python-dateutil = "*" +requests = ">=2.4.0,<3.0.0" +six = "*" +urllib3 = ">=1.26.18,<2" + +[package.extras] +async = ["aiohttp (>=3,<4)"] +develop = ["black", "botocore", "coverage (<8.0.0)", "jinja2", "mock", "myst-parser", "pytest (>=3.0.0)", "pytest-cov", "pytest-mock (<4.0.0)", "pytz", "pyyaml", "requests (>=2.0.0,<3.0.0)", "sphinx", "sphinx-copybutton", "sphinx-rtd-theme"] +docs = ["aiohttp (>=3,<4)", "myst-parser", "sphinx", "sphinx-copybutton", "sphinx-rtd-theme"] +kerberos = ["requests-kerberos"] + [[package]] name = "packaging" version = "24.0" @@ -1902,6 +1926,31 @@ files = [ {file = "types_PyYAML-6.0.12.20240311-py3-none-any.whl", hash = "sha256:b845b06a1c7e54b8e5b4c683043de0d9caf205e7434b3edc678ff2411979b8f6"}, ] +[[package]] +name = "types-requests" +version = "2.31.0.1" +description = "Typing stubs for requests" +optional = false +python-versions = "*" +files = [ + {file = "types-requests-2.31.0.1.tar.gz", hash = "sha256:3de667cffa123ce698591de0ad7db034a5317457a596eb0b4944e5a9d9e8d1ac"}, + {file = "types_requests-2.31.0.1-py3-none-any.whl", hash = "sha256:afb06ef8f25ba83d59a1d424bd7a5a939082f94b94e90ab5e6116bd2559deaa3"}, +] + +[package.dependencies] +types-urllib3 = "*" + +[[package]] +name = "types-urllib3" +version = "1.26.25.14" +description = "Typing stubs for urllib3" +optional = false +python-versions = "*" +files = [ + {file = "types-urllib3-1.26.25.14.tar.gz", hash = "sha256:229b7f577c951b8c1b92c1bc2b2fdb0b49847bd2af6d1cc2a2e3dd340f3bda8f"}, + {file = "types_urllib3-1.26.25.14-py3-none-any.whl", hash = "sha256:9683bbb7fb72e32bfe9d2be6e04875fbe1b3eeec3cbb4ea231435aa7fd6b4f0e"}, +] + [[package]] name = "typing-extensions" version = "4.11.0" @@ -1941,20 +1990,19 @@ files = [ [[package]] name = "urllib3" -version = "2.2.1" +version = "1.26.18" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false -python-versions = ">=3.8" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" files = [ - {file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"}, - {file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"}, + {file = "urllib3-1.26.18-py2.py3-none-any.whl", hash = "sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07"}, + {file = "urllib3-1.26.18.tar.gz", hash = "sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0"}, ] [package.extras] -brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] -h2 = ["h2 (>=4,<5)"] -socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] -zstd = ["zstandard (>=0.18.0)"] +brotli = ["brotli (==1.0.9)", "brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] +secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] +socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] name = "watchdog" @@ -2050,4 +2098,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "c53875955c1b910c3d4aa1748dce786e3cfa6f507895d7ca4111391333decb13" +content-hash = "9671a2d68d2b1bc91b8ce111a7a32d08292475e0d1c4f058c33bf650349757e0" diff --git a/api/pyproject.toml b/api/pyproject.toml index f0a06b447..0f3c2f10b 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -22,6 +22,7 @@ gunicorn = "^22.0.0" psycopg = { extras = ["binary"], version = "^3.1.10" } pydantic-settings = "^2.0.3" flask-cors = "^4.0.0" +opensearch-py = "^2.5.0" [tool.poetry.group.dev.dependencies] black = "^23.9.1" @@ -43,6 +44,12 @@ sadisplay = "0.4.9" ruff = "^0.4.0" debugpy = "^1.8.1" freezegun = "^1.5.0" +# This isn't the latest version of types-requests +# because otherwise it depends on urllib3 v2 but opensearch-py +# needs urlib3 v1. This should be temporary as opensearch-py +# has an unreleased change to switch to v2, so I'm guessing +# in the next few weeks we can just make this the latest? +types-requests = "2.31.0.1" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/api/src/adapters/search/__init__.py b/api/src/adapters/search/__init__.py new file mode 100644 index 000000000..166441e1d --- /dev/null +++ b/api/src/adapters/search/__init__.py @@ -0,0 +1,4 @@ +from src.adapters.search.opensearch_client import SearchClient, get_opensearch_client +from src.adapters.search.opensearch_config import get_opensearch_config + +__all__ = ["SearchClient", "get_opensearch_client", "get_opensearch_config"] diff --git a/api/src/adapters/search/opensearch_client.py b/api/src/adapters/search/opensearch_client.py new file mode 100644 index 000000000..dadcfd7c4 --- /dev/null +++ b/api/src/adapters/search/opensearch_client.py @@ -0,0 +1,36 @@ +from typing import Any + +import opensearchpy + +from src.adapters.search.opensearch_config import OpensearchConfig, get_opensearch_config + +# More configuration/setup coming in: +# TODO - https://github.com/navapbc/simpler-grants-gov/issues/13 + +# Alias the OpenSearch client so that it doesn't need to be imported everywhere +# and to make it clear it's a client +SearchClient = opensearchpy.OpenSearch + + +def get_opensearch_client( + opensearch_config: OpensearchConfig | None = None, +) -> SearchClient: + if opensearch_config is None: + opensearch_config = get_opensearch_config() + + # See: https://opensearch.org/docs/latest/clients/python-low-level/ for more details + return opensearchpy.OpenSearch(**_get_connection_parameters(opensearch_config)) + + +def _get_connection_parameters(opensearch_config: OpensearchConfig) -> dict[str, Any]: + # TODO - we'll want to add the AWS connection params here when we set that up + # See: https://opensearch.org/docs/latest/clients/python-low-level/#connecting-to-amazon-opensearch-serverless + + return dict( + hosts=[{"host": opensearch_config.host, "port": opensearch_config.port}], + http_compress=True, + use_ssl=opensearch_config.use_ssl, + verify_certs=opensearch_config.verify_certs, + ssl_assert_hostname=False, + ssl_show_warn=False, + ) diff --git a/api/src/adapters/search/opensearch_config.py b/api/src/adapters/search/opensearch_config.py new file mode 100644 index 000000000..4975feb3e --- /dev/null +++ b/api/src/adapters/search/opensearch_config.py @@ -0,0 +1,33 @@ +import logging + +from pydantic import Field +from pydantic_settings import SettingsConfigDict + +from src.util.env_config import PydanticBaseEnvConfig + +logger = logging.getLogger(__name__) + + +class OpensearchConfig(PydanticBaseEnvConfig): + model_config = SettingsConfigDict(env_prefix="OPENSEARCH_") + + host: str # OPENSEARCH_HOST + port: int # OPENSEARCH_PORT + use_ssl: bool = Field(default=True) # OPENSEARCH_USE_SSL + verify_certs: bool = Field(default=True) # OPENSEARCH_VERIFY_CERTS + + +def get_opensearch_config() -> OpensearchConfig: + opensearch_config = OpensearchConfig() + + logger.info( + "Constructed opensearch configuration", + extra={ + "host": opensearch_config.host, + "port": opensearch_config.port, + "use_ssl": opensearch_config.use_ssl, + "verify_certs": opensearch_config.verify_certs, + }, + ) + + return opensearch_config diff --git a/api/tests/conftest.py b/api/tests/conftest.py index 928932b67..97173e9a7 100644 --- a/api/tests/conftest.py +++ b/api/tests/conftest.py @@ -11,6 +11,7 @@ import src.adapters.db as db import src.app as app_entry import tests.src.db.models.factories as factories +from src.adapters import search from src.constants.schema import Schemas from src.db import models from src.db.models.lookup.sync_lookup_values import sync_lookup_values @@ -143,6 +144,34 @@ def test_foreign_schema(db_schema_prefix): return f"{db_schema_prefix}{Schemas.LEGACY}" +#################### +# Opensearch Fixtures +#################### + + +@pytest.fixture(scope="session") +def search_client() -> search.SearchClient: + return search.get_opensearch_client() + + +@pytest.fixture(scope="session") +def opportunity_index(search_client): + # TODO - will adjust this in the future to use utils we'll build + # for setting up / aliasing indexes. For now, keep it simple + + # create a random index name just to make sure it won't ever conflict + # with an actual one, similar to how we create schemas for database tests + index_name = f"test_{uuid.uuid4().int}_opportunity" + + search_client.indices.create(index_name, body={}) + + try: + yield index_name + finally: + # Try to clean up the index at the end + search_client.indices.delete(index_name) + + #################### # Test App & Client #################### diff --git a/api/tests/src/adapters/search/__init__.py b/api/tests/src/adapters/search/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/api/tests/src/adapters/search/test_opensearch.py b/api/tests/src/adapters/search/test_opensearch.py new file mode 100644 index 000000000..490ffcb3b --- /dev/null +++ b/api/tests/src/adapters/search/test_opensearch.py @@ -0,0 +1,58 @@ +######################################## +# This is a placeholder set of tests, +# we'll evolve / change the structure +# as we continue developing this +# +# Just wanted something simple so I can verify +# the early steps of this setup are working +# before we actually have code to use +######################################## + + +def test_index_is_running(search_client, opportunity_index): + # Very simple test, will rewrite / remove later once we have something + # more meaningful to test. + + existing_indexes = search_client.cat.indices(format="json") + + found_opportunity_index = False + for index in existing_indexes: + if index["index"] == opportunity_index: + found_opportunity_index = True + break + + assert found_opportunity_index is True + + # Add a few records to the index + + record1 = { + "opportunity_id": 1, + "opportunity_title": "Research into how to make a search engine", + "opportunity_status": "posted", + } + record2 = { + "opportunity_id": 2, + "opportunity_title": "Research about words, and more words!", + "opportunity_status": "forecasted", + } + + search_client.index(index=opportunity_index, body=record1, id=1, refresh=True) + search_client.index(index=opportunity_index, body=record2, id=2, refresh=True) + + search_request = { + "query": { + "bool": { + "must": { + "simple_query_string": {"query": "research", "fields": ["opportunity_title"]} + } + } + } + } + response = search_client.search(index=opportunity_index, body=search_request) + assert response["hits"]["total"]["value"] == 2 + + filter_request = { + "query": {"bool": {"filter": [{"terms": {"opportunity_status": ["forecasted"]}}]}} + } + response = search_client.search(index=opportunity_index, body=filter_request) + assert response["hits"]["total"]["value"] == 1 From b40344d25f3e6ae65ed11012c0b24410f60e03e4 Mon Sep 17 00:00:00 2001 From: Michael Chouinard <46358556+chouinar@users.noreply.github.com> Date: Wed, 22 May 2024 14:05:43 -0400 Subject: [PATCH 09/21] [Issue #12] Setup the opportunity v1 endpoint which will be backed by the index (#44) ## Summary Fixes #12 ### Time to review: __5 mins__ ## Changes proposed Made a new set of v1 endpoints that are basically copy-pastes of the v0.1 opportunity endpoints ## Context for reviewers Some changes I want to make to the schemas wouldn't make sense without the search index (eg. adding the filter counts to the response). As we have no idea what the actual launch of the v0.1 endpoint is going to look like, I don't want to mess with any of that code or try to make a weird hacky approach that needs to account for both the DB implementation and the search index one. Also, I think we've heard that with the launch of the search index, we'll be "officially" launched, so might as well call in v1 at the same time. Other than adjusting the names of a few schemas in v0.1, I left that implementation alone and just copied the boilerplate that I'll fill out in subsequent tickets. ## Additional information The endpoint appears locally: ![Screenshot 2024-05-20 at 12 18 32 PM](https://github.com/navapbc/simpler-grants-gov/assets/46358556/86231ec1-417a-41c6-ad88-3d06bb6214e5) --------- Co-authored-by: nava-platform-bot --- api/openapi.generated.yml | 740 +++++++++++++++++- .../opportunities_v0_1/opportunity_routes.py | 8 +- .../opportunities_v0_1/opportunity_schemas.py | 26 +- api/src/api/opportunities_v1/__init__.py | 6 + .../opportunities_v1/opportunity_blueprint.py | 9 + .../opportunities_v1/opportunity_routes.py | 66 ++ .../opportunities_v1/opportunity_schemas.py | 298 +++++++ api/src/app.py | 2 + api/src/services/opportunities_v1/__init__.py | 0 .../opportunities_v1/get_opportunity.py | 24 + .../opportunities_v1/search_opportunities.py | 39 + .../test_opportunity_route_search.py | 1 - .../src/api/opportunities_v1/__init__.py | 0 .../src/api/opportunities_v1/conftest.py | 183 +++++ .../opportunities_v1/test_opportunity_auth.py | 21 + .../test_opportunity_route_get.py | 97 +++ .../test_opportunity_route_search.py | 19 + 17 files changed, 1488 insertions(+), 51 deletions(-) create mode 100644 api/src/api/opportunities_v1/__init__.py create mode 100644 api/src/api/opportunities_v1/opportunity_blueprint.py create mode 100644 api/src/api/opportunities_v1/opportunity_routes.py create mode 100644 api/src/api/opportunities_v1/opportunity_schemas.py create mode 100644 api/src/services/opportunities_v1/__init__.py create mode 100644 api/src/services/opportunities_v1/get_opportunity.py create mode 100644 api/src/services/opportunities_v1/search_opportunities.py create mode 100644 api/tests/src/api/opportunities_v1/__init__.py create mode 100644 api/tests/src/api/opportunities_v1/conftest.py create mode 100644 api/tests/src/api/opportunities_v1/test_opportunity_auth.py create mode 100644 api/tests/src/api/opportunities_v1/test_opportunity_route_get.py create mode 100644 api/tests/src/api/opportunities_v1/test_opportunity_route_search.py diff --git a/api/openapi.generated.yml b/api/openapi.generated.yml index b6b756ae0..7302ded44 100644 --- a/api/openapi.generated.yml +++ b/api/openapi.generated.yml @@ -23,6 +23,7 @@ tags: - name: Health - name: Opportunity v0 - name: Opportunity v0.1 +- name: Opportunity v1 servers: . paths: /health: @@ -204,7 +205,7 @@ paths: $ref: '#/components/schemas/OpportunitySearch' security: - ApiKeyAuth: [] - /v0.1/opportunities/search: + /v1/opportunities/search: post: parameters: [] responses: @@ -220,7 +221,7 @@ paths: data: type: array items: - $ref: '#/components/schemas/Opportunity' + $ref: '#/components/schemas/OpportunityV1' status_code: type: integer description: The HTTP status code @@ -291,6 +292,118 @@ paths: - $ref: '#/components/schemas/ValidationIssue' description: Authentication error tags: + - Opportunity v1 + summary: Opportunity Search + description: ' + + __ALPHA VERSION__ + + + This endpoint in its current form is primarily for testing and feedback. + + + Features in this endpoint are still under heavy development, and subject to + change. Not for production use. + + + See [Release Phases](https://github.com/github/roadmap?tab=readme-ov-file#release-phases) + for further details. + + ' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/OpportunitySearchRequestV1' + security: + - ApiKeyAuth: [] + /v0.1/opportunities/search: + post: + parameters: [] + responses: + '200': + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: The message to return + data: + type: array + items: + $ref: '#/components/schemas/OpportunityV01' + status_code: + type: integer + description: The HTTP status code + pagination_info: + description: The pagination information for paginated endpoints + type: &id007 + - object + allOf: + - $ref: '#/components/schemas/PaginationInfo' + warnings: + type: array + items: + type: &id008 + - object + allOf: + - $ref: '#/components/schemas/ValidationIssue' + description: Successful response + '422': + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: The message to return + data: + $ref: '#/components/schemas/ErrorResponse' + status_code: + type: integer + description: The HTTP status code + pagination_info: + description: The pagination information for paginated endpoints + type: *id007 + allOf: + - $ref: '#/components/schemas/PaginationInfo' + warnings: + type: array + items: + type: *id008 + allOf: + - $ref: '#/components/schemas/ValidationIssue' + description: Validation error + '401': + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: The message to return + data: + $ref: '#/components/schemas/ErrorResponse' + status_code: + type: integer + description: The HTTP status code + pagination_info: + description: The pagination information for paginated endpoints + type: *id007 + allOf: + - $ref: '#/components/schemas/PaginationInfo' + warnings: + type: array + items: + type: *id008 + allOf: + - $ref: '#/components/schemas/ValidationIssue' + description: Authentication error + tags: - Opportunity v0.1 summary: Opportunity Search description: ' @@ -313,7 +426,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/OpportunitySearchRequest' + $ref: '#/components/schemas/OpportunitySearchRequestV01' examples: example1: summary: No filters @@ -382,14 +495,14 @@ paths: description: The HTTP status code pagination_info: description: The pagination information for paginated endpoints - type: &id007 + type: &id009 - object allOf: - $ref: '#/components/schemas/PaginationInfo' warnings: type: array items: - type: &id008 + type: &id010 - object allOf: - $ref: '#/components/schemas/ValidationIssue' @@ -410,13 +523,13 @@ paths: description: The HTTP status code pagination_info: description: The pagination information for paginated endpoints - type: *id007 + type: *id009 allOf: - $ref: '#/components/schemas/PaginationInfo' warnings: type: array items: - type: *id008 + type: *id010 allOf: - $ref: '#/components/schemas/ValidationIssue' description: Authentication error @@ -436,13 +549,13 @@ paths: description: The HTTP status code pagination_info: description: The pagination information for paginated endpoints - type: *id007 + type: *id009 allOf: - $ref: '#/components/schemas/PaginationInfo' warnings: type: array items: - type: *id008 + type: *id010 allOf: - $ref: '#/components/schemas/ValidationIssue' description: Not found @@ -461,6 +574,116 @@ paths: change. Not for production use. + See [Release Phases](https://github.com/github/roadmap?tab=readme-ov-file#release-phases) + for further details. + + ' + security: + - ApiKeyAuth: [] + /v1/opportunities/{opportunity_id}: + get: + parameters: + - in: path + name: opportunity_id + schema: + type: integer + required: true + responses: + '200': + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: The message to return + data: + $ref: '#/components/schemas/OpportunityV1' + status_code: + type: integer + description: The HTTP status code + pagination_info: + description: The pagination information for paginated endpoints + type: &id011 + - object + allOf: + - $ref: '#/components/schemas/PaginationInfo' + warnings: + type: array + items: + type: &id012 + - object + allOf: + - $ref: '#/components/schemas/ValidationIssue' + description: Successful response + '401': + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: The message to return + data: + $ref: '#/components/schemas/ErrorResponse' + status_code: + type: integer + description: The HTTP status code + pagination_info: + description: The pagination information for paginated endpoints + type: *id011 + allOf: + - $ref: '#/components/schemas/PaginationInfo' + warnings: + type: array + items: + type: *id012 + allOf: + - $ref: '#/components/schemas/ValidationIssue' + description: Authentication error + '404': + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: The message to return + data: + $ref: '#/components/schemas/ErrorResponse' + status_code: + type: integer + description: The HTTP status code + pagination_info: + description: The pagination information for paginated endpoints + type: *id011 + allOf: + - $ref: '#/components/schemas/PaginationInfo' + warnings: + type: array + items: + type: *id012 + allOf: + - $ref: '#/components/schemas/ValidationIssue' + description: Not found + tags: + - Opportunity v1 + summary: Opportunity Get + description: ' + + __ALPHA VERSION__ + + + This endpoint in its current form is primarily for testing and feedback. + + + Features in this endpoint are still under heavy development, and subject to + change. Not for production use. + + See [Release Phases](https://github.com/github/roadmap?tab=readme-ov-file#release-phases) for further details. @@ -486,20 +709,20 @@ paths: type: string description: The message to return data: - $ref: '#/components/schemas/Opportunity' + $ref: '#/components/schemas/OpportunityV01' status_code: type: integer description: The HTTP status code pagination_info: description: The pagination information for paginated endpoints - type: &id009 + type: &id013 - object allOf: - $ref: '#/components/schemas/PaginationInfo' warnings: type: array items: - type: &id010 + type: &id014 - object allOf: - $ref: '#/components/schemas/ValidationIssue' @@ -520,13 +743,13 @@ paths: description: The HTTP status code pagination_info: description: The pagination information for paginated endpoints - type: *id009 + type: *id013 allOf: - $ref: '#/components/schemas/PaginationInfo' warnings: type: array items: - type: *id010 + type: *id014 allOf: - $ref: '#/components/schemas/ValidationIssue' description: Authentication error @@ -546,13 +769,13 @@ paths: description: The HTTP status code pagination_info: description: The pagination information for paginated endpoints - type: *id009 + type: *id013 allOf: - $ref: '#/components/schemas/PaginationInfo' warnings: type: array items: - type: *id010 + type: *id014 allOf: - $ref: '#/components/schemas/ValidationIssue' description: Not found @@ -768,7 +991,7 @@ components: type: string format: date-time readOnly: true - FundingInstrumentFilter: + FundingInstrumentFilterV1: type: object properties: one_of: @@ -782,7 +1005,7 @@ components: - other type: - string - FundingCategoryFilter: + FundingCategoryFilterV1: type: object properties: one_of: @@ -818,7 +1041,7 @@ components: - other type: - string - ApplicantTypeFilter: + ApplicantTypeFilterV1: type: object properties: one_of: @@ -845,7 +1068,7 @@ components: - unrestricted type: - string - OpportunityStatusFilter: + OpportunityStatusFilterV1: type: object properties: one_of: @@ -859,7 +1082,7 @@ components: - archived type: - string - AgencyFilter: + AgencyFilterV1: type: object properties: one_of: @@ -869,34 +1092,34 @@ components: type: string minLength: 2 example: US-ABC - OpportunitySearchFilter: + OpportunitySearchFilterV1: type: object properties: funding_instrument: type: - object allOf: - - $ref: '#/components/schemas/FundingInstrumentFilter' + - $ref: '#/components/schemas/FundingInstrumentFilterV1' funding_category: type: - object allOf: - - $ref: '#/components/schemas/FundingCategoryFilter' + - $ref: '#/components/schemas/FundingCategoryFilterV1' applicant_type: type: - object allOf: - - $ref: '#/components/schemas/ApplicantTypeFilter' + - $ref: '#/components/schemas/ApplicantTypeFilterV1' opportunity_status: type: - object allOf: - - $ref: '#/components/schemas/OpportunityStatusFilter' + - $ref: '#/components/schemas/OpportunityStatusFilterV1' agency: type: - object allOf: - - $ref: '#/components/schemas/AgencyFilter' + - $ref: '#/components/schemas/AgencyFilterV1' OpportunityPagination: type: object properties: @@ -932,7 +1155,7 @@ components: - page_offset - page_size - sort_direction - OpportunitySearchRequest: + OpportunitySearchRequestV1: type: object properties: query: @@ -945,7 +1168,7 @@ components: type: - object allOf: - - $ref: '#/components/schemas/OpportunitySearchFilter' + - $ref: '#/components/schemas/OpportunitySearchFilterV1' pagination: type: - object @@ -953,7 +1176,456 @@ components: - $ref: '#/components/schemas/OpportunityPagination' required: - pagination - OpportunityAssistanceListing: + OpportunityAssistanceListingV1: + type: object + properties: + program_title: + type: string + description: The name of the program, see https://sam.gov/content/assistance-listings + for more detail + example: Space Technology + assistance_listing_number: + type: string + description: The assistance listing number, see https://sam.gov/content/assistance-listings + for more detail + example: '43.012' + OpportunitySummaryV1: + type: object + properties: + summary_description: + type: string + description: The summary of the opportunity + example: This opportunity aims to unravel the mysteries of the universe. + is_cost_sharing: + type: boolean + description: Whether or not the opportunity has a cost sharing/matching + requirement + is_forecast: + type: boolean + description: Whether the opportunity is forecasted, that is, the information + is only an estimate and not yet official + example: false + close_date: + type: string + format: date + description: The date that the opportunity will close - only set if is_forecast=False + close_date_description: + type: string + description: Optional details regarding the close date + example: Proposals are due earlier than usual. + post_date: + type: string + format: date + description: The date the opportunity was posted + archive_date: + type: string + format: date + description: When the opportunity will be archived + expected_number_of_awards: + type: integer + description: The number of awards the opportunity is expected to award + example: 10 + estimated_total_program_funding: + type: integer + description: The total program funding of the opportunity in US Dollars + example: 10000000 + award_floor: + type: integer + description: The minimum amount an opportunity would award + example: 10000 + award_ceiling: + type: integer + description: The maximum amount an opportunity would award + example: 100000 + additional_info_url: + type: string + description: A URL to a website that can provide additional information + about the opportunity + example: grants.gov + additional_info_url_description: + type: string + description: The text to display for the additional_info_url link + example: Click me for more info + forecasted_post_date: + type: string + format: date + description: Forecasted opportunity only. The date the opportunity is expected + to be posted, and transition out of being a forecast + forecasted_close_date: + type: string + format: date + description: Forecasted opportunity only. The date the opportunity is expected + to be close once posted. + forecasted_close_date_description: + type: string + description: Forecasted opportunity only. Optional details regarding the + forecasted closed date. + example: Proposals will probably be due on this date + forecasted_award_date: + type: string + format: date + description: Forecasted opportunity only. The date the grantor plans to + award the opportunity. + forecasted_project_start_date: + type: string + format: date + description: Forecasted opportunity only. The date the grantor expects the + award recipient should start their project + fiscal_year: + type: integer + description: Forecasted opportunity only. The fiscal year the project is + expected to be funded and launched + funding_category_description: + type: string + description: Additional information about the funding category + example: Economic Support + applicant_eligibility_description: + type: string + description: Additional information about the types of applicants that are + eligible + example: All types of domestic applicants are eligible to apply + agency_code: + type: string + description: The agency who owns the opportunity + example: US-ABC + agency_name: + type: string + description: The name of the agency who owns the opportunity + example: US Alphabetical Basic Corp + agency_phone_number: + type: string + description: The phone number of the agency who owns the opportunity + example: 123-456-7890 + agency_contact_description: + type: string + description: Information regarding contacting the agency who owns the opportunity + example: For more information, reach out to Jane Smith at agency US-ABC + agency_email_address: + type: string + description: The contact email of the agency who owns the opportunity + example: fake_email@grants.gov + agency_email_address_description: + type: string + description: The text for the link to the agency email address + example: Click me to email the agency + funding_instruments: + type: array + items: + enum: + - cooperative_agreement + - grant + - procurement_contract + - other + type: + - string + funding_categories: + type: array + items: + enum: + - recovery_act + - agriculture + - arts + - business_and_commerce + - community_development + - consumer_protection + - disaster_prevention_and_relief + - education + - employment_labor_and_training + - energy + - environment + - food_and_nutrition + - health + - housing + - humanities + - infrastructure_investment_and_jobs_act + - information_and_statistics + - income_security_and_social_services + - law_justice_and_legal_services + - natural_resources + - opportunity_zone_benefits + - regional_development + - science_technology_and_other_research_and_development + - transportation + - affordable_care_act + - other + type: + - string + applicant_types: + type: array + items: + enum: + - state_governments + - county_governments + - city_or_township_governments + - special_district_governments + - independent_school_districts + - public_and_state_institutions_of_higher_education + - private_institutions_of_higher_education + - federally_recognized_native_american_tribal_governments + - other_native_american_tribal_organizations + - public_and_indian_housing_authorities + - nonprofits_non_higher_education_with_501c3 + - nonprofits_non_higher_education_without_501c3 + - individuals + - for_profit_organizations_other_than_small_businesses + - small_businesses + - other + - unrestricted + type: + - string + OpportunityV1: + type: object + properties: + opportunity_id: + type: integer + readOnly: true + description: The internal ID of the opportunity + example: 12345 + opportunity_number: + type: string + description: The funding opportunity number + example: ABC-123-XYZ-001 + opportunity_title: + type: string + description: The title of the opportunity + example: Research into conservation techniques + agency: + type: string + description: The agency who created the opportunity + example: US-ABC + category: + description: The opportunity category + example: !!python/object/apply:src.constants.lookup_constants.OpportunityCategory + - discretionary + enum: + - discretionary + - mandatory + - continuation + - earmark + - other + type: + - string + category_explanation: + type: string + description: Explanation of the category when the category is 'O' (other) + example: null + opportunity_assistance_listings: + type: array + items: + type: + - object + allOf: + - $ref: '#/components/schemas/OpportunityAssistanceListingV1' + summary: + type: + - object + allOf: + - $ref: '#/components/schemas/OpportunitySummaryV1' + opportunity_status: + description: The current status of the opportunity + example: !!python/object/apply:src.constants.lookup_constants.OpportunityStatus + - posted + enum: + - forecasted + - posted + - closed + - archived + type: + - string + created_at: + type: string + format: date-time + readOnly: true + updated_at: + type: string + format: date-time + readOnly: true + FundingInstrumentFilterV01: + type: object + properties: + one_of: + type: array + minItems: 1 + items: + enum: + - cooperative_agreement + - grant + - procurement_contract + - other + type: + - string + FundingCategoryFilterV01: + type: object + properties: + one_of: + type: array + minItems: 1 + items: + enum: + - recovery_act + - agriculture + - arts + - business_and_commerce + - community_development + - consumer_protection + - disaster_prevention_and_relief + - education + - employment_labor_and_training + - energy + - environment + - food_and_nutrition + - health + - housing + - humanities + - infrastructure_investment_and_jobs_act + - information_and_statistics + - income_security_and_social_services + - law_justice_and_legal_services + - natural_resources + - opportunity_zone_benefits + - regional_development + - science_technology_and_other_research_and_development + - transportation + - affordable_care_act + - other + type: + - string + ApplicantTypeFilterV01: + type: object + properties: + one_of: + type: array + minItems: 1 + items: + enum: + - state_governments + - county_governments + - city_or_township_governments + - special_district_governments + - independent_school_districts + - public_and_state_institutions_of_higher_education + - private_institutions_of_higher_education + - federally_recognized_native_american_tribal_governments + - other_native_american_tribal_organizations + - public_and_indian_housing_authorities + - nonprofits_non_higher_education_with_501c3 + - nonprofits_non_higher_education_without_501c3 + - individuals + - for_profit_organizations_other_than_small_businesses + - small_businesses + - other + - unrestricted + type: + - string + OpportunityStatusFilterV01: + type: object + properties: + one_of: + type: array + minItems: 1 + items: + enum: + - forecasted + - posted + - closed + - archived + type: + - string + AgencyFilterV01: + type: object + properties: + one_of: + type: array + minItems: 1 + items: + type: string + minLength: 2 + example: US-ABC + OpportunitySearchFilterV01: + type: object + properties: + funding_instrument: + type: + - object + allOf: + - $ref: '#/components/schemas/FundingInstrumentFilterV01' + funding_category: + type: + - object + allOf: + - $ref: '#/components/schemas/FundingCategoryFilterV01' + applicant_type: + type: + - object + allOf: + - $ref: '#/components/schemas/ApplicantTypeFilterV01' + opportunity_status: + type: + - object + allOf: + - $ref: '#/components/schemas/OpportunityStatusFilterV01' + agency: + type: + - object + allOf: + - $ref: '#/components/schemas/AgencyFilterV01' + OpportunityPagination1: + type: object + properties: + order_by: + type: string + enum: + - opportunity_id + - opportunity_number + - opportunity_title + - post_date + - close_date + - agency_code + description: The field to sort the response by + sort_direction: + description: Whether to sort the response ascending or descending + enum: + - ascending + - descending + type: + - string + page_size: + type: integer + minimum: 1 + description: The size of the page to fetch + example: 25 + page_offset: + type: integer + minimum: 1 + description: The page number to fetch, starts counting from 1 + example: 1 + required: + - order_by + - page_offset + - page_size + - sort_direction + OpportunitySearchRequestV01: + type: object + properties: + query: + type: string + minLength: 1 + maxLength: 100 + description: Query string which searches against several text fields + example: research + filters: + type: + - object + allOf: + - $ref: '#/components/schemas/OpportunitySearchFilterV01' + pagination: + type: + - object + allOf: + - $ref: '#/components/schemas/OpportunityPagination1' + required: + - pagination + OpportunityAssistanceListingV01: type: object properties: program_title: @@ -966,7 +1638,7 @@ components: description: The assistance listing number, see https://sam.gov/content/assistance-listings for more detail example: '43.012' - OpportunitySummary: + OpportunitySummaryV01: type: object properties: summary_description: @@ -1150,7 +1822,7 @@ components: - unrestricted type: - string - Opportunity: + OpportunityV01: type: object properties: opportunity_id: @@ -1192,12 +1864,12 @@ components: type: - object allOf: - - $ref: '#/components/schemas/OpportunityAssistanceListing' + - $ref: '#/components/schemas/OpportunityAssistanceListingV01' summary: type: - object allOf: - - $ref: '#/components/schemas/OpportunitySummary' + - $ref: '#/components/schemas/OpportunitySummaryV01' opportunity_status: description: The current status of the opportunity example: !!python/object/apply:src.constants.lookup_constants.OpportunityStatus diff --git a/api/src/api/opportunities_v0_1/opportunity_routes.py b/api/src/api/opportunities_v0_1/opportunity_routes.py index a3b57f6f1..6ae77d6d0 100644 --- a/api/src/api/opportunities_v0_1/opportunity_routes.py +++ b/api/src/api/opportunities_v0_1/opportunity_routes.py @@ -62,10 +62,12 @@ @opportunity_blueprint.post("/opportunities/search") @opportunity_blueprint.input( - opportunity_schemas.OpportunitySearchRequestSchema, arg_name="search_params", examples=examples + opportunity_schemas.OpportunitySearchRequestV01Schema, + arg_name="search_params", + examples=examples, ) # many=True allows us to return a list of opportunity objects -@opportunity_blueprint.output(opportunity_schemas.OpportunitySchema(many=True)) +@opportunity_blueprint.output(opportunity_schemas.OpportunityV01Schema(many=True)) @opportunity_blueprint.auth_required(api_key_auth) @opportunity_blueprint.doc(description=SHARED_ALPHA_DESCRIPTION) @flask_db.with_db_session() @@ -90,7 +92,7 @@ def opportunity_search(db_session: db.Session, search_params: dict) -> response. @opportunity_blueprint.get("/opportunities/") -@opportunity_blueprint.output(opportunity_schemas.OpportunitySchema) +@opportunity_blueprint.output(opportunity_schemas.OpportunityV01Schema) @opportunity_blueprint.auth_required(api_key_auth) @opportunity_blueprint.doc(description=SHARED_ALPHA_DESCRIPTION) @flask_db.with_db_session() diff --git a/api/src/api/opportunities_v0_1/opportunity_schemas.py b/api/src/api/opportunities_v0_1/opportunity_schemas.py index 257b05cd8..a54384660 100644 --- a/api/src/api/opportunities_v0_1/opportunity_schemas.py +++ b/api/src/api/opportunities_v0_1/opportunity_schemas.py @@ -10,7 +10,7 @@ from src.pagination.pagination_schema import generate_pagination_schema -class OpportunitySummarySchema(Schema): +class OpportunitySummaryV01Schema(Schema): summary_description = fields.String( metadata={ "description": "The summary of the opportunity", @@ -178,7 +178,7 @@ class OpportunitySummarySchema(Schema): applicant_types = fields.List(fields.Enum(ApplicantType)) -class OpportunityAssistanceListingSchema(Schema): +class OpportunityAssistanceListingV01Schema(Schema): program_title = fields.String( metadata={ "description": "The name of the program, see https://sam.gov/content/assistance-listings for more detail", @@ -193,7 +193,7 @@ class OpportunityAssistanceListingSchema(Schema): ) -class OpportunitySchema(Schema): +class OpportunityV01Schema(Schema): opportunity_id = fields.Integer( dump_only=True, metadata={"description": "The internal ID of the opportunity", "example": 12345}, @@ -227,9 +227,9 @@ class OpportunitySchema(Schema): ) opportunity_assistance_listings = fields.List( - fields.Nested(OpportunityAssistanceListingSchema()) + fields.Nested(OpportunityAssistanceListingV01Schema()) ) - summary = fields.Nested(OpportunitySummarySchema()) + summary = fields.Nested(OpportunitySummaryV01Schema()) opportunity_status = fields.Enum( OpportunityStatus, @@ -243,35 +243,35 @@ class OpportunitySchema(Schema): updated_at = fields.DateTime(dump_only=True) -class OpportunitySearchFilterSchema(Schema): +class OpportunitySearchFilterV01Schema(Schema): funding_instrument = fields.Nested( - StrSearchSchemaBuilder("FundingInstrumentFilterSchema") + StrSearchSchemaBuilder("FundingInstrumentFilterV01Schema") .with_one_of(allowed_values=FundingInstrument) .build() ) funding_category = fields.Nested( - StrSearchSchemaBuilder("FundingCategoryFilterSchema") + StrSearchSchemaBuilder("FundingCategoryFilterV01Schema") .with_one_of(allowed_values=FundingCategory) .build() ) applicant_type = fields.Nested( - StrSearchSchemaBuilder("ApplicantTypeFilterSchema") + StrSearchSchemaBuilder("ApplicantTypeFilterV01Schema") .with_one_of(allowed_values=ApplicantType) .build() ) opportunity_status = fields.Nested( - StrSearchSchemaBuilder("OpportunityStatusFilterSchema") + StrSearchSchemaBuilder("OpportunityStatusFilterV01Schema") .with_one_of(allowed_values=OpportunityStatus) .build() ) agency = fields.Nested( - StrSearchSchemaBuilder("AgencyFilterSchema") + StrSearchSchemaBuilder("AgencyFilterV01Schema") .with_one_of(example="US-ABC", minimum_length=2) .build() ) -class OpportunitySearchRequestSchema(Schema): +class OpportunitySearchRequestV01Schema(Schema): query = fields.String( metadata={ "description": "Query string which searches against several text fields", @@ -280,7 +280,7 @@ class OpportunitySearchRequestSchema(Schema): validate=[validators.Length(min=1, max=100)], ) - filters = fields.Nested(OpportunitySearchFilterSchema()) + filters = fields.Nested(OpportunitySearchFilterV01Schema()) pagination = fields.Nested( generate_pagination_schema( diff --git a/api/src/api/opportunities_v1/__init__.py b/api/src/api/opportunities_v1/__init__.py new file mode 100644 index 000000000..c757789dc --- /dev/null +++ b/api/src/api/opportunities_v1/__init__.py @@ -0,0 +1,6 @@ +from src.api.opportunities_v1.opportunity_blueprint import opportunity_blueprint + +# import opportunity_routes module to register the API routes on the blueprint +import src.api.opportunities_v1.opportunity_routes # noqa: F401 E402 isort:skip + +__all__ = ["opportunity_blueprint"] diff --git a/api/src/api/opportunities_v1/opportunity_blueprint.py b/api/src/api/opportunities_v1/opportunity_blueprint.py new file mode 100644 index 000000000..db88ee426 --- /dev/null +++ b/api/src/api/opportunities_v1/opportunity_blueprint.py @@ -0,0 +1,9 @@ +from apiflask import APIBlueprint + +opportunity_blueprint = APIBlueprint( + "opportunity_v1", + __name__, + tag="Opportunity v1", + cli_group="opportunity_v1", + url_prefix="/v1", +) diff --git a/api/src/api/opportunities_v1/opportunity_routes.py b/api/src/api/opportunities_v1/opportunity_routes.py new file mode 100644 index 000000000..0d94996b0 --- /dev/null +++ b/api/src/api/opportunities_v1/opportunity_routes.py @@ -0,0 +1,66 @@ +import logging + +import src.adapters.db as db +import src.adapters.db.flask_db as flask_db +import src.api.opportunities_v1.opportunity_schemas as opportunity_schemas +import src.api.response as response +from src.api.opportunities_v1.opportunity_blueprint import opportunity_blueprint +from src.auth.api_key_auth import api_key_auth +from src.logging.flask_logger import add_extra_data_to_current_request_logs +from src.services.opportunities_v1.get_opportunity import get_opportunity +from src.services.opportunities_v1.search_opportunities import search_opportunities +from src.util.dict_util import flatten_dict + +logger = logging.getLogger(__name__) + +# Descriptions in OpenAPI support markdown https://swagger.io/specification/ +SHARED_ALPHA_DESCRIPTION = """ +__ALPHA VERSION__ + +This endpoint in its current form is primarily for testing and feedback. + +Features in this endpoint are still under heavy development, and subject to change. Not for production use. + +See [Release Phases](https://github.com/github/roadmap?tab=readme-ov-file#release-phases) for further details. +""" + + +@opportunity_blueprint.post("/opportunities/search") +@opportunity_blueprint.input( + opportunity_schemas.OpportunitySearchRequestV1Schema, arg_name="search_params" +) +# many=True allows us to return a list of opportunity objects +@opportunity_blueprint.output(opportunity_schemas.OpportunityV1Schema(many=True)) +@opportunity_blueprint.auth_required(api_key_auth) +@opportunity_blueprint.doc(description=SHARED_ALPHA_DESCRIPTION) +def opportunity_search(search_params: dict) -> response.ApiResponse: + add_extra_data_to_current_request_logs(flatten_dict(search_params, prefix="request.body")) + logger.info("POST /v1/opportunities/search") + + opportunities, pagination_info = search_opportunities(search_params) + + add_extra_data_to_current_request_logs( + { + "response.pagination.total_pages": pagination_info.total_pages, + "response.pagination.total_records": pagination_info.total_records, + } + ) + logger.info("Successfully fetched opportunities") + + return response.ApiResponse( + message="Success", data=opportunities, pagination_info=pagination_info + ) + + +@opportunity_blueprint.get("/opportunities/") +@opportunity_blueprint.output(opportunity_schemas.OpportunityV1Schema) +@opportunity_blueprint.auth_required(api_key_auth) +@opportunity_blueprint.doc(description=SHARED_ALPHA_DESCRIPTION) +@flask_db.with_db_session() +def opportunity_get(db_session: db.Session, opportunity_id: int) -> response.ApiResponse: + add_extra_data_to_current_request_logs({"opportunity.opportunity_id": opportunity_id}) + logger.info("GET /v1/opportunities/:opportunity_id") + with db_session.begin(): + opportunity = get_opportunity(db_session, opportunity_id) + + return response.ApiResponse(message="Success", data=opportunity) diff --git a/api/src/api/opportunities_v1/opportunity_schemas.py b/api/src/api/opportunities_v1/opportunity_schemas.py new file mode 100644 index 000000000..5f72c7958 --- /dev/null +++ b/api/src/api/opportunities_v1/opportunity_schemas.py @@ -0,0 +1,298 @@ +from src.api.schemas.extension import Schema, fields, validators +from src.api.schemas.search_schema import StrSearchSchemaBuilder +from src.constants.lookup_constants import ( + ApplicantType, + FundingCategory, + FundingInstrument, + OpportunityCategory, + OpportunityStatus, +) +from src.pagination.pagination_schema import generate_pagination_schema + + +class OpportunitySummaryV1Schema(Schema): + summary_description = fields.String( + metadata={ + "description": "The summary of the opportunity", + "example": "This opportunity aims to unravel the mysteries of the universe.", + } + ) + is_cost_sharing = fields.Boolean( + metadata={ + "description": "Whether or not the opportunity has a cost sharing/matching requirement", + } + ) + is_forecast = fields.Boolean( + metadata={ + "description": "Whether the opportunity is forecasted, that is, the information is only an estimate and not yet official", + "example": False, + } + ) + + close_date = fields.Date( + metadata={ + "description": "The date that the opportunity will close - only set if is_forecast=False", + } + ) + close_date_description = fields.String( + metadata={ + "description": "Optional details regarding the close date", + "example": "Proposals are due earlier than usual.", + } + ) + + post_date = fields.Date( + metadata={ + "description": "The date the opportunity was posted", + } + ) + archive_date = fields.Date( + metadata={ + "description": "When the opportunity will be archived", + } + ) + # not including unarchive date at the moment + + expected_number_of_awards = fields.Integer( + metadata={ + "description": "The number of awards the opportunity is expected to award", + "example": 10, + } + ) + estimated_total_program_funding = fields.Integer( + metadata={ + "description": "The total program funding of the opportunity in US Dollars", + "example": 10_000_000, + } + ) + award_floor = fields.Integer( + metadata={ + "description": "The minimum amount an opportunity would award", + "example": 10_000, + } + ) + award_ceiling = fields.Integer( + metadata={ + "description": "The maximum amount an opportunity would award", + "example": 100_000, + } + ) + + additional_info_url = fields.String( + metadata={ + "description": "A URL to a website that can provide additional information about the opportunity", + "example": "grants.gov", + } + ) + additional_info_url_description = fields.String( + metadata={ + "description": "The text to display for the additional_info_url link", + "example": "Click me for more info", + } + ) + + forecasted_post_date = fields.Date( + metadata={ + "description": "Forecasted opportunity only. The date the opportunity is expected to be posted, and transition out of being a forecast" + } + ) + forecasted_close_date = fields.Date( + metadata={ + "description": "Forecasted opportunity only. The date the opportunity is expected to be close once posted." + } + ) + forecasted_close_date_description = fields.String( + metadata={ + "description": "Forecasted opportunity only. Optional details regarding the forecasted closed date.", + "example": "Proposals will probably be due on this date", + } + ) + forecasted_award_date = fields.Date( + metadata={ + "description": "Forecasted opportunity only. The date the grantor plans to award the opportunity." + } + ) + forecasted_project_start_date = fields.Date( + metadata={ + "description": "Forecasted opportunity only. The date the grantor expects the award recipient should start their project" + } + ) + fiscal_year = fields.Integer( + metadata={ + "description": "Forecasted opportunity only. The fiscal year the project is expected to be funded and launched" + } + ) + + funding_category_description = fields.String( + metadata={ + "description": "Additional information about the funding category", + "example": "Economic Support", + } + ) + applicant_eligibility_description = fields.String( + metadata={ + "description": "Additional information about the types of applicants that are eligible", + "example": "All types of domestic applicants are eligible to apply", + } + ) + + agency_code = fields.String( + metadata={ + "description": "The agency who owns the opportunity", + "example": "US-ABC", + } + ) + agency_name = fields.String( + metadata={ + "description": "The name of the agency who owns the opportunity", + "example": "US Alphabetical Basic Corp", + } + ) + agency_phone_number = fields.String( + metadata={ + "description": "The phone number of the agency who owns the opportunity", + "example": "123-456-7890", + } + ) + agency_contact_description = fields.String( + metadata={ + "description": "Information regarding contacting the agency who owns the opportunity", + "example": "For more information, reach out to Jane Smith at agency US-ABC", + } + ) + agency_email_address = fields.String( + metadata={ + "description": "The contact email of the agency who owns the opportunity", + "example": "fake_email@grants.gov", + } + ) + agency_email_address_description = fields.String( + metadata={ + "description": "The text for the link to the agency email address", + "example": "Click me to email the agency", + } + ) + + funding_instruments = fields.List(fields.Enum(FundingInstrument)) + funding_categories = fields.List(fields.Enum(FundingCategory)) + applicant_types = fields.List(fields.Enum(ApplicantType)) + + +class OpportunityAssistanceListingV1Schema(Schema): + program_title = fields.String( + metadata={ + "description": "The name of the program, see https://sam.gov/content/assistance-listings for more detail", + "example": "Space Technology", + } + ) + assistance_listing_number = fields.String( + metadata={ + "description": "The assistance listing number, see https://sam.gov/content/assistance-listings for more detail", + "example": "43.012", + } + ) + + +class OpportunityV1Schema(Schema): + opportunity_id = fields.Integer( + dump_only=True, + metadata={"description": "The internal ID of the opportunity", "example": 12345}, + ) + + opportunity_number = fields.String( + metadata={"description": "The funding opportunity number", "example": "ABC-123-XYZ-001"} + ) + opportunity_title = fields.String( + metadata={ + "description": "The title of the opportunity", + "example": "Research into conservation techniques", + } + ) + agency = fields.String( + metadata={"description": "The agency who created the opportunity", "example": "US-ABC"} + ) + + category = fields.Enum( + OpportunityCategory, + metadata={ + "description": "The opportunity category", + "example": OpportunityCategory.DISCRETIONARY, + }, + ) + category_explanation = fields.String( + metadata={ + "description": "Explanation of the category when the category is 'O' (other)", + "example": None, + } + ) + + opportunity_assistance_listings = fields.List( + fields.Nested(OpportunityAssistanceListingV1Schema()) + ) + summary = fields.Nested(OpportunitySummaryV1Schema()) + + opportunity_status = fields.Enum( + OpportunityStatus, + metadata={ + "description": "The current status of the opportunity", + "example": OpportunityStatus.POSTED, + }, + ) + + created_at = fields.DateTime(dump_only=True) + updated_at = fields.DateTime(dump_only=True) + + +class OpportunitySearchFilterV1Schema(Schema): + funding_instrument = fields.Nested( + StrSearchSchemaBuilder("FundingInstrumentFilterV1Schema") + .with_one_of(allowed_values=FundingInstrument) + .build() + ) + funding_category = fields.Nested( + StrSearchSchemaBuilder("FundingCategoryFilterV1Schema") + .with_one_of(allowed_values=FundingCategory) + .build() + ) + applicant_type = fields.Nested( + StrSearchSchemaBuilder("ApplicantTypeFilterV1Schema") + .with_one_of(allowed_values=ApplicantType) + .build() + ) + opportunity_status = fields.Nested( + StrSearchSchemaBuilder("OpportunityStatusFilterV1Schema") + .with_one_of(allowed_values=OpportunityStatus) + .build() + ) + agency = fields.Nested( + StrSearchSchemaBuilder("AgencyFilterV1Schema") + .with_one_of(example="US-ABC", minimum_length=2) + .build() + ) + + +class OpportunitySearchRequestV1Schema(Schema): + query = fields.String( + metadata={ + "description": "Query string which searches against several text fields", + "example": "research", + }, + validate=[validators.Length(min=1, max=100)], + ) + + filters = fields.Nested(OpportunitySearchFilterV1Schema()) + + pagination = fields.Nested( + generate_pagination_schema( + "OpportunityPaginationSchema", + [ + "opportunity_id", + "opportunity_number", + "opportunity_title", + "post_date", + "close_date", + "agency_code", + ], + ), + required=True, + ) diff --git a/api/src/app.py b/api/src/app.py index 8e617cce8..0d584a683 100644 --- a/api/src/app.py +++ b/api/src/app.py @@ -13,6 +13,7 @@ from src.api.healthcheck import healthcheck_blueprint from src.api.opportunities_v0 import opportunity_blueprint as opportunities_v0_blueprint from src.api.opportunities_v0_1 import opportunity_blueprint as opportunities_v0_1_blueprint +from src.api.opportunities_v1 import opportunity_blueprint as opportunities_v1_blueprint from src.api.response import restructure_error_response from src.api.schemas import response_schema from src.auth.api_key_auth import get_app_security_scheme @@ -101,6 +102,7 @@ def register_blueprints(app: APIFlask) -> None: app.register_blueprint(healthcheck_blueprint) app.register_blueprint(opportunities_v0_blueprint) app.register_blueprint(opportunities_v0_1_blueprint) + app.register_blueprint(opportunities_v1_blueprint) app.register_blueprint(data_migration_blueprint) app.register_blueprint(task_blueprint) diff --git a/api/src/services/opportunities_v1/__init__.py b/api/src/services/opportunities_v1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/api/src/services/opportunities_v1/get_opportunity.py b/api/src/services/opportunities_v1/get_opportunity.py new file mode 100644 index 000000000..9b26cfada --- /dev/null +++ b/api/src/services/opportunities_v1/get_opportunity.py @@ -0,0 +1,24 @@ +from sqlalchemy import select +from sqlalchemy.orm import noload, selectinload + +import src.adapters.db as db +from src.api.route_utils import raise_flask_error +from src.db.models.opportunity_models import Opportunity + + +def get_opportunity(db_session: db.Session, opportunity_id: int) -> Opportunity: + opportunity: Opportunity | None = ( + db_session.execute( + select(Opportunity) + .where(Opportunity.opportunity_id == opportunity_id) + .where(Opportunity.is_draft.is_(False)) + .options(selectinload("*"), noload(Opportunity.all_opportunity_summaries)) + ) + .unique() + .scalar_one_or_none() + ) + + if opportunity is None: + raise_flask_error(404, message=f"Could not find Opportunity with ID {opportunity_id}") + + return opportunity diff --git a/api/src/services/opportunities_v1/search_opportunities.py b/api/src/services/opportunities_v1/search_opportunities.py new file mode 100644 index 000000000..1823bc31d --- /dev/null +++ b/api/src/services/opportunities_v1/search_opportunities.py @@ -0,0 +1,39 @@ +import logging +from typing import Sequence, Tuple + +from pydantic import BaseModel, Field + +from src.db.models.opportunity_models import Opportunity +from src.pagination.pagination_models import PaginationInfo, PaginationParams + +logger = logging.getLogger(__name__) + + +class SearchOpportunityFilters(BaseModel): + funding_instrument: dict | None = Field(default=None) + funding_category: dict | None = Field(default=None) + applicant_type: dict | None = Field(default=None) + opportunity_status: dict | None = Field(default=None) + agency: dict | None = Field(default=None) + + +class SearchOpportunityParams(BaseModel): + pagination: PaginationParams + + query: str | None = Field(default=None) + filters: SearchOpportunityFilters | None = Field(default=None) + + +def search_opportunities(raw_search_params: dict) -> Tuple[Sequence[Opportunity], PaginationInfo]: + search_params = SearchOpportunityParams.model_validate(raw_search_params) + + pagination_info = PaginationInfo( + page_offset=search_params.pagination.page_offset, + page_size=search_params.pagination.page_size, + order_by=search_params.pagination.order_by, + sort_direction=search_params.pagination.sort_direction, + total_records=0, + total_pages=0, + ) + + return [], pagination_info diff --git a/api/tests/src/api/opportunities_v0_1/test_opportunity_route_search.py b/api/tests/src/api/opportunities_v0_1/test_opportunity_route_search.py index 4ee7c6ba4..6529fc651 100644 --- a/api/tests/src/api/opportunities_v0_1/test_opportunity_route_search.py +++ b/api/tests/src/api/opportunities_v0_1/test_opportunity_route_search.py @@ -1121,6 +1121,5 @@ def test_opportunity_search_invalid_request_422( ) assert resp.status_code == 422 - print(resp.get_json()) response_data = resp.get_json()["errors"] assert response_data == expected_response_data diff --git a/api/tests/src/api/opportunities_v1/__init__.py b/api/tests/src/api/opportunities_v1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/api/tests/src/api/opportunities_v1/conftest.py b/api/tests/src/api/opportunities_v1/conftest.py new file mode 100644 index 000000000..c00490cff --- /dev/null +++ b/api/tests/src/api/opportunities_v1/conftest.py @@ -0,0 +1,183 @@ +from src.constants.lookup_constants import ( + ApplicantType, + FundingCategory, + FundingInstrument, + OpportunityStatus, +) +from src.db.models.opportunity_models import ( + Opportunity, + OpportunityAssistanceListing, + OpportunitySummary, +) + + +def get_search_request( + page_offset: int = 1, + page_size: int = 5, + order_by: str = "opportunity_id", + sort_direction: str = "descending", + query: str | None = None, + funding_instrument_one_of: list[FundingInstrument] | None = None, + funding_category_one_of: list[FundingCategory] | None = None, + applicant_type_one_of: list[ApplicantType] | None = None, + opportunity_status_one_of: list[OpportunityStatus] | None = None, + agency_one_of: list[str] | None = None, +): + req = { + "pagination": { + "page_offset": page_offset, + "page_size": page_size, + "order_by": order_by, + "sort_direction": sort_direction, + } + } + + filters = {} + + if funding_instrument_one_of is not None: + filters["funding_instrument"] = {"one_of": funding_instrument_one_of} + + if funding_category_one_of is not None: + filters["funding_category"] = {"one_of": funding_category_one_of} + + if applicant_type_one_of is not None: + filters["applicant_type"] = {"one_of": applicant_type_one_of} + + if opportunity_status_one_of is not None: + filters["opportunity_status"] = {"one_of": opportunity_status_one_of} + + if agency_one_of is not None: + filters["agency"] = {"one_of": agency_one_of} + + if len(filters) > 0: + req["filters"] = filters + + if query is not None: + req["query"] = query + + return req + + +##################################### +# Validation utils +##################################### + + +def validate_opportunity(db_opportunity: Opportunity, resp_opportunity: dict): + assert db_opportunity.opportunity_id == resp_opportunity["opportunity_id"] + assert db_opportunity.opportunity_number == resp_opportunity["opportunity_number"] + assert db_opportunity.opportunity_title == resp_opportunity["opportunity_title"] + assert db_opportunity.agency == resp_opportunity["agency"] + assert db_opportunity.category == resp_opportunity["category"] + assert db_opportunity.category_explanation == resp_opportunity["category_explanation"] + + validate_opportunity_summary(db_opportunity.summary, resp_opportunity["summary"]) + validate_assistance_listings( + db_opportunity.opportunity_assistance_listings, + resp_opportunity["opportunity_assistance_listings"], + ) + + assert db_opportunity.opportunity_status == resp_opportunity["opportunity_status"] + + +def validate_opportunity_summary(db_summary: OpportunitySummary, resp_summary: dict): + if db_summary is None: + assert resp_summary is None + return + + assert db_summary.summary_description == resp_summary["summary_description"] + assert db_summary.is_cost_sharing == resp_summary["is_cost_sharing"] + assert db_summary.is_forecast == resp_summary["is_forecast"] + assert str(db_summary.close_date) == str(resp_summary["close_date"]) + assert db_summary.close_date_description == resp_summary["close_date_description"] + assert str(db_summary.post_date) == str(resp_summary["post_date"]) + assert str(db_summary.archive_date) == str(resp_summary["archive_date"]) + assert db_summary.expected_number_of_awards == resp_summary["expected_number_of_awards"] + assert ( + db_summary.estimated_total_program_funding + == resp_summary["estimated_total_program_funding"] + ) + assert db_summary.award_floor == resp_summary["award_floor"] + assert db_summary.award_ceiling == resp_summary["award_ceiling"] + assert db_summary.additional_info_url == resp_summary["additional_info_url"] + assert ( + db_summary.additional_info_url_description + == resp_summary["additional_info_url_description"] + ) + + assert str(db_summary.forecasted_post_date) == str(resp_summary["forecasted_post_date"]) + assert str(db_summary.forecasted_close_date) == str(resp_summary["forecasted_close_date"]) + assert ( + db_summary.forecasted_close_date_description + == resp_summary["forecasted_close_date_description"] + ) + assert str(db_summary.forecasted_award_date) == str(resp_summary["forecasted_award_date"]) + assert str(db_summary.forecasted_project_start_date) == str( + resp_summary["forecasted_project_start_date"] + ) + assert db_summary.fiscal_year == resp_summary["fiscal_year"] + + assert db_summary.funding_category_description == resp_summary["funding_category_description"] + assert ( + db_summary.applicant_eligibility_description + == resp_summary["applicant_eligibility_description"] + ) + + assert db_summary.agency_code == resp_summary["agency_code"] + assert db_summary.agency_name == resp_summary["agency_name"] + assert db_summary.agency_phone_number == resp_summary["agency_phone_number"] + assert db_summary.agency_contact_description == resp_summary["agency_contact_description"] + assert db_summary.agency_email_address == resp_summary["agency_email_address"] + assert ( + db_summary.agency_email_address_description + == resp_summary["agency_email_address_description"] + ) + + assert set(db_summary.funding_instruments) == set(resp_summary["funding_instruments"]) + assert set(db_summary.funding_categories) == set(resp_summary["funding_categories"]) + assert set(db_summary.applicant_types) == set(resp_summary["applicant_types"]) + + +def validate_assistance_listings( + db_assistance_listings: list[OpportunityAssistanceListing], resp_listings: list[dict] +) -> None: + # In order to compare this list, sort them both the same and compare from there + db_assistance_listings.sort(key=lambda a: (a.assistance_listing_number, a.program_title)) + resp_listings.sort(key=lambda a: (a["assistance_listing_number"], a["program_title"])) + + assert len(db_assistance_listings) == len(resp_listings) + for db_assistance_listing, resp_listing in zip( + db_assistance_listings, resp_listings, strict=True + ): + assert ( + db_assistance_listing.assistance_listing_number + == resp_listing["assistance_listing_number"] + ) + assert db_assistance_listing.program_title == resp_listing["program_title"] + + +def validate_search_pagination( + search_response: dict, + search_request: dict, + expected_total_pages: int, + expected_total_records: int, + expected_response_record_count: int, +): + pagination_info = search_response["pagination_info"] + assert pagination_info["page_offset"] == search_request["pagination"]["page_offset"] + assert pagination_info["page_size"] == search_request["pagination"]["page_size"] + assert pagination_info["order_by"] == search_request["pagination"]["order_by"] + assert pagination_info["sort_direction"] == search_request["pagination"]["sort_direction"] + + assert pagination_info["total_pages"] == expected_total_pages + assert pagination_info["total_records"] == expected_total_records + + searched_opportunities = search_response["data"] + assert len(searched_opportunities) == expected_response_record_count + + # Verify data is sorted as expected + reverse = pagination_info["sort_direction"] == "descending" + resorted_opportunities = sorted( + searched_opportunities, key=lambda u: u[pagination_info["order_by"]], reverse=reverse + ) + assert resorted_opportunities == searched_opportunities diff --git a/api/tests/src/api/opportunities_v1/test_opportunity_auth.py b/api/tests/src/api/opportunities_v1/test_opportunity_auth.py new file mode 100644 index 000000000..352c57bfc --- /dev/null +++ b/api/tests/src/api/opportunities_v1/test_opportunity_auth.py @@ -0,0 +1,21 @@ +import pytest + +from tests.src.api.opportunities_v1.conftest import get_search_request + + +@pytest.mark.parametrize( + "method,url,body", + [ + ("POST", "/v1/opportunities/search", get_search_request()), + ("GET", "/v1/opportunities/1", None), + ], +) +def test_opportunity_unauthorized_401(client, api_auth_token, method, url, body): + # open is just the generic method that post/get/etc. call under the hood + response = client.open(url, method=method, json=body, headers={"X-Auth": "incorrect token"}) + + assert response.status_code == 401 + assert ( + response.get_json()["message"] + == "The server could not verify that you are authorized to access the URL requested" + ) diff --git a/api/tests/src/api/opportunities_v1/test_opportunity_route_get.py b/api/tests/src/api/opportunities_v1/test_opportunity_route_get.py new file mode 100644 index 000000000..875cddfd3 --- /dev/null +++ b/api/tests/src/api/opportunities_v1/test_opportunity_route_get.py @@ -0,0 +1,97 @@ +import pytest + +from src.db.models.opportunity_models import Opportunity +from tests.src.api.opportunities_v1.conftest import validate_opportunity +from tests.src.db.models.factories import ( + CurrentOpportunitySummaryFactory, + OpportunityFactory, + OpportunitySummaryFactory, +) + + +@pytest.fixture +def truncate_opportunities(db_session): + # Note that we can't just do db_session.query(Opportunity).delete() as the cascade deletes won't work automatically: + # https://docs.sqlalchemy.org/en/20/orm/queryguide/dml.html#orm-queryguide-update-delete-caveats + # but if we do it individually they will + opportunities = db_session.query(Opportunity).all() + for opp in opportunities: + db_session.delete(opp) + + # Force the deletes to the DB + db_session.commit() + + +##################################### +# GET opportunity tests +##################################### + + +@pytest.mark.parametrize( + "opportunity_params,opportunity_summary_params", + [ + ({}, {}), + # Only an opportunity exists, no other connected records + ( + { + "opportunity_assistance_listings": [], + }, + None, + ), + # Summary exists, but none of the list values set + ( + {}, + { + "link_funding_instruments": [], + "link_funding_categories": [], + "link_applicant_types": [], + }, + ), + # All possible values set to null/empty + # Note this uses traits on the factories to handle setting everything + ({"all_fields_null": True}, {"all_fields_null": True}), + ], +) +def test_get_opportunity_200( + client, api_auth_token, enable_factory_create, opportunity_params, opportunity_summary_params +): + # Split the setup of the opportunity from the opportunity summary to simplify the factory usage a bit + db_opportunity = OpportunityFactory.create( + **opportunity_params, current_opportunity_summary=None + ) # We'll set the current opportunity below + + if opportunity_summary_params is not None: + db_opportunity_summary = OpportunitySummaryFactory.create( + **opportunity_summary_params, opportunity=db_opportunity + ) + CurrentOpportunitySummaryFactory.create( + opportunity=db_opportunity, opportunity_summary=db_opportunity_summary + ) + + resp = client.get( + f"/v1/opportunities/{db_opportunity.opportunity_id}", headers={"X-Auth": api_auth_token} + ) + assert resp.status_code == 200 + response_data = resp.get_json()["data"] + + validate_opportunity(db_opportunity, response_data) + + +def test_get_opportunity_404_not_found(client, api_auth_token, truncate_opportunities): + resp = client.get("/v1/opportunities/1", headers={"X-Auth": api_auth_token}) + assert resp.status_code == 404 + assert resp.get_json()["message"] == "Could not find Opportunity with ID 1" + + +def test_get_opportunity_404_not_found_is_draft(client, api_auth_token, enable_factory_create): + # The endpoint won't return drafts, so this'll be a 404 despite existing + opportunity = OpportunityFactory.create(is_draft=True) + + resp = client.get( + f"/v1/opportunities/{opportunity.opportunity_id}", headers={"X-Auth": api_auth_token} + ) + assert resp.status_code == 404 + assert ( + resp.get_json()["message"] + == f"Could not find Opportunity with ID {opportunity.opportunity_id}" + ) diff --git a/api/tests/src/api/opportunities_v1/test_opportunity_route_search.py b/api/tests/src/api/opportunities_v1/test_opportunity_route_search.py new file mode 100644 index 000000000..6e79419db --- /dev/null +++ b/api/tests/src/api/opportunities_v1/test_opportunity_route_search.py @@ -0,0 +1,19 @@ +from tests.src.api.opportunities_v1.conftest import get_search_request + + +def test_opportunity_route_search_200(client, api_auth_token): + req = get_search_request() + + resp = client.post("/v1/opportunities/search", json=req, headers={"X-Auth": api_auth_token}) + + assert resp.status_code == 200 + + # The endpoint meaningfully only returns the pagination params back + # at the moment, so just validate that for now. + resp_body = resp.get_json() + assert resp_body["pagination_info"]["page_offset"] == req["pagination"]["page_offset"] + assert resp_body["pagination_info"]["page_size"] == req["pagination"]["page_size"] + assert resp_body["pagination_info"]["sort_direction"] == req["pagination"]["sort_direction"] + assert resp_body["pagination_info"]["order_by"] == req["pagination"]["order_by"] + assert resp_body["pagination_info"]["total_records"] == 0 + assert resp_body["pagination_info"]["total_pages"] == 0 From 879e7430d0bd9fd273dd85bd5502bdd9c3af9ac7 Mon Sep 17 00:00:00 2001 From: Michael Chouinard <46358556+chouinar@users.noreply.github.com> Date: Wed, 22 May 2024 16:15:25 -0400 Subject: [PATCH 10/21] [Issue #10] Populate the search index from the opportunity tables (#47) ## Summary Fixes #10 ### Time to review: __10 mins__ ## Changes proposed Setup a script to populate the search index by loading opportunities from the DB, jsonify'ing them, loading them into a new index, and then aliasing that index. Several utilities were created for simplifying working with the OpenSearch client (a wrapper for setting up configuration / patterns) ## Context for reviewers Iterating over the opportunities and doing something with them is a common pattern in several of our scripts, so nothing is really different there. The meaningful implementation is how we handle creating and aliasing the index. In OpenSearch you can give any index an alias (including putting multiple indexes behind the same alias). The approach is pretty simple: * Create an index * Load opportunities into the index * Atomically swap the index backing the `opportunity-index-alias` * Delete the old index if they exist This approach means that our search endpoint just needs to query the alias, and we can keep making new indexes and swapping them out behind the scenes. Because we could remake the index every few minutes, if we ever need to re-configure things like the number of shards, or any other index-creation configuration, we just update that in this script and wait for it to run again. ## Additional information I ran this locally after loading `83250` records, and it took about 61s. You can run this locally yourself by doing: ```sh make init make db-seed-local poetry run flask load-search-data load-opportunity-data ``` If you'd like to see the data, you can test it out on http://localhost:5601/app/dev_tools#/console - here is an example query that filters by the word `research` across a few fields and filters to just forecasted/posted. ```json GET opportunity-index-alias/_search { "size": 25, "from": 0, "query": { "bool": { "must": [ { "simple_query_string": { "query": "research", "default_operator": "AND", "fields": ["agency.keyword^16", "opportunity_title^2", "opportunity_number^12", "summary.summary_description", "opportunity_assistance_listings.assistance_listing_number^10", "opportunity_assistance_listings.program_title^4"] } } ], "filter": [ { "terms": { "opportunity_status": [ "forecasted", "posted" ] } } ] } } } ``` --- api/src/adapters/search/__init__.py | 4 +- api/src/adapters/search/opensearch_client.py | 115 ++++++++++++++++-- api/src/app.py | 4 + api/src/search/__init__.py | 0 api/src/search/backend/__init__.py | 2 + .../backend/load_opportunities_to_index.py | 112 +++++++++++++++++ api/src/search/backend/load_search_data.py | 15 +++ .../backend/load_search_data_blueprint.py | 5 + api/tests/conftest.py | 24 ++-- .../src/adapters/search/test_opensearch.py | 58 --------- .../adapters/search/test_opensearch_client.py | 105 ++++++++++++++++ api/tests/src/search/__init__.py | 0 api/tests/src/search/backend/__init__.py | 0 .../test_load_opportunities_to_index.py | 91 ++++++++++++++ 14 files changed, 455 insertions(+), 80 deletions(-) create mode 100644 api/src/search/__init__.py create mode 100644 api/src/search/backend/__init__.py create mode 100644 api/src/search/backend/load_opportunities_to_index.py create mode 100644 api/src/search/backend/load_search_data.py create mode 100644 api/src/search/backend/load_search_data_blueprint.py delete mode 100644 api/tests/src/adapters/search/test_opensearch.py create mode 100644 api/tests/src/adapters/search/test_opensearch_client.py create mode 100644 api/tests/src/search/__init__.py create mode 100644 api/tests/src/search/backend/__init__.py create mode 100644 api/tests/src/search/backend/test_load_opportunities_to_index.py diff --git a/api/src/adapters/search/__init__.py b/api/src/adapters/search/__init__.py index 166441e1d..6b2607a04 100644 --- a/api/src/adapters/search/__init__.py +++ b/api/src/adapters/search/__init__.py @@ -1,4 +1,4 @@ -from src.adapters.search.opensearch_client import SearchClient, get_opensearch_client +from src.adapters.search.opensearch_client import SearchClient from src.adapters.search.opensearch_config import get_opensearch_config -__all__ = ["SearchClient", "get_opensearch_client", "get_opensearch_config"] +__all__ = ["SearchClient", "get_opensearch_config"] diff --git a/api/src/adapters/search/opensearch_client.py b/api/src/adapters/search/opensearch_client.py index dadcfd7c4..b93d33917 100644 --- a/api/src/adapters/search/opensearch_client.py +++ b/api/src/adapters/search/opensearch_client.py @@ -1,25 +1,114 @@ -from typing import Any +import logging +from typing import Any, Sequence import opensearchpy from src.adapters.search.opensearch_config import OpensearchConfig, get_opensearch_config -# More configuration/setup coming in: -# TODO - https://github.com/navapbc/simpler-grants-gov/issues/13 +logger = logging.getLogger(__name__) -# Alias the OpenSearch client so that it doesn't need to be imported everywhere -# and to make it clear it's a client -SearchClient = opensearchpy.OpenSearch +class SearchClient: + def __init__(self, opensearch_config: OpensearchConfig | None = None) -> None: + if opensearch_config is None: + opensearch_config = get_opensearch_config() -def get_opensearch_client( - opensearch_config: OpensearchConfig | None = None, -) -> SearchClient: - if opensearch_config is None: - opensearch_config = get_opensearch_config() + # See: https://opensearch.org/docs/latest/clients/python-low-level/ for more details + self._client = opensearchpy.OpenSearch(**_get_connection_parameters(opensearch_config)) - # See: https://opensearch.org/docs/latest/clients/python-low-level/ for more details - return opensearchpy.OpenSearch(**_get_connection_parameters(opensearch_config)) + def create_index( + self, index_name: str, *, shard_count: int = 1, replica_count: int = 1 + ) -> None: + """ + Create an empty search index + """ + body = { + "settings": { + "index": {"number_of_shards": shard_count, "number_of_replicas": replica_count} + } + } + + logger.info("Creating search index %s", index_name, extra={"index_name": index_name}) + self._client.indices.create(index_name, body=body) + + def delete_index(self, index_name: str) -> None: + """ + Delete an index. Can also delete all indexes via a prefix. + """ + logger.info("Deleting search index %s", index_name, extra={"index_name": index_name}) + self._client.indices.delete(index=index_name) + + def bulk_upsert( + self, + index_name: str, + records: Sequence[dict[str, Any]], + primary_key_field: str, + *, + refresh: bool = True + ) -> None: + """ + Bulk upsert records to an index + + See: https://opensearch.org/docs/latest/api-reference/document-apis/bulk/ for details + In this method we only use the "index" operation which creates or updates a record + based on the id value. + """ + + bulk_operations = [] + + for record in records: + # For each record, we create two entries in the bulk operation list + # which include the unique ID + the actual record on separate lines + # When this is sent to the search index, this will send two lines like: + # + # {"index": {"_id": 123}} + # {"opportunity_id": 123, "opportunity_title": "example title", ...} + bulk_operations.append({"index": {"_id": record[primary_key_field]}}) + bulk_operations.append(record) + + logger.info( + "Upserting records to %s", + index_name, + extra={"index_name": index_name, "record_count": int(len(bulk_operations) / 2)}, + ) + self._client.bulk(index=index_name, body=bulk_operations, refresh=refresh) + + def swap_alias_index( + self, index_name: str, alias_name: str, *, delete_prior_indexes: bool = False + ) -> None: + """ + For a given index, set it to the given alias. If any existing index(es) are + attached to the alias, remove them from the alias. + + This operation is done atomically. + """ + extra = {"index_name": index_name, "index_alias": alias_name} + logger.info("Swapping index that backs alias %s", alias_name, extra=extra) + + existing_index_mapping = self._client.cat.aliases(alias_name, format="json") + existing_indexes = [i["index"] for i in existing_index_mapping] + + logger.info( + "Found existing indexes", extra=extra | {"existing_indexes": ",".join(existing_indexes)} + ) + + actions = [{"add": {"index": index_name, "alias": alias_name}}] + + for index in existing_indexes: + actions.append({"remove": {"index": index, "alias": alias_name}}) + + self._client.indices.update_aliases({"actions": actions}) + + # Cleanup old indexes now that they aren't connected to the alias + if delete_prior_indexes: + for index in existing_indexes: + self.delete_index(index) + + def search(self, index_name: str, search_query: dict) -> dict: + # TODO - add more when we build out the request/response parsing logic + # we use something like Pydantic to help reorganize the response + # object into something easier to parse. + return self._client.search(index=index_name, body=search_query) def _get_connection_parameters(opensearch_config: OpensearchConfig) -> dict[str, Any]: diff --git a/api/src/app.py b/api/src/app.py index 0d584a683..e9604157b 100644 --- a/api/src/app.py +++ b/api/src/app.py @@ -18,6 +18,7 @@ from src.api.schemas import response_schema from src.auth.api_key_auth import get_app_security_scheme from src.data_migration.data_migration_blueprint import data_migration_blueprint +from src.search.backend.load_search_data_blueprint import load_search_data_blueprint from src.task import task_blueprint logger = logging.getLogger(__name__) @@ -103,8 +104,11 @@ def register_blueprints(app: APIFlask) -> None: app.register_blueprint(opportunities_v0_blueprint) app.register_blueprint(opportunities_v0_1_blueprint) app.register_blueprint(opportunities_v1_blueprint) + + # Non-api blueprints app.register_blueprint(data_migration_blueprint) app.register_blueprint(task_blueprint) + app.register_blueprint(load_search_data_blueprint) def get_project_root_dir() -> str: diff --git a/api/src/search/__init__.py b/api/src/search/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/api/src/search/backend/__init__.py b/api/src/search/backend/__init__.py new file mode 100644 index 000000000..00a43e108 --- /dev/null +++ b/api/src/search/backend/__init__.py @@ -0,0 +1,2 @@ +# import all files so they get initialized and attached to the blueprint +from . import load_search_data # noqa: F401 diff --git a/api/src/search/backend/load_opportunities_to_index.py b/api/src/search/backend/load_opportunities_to_index.py new file mode 100644 index 000000000..a01357a96 --- /dev/null +++ b/api/src/search/backend/load_opportunities_to_index.py @@ -0,0 +1,112 @@ +import logging +from enum import StrEnum +from typing import Iterator, Sequence + +from pydantic import Field +from pydantic_settings import SettingsConfigDict +from sqlalchemy import select +from sqlalchemy.orm import noload, selectinload + +import src.adapters.db as db +import src.adapters.search as search +from src.api.opportunities_v0_1.opportunity_schemas import OpportunityV01Schema +from src.db.models.opportunity_models import CurrentOpportunitySummary, Opportunity +from src.task.task import Task +from src.util.datetime_util import get_now_us_eastern_datetime +from src.util.env_config import PydanticBaseEnvConfig + +logger = logging.getLogger(__name__) + + +class LoadOpportunitiesToIndexConfig(PydanticBaseEnvConfig): + model_config = SettingsConfigDict(env_prefix="LOAD_OPP_SEARCH_") + + shard_count: int = Field(default=1) # LOAD_OPP_SEARCH_SHARD_COUNT + replica_count: int = Field(default=1) # LOAD_OPP_SEARCH_REPLICA_COUNT + + # TODO - these might make sense to come from some sort of opportunity-search-index-config? + # look into this a bit more when we setup the search endpoint itself. + alias_name: str = Field(default="opportunity-index-alias") # LOAD_OPP_SEARCH_ALIAS_NAME + index_prefix: str = Field(default="opportunity-index") # LOAD_OPP_INDEX_PREFIX + + +class LoadOpportunitiesToIndex(Task): + class Metrics(StrEnum): + RECORDS_LOADED = "records_loaded" + + def __init__( + self, + db_session: db.Session, + search_client: search.SearchClient, + config: LoadOpportunitiesToIndexConfig | None = None, + ) -> None: + super().__init__(db_session) + + self.search_client = search_client + + if config is None: + config = LoadOpportunitiesToIndexConfig() + self.config = config + + current_timestamp = get_now_us_eastern_datetime().strftime("%Y-%m-%d_%H-%M-%S") + self.index_name = f"{self.config.index_prefix}-{current_timestamp}" + self.set_metrics({"index_name": self.index_name}) + + def run_task(self) -> None: + # create the index + self.search_client.create_index( + self.index_name, + shard_count=self.config.shard_count, + replica_count=self.config.replica_count, + ) + + # load the records + for opp_batch in self.fetch_opportunities(): + self.load_records(opp_batch) + + # handle aliasing of endpoints + self.search_client.swap_alias_index( + self.index_name, self.config.alias_name, delete_prior_indexes=True + ) + + def fetch_opportunities(self) -> Iterator[Sequence[Opportunity]]: + """ + Fetch the opportunities in batches. The iterator returned + will give you each individual batch to be processed. + + Fetches all opportunities where: + * is_draft = False + * current_opportunity_summary is not None + """ + return ( + self.db_session.execute( + select(Opportunity) + .join(CurrentOpportunitySummary) + .where( + Opportunity.is_draft.is_(False), + CurrentOpportunitySummary.opportunity_status.isnot(None), + ) + .options(selectinload("*"), noload(Opportunity.all_opportunity_summaries)) + .execution_options(yield_per=5000) + ) + .scalars() + .partitions() + ) + + def load_records(self, records: Sequence[Opportunity]) -> None: + logger.info("Loading batch of opportunities...") + schema = OpportunityV01Schema() + json_records = [] + + for record in records: + logger.info( + "Preparing opportunity for upload to search index", + extra={ + "opportunity_id": record.opportunity_id, + "opportunity_status": record.opportunity_status, + }, + ) + json_records.append(schema.dump(record)) + self.increment(self.Metrics.RECORDS_LOADED) + + self.search_client.bulk_upsert(self.index_name, json_records, "opportunity_id") diff --git a/api/src/search/backend/load_search_data.py b/api/src/search/backend/load_search_data.py new file mode 100644 index 000000000..cf6f0445f --- /dev/null +++ b/api/src/search/backend/load_search_data.py @@ -0,0 +1,15 @@ +import src.adapters.db as db +import src.adapters.search as search +from src.adapters.db import flask_db +from src.search.backend.load_opportunities_to_index import LoadOpportunitiesToIndex +from src.search.backend.load_search_data_blueprint import load_search_data_blueprint + + +@load_search_data_blueprint.cli.command( + "load-opportunity-data", help="Load opportunity data from our database to the search index" +) +@flask_db.with_db_session() +def load_opportunity_data(db_session: db.Session) -> None: + search_client = search.SearchClient() + + LoadOpportunitiesToIndex(db_session, search_client).run() diff --git a/api/src/search/backend/load_search_data_blueprint.py b/api/src/search/backend/load_search_data_blueprint.py new file mode 100644 index 000000000..fffd9f915 --- /dev/null +++ b/api/src/search/backend/load_search_data_blueprint.py @@ -0,0 +1,5 @@ +from apiflask import APIBlueprint + +load_search_data_blueprint = APIBlueprint( + "load-search-data", __name__, enable_openapi=False, cli_group="load-search-data" +) diff --git a/api/tests/conftest.py b/api/tests/conftest.py index 97173e9a7..4b45c4f2c 100644 --- a/api/tests/conftest.py +++ b/api/tests/conftest.py @@ -151,25 +151,35 @@ def test_foreign_schema(db_schema_prefix): @pytest.fixture(scope="session") def search_client() -> search.SearchClient: - return search.get_opensearch_client() + client = search.SearchClient() + try: + yield client + finally: + # Just in case a test setup an index + # in a way that didn't clean it up, delete + # all indexes at the end of a run that start with test + client.delete_index("test-*") @pytest.fixture(scope="session") def opportunity_index(search_client): - # TODO - will adjust this in the future to use utils we'll build - # for setting up / aliasing indexes. For now, keep it simple - # create a random index name just to make sure it won't ever conflict # with an actual one, similar to how we create schemas for database tests - index_name = f"test_{uuid.uuid4().int}_opportunity" + index_name = f"test-opportunity-index-{uuid.uuid4().int}" - search_client.indices.create(index_name, body={}) + search_client.create_index(index_name) try: yield index_name finally: # Try to clean up the index at the end - search_client.indices.delete(index_name) + search_client.delete_index(index_name) + + +@pytest.fixture(scope="session") +def opportunity_index_alias(search_client): + # Note we don't actually create anything, this is just a random name + return f"test-opportunity-index-alias-{uuid.uuid4().int}" #################### diff --git a/api/tests/src/adapters/search/test_opensearch.py b/api/tests/src/adapters/search/test_opensearch.py deleted file mode 100644 index 490ffcb3b..000000000 --- a/api/tests/src/adapters/search/test_opensearch.py +++ /dev/null @@ -1,58 +0,0 @@ -######################################## -# This is a placeholder set of tests, -# we'll evolve / change the structure -# as we continue developing this -# -# Just wanted something simple so I can verify -# the early steps of this setup are working -# before we actually have code to use -######################################## - - -def test_index_is_running(search_client, opportunity_index): - # Very simple test, will rewrite / remove later once we have something - # more meaningful to test. - - existing_indexes = search_client.cat.indices(format="json") - - found_opportunity_index = False - for index in existing_indexes: - if index["index"] == opportunity_index: - found_opportunity_index = True - break - - assert found_opportunity_index is True - - # Add a few records to the index - - record1 = { - "opportunity_id": 1, - "opportunity_title": "Research into how to make a search engine", - "opportunity_status": "posted", - } - record2 = { - "opportunity_id": 2, - "opportunity_title": "Research about words, and more words!", - "opportunity_status": "forecasted", - } - - search_client.index(index=opportunity_index, body=record1, id=1, refresh=True) - search_client.index(index=opportunity_index, body=record2, id=2, refresh=True) - - search_request = { - "query": { - "bool": { - "must": { - "simple_query_string": {"query": "research", "fields": ["opportunity_title"]} - } - } - } - } - response = search_client.search(index=opportunity_index, body=search_request) - assert response["hits"]["total"]["value"] == 2 - - filter_request = { - "query": {"bool": {"filter": [{"terms": {"opportunity_status": ["forecasted"]}}]}} - } - response = search_client.search(index=opportunity_index, body=filter_request) - assert response["hits"]["total"]["value"] == 1 diff --git a/api/tests/src/adapters/search/test_opensearch_client.py b/api/tests/src/adapters/search/test_opensearch_client.py new file mode 100644 index 000000000..d9ba22194 --- /dev/null +++ b/api/tests/src/adapters/search/test_opensearch_client.py @@ -0,0 +1,105 @@ +import uuid + +import pytest + +######################################################################## +# These tests are primarily looking to validate +# that our wrappers around the OpenSearch client +# are being used correctly / account for error cases correctly. +# +# We are not validating all the intricacies of OpenSearch itself. +######################################################################## + + +@pytest.fixture +def generic_index(search_client): + # This is very similar to the opportunity_index fixture, but + # is reused per unit test rather than a global value + index_name = f"test-index-{uuid.uuid4().int}" + + search_client.create_index(index_name) + + try: + yield index_name + finally: + # Try to clean up the index at the end + search_client.delete_index(index_name) + + +def test_create_and_delete_index_duplicate(search_client): + index_name = f"test-index-{uuid.uuid4().int}" + + search_client.create_index(index_name) + with pytest.raises(Exception, match="already exists"): + search_client.create_index(index_name) + + # Cleanup the index + search_client.delete_index(index_name) + with pytest.raises(Exception, match="no such index"): + search_client.delete_index(index_name) + + +def test_bulk_upsert(search_client, generic_index): + records = [ + {"id": 1, "title": "Green Eggs & Ham", "notes": "why are the eggs green?"}, + {"id": 2, "title": "The Cat in the Hat", "notes": "silly cat wears a hat"}, + {"id": 3, "title": "One Fish, Two Fish, Red Fish, Blue Fish", "notes": "fish"}, + ] + + search_client.bulk_upsert(generic_index, records, primary_key_field="id") + + # Verify the records are in the index + for record in records: + assert search_client._client.get(generic_index, record["id"])["_source"] == record + + # Can update + add more + records = [ + {"id": 1, "title": "Green Eggs & Ham", "notes": "Sam, eat the eggs"}, + {"id": 2, "title": "The Cat in the Hat", "notes": "watch the movie"}, + {"id": 3, "title": "One Fish, Two Fish, Red Fish, Blue Fish", "notes": "colors & numbers"}, + {"id": 4, "title": "How the Grinch Stole Christmas", "notes": "who"}, + ] + search_client.bulk_upsert(generic_index, records, primary_key_field="id") + + for record in records: + assert search_client._client.get(generic_index, record["id"])["_source"] == record + + +def test_swap_alias_index(search_client, generic_index): + alias_name = f"tmp-alias-{uuid.uuid4().int}" + + # Populate the generic index, we won't immediately use this one + records = [ + {"id": 1, "data": "abc123"}, + {"id": 2, "data": "def456"}, + {"id": 3, "data": "xyz789"}, + ] + search_client.bulk_upsert(generic_index, records, primary_key_field="id") + + # Create a different index that we'll attach to the alias first. + tmp_index = f"test-tmp-index-{uuid.uuid4().int}" + search_client.create_index(tmp_index) + # Add a few records + tmp_index_records = [ + {"id": 1, "data": "abc123"}, + {"id": 2, "data": "xyz789"}, + ] + search_client.bulk_upsert(tmp_index, tmp_index_records, primary_key_field="id") + + # Set the alias + search_client.swap_alias_index(tmp_index, alias_name, delete_prior_indexes=True) + + # Can search by this alias and get records from the tmp index + resp = search_client.search(alias_name, {}) + resp_records = [record["_source"] for record in resp["hits"]["hits"]] + assert resp_records == tmp_index_records + + # Swap the index to the generic one + delete the tmp one + search_client.swap_alias_index(generic_index, alias_name, delete_prior_indexes=True) + + resp = search_client.search(alias_name, {}) + resp_records = [record["_source"] for record in resp["hits"]["hits"]] + assert resp_records == records + + # Verify the tmp one was deleted + assert search_client._client.indices.exists(tmp_index) is False diff --git a/api/tests/src/search/__init__.py b/api/tests/src/search/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/api/tests/src/search/backend/__init__.py b/api/tests/src/search/backend/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/api/tests/src/search/backend/test_load_opportunities_to_index.py b/api/tests/src/search/backend/test_load_opportunities_to_index.py new file mode 100644 index 000000000..a079b83c8 --- /dev/null +++ b/api/tests/src/search/backend/test_load_opportunities_to_index.py @@ -0,0 +1,91 @@ +import pytest + +from src.search.backend.load_opportunities_to_index import ( + LoadOpportunitiesToIndex, + LoadOpportunitiesToIndexConfig, +) +from tests.conftest import BaseTestClass +from tests.src.db.models.factories import OpportunityFactory + + +class TestLoadOpportunitiesToIndex(BaseTestClass): + @pytest.fixture(scope="class") + def load_opportunities_to_index(self, db_session, search_client, opportunity_index_alias): + config = LoadOpportunitiesToIndexConfig( + alias_name=opportunity_index_alias, index_prefix="test-load-opps" + ) + return LoadOpportunitiesToIndex(db_session, search_client, config) + + def test_load_opportunities_to_index( + self, + truncate_opportunities, + enable_factory_create, + search_client, + opportunity_index_alias, + load_opportunities_to_index, + ): + # Create 25 opportunities we will load into the search index + opportunities = [] + opportunities.extend(OpportunityFactory.create_batch(size=6, is_posted_summary=True)) + opportunities.extend(OpportunityFactory.create_batch(size=3, is_forecasted_summary=True)) + opportunities.extend(OpportunityFactory.create_batch(size=2, is_closed_summary=True)) + opportunities.extend( + OpportunityFactory.create_batch(size=8, is_archived_non_forecast_summary=True) + ) + opportunities.extend( + OpportunityFactory.create_batch(size=6, is_archived_forecast_summary=True) + ) + + # Create some opportunities that won't get fetched / loaded into search + OpportunityFactory.create_batch(size=3, is_draft=True) + OpportunityFactory.create_batch(size=4, no_current_summary=True) + + load_opportunities_to_index.run() + # Verify some metrics first + assert ( + len(opportunities) + == load_opportunities_to_index.metrics[ + load_opportunities_to_index.Metrics.RECORDS_LOADED + ] + ) + + # Just do some rough validation that the data is present + resp = search_client.search(opportunity_index_alias, {"size": 100}) + + total_records = resp["hits"]["total"]["value"] + assert total_records == len(opportunities) + + records = [record["_source"] for record in resp["hits"]["hits"]] + assert set([opp.opportunity_id for opp in opportunities]) == set( + [record["opportunity_id"] for record in records] + ) + + # Rerunning without changing anything about the data in the DB doesn't meaningfully change anything + load_opportunities_to_index.index_name = load_opportunities_to_index.index_name + "-another" + load_opportunities_to_index.run() + resp = search_client.search(opportunity_index_alias, {"size": 100}) + + total_records = resp["hits"]["total"]["value"] + assert total_records == len(opportunities) + + records = [record["_source"] for record in resp["hits"]["hits"]] + assert set([opp.opportunity_id for opp in opportunities]) == set( + [record["opportunity_id"] for record in records] + ) + + # Rerunning but first add a few more opportunities to show up + opportunities.extend(OpportunityFactory.create_batch(size=3)) + load_opportunities_to_index.index_name = ( + load_opportunities_to_index.index_name + "-new-data" + ) + load_opportunities_to_index.run() + + resp = search_client.search(opportunity_index_alias, {"size": 100}) + + total_records = resp["hits"]["total"]["value"] + assert total_records == len(opportunities) + + records = [record["_source"] for record in resp["hits"]["hits"]] + assert set([opp.opportunity_id for opp in opportunities]) == set( + [record["opportunity_id"] for record in records] + ) From 2572fe00077df2ba7e98448751698729d2c2e5f2 Mon Sep 17 00:00:00 2001 From: Aaron Couch Date: Thu, 23 May 2024 16:26:15 -0400 Subject: [PATCH 11/21] Move Pages to App Router (#7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes #6 ### Time to review: __60 mins__ ## Changes proposed ### Move pages from page to app router: 1. Move all pages to [`[locale]`](https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing#getting-started) folder 2. Add [`generateMetata()`](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function) function and [next-intl `getTranslations()`](https://next-intl-docs.vercel.app/docs/environments/metadata-route-handlers#metadata-api) implementation * @rylew1 commented we could remove this from each page. To do that we could use [prop arguments](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#with-segment-props) and update the based on the param. There is also more we can do with the metadata to properly add [app links and twitter cards](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#applinks). TODO: create ticket 4. Replace i18n's `useTranslation` with next-intl's `useTranslations` 5. Remove hard-coded strings that were present b/c we were still b/w i18next and next-intl #### Changes * [Move process page to app](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/32ba4ee29365444aa3260237912c340def137ad2) * [Move research page to app](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/5b5ad1a5ecb21f82378c5d9eaf58bcdd246aa8fc) * [Move health page to app](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/a3e62551644aa85fdef5921e89123cad66b4ec1c) * [Move feature flag page to app](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/395baed01983914f9ba04242abf6e379c4695216) * [Move search page to app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/1e261e3d9723d83a34492e05facc2a04b96d19d8) * [Move newsletter pages to app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/b509ef8a1744ae51f96de17fad266b6baa566962) * [Move home page to app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/de1be98ac22e68266bc61bd619821a2da1045c36) * [Move home page to app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/74077aeb617650fb3eefb23a237fa3f95814ab5d) * [Move 404 page to app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/ccbc9563ba63647db7fb1ee8365f166396014e9d) ### Misc 1. [Delete hello api](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/5bad6ea9c5656515bed20a215c8751b825214368) * This was left from the project creation 2. [Add USWDS icon component](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/0120c7bd15f5ec4f8f36ab7249c3c802c1b47c34) * as noted in a slack discussion, when trying to access [one of the icons](https://github.com/trussworks/react-uswds/blob/main/src/components/Icon/Icons.ts) using `` next errors: `You cannot dot into a client module from a server component. You can only pass the imported name through`. I'm not sure why it thinks the Icon component is a client module. [Dan A. suggests](https://github.com/vercel/next.js/issues/51593#issuecomment-1748001262) trussworks should re-export as named exports. I tried importing the SVGs directly from the trussworks library but [svgr requires a custom webpack config](https://react-svgr.com/docs/next/) which is a road I didn't want to go down and [react svg](https://www.npmjs.com/package/react-svg) through an error in the app router 😥 . * I implemented @sawyerh 's [suggestion](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/0120c7bd15f5ec4f8f36ab7249c3c802c1b47c34#diff-dadb35bd2f3f61f2c179f033cd0a2874fc343974236f2fb8613664703c751429), which did not work initially b/c next reported the USWDS icon was corrupt, which was fixed by adding a `viewBox` to the svg element 😮‍💨 . * [Remove unused WtGIContent](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/75490f73af2d2c2ec3705c2a02d2d27692316fc6) ### Layout and component updates * [Move layout and update for app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/af112fd25935549048c9941be7c160b28c01ae7f) * [Update global components for the app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/40119e66c99b2c4047967111cf06e1f904e6eab6) ### Remaining next-intl config and removal of * [Move i18n strings for app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/eb3c07c82f4dfe2845f9532943c3ef71b1789ff0) * [Adds next-intl config and removes i18n](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/c546571fdc5443e15cbcecc48db2ef33fcad77c0) * [Update tests for app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/3b9b1931bb36fa9795a38e0898c9f40ad8deb4af) * [Removes i18next and next-i18n packages](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/9d2e08ad44f21b0f8b62a60cc66fdda7843314b2) * [Update storybook settings for app router](https://github.com/navapbc/simpler-grants-gov/pull/7/commits/39f115d6eb8f57d8aefbe12002b12c01d1dad2c4) --- frontend/.storybook/I18nStoryWrapper.tsx | 30 ++ frontend/.storybook/i18next.js | 22 -- frontend/.storybook/main.js | 6 +- frontend/.storybook/preview.js | 43 --- frontend/.storybook/preview.tsx | 64 ++++ frontend/jest.config.js | 5 +- frontend/next-i18next.config.js | 52 ---- frontend/next.config.js | 8 +- frontend/package-lock.json | 92 ++---- frontend/package.json | 3 - frontend/public/img/uswds-sprite.svg | 1 + frontend/public/locales/en/common.json | 294 ------------------ frontend/public/locales/es/common.json | 8 - .../dev/feature-flags/FeatureFlagsTable.tsx | 61 ++++ .../app/[locale]/dev/feature-flags/page.tsx | 30 ++ frontend/src/app/[locale]/health/page.tsx | 3 + .../[locale]/newsletter/NewsletterForm.tsx | 217 +++++++++++++ .../[locale]/newsletter/confirmation/page.tsx | 66 ++++ frontend/src/app/[locale]/newsletter/page.tsx | 71 +++++ .../[locale]/newsletter/unsubscribe/page.tsx | 69 ++++ frontend/src/app/[locale]/page.tsx | 31 ++ .../src/app/[locale]/process/ProcessIntro.tsx | 51 +++ .../app/[locale]/process/ProcessInvolved.tsx | 67 ++++ .../[locale]/process}/ProcessMilestones.tsx | 147 ++++----- frontend/src/app/[locale]/process/page.tsx | 38 +++ .../[locale]/research}/ResearchArchetypes.tsx | 13 +- .../app/[locale]/research/ResearchImpact.tsx | 80 +++++ .../[locale]/research}/ResearchIntro.tsx | 4 +- .../research}/ResearchMethodology.tsx | 48 ++- .../[locale]/research}/ResearchThemes.tsx | 4 +- frontend/src/app/[locale]/research/page.tsx | 41 +++ .../app/{ => [locale]}/search/SearchForm.tsx | 22 +- .../src/app/{ => [locale]}/search/actions.ts | 6 +- .../src/app/{ => [locale]}/search/error.tsx | 2 +- .../src/app/{ => [locale]}/search/loading.tsx | 2 +- .../src/app/{ => [locale]}/search/page.tsx | 15 +- frontend/src/app/layout.tsx | 4 +- frontend/src/app/not-found.tsx | 15 +- frontend/src/app/template.tsx | 2 +- frontend/src/components/AppBetaAlert.tsx | 23 -- frontend/src/components/AppLayout.tsx | 59 ---- frontend/src/components/BetaAlert.tsx | 47 +-- frontend/src/components/Footer.tsx | 88 +++--- frontend/src/components/GrantsIdentifier.tsx | 58 ++-- frontend/src/components/Header.tsx | 38 +-- frontend/src/components/Hero.tsx | 13 +- frontend/src/components/Layout.tsx | 64 ++-- frontend/src/components/USWDSIcon.tsx | 23 ++ .../content/FundingContent.tsx | 6 +- .../content/IndexGoalContent.tsx | 15 +- .../content/ProcessAndResearchContent.tsx | 19 +- .../components/search/SearchResultsList.tsx | 2 +- frontend/src/hooks/useSearchFormState.ts | 2 +- frontend/src/i18n/messages/en/index.ts | 9 +- frontend/src/middleware.ts | 2 +- frontend/src/pages/404.tsx | 39 --- frontend/src/pages/_app.tsx | 28 -- frontend/src/pages/api/hello.ts | 13 - frontend/src/pages/content/ProcessIntro.tsx | 58 ---- .../src/pages/content/ProcessInvolved.tsx | 70 ----- frontend/src/pages/content/ResearchImpact.tsx | 83 ----- frontend/src/pages/content/WtGIContent.tsx | 90 ------ frontend/src/pages/dev/feature-flags.tsx | 87 ------ frontend/src/pages/health.tsx | 15 - frontend/src/pages/index.tsx | 40 --- .../src/pages/newsletter/confirmation.tsx | 71 ----- frontend/src/pages/newsletter/index.tsx | 276 ---------------- frontend/src/pages/newsletter/unsubscribe.tsx | 78 ----- frontend/src/pages/process.tsx | 45 --- frontend/src/pages/research.tsx | 49 --- .../components/FundingContent.stories.tsx | 2 +- .../components/GoalContent.stories.tsx | 2 +- .../components/ProcessContent.stories.tsx | 2 +- .../components/ReaserchImpact.stories.tsx | 2 +- .../components/ReaserchIntro.stories.tsx | 2 +- .../components/ReaserchThemes.stories.tsx | 2 +- .../components/ResearchArchetypes.stories.tsx | 2 +- .../ResearchMethodology.stories.tsx | 2 +- .../components/WtGIContent.stories.tsx | 17 - frontend/stories/pages/404.stories.tsx | 2 +- frontend/stories/pages/Index.stories.tsx | 2 +- frontend/stories/pages/process.stories.tsx | 2 +- frontend/stories/pages/research.stories.tsx | 2 +- frontend/stories/pages/search.stories.tsx | 2 +- frontend/tests/components/AppLayout.test.tsx | 29 -- frontend/tests/components/BetaAlert.test.tsx | 11 +- frontend/tests/components/Footer.test.tsx | 20 +- .../tests/components/FullWidthAlert.test.tsx | 2 +- .../tests/components/FundingContent.test.tsx | 4 +- .../tests/components/GoalContent.test.tsx | 4 +- .../components/GrantsIdentifier.test.tsx | 19 +- frontend/tests/components/Header.test.tsx | 14 +- frontend/tests/components/Hero.test.tsx | 2 +- frontend/tests/components/Layout.test.tsx | 10 +- .../ProcessAndResearchContent.test.tsx | 4 +- .../tests/components/ProcessIntro.test.tsx | 4 +- .../tests/components/ProcessInvolved.test.tsx | 4 +- .../components/ProcessMilestones.test.tsx | 4 +- .../components/ResearchArchetypes.test.tsx | 4 +- .../tests/components/ResearchImpact.test.tsx | 4 +- .../tests/components/ResearchIntro.test.tsx | 4 +- .../components/ResearchMethodology.test.tsx | 4 +- .../tests/components/ResearchThemes.test.tsx | 4 +- frontend/tests/components/USWDSIcon.test.tsx | 12 + .../tests/components/WtGIContent.test.tsx | 10 - frontend/tests/e2e/404.spec.ts | 20 ++ frontend/tests/e2e/newsletter.spec.ts | 2 +- frontend/tests/e2e/search/search.spec.ts | 2 + frontend/tests/errors.test.ts | 2 +- frontend/tests/jest-i18n.ts | 53 ---- frontend/tests/pages/404.test.tsx | 27 -- .../tests/pages/dev/feature-flags.test.tsx | 12 +- frontend/tests/pages/index.test.tsx | 5 +- .../pages/newsletter/confirmation.test.tsx | 4 +- .../tests/pages/newsletter/index.test.tsx | 18 +- .../pages/newsletter/unsubscribe.test.tsx | 4 +- frontend/tests/pages/process.test.tsx | 5 +- frontend/tests/pages/research.test.tsx | 5 +- frontend/tests/playwright.config.ts | 1 + frontend/tsconfig.json | 1 + 120 files changed, 1345 insertions(+), 2279 deletions(-) create mode 100644 frontend/.storybook/I18nStoryWrapper.tsx delete mode 100644 frontend/.storybook/i18next.js delete mode 100644 frontend/.storybook/preview.js create mode 100644 frontend/.storybook/preview.tsx delete mode 100644 frontend/next-i18next.config.js create mode 100644 frontend/public/img/uswds-sprite.svg delete mode 100644 frontend/public/locales/en/common.json delete mode 100644 frontend/public/locales/es/common.json create mode 100644 frontend/src/app/[locale]/dev/feature-flags/FeatureFlagsTable.tsx create mode 100644 frontend/src/app/[locale]/dev/feature-flags/page.tsx create mode 100644 frontend/src/app/[locale]/health/page.tsx create mode 100644 frontend/src/app/[locale]/newsletter/NewsletterForm.tsx create mode 100644 frontend/src/app/[locale]/newsletter/confirmation/page.tsx create mode 100644 frontend/src/app/[locale]/newsletter/page.tsx create mode 100644 frontend/src/app/[locale]/newsletter/unsubscribe/page.tsx create mode 100644 frontend/src/app/[locale]/page.tsx create mode 100644 frontend/src/app/[locale]/process/ProcessIntro.tsx create mode 100644 frontend/src/app/[locale]/process/ProcessInvolved.tsx rename frontend/src/{pages/content => app/[locale]/process}/ProcessMilestones.tsx (50%) create mode 100644 frontend/src/app/[locale]/process/page.tsx rename frontend/src/{pages/content => app/[locale]/research}/ResearchArchetypes.tsx (91%) create mode 100644 frontend/src/app/[locale]/research/ResearchImpact.tsx rename frontend/src/{pages/content => app/[locale]/research}/ResearchIntro.tsx (81%) rename frontend/src/{pages/content => app/[locale]/research}/ResearchMethodology.tsx (53%) rename frontend/src/{pages/content => app/[locale]/research}/ResearchThemes.tsx (93%) create mode 100644 frontend/src/app/[locale]/research/page.tsx rename frontend/src/app/{ => [locale]}/search/SearchForm.tsx (80%) rename frontend/src/app/{ => [locale]}/search/actions.ts (68%) rename frontend/src/app/{ => [locale]}/search/error.tsx (98%) rename frontend/src/app/{ => [locale]}/search/loading.tsx (88%) rename frontend/src/app/{ => [locale]}/search/page.tsx (71%) delete mode 100644 frontend/src/components/AppBetaAlert.tsx delete mode 100644 frontend/src/components/AppLayout.tsx create mode 100644 frontend/src/components/USWDSIcon.tsx rename frontend/src/{pages => components}/content/FundingContent.tsx (93%) rename frontend/src/{pages => components}/content/IndexGoalContent.tsx (80%) rename frontend/src/{pages => components}/content/ProcessAndResearchContent.tsx (77%) delete mode 100644 frontend/src/pages/404.tsx delete mode 100644 frontend/src/pages/_app.tsx delete mode 100644 frontend/src/pages/api/hello.ts delete mode 100644 frontend/src/pages/content/ProcessIntro.tsx delete mode 100644 frontend/src/pages/content/ProcessInvolved.tsx delete mode 100644 frontend/src/pages/content/ResearchImpact.tsx delete mode 100644 frontend/src/pages/content/WtGIContent.tsx delete mode 100644 frontend/src/pages/dev/feature-flags.tsx delete mode 100644 frontend/src/pages/health.tsx delete mode 100644 frontend/src/pages/index.tsx delete mode 100644 frontend/src/pages/newsletter/confirmation.tsx delete mode 100644 frontend/src/pages/newsletter/index.tsx delete mode 100644 frontend/src/pages/newsletter/unsubscribe.tsx delete mode 100644 frontend/src/pages/process.tsx delete mode 100644 frontend/src/pages/research.tsx delete mode 100644 frontend/stories/components/WtGIContent.stories.tsx delete mode 100644 frontend/tests/components/AppLayout.test.tsx create mode 100644 frontend/tests/components/USWDSIcon.test.tsx delete mode 100644 frontend/tests/components/WtGIContent.test.tsx create mode 100644 frontend/tests/e2e/404.spec.ts delete mode 100644 frontend/tests/jest-i18n.ts delete mode 100644 frontend/tests/pages/404.test.tsx diff --git a/frontend/.storybook/I18nStoryWrapper.tsx b/frontend/.storybook/I18nStoryWrapper.tsx new file mode 100644 index 000000000..f05ca54a0 --- /dev/null +++ b/frontend/.storybook/I18nStoryWrapper.tsx @@ -0,0 +1,30 @@ +/** + * @file Storybook decorator, enabling internationalization for each story. + * @see https://storybook.js.org/docs/writing-stories/decorators + */ +import { StoryContext } from "@storybook/react"; + +import { NextIntlClientProvider } from "next-intl"; +import React from "react"; + +import { defaultLocale, formats, timeZone } from "../src/i18n/config"; + +const I18nStoryWrapper = ( + Story: React.ComponentType, + context: StoryContext, +) => { + const locale = (context.globals.locale as string) ?? defaultLocale; + + return ( + + + + ); +}; + +export default I18nStoryWrapper; diff --git a/frontend/.storybook/i18next.js b/frontend/.storybook/i18next.js deleted file mode 100644 index a3eeb9d9c..000000000 --- a/frontend/.storybook/i18next.js +++ /dev/null @@ -1,22 +0,0 @@ -// Configure i18next for Storybook -// See https://storybook.js.org/addons/storybook-react-i18next -import i18nConfig from "../next-i18next.config"; -import i18next from "i18next"; -import LanguageDetector from "i18next-browser-languagedetector"; -import Backend from "i18next-http-backend"; -import { initReactI18next } from "react-i18next"; - -i18next - .use(initReactI18next) - .use(LanguageDetector) - .use(Backend) - .init({ - ...i18nConfig, - backend: { - loadPath: `${ - process.env.NEXT_PUBLIC_BASE_PATH ?? "" - }/locales/{{lng}}/{{ns}}.json`, - }, - }); - -export default i18next; diff --git a/frontend/.storybook/main.js b/frontend/.storybook/main.js index 6ef68f43b..a673aa99b 100644 --- a/frontend/.storybook/main.js +++ b/frontend/.storybook/main.js @@ -25,11 +25,7 @@ function blockSearchEnginesInHead(head) { */ const config = { stories: ["../stories/**/*.stories.@(mdx|js|jsx|ts|tsx)"], - addons: [ - "@storybook/addon-essentials", - "storybook-react-i18next", - "@storybook/addon-designs", - ], + addons: ["@storybook/addon-essentials", "@storybook/addon-designs"], framework: { name: "@storybook/nextjs", options: { diff --git a/frontend/.storybook/preview.js b/frontend/.storybook/preview.js deleted file mode 100644 index d75bcc900..000000000 --- a/frontend/.storybook/preview.js +++ /dev/null @@ -1,43 +0,0 @@ -// @ts-check -import i18nConfig from "../next-i18next.config"; - -// Apply global styling to our stories -import "../src/styles/styles.scss"; - -// Import i18next config. -import i18n from "./i18next.js"; - -// Generate the options for the Language menu using the locale codes. -// Teams can override these labels, but this helps ensure that the language -// is at least exposed in the list. -const initialLocales = {}; -i18nConfig.i18n.locales.forEach((locale) => (initialLocales[locale] = locale)); - -const parameters = { - actions: { argTypesRegex: "^on[A-Z].*" }, - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/, - }, - }, - // Configure i18next and locale/dropdown options. - i18n, -}; - -/** - * @type {import("@storybook/react").Preview} - */ -const preview = { - parameters, - globals: { - locale: "en", - locales: { - ...initialLocales, - en: "English", - es: "Español", - }, - }, -}; - -export default preview; diff --git a/frontend/.storybook/preview.tsx b/frontend/.storybook/preview.tsx new file mode 100644 index 000000000..9b135fadc --- /dev/null +++ b/frontend/.storybook/preview.tsx @@ -0,0 +1,64 @@ +/** + * @file Setup the toolbar, styling, and global context for each Storybook story. + * @see https://storybook.js.org/docs/configure#configure-story-rendering + */ +import { Loader, Preview } from "@storybook/react"; + +import "../src/styles/styles.scss"; + +import { defaultLocale, locales } from "../src/i18n/config"; +import { getMessagesWithFallbacks } from "../src/i18n/getMessagesWithFallbacks"; +import I18nStoryWrapper from "./I18nStoryWrapper"; + +const parameters = { + nextjs: { + appDirectory: true, + }, + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/, + }, + }, + options: { + storySort: { + method: "alphabetical", + order: [ + "Welcome", + "Core", + // Storybook infers the title when not explicitly set, but is case-sensitive + // so we need to explicitly set both casings here for this to properly sort. + "Components", + "components", + "Templates", + "Pages", + "pages", + ], + }, + }, +}; + +const i18nMessagesLoader: Loader = async (context) => { + const messages = await getMessagesWithFallbacks( + context.globals.locale as string, + ); + return { messages }; +}; + +const preview: Preview = { + loaders: [i18nMessagesLoader], + decorators: [I18nStoryWrapper], + parameters, + globalTypes: { + locale: { + description: "Active language", + defaultValue: defaultLocale, + toolbar: { + icon: "globe", + items: locales, + }, + }, + }, +}; + +export default preview; diff --git a/frontend/jest.config.js b/frontend/jest.config.js index 8b2ea6cd4..0ed77a928 100644 --- a/frontend/jest.config.js +++ b/frontend/jest.config.js @@ -9,10 +9,7 @@ const createJestConfig = nextJest({ // Add any custom config to be passed to Jest /** @type {import('jest').Config} */ const customJestConfig = { - setupFilesAfterEnv: [ - "/tests/jest.setup.js", - "/tests/jest-i18n.ts", - ], + setupFilesAfterEnv: ["/tests/jest.setup.js"], testEnvironment: "jsdom", // if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work moduleDirectories: ["node_modules", "/"], diff --git a/frontend/next-i18next.config.js b/frontend/next-i18next.config.js deleted file mode 100644 index 5ebe1d0a8..000000000 --- a/frontend/next-i18next.config.js +++ /dev/null @@ -1,52 +0,0 @@ -// @ts-check -/** - * Next.js i18n routing options - * https://nextjs.org/docs/advanced-features/i18n-routing - * @type {import('next').NextConfig['i18n']} - */ -const i18n = { - defaultLocale: "en", - // Source of truth for the list of languages supported by the application. Other tools (i18next, Storybook, tests) reference this. - // These must be BCP47 language tags: https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags - locales: ["en", "es"], -}; - -/** - * i18next and react-i18next options - * https://www.i18next.com/overview/configuration-options - * https://react.i18next.com/latest/i18next-instance - * @type {import("i18next").InitOptions} - */ -const i18next = { - // Default namespace to load, typically overridden within components, - // but set here to prevent the system from attempting to load - // translation.json, which is the default, and doesn't exist - // in this codebase - ns: "common", - defaultNS: "common", - fallbackLng: i18n.defaultLocale, - interpolation: { - escapeValue: false, // React already does escaping - }, -}; - -/** - * next-i18next options - * https://github.com/i18next/next-i18next#options - * @type {Partial} - */ -const nextI18next = { - // Locale resources are loaded once when the server is started, which - // is good for production but not ideal for local development. Show - // updates to locale files without having to restart the server: - reloadOnPrerender: process.env.NODE_ENV === "development", -}; - -/** - * @type {import("next-i18next").UserConfig} - */ -module.exports = { - i18n, - ...i18next, - ...nextI18next, -}; diff --git a/frontend/next.config.js b/frontend/next.config.js index a7743e46f..9e5127fac 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,5 +1,5 @@ // @ts-check -const { i18n } = require("./next-i18next.config"); + const withNextIntl = require("next-intl/plugin")("./src/i18n/server.ts"); const sassOptions = require("./scripts/sassOptions"); @@ -16,17 +16,11 @@ const appSassOptions = sassOptions(basePath); /** @type {import('next').NextConfig} */ const nextConfig = { basePath, - i18n, reactStrictMode: true, // Output only the necessary files for a deployment, excluding irrelevant node_modules // https://nextjs.org/docs/app/api-reference/next-config-js/output output: "standalone", sassOptions: appSassOptions, - transpilePackages: [ - // Continue to support older browsers (ES5) - // https://github.com/i18next/i18next/issues/1948 - "i18next", - ], }; module.exports = withNextIntl(nextConfig); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 68a0052ab..c4253e22e 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -13,15 +13,12 @@ "@opentelemetry/api": "^1.8.0", "@trussworks/react-uswds": "^7.0.0", "@uswds/uswds": "^3.6.0", - "i18next": "^23.0.0", "js-cookie": "^3.0.5", "lodash": "^4.17.21", "next": "^14.1.4", - "next-i18next": "^15.0.0", "next-intl": "^3.2.1", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-i18next": "^14.0.0", "server-only": "^0.0.1", "sharp": "^0.33.0", "use-debounce": "^10.0.0" @@ -2143,6 +2140,7 @@ "version": "7.23.9", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.9.tgz", "integrity": "sha512-0CX6F+BI2s9dkUqr08KFrAIZgNFj75rdBU/DjCyYLIaV/quFjkk6T+EJ2LkZHyZTbEV4L5p97mNkUsHl2wLFAw==", + "dev": true, "dependencies": { "regenerator-runtime": "^0.14.0" }, @@ -9188,15 +9186,6 @@ "@types/node": "*" } }, - "node_modules/@types/hoist-non-react-statics": { - "version": "3.3.5", - "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.5.tgz", - "integrity": "sha512-SbcrWzkKBw2cdwRTwQAswfpB9g9LJWfjtUeW/jvNwbhC8cpmmNYVePa+ncbUe0rGTQ7G3Ff6mYUN2VMfLVr+Sg==", - "dependencies": { - "@types/react": "*", - "hoist-non-react-statics": "^3.3.0" - } - }, "node_modules/@types/html-minifier-terser": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@types/html-minifier-terser/-/html-minifier-terser-6.1.0.tgz", @@ -9378,7 +9367,8 @@ "node_modules/@types/prop-types": { "version": "15.7.11", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.11.tgz", - "integrity": "sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==" + "integrity": "sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==", + "dev": true }, "node_modules/@types/qs": { "version": "6.9.11", @@ -9396,6 +9386,7 @@ "version": "18.2.74", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.74.tgz", "integrity": "sha512-9AEqNZZyBx8OdZpxzQlaFEVCSFUM2YXJH46yPOiOpm078k6ZLOCcuAzGum/zK8YBwY+dbahVNbHrbgrAwIRlqw==", + "dev": true, "dependencies": { "@types/prop-types": "*", "csstype": "^3.0.2" @@ -12064,16 +12055,6 @@ "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", "dev": true }, - "node_modules/core-js": { - "version": "3.35.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.35.1.tgz", - "integrity": "sha512-IgdsbxNyMskrTFxa9lWHyMwAJU5gXOPP+1yO+K59d50VLVAIDAbs7gIv705KzALModfK3ZrSZTPNpC0PQgIZuw==", - "hasInstallScript": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/core-js" - } - }, "node_modules/core-js-compat": { "version": "3.35.1", "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.35.1.tgz", @@ -12470,7 +12451,8 @@ "node_modules/csstype": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", - "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" + "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", + "dev": true }, "node_modules/damerau-levenshtein": { "version": "1.0.8", @@ -15649,14 +15631,6 @@ "minimalistic-crypto-utils": "^1.0.1" } }, - "node_modules/hoist-non-react-statics": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", - "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", - "dependencies": { - "react-is": "^16.7.0" - } - }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -15722,6 +15696,8 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz", "integrity": "sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==", + "dev": true, + "peer": true, "dependencies": { "void-elements": "3.1.0" } @@ -15860,6 +15836,7 @@ "version": "23.8.2", "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.8.2.tgz", "integrity": "sha512-Z84zyEangrlERm0ZugVy4bIt485e/H8VecGUZkZWrH7BDePG6jT73QdL9EA1tRTTVVMpry/MgWIP1FjEn0DRXA==", + "dev": true, "funding": [ { "type": "individual", @@ -15874,6 +15851,7 @@ "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" } ], + "peer": true, "dependencies": { "@babel/runtime": "^7.23.2" } @@ -15887,11 +15865,6 @@ "@babel/runtime": "^7.23.2" } }, - "node_modules/i18next-fs-backend": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/i18next-fs-backend/-/i18next-fs-backend-2.3.1.tgz", - "integrity": "sha512-tvfXskmG/9o+TJ5Fxu54sSO5OkY6d+uMn+K6JiUGLJrwxAVfer+8V3nU8jq3ts9Pe5lXJv4b1N7foIjJ8Iy2Gg==" - }, "node_modules/i18next-http-backend": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/i18next-http-backend/-/i18next-http-backend-2.4.3.tgz", @@ -19716,41 +19689,6 @@ } } }, - "node_modules/next-i18next": { - "version": "15.2.0", - "resolved": "https://registry.npmjs.org/next-i18next/-/next-i18next-15.2.0.tgz", - "integrity": "sha512-Rl5yZ4oGffsB0AjRykZ5PzNQ2M6am54MaMayldGmH/UKZisrIxk2SKEPJvaHhKlWe1qgdNi2FkodwK8sEjfEmg==", - "funding": [ - { - "type": "individual", - "url": "https://locize.com/i18next.html" - }, - { - "type": "individual", - "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" - }, - { - "type": "individual", - "url": "https://locize.com" - } - ], - "dependencies": { - "@babel/runtime": "^7.23.2", - "@types/hoist-non-react-statics": "^3.3.4", - "core-js": "^3", - "hoist-non-react-statics": "^3.3.2", - "i18next-fs-backend": "^2.3.1" - }, - "engines": { - "node": ">=14" - }, - "peerDependencies": { - "i18next": ">= 23.7.13", - "next": ">= 12.0.0", - "react": ">= 17.0.2", - "react-i18next": ">= 13.5.0" - } - }, "node_modules/next-intl": { "version": "3.11.1", "resolved": "https://registry.npmjs.org/next-intl/-/next-intl-3.11.1.tgz", @@ -22187,6 +22125,8 @@ "version": "14.0.1", "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-14.0.1.tgz", "integrity": "sha512-TMV8hFismBmpMdIehoFHin/okfvgjFhp723RYgIqB4XyhDobVMyukyM3Z8wtTRmajyFMZrBl/OaaXF2P6WjUAw==", + "dev": true, + "peer": true, "dependencies": { "@babel/runtime": "^7.22.5", "html-parse-stringify": "^3.0.1" @@ -22207,7 +22147,8 @@ "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "dev": true }, "node_modules/react-refresh": { "version": "0.14.0", @@ -22520,7 +22461,8 @@ "node_modules/regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "dev": true }, "node_modules/regenerator-transform": { "version": "0.15.2", @@ -25176,6 +25118,8 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz", "integrity": "sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==", + "dev": true, + "peer": true, "engines": { "node": ">=0.10.0" } diff --git a/frontend/package.json b/frontend/package.json index 048464bb1..114ae1cb9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -28,15 +28,12 @@ "@opentelemetry/api": "^1.8.0", "@trussworks/react-uswds": "^7.0.0", "@uswds/uswds": "^3.6.0", - "i18next": "^23.0.0", "js-cookie": "^3.0.5", "lodash": "^4.17.21", "next": "^14.1.4", - "next-i18next": "^15.0.0", "next-intl": "^3.2.1", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-i18next": "^14.0.0", "server-only": "^0.0.1", "sharp": "^0.33.0", "use-debounce": "^10.0.0" diff --git a/frontend/public/img/uswds-sprite.svg b/frontend/public/img/uswds-sprite.svg new file mode 100644 index 000000000..8ae1eca92 --- /dev/null +++ b/frontend/public/img/uswds-sprite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/locales/en/common.json b/frontend/public/locales/en/common.json deleted file mode 100644 index 788b4be6e..000000000 --- a/frontend/public/locales/en/common.json +++ /dev/null @@ -1,294 +0,0 @@ -{ - "Beta_alert": { - "alert_title": "Attention! Go to www.grants.gov to search and apply for grants.", - "alert": "Simpler.Grants.gov is a work in progress. Thank you for your patience as we build this new website." - }, - "Index": { - "page_title": "Simpler.Grants.gov", - "meta_description": "A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.", - "goal": { - "title": "The goal", - "paragraph_1": "We want Grants.gov to be an extremely simple, accessible, and easy-to-use tool for posting, finding, sharing, and applying for federal financial assistance. Our mission is to increase access to grants and improve the grants experience for everyone.", - "title_2": "For applicants", - "paragraph_2": "We’re improving the way you search for and discover funding opportunities, making it easier to find and apply.", - "title_3": "For grantmakers", - "paragraph_3": "If you work for a federal grantmaking agency, we’re making it easier for your communities to find the funding they need.", - "cta": "Sign up for project updates" - }, - "process_and_research": { - "title_1": "The process", - "title_2": "The research", - "paragraph_1": "This project is transparent, iterative, and agile. All of the code we’re writing is open source and our roadmap is public. As we release new versions, you can try out functional software and give us feedback on what works and what can be improved to inform what happens next.", - "paragraph_2": "We conducted extensive research in 2023 to gather insights from applicants, potential applicants, and grantmakers. We’re using these findings to guide our work. And your ongoing feedback will inform and inspire new features as we build a simpler Grants.gov together.", - "cta_1": "Learn about what’s happening", - "cta_2": "Read the research findings" - }, - "fo_title": "Improvements to funding opportunity announcements", - "fo_paragraph_1": "Funding opportunities should not only be easy to find, share, and apply for. They should also be easy to read and understand. Our objective is to simplify and organize funding opportunities announcements. ", - "fo_paragraph_2": "We want to help grantmakers write clear, concise announcements that encourage strong submissions from qualified applicants and make opportunities more accessible to everyone.", - "fo_title_2": "View our grant announcement prototypes", - "fo_paragraph_3": "We recently simplified the language of four grant announcements and applied visual and user‑centered design principles to increase their readability and usability.", - "acl_prototype": "Link to ACL Notice of Funding Opportunity example pdf", - "acf_prototype": "Link to ACF Notice of Funding Opportunity example pdf", - "cdc_prototype": "Link to CDC Notice of Funding Opportunity example pdf", - "samhsa_prototype": "Link to SAMHSA Notice of Funding Opportunity example pdf", - "fo_title_3": "We want to hear from you!", - "fo_paragraph_4": "We value your feedback. Tell us what you think of grant announcements and grants.gov.", - "fo_title_4": "Are you a first‑time applicant? Created a workspace but haven't applied yet?", - "fo_paragraph_5": "We're especially interested in hearing from first‑time applicants and organizations that have never applied for funding opportunities. We encourage you to review our announcements and share your feedback, regardless of your experience with federal grants.", - "wtgi_paragraph_2": "Questions? Contact us at {{email}}." - }, - "Research": { - "page_title": "Research | Simpler.Grants.gov", - "meta_description": "A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.", - "intro": { - "title": "Our existing research", - "content": "We conducted extensive research in 2023 to gather insights from applicants, potential applicants, and grantmakers. We’re using these findings to guide our work. And your ongoing feedback will inform and inspire new features as we build a simpler Grants.gov together." - }, - "methodology": { - "title": "The methodology", - "paragraph_1": "

Applicants and grantmakers were selected for a series of user interviews to better understand their experience using Grants.gov. We recruited equitably to ensure a diverse pool of participants.

The quantity of participants was well above industry standards. Of the applicants who were interviewed, 26% were first-time applicants, 39% were occasional applicants, and 34% were frequent applicants.

With the findings from these interviews, we defined user archetypes and general themes to guide the Simpler.Grants.gov user experience.

", - "title_2": "Research objectives:", - "paragraph_2": "
  • Examine existing user journeys and behaviors, identifying how Grants.gov fits into their overall approach
  • Learn from user experiences, roles, challenges
  • Identify barriers and how a simpler Grants.gov can create a more intuitive user experience, especially for new users
", - "title_3": "Want to be notified when there are upcoming user research efforts?", - "cta": "Sign up for project updates" - }, - "archetypes": { - "title": "Applicant archetypes", - "paragraph_1": "Archetypes are compelling summaries that highlight the types of applicants that Grants.gov serves. They’re informed by and summarize user research data, and represent user behaviors, attitudes, motivations, pain points, and goals. We’ll use these archetypes to influence our design decisions, guide the product’s direction, and keep our work human-centered. ", - "novice": { - "title": "The Novice", - "paragraph_1": "Applicants lacking familiarity with the grant application process, including first-time or infrequent applicants and those who never apply", - "paragraph_2": "Novices are often new to the grants application process. They face a steep learning curve to find and apply for funding opportunities. Solving their needs will generate a more inclusive Grants.gov experience." - }, - "collaborator": { - "title": "The Collaborator", - "paragraph_1": "Applicants who've applied before, working with colleagues or partner organizations to increase their chances of success", - "paragraph_2": "Collaborators have more familiarity with Grants.gov. But they face challenges with coordinating application materials, and often resorting to tools and resources outside of Grants.gov." - }, - "maestro": { - "title": "The Maestro", - "paragraph_1": "Frequent applicants familiar with Grants.gov, who are often directly responsible for managing multiple applications at once", - "paragraph_2": "Maestros have an established approach to applying, which may include software and tools outside of Grants.gov. Their primary concerns are rooted in determining grant feasibility and staying ahead of deadlines." - }, - "supervisor": { - "title": "The Supervisor", - "paragraph_1": "Applicants who have a more senior role at organizations and have less frequent direct involvement with Grants.gov than Maestros.", - "paragraph_2": "Supervisors are responsible for oversight, approvals, final submissions, and keeping registrations up to date. Their time is limited, as they're often busy with the organization's other needs." - } - }, - "themes": { - "title": "General themes", - "paragraph_1": "The existing Grants.gov website works best for those who use it regularly. Larger organizations and teams of Collaborators and Maestros are typically more familiar with the ins and outs of the system. To create a simpler Grants.gov with an intuitive user experience that addresses the needs of all archetypes, four themes were defined:", - "title_2": "Frictionless functionality ", - "paragraph_2": "Reduce the burden on applicants and grantmakers, from both a process and systems perspective, by addressing the pain points that negatively affect their experience", - "title_3": "Sophisticated self-direction", - "paragraph_3": "Meet users where they are during crucial moments, by providing a guided journey through opt-in contextual support that reduces their need to find help outside the system", - "title_4": "Demystify the grants process", - "paragraph_4": "Ensure that all users have the same easy access to instructional and educational information that empowers them to have a smoother, informed, and confident user experience", - "title_5": "Create an ownable identity", - "paragraph_5": "Create a presence that reflections our mission and supports our users through visual brand, content strategy, and user interface design systems" - }, - "impact": { - "title": "Where can we have the most impact?", - "paragraph_1": "The most burden is on the Novice to become an expert on the grants process and system. In order to execute our mission, there is a need to improve awareness, access, and choice. This requires reaching out to those who are unfamiliar with the grant application process.", - "paragraph_2": "There are many common barriers that users face:", - "title_2": "Are there challenges you’ve experienced that aren’t captured here?", - "paragraph_3": "If you would like to share your experiences and challenges as either an applicant or grantmaker, reach out to us at simpler@grants.gov or sign up for project updates to be notified of upcoming user research efforts.", - "boxes": [ - { - "title": "Digital connectivity", - "content": "Depending on availability and geography, a stable internet connection is not a guarantee to support a digital-only experience." - }, - { - "title": "Organization size", - "content": "Not all organizations have dedicated resources for seeking grant funding. Many are 1-person shops who are trying to do it all." - }, - { - "title": "Overworked", - "content": "New organizations are often too burdened with internal paperwork and infrastructure to support external funding and reporting." - }, - { - "title": "Expertise", - "content": "Small organizations face higher turnover, and alumni often take their institutional knowledge and expertise with them when they leave." - }, - { - "title": "Cognitive load", - "content": "Applicants often apply for funding through several agencies, requiring they learn multiple processes and satisfy varying requirements." - }, - { - "title": "Language", - "content": "Applicants are faced with a lot of jargon without context or definitions, which is especially difficult when English is not their native language." - }, - { - "title": "Education", - "content": "It often requires a high level of education to comprehend the complexity and language of funding opportunity announcements." - }, - { - "title": "Lost at the start", - "content": "Novices don’t see a clear call-to-action for getting started, and they have trouble finding the one-on-one help at the beginning of the process." - }, - { - "title": "Overwhelmed by search", - "content": "New applicants misuse the keyword search function and have trouble understanding the acronyms and terminology." - }, - { - "title": "Confused by announcements", - "content": "Novices have difficulty determining their eligibility and understanding the details of the funding opportunity announcement." - }, - { - "title": "Time", - "content": "Most individuals wear a lot of hats (community advocate, program lead, etc.) and \"grants applicant\" is only part of their responsibilities and requires efficiency." - }, - { - "title": "Blindsided by requirements", - "content": "New applicants are caught off guard by SAM.gov registration and often miss the format and file name requirements." - } - ] - } - }, - "Process": { - "page_title": "Process | Simpler.Grants.gov", - "meta_description": "A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.", - "intro": { - "title": "Our open process", - "content": "This project is transparent, iterative, and agile. All of the code we’re writing is open source and our roadmap is public. As we regularly release new versions of Simpler.Grants.gov, you'll see what we're building and prioritizing. With each iteration, you'll be able to try out functional software and give us feedback on what works and what can be improved to inform what happens next.", - "boxes": [ - { - "title": "Transparent", - "content": "We’re building a simpler Grants.gov in the open. You can see our plans and our progress. And you can join us in shaping the vision and details of the features we build." - }, - { - "title": "Iterative", - "content": "We’re releasing features early and often through a continuous cycle of planning, implementation, and assessment. Each cycle will incrementally improve the product, as we incorporate your feedback from the prior iteration." - }, - { - "title": "Agile", - "content": "We’re building a simpler Grants.gov with you, not for you. Our process gives us the flexibility to swiftly respond to feedback and adapt to changing priorities and requirements." - } - ] - }, - "milestones": { - "tag": "The high-level roadmap", - "icon_list": [ - { - "title": "Find", - "content": "

Improve how applicants discover funding opportunities that they’re qualified for and that meet their needs.

" - }, - { - "title": "Advanced reporting", - "content": "

Improve stakeholders’ capacity to understand, analyze, and assess grants from application to acceptance.

Make non-confidential Grants.gov data open for public analysis.

" - }, - { - "title": "Apply", - "content": "

Streamline the application process to make it easier for all applicants to apply for funding opportunities.

" - } - ], - "roadmap_1": "Find", - "title_1": "Milestone 1", - "name_1": "Laying the foundation with a modern Application Programming Interface (API)", - "paragraph_1": "To make it easier to discover funding opportunities, we’re starting with a new modern API to make grants data more accessible. Our API‑first approach will prioritize data at the beginning, and make sure data remains a priority as we iterate. It’s crucial that the Grants.gov website, 3rd‑party apps, and other services can more easily access grants data. Our new API will foster innovation and be a foundation for interacting with grants in new ways, like SMS, phone, email, chat, and notifications.", - "sub_title_1": "What’s an API?", - "sub_paragraph_1": "Think of the API as a liaison between the Grants.gov website and the information and services that power it. It’s software that allows two applications to talk to each other or sends data back and forth between a website and a user.", - "sub_title_2": "Are you interested in the tech?", - "sub_paragraph_2": "We’re building a RESTful API. And we’re starting with an initial endpoint that allows API users to retrieve basic information about each funding opportunity.", - "cta_1": "View the API milestone on GitHub", - "roadmap_2": "Find", - "title_2": "Milestone 2", - "name_2": "A new search interface accessible to everyone", - "paragraph_2": "Once our new API is in place, we’ll begin focusing on how applicants most commonly access grants data. Our first user-facing milestone will be a simple search interface that makes data from our modern API accessible to anyone who wants to try out new ways to search for funding opportunities.", - "sub_title_3": "Can’t wait to try out the new search?", - "sub_paragraph_3": "Search will be the first feature on Simpler.Grants.gov that you’ll be able to test. It’ll be quite basic at first, and you’ll need to continue using www.grants.gov as we iterate. But your feedback will inform what happens next.", - "sub_paragraph_4": "Be sure to sign up for product updates so you know when the new search is available.", - "cta_2": "View the search milestone on GitHub" - }, - "involved": { - "title_1": "Do you have data expertise?", - "paragraph_1": "We're spending time up-front collaborating with stakeholders on API design and data standards. If you have subject matter expertise with grants data, we want to talk. Contact us at simpler@grants.gov.", - "title_2": "Are you code-savvy?", - "paragraph_2": "If you’re interested in contributing to the open-source project or exploring the details of exactly what we’re building, check out the project at https://github.com/HHS/simpler-grants-gov or join our community at wiki.simpler.hhs.gov." - } - }, - "Newsletter": { - "page_title": "Newsletter | Simpler.Grants.gov", - "title": "Newsletter signup", - "intro": "Subscribe to get Simpler.Grants.gov project updates in your inbox!", - "paragraph_1": "If you sign up for the Simpler.Grants.gov newsletter, we’ll keep you informed of our progress and you’ll know about every opportunity to get involved.", - "list": "
  • Hear about upcoming milestones
  • Be the first to know when we launch new code
  • Test out new features and functionalities
  • Participate in usability tests and other user research efforts
  • Learn about ways to provide feedback
", - "disclaimer": "The Simpler.Grants.gov newsletter is powered by the Sendy data service. Personal information is not stored within Simpler.Grants.gov.", - "errors": { - "missing_name": "Enter your first name.", - "missing_email": "Enter your email address.", - "invalid_email": "Enter an email address in the correct format, like name@example.com.", - "already_subscribed": "{{email_address}} is already subscribed. If you’re not seeing our emails, check your spam folder and add no-reply@grants.gov to your contacts, address book, or safe senders list. If you continue to not receive our emails, contact simpler@grants.gov.", - "sendy": "Sorry, an unexpected error in our system occured when trying to save your subscription. If this continues to happen, you may email simpler@grants.gov. Error: {{sendy_error}}" - } - }, - "Newsletter_confirmation": { - "page_title": "Newsletter Confirmation | Simpler.Grants.gov", - "title": "You’re subscribed", - "intro": "You are signed up to receive project updates from Simpler.Grants.gov.", - "paragraph_1": "Thank you for subscribing. We’ll keep you informed of our progress and you’ll know about every opportunity to get involved.", - "heading": "Learn more", - "paragraph_2": "You can read all about our transparent process and what we’re doing now, or explore our existing user research and the findings that are guiding our work.", - "disclaimer": "The Simpler.Grants.gov newsletter is powered by the Sendy data service. Personal information is not stored within Simpler.Grants.gov. " - }, - "Newsletter_unsubscribe": { - "page_title": "Newsletter Unsubscribe | Simpler.Grants.gov", - "title": "You have unsubscribed", - "intro": "You will no longer receive project updates from Simpler.Grants.gov. ", - "paragraph_1": "Did you unsubscribe by accident? Sign up again.", - "button_resub": "Re-subscribe", - "heading": "Learn more", - "paragraph_2": "You can read all about our transparent process and what we’re doing now, or explore our existing user research and the findings that are guiding our work.", - "disclaimer": "The Simpler.Grants.gov newsletter is powered by the Sendy data service. Personal information is not stored within Simpler.Grants.gov. " - }, - "ErrorPages": { - "page_not_found": { - "title": "Oops! Page Not Found", - "message_content_1": "The page you have requested cannot be displayed because it does not exist, has been moved, or the server has been instructed not to let you view it. There is nothing to see here.", - "visit_homepage_button": "Return Home" - } - }, - "Header": { - "nav_link_home": "Home", - "nav_link_process": "Process", - "nav_link_research": "Research", - "nav_link_newsletter": "Newsletter", - "nav_menu_toggle": "Menu", - "title": "Simpler.Grants.gov" - }, - "Hero": { - "title": "We're building a simpler Grants.gov!", - "content": "This new website will be your go‑to resource to follow our progress as we improve and modernize the Grants.gov experience, making it easier to find, share, and apply for grants.", - "github_link": "Follow on GitHub" - }, - "Footer": { - "agency_name": "Grants.gov", - "agency_contact_center": "Grants.gov Program Management Office", - "telephone": "1-877-696-6775", - "return_to_top": "Return to top", - "link_twitter": "Twitter", - "link_youtube": "YouTube", - "link_github": "Github", - "link_rss": "RSS", - "link_newsletter": "Newsletter", - "link_blog": "Blog", - "logo_alt": "Grants.gov logo" - }, - "Identifier": { - "identity": "An official website of the U.S. Department of Health and Human Services", - "gov_content": "Looking for U.S. government information and services? Visit USA.gov", - "link_about": "About HHS", - "link_accessibility": "Accessibility support", - "link_foia": "FOIA requests", - "link_fear": "EEO/No Fear Act", - "link_ig": "Office of the Inspector General", - "link_performance": "Performance reports", - "link_privacy": "Privacy Policy", - "logo_alt": "HHS logo" - }, - "Layout": { - "skip_to_main": "Skip to main content" - } -} diff --git a/frontend/public/locales/es/common.json b/frontend/public/locales/es/common.json deleted file mode 100644 index d1d16ccfd..000000000 --- a/frontend/public/locales/es/common.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Index": { - "title": "Página principal" - }, - "Header": { - "title": "Título del sitio" - } -} diff --git a/frontend/src/app/[locale]/dev/feature-flags/FeatureFlagsTable.tsx b/frontend/src/app/[locale]/dev/feature-flags/FeatureFlagsTable.tsx new file mode 100644 index 000000000..604e58015 --- /dev/null +++ b/frontend/src/app/[locale]/dev/feature-flags/FeatureFlagsTable.tsx @@ -0,0 +1,61 @@ +"use client"; +import { useFeatureFlags } from "src/hooks/useFeatureFlags"; + +import React from "react"; +import { Button, Table } from "@trussworks/react-uswds"; + +/** + * View for managing feature flags + */ +export default function FeatureFlagsTable() { + const { featureFlagsManager, mounted, setFeatureFlag } = useFeatureFlags(); + + if (!mounted) { + return null; + } + + return ( + + + + + + + + + + {Object.entries(featureFlagsManager.featureFlags).map( + ([featureName, enabled]) => ( + + + + + + ), + )} + +
StatusFeature FlagActions
+ {enabled ? "Enabled" : "Disabled"} + {featureName} + + +
+ ); +} diff --git a/frontend/src/app/[locale]/dev/feature-flags/page.tsx b/frontend/src/app/[locale]/dev/feature-flags/page.tsx new file mode 100644 index 000000000..8a25a8328 --- /dev/null +++ b/frontend/src/app/[locale]/dev/feature-flags/page.tsx @@ -0,0 +1,30 @@ +import { Metadata } from "next"; + +import Head from "next/head"; +import React from "react"; +import FeatureFlagsTable from "./FeatureFlagsTable"; + +export function generateMetadata() { + const meta: Metadata = { + title: "Feature flag manager", + }; + + return meta; +} + +/** + * View for managing feature flags + */ +export default function FeatureFlags() { + return ( + <> + + Manage Feature Flags + +
+

Manage Feature Flags

+ +
+ + ); +} diff --git a/frontend/src/app/[locale]/health/page.tsx b/frontend/src/app/[locale]/health/page.tsx new file mode 100644 index 000000000..1c4e40ea2 --- /dev/null +++ b/frontend/src/app/[locale]/health/page.tsx @@ -0,0 +1,3 @@ +export default function Health() { + return <>healthy; +} diff --git a/frontend/src/app/[locale]/newsletter/NewsletterForm.tsx b/frontend/src/app/[locale]/newsletter/NewsletterForm.tsx new file mode 100644 index 000000000..9495a2674 --- /dev/null +++ b/frontend/src/app/[locale]/newsletter/NewsletterForm.tsx @@ -0,0 +1,217 @@ +"use client"; +import { NEWSLETTER_CONFIRMATION } from "src/constants/breadcrumbs"; +import { ExternalRoutes } from "src/constants/routes"; + +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { + Alert, + Button, + ErrorMessage, + FormGroup, + Label, + TextInput, +} from "@trussworks/react-uswds"; + +import { Data } from "src/pages/api/subscribe"; +import { useTranslations } from "next-intl"; + +export default function NewsletterForm() { + const t = useTranslations("Newsletter"); + + const router = useRouter(); + const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; + + const [formSubmitted, setFormSubmitted] = useState(false); + + const [formData, setFormData] = useState({ + name: "", + LastName: "", + email: "", + hp: "", + }); + + const [sendyError, setSendyError] = useState(""); + const [erroredEmail, setErroredEmail] = useState(""); + + const validateField = (fieldName: string) => { + // returns the string "valid" or the i18n key for the error message + const emailRegex = + /^(\D)+(\w)*((\.(\w)+)?)+@(\D)+(\w)*((\.(\D)+(\w)*)+)?(\.)[a-z]{2,}$/g; + if (fieldName === "name" && formData.name === "") + return t("errors.missing_name"); + if (fieldName === "email" && formData.email === "") + return t("errors.missing_email"); + if (fieldName === "email" && !emailRegex.test(formData.email)) + return t("errors.invalid_email"); + return "valid"; + }; + + const showError = (fieldName: string): boolean => + formSubmitted && validateField(fieldName) !== "valid"; + + const handleInput = (e: React.ChangeEvent) => { + const fieldName = e.target.name; + const fieldValue = e.target.value; + + setFormData((prevState) => ({ + ...prevState, + [fieldName]: fieldValue, + })); + }; + + const submitForm = async () => { + const formURL = "api/subscribe"; + if (validateField("email") !== "valid" || validateField("name") !== "valid") + return; + + const res = await fetch(formURL, { + method: "POST", + body: JSON.stringify(formData), + headers: { + Accept: "application/json", + }, + }); + + if (res.ok) { + const { message } = (await res.json()) as Data; + router.push(`${NEWSLETTER_CONFIRMATION.path}?sendy=${message as string}`); + return setSendyError(""); + } else { + const { error } = (await res.json()) as Data; + console.error("client error", error); + setErroredEmail(formData.email); + return setSendyError(error || ""); + } + }; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + setFormSubmitted(true); + submitForm().catch((err) => { + console.error("catch block", err); + }); + }; + + return ( +
+ {sendyError ? ( + + {t.rich( + sendyError === "Already subscribed." + ? "errors.already_subscribed" + : "errors.sendy", + { + email: (chunks) => ( + + {chunks} + + ), + sendy_error: (chunks) => ( + + {chunks} + + ), + email_address: (chunks) => ( + + {chunks} + + ), + }, + )} + + ) : ( + <> + )} + + + {showError("name") ? ( + + {validateField("name")} + + ) : ( + <> + )} + + + + + + + {showError("email") ? ( + + {validateField("email")} + + ) : ( + <> + )} + + +
+ + +
+ + + ); +} diff --git a/frontend/src/app/[locale]/newsletter/confirmation/page.tsx b/frontend/src/app/[locale]/newsletter/confirmation/page.tsx new file mode 100644 index 000000000..e621b610a --- /dev/null +++ b/frontend/src/app/[locale]/newsletter/confirmation/page.tsx @@ -0,0 +1,66 @@ +import { NEWSLETTER_CONFIRMATION_CRUMBS } from "src/constants/breadcrumbs"; + +import Link from "next/link"; +import { Grid, GridContainer } from "@trussworks/react-uswds"; + +import Breadcrumbs from "src/components/Breadcrumbs"; +import PageSEO from "src/components/PageSEO"; +import BetaAlert from "src/components/BetaAlert"; +import { useTranslations } from "next-intl"; +import { Metadata } from "next"; +import { getTranslations } from "next-intl/server"; + +export async function generateMetadata() { + const t = await getTranslations({ locale: "en" }); + const meta: Metadata = { + title: t("Newsletter.page_title"), + description: t("Index.meta_description"), + }; + + return meta; +} + +export default function NewsletterConfirmation() { + const t = useTranslations("Newsletter_confirmation"); + + return ( + <> + + + + + +

+ {t("title")} +

+

+ {t("intro")} +

+ + +

{t("paragraph_1")}

+
+ +

+ {t("heading")} +

+

+ {t.rich("paragraph_2", { + strong: (chunks) => {chunks}, + "process-link": (chunks) => ( + {chunks} + ), + "research-link": (chunks) => ( + {chunks} + ), + })} +

+
+
+
+ +

{t("disclaimer")}

+
+ + ); +} diff --git a/frontend/src/app/[locale]/newsletter/page.tsx b/frontend/src/app/[locale]/newsletter/page.tsx new file mode 100644 index 000000000..080aaed5a --- /dev/null +++ b/frontend/src/app/[locale]/newsletter/page.tsx @@ -0,0 +1,71 @@ +import { NEWSLETTER_CRUMBS } from "src/constants/breadcrumbs"; + +import { Grid, GridContainer } from "@trussworks/react-uswds"; +import pick from "lodash/pick"; +import Breadcrumbs from "src/components/Breadcrumbs"; +import PageSEO from "src/components/PageSEO"; +import BetaAlert from "src/components/BetaAlert"; +import NewsletterForm from "src/app/[locale]/newsletter/NewsletterForm"; +import { Metadata } from "next"; +import { getTranslations } from "next-intl/server"; +import { + useTranslations, + useMessages, + NextIntlClientProvider, +} from "next-intl"; + +export async function generateMetadata() { + const t = await getTranslations({ locale: "en" }); + const meta: Metadata = { + title: t("Newsletter.page_title"), + description: t("Index.meta_description"), + }; + + return meta; +} + +export default function Newsletter() { + const t = useTranslations("Newsletter"); + const messages = useMessages(); + + return ( + <> + + + + + +

+ {t("title")} +

+

+ {t("intro")} +

+ + +

{t("paragraph_1")}

+ {t.rich("list", { + ul: (chunks) => ( +
    + {chunks} +
+ ), + li: (chunks) =>
  • {chunks}
  • , + })} +
    + + + + + +
    +
    + +

    {t("disclaimer")}

    +
    + + ); +} diff --git a/frontend/src/app/[locale]/newsletter/unsubscribe/page.tsx b/frontend/src/app/[locale]/newsletter/unsubscribe/page.tsx new file mode 100644 index 000000000..9a095211a --- /dev/null +++ b/frontend/src/app/[locale]/newsletter/unsubscribe/page.tsx @@ -0,0 +1,69 @@ +import { NEWSLETTER_UNSUBSCRIBE_CRUMBS } from "src/constants/breadcrumbs"; + +import Link from "next/link"; +import { Grid, GridContainer } from "@trussworks/react-uswds"; + +import Breadcrumbs from "src/components/Breadcrumbs"; +import PageSEO from "src/components/PageSEO"; +import BetaAlert from "src/components/BetaAlert"; +import { useTranslations } from "next-intl"; +import { Metadata } from "next"; +import { getTranslations } from "next-intl/server"; + +export async function generateMetadata() { + const t = await getTranslations({ locale: "en" }); + const meta: Metadata = { + title: t("Newsletter.page_title"), + description: t("Index.meta_description"), + }; + + return meta; +} + +export default function NewsletterUnsubscribe() { + const t = useTranslations("Newsletter_unsubscribe"); + + return ( + <> + + + + + +

    + {t("title")} +

    +

    + {t("intro")} +

    + + +

    {t("paragraph_1")}

    + + {t("button_resub")} + +
    + +

    + {t("heading")} +

    +

    + {t.rich("paragraph_2", { + strong: (chunks) => {chunks}, + "process-link": (chunks) => ( + {chunks} + ), + "research-link": (chunks) => ( + {chunks} + ), + })} +

    +
    +
    +
    + +

    {t("disclaimer")}

    +
    + + ); +} diff --git a/frontend/src/app/[locale]/page.tsx b/frontend/src/app/[locale]/page.tsx new file mode 100644 index 000000000..795c8d84d --- /dev/null +++ b/frontend/src/app/[locale]/page.tsx @@ -0,0 +1,31 @@ +import BetaAlert from "src/components/BetaAlert"; +import PageSEO from "src/components/PageSEO"; +import Hero from "src/components/Hero"; +import IndexGoalContent from "src/components/content/IndexGoalContent"; +import ProcessAndResearchContent from "src/components/content/ProcessAndResearchContent"; +import { Metadata } from "next"; +import { useTranslations } from "next-intl"; +import { getTranslations } from "next-intl/server"; + +export async function generateMetadata() { + const t = await getTranslations({ locale: "en" }); + const meta: Metadata = { + title: t("Index.page_title"), + description: t("Index.meta_description"), + }; + return meta; +} + +export default function Home() { + const t = useTranslations("Index"); + + return ( + <> + + + + + + + ); +} diff --git a/frontend/src/app/[locale]/process/ProcessIntro.tsx b/frontend/src/app/[locale]/process/ProcessIntro.tsx new file mode 100644 index 000000000..f3b481318 --- /dev/null +++ b/frontend/src/app/[locale]/process/ProcessIntro.tsx @@ -0,0 +1,51 @@ +import { Grid } from "@trussworks/react-uswds"; +import { useTranslations, useMessages } from "next-intl"; +import ContentLayout from "src/components/ContentLayout"; + +const ProcessIntro = () => { + const t = useTranslations("Process"); + + const messages = useMessages() as unknown as IntlMessages; + const keys = Object.keys(messages.Process.intro.boxes); + + return ( + + + +

    + {t("intro.content")} +

    +
    +
    + + + {keys.map((key) => { + const title = t(`intro.boxes.${key}.title`); + const content = t.rich(`intro.boxes.${key}.content`, { + italics: (chunks) => {chunks}, + }); + return ( + +
    +

    {title}

    +

    + {content} +

    +
    +
    + ); + })} +
    +
    + ); +}; + +export default ProcessIntro; diff --git a/frontend/src/app/[locale]/process/ProcessInvolved.tsx b/frontend/src/app/[locale]/process/ProcessInvolved.tsx new file mode 100644 index 000000000..81294b3f8 --- /dev/null +++ b/frontend/src/app/[locale]/process/ProcessInvolved.tsx @@ -0,0 +1,67 @@ +import { ExternalRoutes } from "src/constants/routes"; + +import { useTranslations } from "next-intl"; +import { Grid } from "@trussworks/react-uswds"; + +import ContentLayout from "src/components/ContentLayout"; + +const ProcessInvolved = () => { + const t = useTranslations("Process"); + + const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; + const para1 = t.rich("involved.paragraph_1", { + email: (chunks) => ( + + {chunks} + + ), + strong: (chunks) => {chunks} , + }); + const para2 = t.rich("involved.paragraph_2", { + github: (chunks) => ( + + {chunks} + + ), + wiki: (chunks) => ( + + {chunks} + + ), + strong: (chunks) => {chunks} , + }); + return ( + + + +

    + {t("involved.title_1")} +

    +

    + {para1} +

    +
    + +

    + {t("involved.title_2")} +

    +

    + {para2} +

    +
    +
    +
    + ); +}; + +export default ProcessInvolved; diff --git a/frontend/src/pages/content/ProcessMilestones.tsx b/frontend/src/app/[locale]/process/ProcessMilestones.tsx similarity index 50% rename from frontend/src/pages/content/ProcessMilestones.tsx rename to frontend/src/app/[locale]/process/ProcessMilestones.tsx index d99c82e17..f275dbd09 100644 --- a/frontend/src/pages/content/ProcessMilestones.tsx +++ b/frontend/src/app/[locale]/process/ProcessMilestones.tsx @@ -1,38 +1,35 @@ import { ExternalRoutes } from "src/constants/routes"; +import React from "react"; -import { Trans, useTranslation } from "next-i18next"; +import { useTranslations, useMessages } from "next-intl"; import Link from "next/link"; import { Button, Grid, - Icon, IconList, IconListContent, IconListIcon, IconListItem, IconListTitle, } from "@trussworks/react-uswds"; +import { USWDSIcon } from "src/components/USWDSIcon"; import ContentLayout from "src/components/ContentLayout"; -type Boxes = { - title: string; - content: string; -}; - const ProcessMilestones = () => { - const { t } = useTranslation("common", { keyPrefix: "Process" }); + const t = useTranslations("Process"); - const iconList: Boxes[] = t("milestones.icon_list", { returnObjects: true }); + const messages = useMessages() as unknown as IntlMessages; + const keys = Object.keys(messages.Process.milestones.icon_list); const getIcon = (iconIndex: number) => { switch (iconIndex) { case 0: - return ; + return ; case 1: - return ; + return ; case 2: - return ; + return ; default: return <>; } @@ -47,50 +44,55 @@ const ProcessMilestones = () => { bottomBorder="dark" gridGap={6} > - {!Array.isArray(iconList) - ? "" - : iconList.map((box, index) => { - return ( - - - - {getIcon(index)} - - - {box.title} - -

    - ), - chevron: ( - - ), - }} + {keys.map((key, index) => { + const title = t(`milestones.icon_list.${key}.title`); + const content = t.rich(`milestones.icon_list.${key}.content`, { + p: (chunks) => ( +

    + {chunks} +

    + ), + italics: (chunks) => {chunks}, + }); + + return ( + + + + {getIcon(index)} + + + {title} + +
    + {content} +
    + { + // Don't show the chevron in the last row item. + index < keys.length - 1 ? ( + -
    -
    -
    -
    - ); - })} + ) : ( + "" + ) + } +
    +
    +
    +
    + ); + })} {t("milestones.roadmap_1")} - {t("milestones.title_1")} @@ -120,10 +122,9 @@ const ProcessMilestones = () => { @@ -134,10 +135,9 @@ const ProcessMilestones = () => { <> {t("milestones.roadmap_2")} - {t("milestones.title_2")} @@ -156,37 +156,14 @@ const ProcessMilestones = () => {

    {t("milestones.sub_title_3")}

    -

    - - ), - }} - /> -

    -

    - , - }} - /> -

    +

    +

    diff --git a/frontend/src/app/[locale]/process/page.tsx b/frontend/src/app/[locale]/process/page.tsx new file mode 100644 index 000000000..788627afa --- /dev/null +++ b/frontend/src/app/[locale]/process/page.tsx @@ -0,0 +1,38 @@ +import { PROCESS_CRUMBS } from "src/constants/breadcrumbs"; + +import BetaAlert from "src/components/BetaAlert"; + +import Breadcrumbs from "src/components/Breadcrumbs"; +import PageSEO from "src/components/PageSEO"; +import { Metadata } from "next"; +import ProcessIntro from "src/app/[locale]/process/ProcessIntro"; +import ProcessInvolved from "src/app/[locale]/process/ProcessInvolved"; +import ProcessMilestones from "src/app/[locale]/process/ProcessMilestones"; +import { useTranslations } from "next-intl"; +import { getTranslations } from "next-intl/server"; + +export async function generateMetadata() { + const t = await getTranslations({ locale: "en" }); + const meta: Metadata = { + title: t("Process.page_title"), + description: t("Process.meta_description"), + }; + return meta; +} + +export default function Process() { + const t = useTranslations("Process"); + + return ( + <> + + + + +
    + +
    + + + ); +} diff --git a/frontend/src/pages/content/ResearchArchetypes.tsx b/frontend/src/app/[locale]/research/ResearchArchetypes.tsx similarity index 91% rename from frontend/src/pages/content/ResearchArchetypes.tsx rename to frontend/src/app/[locale]/research/ResearchArchetypes.tsx index 80eb6931b..adf597d80 100644 --- a/frontend/src/pages/content/ResearchArchetypes.tsx +++ b/frontend/src/app/[locale]/research/ResearchArchetypes.tsx @@ -1,15 +1,14 @@ -import { useTranslation } from "next-i18next"; import Image from "next/image"; import { Grid } from "@trussworks/react-uswds"; - +import { useTranslations } from "next-intl"; import ContentLayout from "src/components/ContentLayout"; -import embarrassed from "../../../public/img/noun-embarrassed.svg"; -import goal from "../../../public/img/noun-goal.svg"; -import hiring from "../../../public/img/noun-hiring.svg"; -import leadership from "../../../public/img/noun-leadership.svg"; +import embarrassed from "public/img/noun-embarrassed.svg"; +import goal from "public/img/noun-goal.svg"; +import hiring from "public/img/noun-hiring.svg"; +import leadership from "public/img/noun-leadership.svg"; const ResearchArchetypes = () => { - const { t } = useTranslation("common", { keyPrefix: "Research" }); + const t = useTranslations("Research"); return ( { + const t = useTranslations("Research"); + + const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; + + const messages = useMessages() as unknown as IntlMessages; + const keys = Object.keys(messages.Research.impact.boxes); + + return ( + + +

    {t("impact.paragraph_1")}

    +

    + {t("impact.paragraph_2")} +

    +
    + + {keys.map((key) => { + const title = t(`impact.boxes.${key}.title`); + const content = t(`impact.boxes.${key}.content`); + return ( + +
    +

    {title}

    +

    + {content} +

    +
    +
    + ); + })} +
    + +

    + {t("impact.title_2")} +

    +

    + {t.rich("impact.paragraph_3", { + email: (chunks) => ( + + {chunks} + + ), + strong: (chunks) => {chunks}, + newsletter: (chunks) => {chunks}, + arrowUpRightFromSquare: () => ( + + ), + })} +

    +
    +
    + ); +}; + +export default ResearchImpact; diff --git a/frontend/src/pages/content/ResearchIntro.tsx b/frontend/src/app/[locale]/research/ResearchIntro.tsx similarity index 81% rename from frontend/src/pages/content/ResearchIntro.tsx rename to frontend/src/app/[locale]/research/ResearchIntro.tsx index e98168a91..3f5fd3a14 100644 --- a/frontend/src/pages/content/ResearchIntro.tsx +++ b/frontend/src/app/[locale]/research/ResearchIntro.tsx @@ -1,10 +1,10 @@ -import { useTranslation } from "next-i18next"; +import { useTranslations } from "next-intl"; import { Grid } from "@trussworks/react-uswds"; import ContentLayout from "src/components/ContentLayout"; const ResearchIntro = () => { - const { t } = useTranslation("common", { keyPrefix: "Research" }); + const t = useTranslations("Research"); return ( { - const { t } = useTranslation("common", { keyPrefix: "Research" }); + const t = useTranslations("Research"); return ( { >
    - - ), - }} - /> + {t.rich("methodology.paragraph_1", { + p: (chunks) => ( +

    + {chunks} +

    + ), + })}

    {t("methodology.title_2")}

    - - ), - li:
  • , - }} - /> + {t.rich("methodology.paragraph_2", { + ul: (chunks) => ( +
      + {chunks} +
    + ), + li: (chunks) =>
  • {chunks}
  • , + })}

    {t("methodology.title_3")}

    diff --git a/frontend/src/pages/content/ResearchThemes.tsx b/frontend/src/app/[locale]/research/ResearchThemes.tsx similarity index 93% rename from frontend/src/pages/content/ResearchThemes.tsx rename to frontend/src/app/[locale]/research/ResearchThemes.tsx index be8a95103..ceaaf5a08 100644 --- a/frontend/src/pages/content/ResearchThemes.tsx +++ b/frontend/src/app/[locale]/research/ResearchThemes.tsx @@ -1,10 +1,10 @@ -import { useTranslation } from "next-i18next"; +import { useTranslations } from "next-intl"; import { Grid } from "@trussworks/react-uswds"; import ContentLayout from "src/components/ContentLayout"; const ResearchThemes = () => { - const { t } = useTranslation("common", { keyPrefix: "Research" }); + const t = useTranslations("Research"); return ( + + + + + +
    + + +
    + + + ); +} diff --git a/frontend/src/app/search/SearchForm.tsx b/frontend/src/app/[locale]/search/SearchForm.tsx similarity index 80% rename from frontend/src/app/search/SearchForm.tsx rename to frontend/src/app/[locale]/search/SearchForm.tsx index 047cfd71c..1f5d60341 100644 --- a/frontend/src/app/search/SearchForm.tsx +++ b/frontend/src/app/[locale]/search/SearchForm.tsx @@ -2,20 +2,20 @@ import SearchPagination, { PaginationPosition, -} from "../../components/search/SearchPagination"; +} from "../../../components/search/SearchPagination"; import { AgencyNamyLookup } from "src/utils/search/generateAgencyNameLookup"; -import { QueryParamData } from "../../services/search/searchfetcher/SearchFetcher"; -import { SearchAPIResponse } from "../../types/search/searchResponseTypes"; -import SearchBar from "../../components/search/SearchBar"; +import { QueryParamData } from "../../../services/search/searchfetcher/SearchFetcher"; +import { SearchAPIResponse } from "../../../types/search/searchResponseTypes"; +import SearchBar from "../../../components/search/SearchBar"; import SearchFilterAgency from "src/components/search/SearchFilterAgency"; -import SearchFilterCategory from "../../components/search/SearchFilterCategory"; -import SearchFilterEligibility from "../../components/search/SearchFilterEligibility"; -import SearchFilterFundingInstrument from "../../components/search/SearchFilterFundingInstrument"; -import SearchOpportunityStatus from "../../components/search/SearchOpportunityStatus"; -import SearchResultsHeader from "../../components/search/SearchResultsHeader"; -import SearchResultsList from "../../components/search/SearchResultsList"; -import { useSearchFormState } from "../../hooks/useSearchFormState"; +import SearchFilterCategory from "../../../components/search/SearchFilterCategory"; +import SearchFilterEligibility from "../../../components/search/SearchFilterEligibility"; +import SearchFilterFundingInstrument from "../../../components/search/SearchFilterFundingInstrument"; +import SearchOpportunityStatus from "../../../components/search/SearchOpportunityStatus"; +import SearchResultsHeader from "../../../components/search/SearchResultsHeader"; +import SearchResultsList from "../../../components/search/SearchResultsList"; +import { useSearchFormState } from "../../../hooks/useSearchFormState"; interface SearchFormProps { initialSearchResults: SearchAPIResponse; diff --git a/frontend/src/app/search/actions.ts b/frontend/src/app/[locale]/search/actions.ts similarity index 68% rename from frontend/src/app/search/actions.ts rename to frontend/src/app/[locale]/search/actions.ts index cfe9b5076..d8a56149b 100644 --- a/frontend/src/app/search/actions.ts +++ b/frontend/src/app/[locale]/search/actions.ts @@ -1,9 +1,9 @@ // All exports in this file are server actions "use server"; -import { FormDataService } from "../../services/search/FormDataService"; -import { SearchAPIResponse } from "../../types/search/searchResponseTypes"; -import { getSearchFetcher } from "../../services/search/searchfetcher/SearchFetcherUtil"; +import { FormDataService } from "../../../services/search/FormDataService"; +import { SearchAPIResponse } from "../../../types/search/searchResponseTypes"; +import { getSearchFetcher } from "../../../services/search/searchfetcher/SearchFetcherUtil"; // Gets MockSearchFetcher or APISearchFetcher based on environment variable const searchFetcher = getSearchFetcher(); diff --git a/frontend/src/app/search/error.tsx b/frontend/src/app/[locale]/search/error.tsx similarity index 98% rename from frontend/src/app/search/error.tsx rename to frontend/src/app/[locale]/search/error.tsx index 3716f9ceb..ddfc71891 100644 --- a/frontend/src/app/search/error.tsx +++ b/frontend/src/app/[locale]/search/error.tsx @@ -8,7 +8,7 @@ import { import PageSEO from "src/components/PageSEO"; import { QueryParamData } from "src/services/search/searchfetcher/SearchFetcher"; import SearchCallToAction from "src/components/search/SearchCallToAction"; -import { SearchForm } from "src/app/search/SearchForm"; +import { SearchForm } from "src/app/[locale]/search/SearchForm"; import { useEffect } from "react"; interface ErrorProps { diff --git a/frontend/src/app/search/loading.tsx b/frontend/src/app/[locale]/search/loading.tsx similarity index 88% rename from frontend/src/app/search/loading.tsx rename to frontend/src/app/[locale]/search/loading.tsx index e9e7487c6..8b4feb238 100644 --- a/frontend/src/app/search/loading.tsx +++ b/frontend/src/app/[locale]/search/loading.tsx @@ -1,5 +1,5 @@ import React from "react"; -import Spinner from "../../components/Spinner"; +import Spinner from "../../../components/Spinner"; export default function Loading() { // TODO (Issue #1937): Use translation utility for strings in this file diff --git a/frontend/src/app/search/page.tsx b/frontend/src/app/[locale]/search/page.tsx similarity index 71% rename from frontend/src/app/search/page.tsx rename to frontend/src/app/[locale]/search/page.tsx index 319d16961..36cb75ef4 100644 --- a/frontend/src/app/search/page.tsx +++ b/frontend/src/app/[locale]/search/page.tsx @@ -1,18 +1,18 @@ import { ServerSideRouteParams, ServerSideSearchParams, -} from "../../types/searchRequestURLTypes"; +} from "../../../types/searchRequestURLTypes"; -import BetaAlert from "../../components/AppBetaAlert"; +import BetaAlert from "src/components/BetaAlert"; import { Metadata } from "next"; import React from "react"; -import SearchCallToAction from "../../components/search/SearchCallToAction"; +import SearchCallToAction from "../../../components/search/SearchCallToAction"; import { SearchForm } from "./SearchForm"; -import { convertSearchParamsToProperTypes } from "../../utils/search/convertSearchParamsToProperTypes"; +import { convertSearchParamsToProperTypes } from "../../../utils/search/convertSearchParamsToProperTypes"; import { generateAgencyNameLookup } from "src/utils/search/generateAgencyNameLookup"; -import { getSearchFetcher } from "../../services/search/searchfetcher/SearchFetcherUtil"; +import { getSearchFetcher } from "../../../services/search/searchfetcher/SearchFetcherUtil"; import { getTranslations } from "next-intl/server"; -import withFeatureFlag from "../../hoc/search/withFeatureFlag"; +import withFeatureFlag from "../../../hoc/search/withFeatureFlag"; const searchFetcher = getSearchFetcher(); @@ -25,10 +25,11 @@ export async function generateMetadata() { const t = await getTranslations({ locale: "en" }); const meta: Metadata = { title: t("Search.title"), + description: t("Index.meta_description"), }; - return meta; } + async function Search({ searchParams }: ServerPageProps) { const convertedSearchParams = convertSearchParamsToProperTypes(searchParams); const initialSearchResults = await searchFetcher.fetchOpportunities( diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index 5c52b5004..e45e82c42 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -1,8 +1,8 @@ import "src/styles/styles.scss"; import { GoogleAnalytics } from "@next/third-parties/google"; -import { PUBLIC_ENV } from "../constants/environments"; +import { PUBLIC_ENV } from "src/constants/environments"; -import Layout from "src/components/AppLayout"; +import Layout from "src/components/Layout"; import { unstable_setRequestLocale } from "next-intl/server"; /** * Root layout component, wraps all pages. diff --git a/frontend/src/app/not-found.tsx b/frontend/src/app/not-found.tsx index 6615f073a..08416f07f 100644 --- a/frontend/src/app/not-found.tsx +++ b/frontend/src/app/not-found.tsx @@ -1,12 +1,23 @@ -import BetaAlert from "src/components/AppBetaAlert"; +import BetaAlert from "src/components/BetaAlert"; import { GridContainer } from "@trussworks/react-uswds"; import Link from "next/link"; import { useTranslations } from "next-intl"; -import { unstable_setRequestLocale } from "next-intl/server"; +import { getTranslations, unstable_setRequestLocale } from "next-intl/server"; +import { Metadata } from "next"; + +export async function generateMetadata() { + const t = await getTranslations({ locale: "en" }); + const meta: Metadata = { + title: t("ErrorPages.page_not_found.title"), + description: t("Index.meta_description"), + }; + return meta; +} export default function NotFound() { unstable_setRequestLocale("en"); const t = useTranslations("ErrorPages.page_not_found"); + return ( <> diff --git a/frontend/src/app/template.tsx b/frontend/src/app/template.tsx index a79e15041..b7250859f 100644 --- a/frontend/src/app/template.tsx +++ b/frontend/src/app/template.tsx @@ -2,7 +2,7 @@ import { useEffect } from "react"; import { sendGAEvent } from "@next/third-parties/google"; -import { PUBLIC_ENV } from "../constants/environments"; +import { PUBLIC_ENV } from "src/constants/environments"; export default function Template({ children }: { children: React.ReactNode }) { const isProd = process.env.NODE_ENV === "production"; diff --git a/frontend/src/components/AppBetaAlert.tsx b/frontend/src/components/AppBetaAlert.tsx deleted file mode 100644 index 2cbf5f2fe..000000000 --- a/frontend/src/components/AppBetaAlert.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { useTranslations } from "next-intl"; - -import FullWidthAlert from "./FullWidthAlert"; - -const BetaAlert = () => { - const t = useTranslations("Beta_alert"); - const heading = t.rich("alert_title", { - LinkToGrants: (content) => {content}, - }); - - return ( -
    - - {t("alert")} - -
    - ); -}; - -export default BetaAlert; diff --git a/frontend/src/components/AppLayout.tsx b/frontend/src/components/AppLayout.tsx deleted file mode 100644 index a539f90d5..000000000 --- a/frontend/src/components/AppLayout.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import Footer from "./Footer"; -import GrantsIdentifier from "./GrantsIdentifier"; -import Header from "./Header"; -import { useTranslations } from "next-intl"; - -type Props = { - children: React.ReactNode; - locale: string; -}; - -export default function Layout({ children, locale }: Props) { - const t = useTranslations(); - - const header_strings = { - title: t("Header.title"), - nav_menu_toggle: t("Header.nav_menu_toggle"), - nav_link_home: t("Header.nav_link_home"), - nav_link_search: "Search", - nav_link_process: t("Header.nav_link_process"), - nav_link_research: t("Header.nav_link_research"), - nav_link_newsletter: t("Header.nav_link_newsletter"), - }; - const footer_strings = { - agency_name: t("Footer.agency_name"), - agency_contact_center: t("Footer.agency_contact_center"), - telephone: t("Footer.telephone"), - return_to_top: t("Footer.return_to_top"), - link_twitter: t("Footer.link_twitter"), - link_youtube: t("Footer.link_youtube"), - link_blog: t("Footer.link_blog"), - link_newsletter: t("Footer.link_newsletter"), - link_rss: t("Footer.link_rss"), - link_github: t("Footer.link_github"), - logo_alt: t("Footer.logo_alt"), - }; - - const identifier_strings = { - link_about: t("Identifier.link_about"), - link_accessibility: t("Identifier.link_accessibility"), - link_foia: t("Identifier.link_foia"), - link_fear: t("Identifier.link_fear"), - link_ig: t("Identifier.link_ig"), - link_performance: t("Identifier.link_performance"), - link_privacy: t("Identifier.link_privacy"), - logo_alt: t("Identifier.logo_alt"), - }; - return ( - // Stick the footer to the bottom of the page -
    - - {t("Layout.skip_to_main")} - -
    -
    {children}
    -
    - -
    - ); -} diff --git a/frontend/src/components/BetaAlert.tsx b/frontend/src/components/BetaAlert.tsx index fe7acd079..2cbf5f2fe 100644 --- a/frontend/src/components/BetaAlert.tsx +++ b/frontend/src/components/BetaAlert.tsx @@ -1,51 +1,20 @@ -"use client"; +import { useTranslations } from "next-intl"; -import Link from "next/link"; - -import { ExternalRoutes } from "src/constants/routes"; import FullWidthAlert from "./FullWidthAlert"; -// TODO: Remove for i18n update. -type BetaStrings = { - alert_title: string; - alert: string; -}; - -type Props = { - beta_strings: BetaStrings; -}; - -const BetaAlert = ({ beta_strings }: Props) => { - // TODO: Remove during move to app router and next-intl upgrade - const title_start = beta_strings.alert_title.substring( - 0, - beta_strings.alert_title.indexOf(""), - ); - const title_end = beta_strings.alert_title.substring( - beta_strings.alert_title.indexOf("") + - "".length, - ); - const link = ( - <> - {title_start} - - www.grants.gov - - {title_end} - - ); +const BetaAlert = () => { + const t = useTranslations("Beta_alert"); + const heading = t.rich("alert_title", { + LinkToGrants: (content) => {content}, + }); return (
    - - {beta_strings.alert} + + {t("alert")}
    ); diff --git a/frontend/src/components/Footer.tsx b/frontend/src/components/Footer.tsx index 1c4f60598..bf8ca8761 100644 --- a/frontend/src/components/Footer.tsx +++ b/frontend/src/components/Footer.tsx @@ -1,86 +1,73 @@ -"use client"; - import { ExternalRoutes } from "src/constants/routes"; -import { assetPath } from "src/utils/assetPath"; +import { useTranslations } from "next-intl"; +import { USWDSIcon } from "src/components/USWDSIcon"; +import GrantsLogo from "public/img/grants-gov-logo.png"; + +import Image from "next/image"; -import { ComponentType } from "react"; import { Address, Grid, GridContainer, - Icon, SocialLinks, Footer as USWDSFooter, } from "@trussworks/react-uswds"; -import { IconProps } from "@trussworks/react-uswds/lib/components/Icon/Icon"; // Recreate @trussworks/react-uswds SocialLink component to accept any Icon // https://github.com/trussworks/react-uswds/blob/cf5b4555e25f0e52fc8af66afe29253922bed2a5/src/components/Footer/SocialLinks/SocialLinks.tsx#L33 type SocialLinkProps = { href: string; name: string; - Tag: ComponentType; + icon: string; }; -const SocialLink = ({ href, name, Tag }: SocialLinkProps) => ( +const SocialLink = ({ href, name, icon }: SocialLinkProps) => ( - + ); -// TODO: Remove during move to app router and next-intl upgrade -type FooterStrings = { - agency_name: string; - agency_contact_center: string; - telephone: string; - return_to_top: string; - link_twitter: string; - link_youtube: string; - link_blog: string; - link_newsletter: string; - link_rss: string; - link_github: string; - logo_alt: string; -}; - -type Props = { - footer_strings: FooterStrings; -}; +const Footer = () => { + const t = useTranslations("Footer"); -const Footer = ({ footer_strings }: Props) => { const links = [ { href: ExternalRoutes.GRANTS_TWITTER, - name: footer_strings.link_twitter, - Tag: Icon.Twitter, + name: t("link_twitter"), + icon: "twitter", }, { href: ExternalRoutes.GRANTS_YOUTUBE, - name: footer_strings.link_youtube, - Tag: Icon.Youtube, + name: t("link_youtube"), + icon: "youtube", }, { href: ExternalRoutes.GRANTS_BLOG, - name: footer_strings.link_blog, - Tag: Icon.LocalLibrary, + name: t("link_blog"), + icon: "local_library", }, { href: ExternalRoutes.GRANTS_NEWSLETTER, - name: footer_strings.link_newsletter, - Tag: Icon.Mail, + name: t("link_newsletter"), + icon: "mail", }, { href: ExternalRoutes.GRANTS_RSS, - name: footer_strings.link_rss, - Tag: Icon.RssFeed, + name: t("link_rss"), + icon: "rss_feed", }, { href: ExternalRoutes.GITHUB_REPO, - name: footer_strings.link_github, - Tag: Icon.Github, + name: t("link_github"), + icon: "github", }, - ].map(({ href, name, Tag }) => ( - + ].map(({ href, name, icon }) => ( + )); return ( @@ -89,17 +76,20 @@ const Footer = ({ footer_strings }: Props) => { size="medium" returnToTop={ - {footer_strings.return_to_top} + {t("return_to_top")} } primary={null} secondary={ - {footer_strings.logo_alt} { >

    - {footer_strings.agency_contact_center} + {t("agency_contact_center")}

    - {footer_strings.telephone} + + {t("telephone")} , {ExternalRoutes.EMAIL_SUPPORT} diff --git a/frontend/src/components/GrantsIdentifier.tsx b/frontend/src/components/GrantsIdentifier.tsx index dc4fcebf0..8b4975188 100644 --- a/frontend/src/components/GrantsIdentifier.tsx +++ b/frontend/src/components/GrantsIdentifier.tsx @@ -1,8 +1,7 @@ -"use client"; - import { ExternalRoutes } from "src/constants/routes"; -import { Trans, useTranslation } from "next-i18next"; +import { useTranslations } from "next-intl"; + import Image from "next/image"; import { Identifier, @@ -16,28 +15,21 @@ import { IdentifierMasthead, } from "@trussworks/react-uswds"; -import logo from "../../public/img/logo-white-lg.webp"; +import logo from "public/img/logo-white-lg.webp"; -// TODO: Remove during move to app router and next-intl upgrade -type IdentifierStrings = { - link_about: string; - link_accessibility: string; - link_foia: string; - link_fear: string; - link_ig: string; - link_performance: string; - link_privacy: string; - logo_alt: string; -}; - -type Props = { - identifier_strings: IdentifierStrings; -}; +const GrantsIdentifier = () => { + const t = useTranslations("Identifier"); -const GrantsIdentifier = ({ identifier_strings }: Props) => { - const { t } = useTranslation("common", { - keyPrefix: "Identifier", - }); + const identifier_strings = { + link_about: t("link_about"), + link_accessibility: t("link_accessibility"), + link_foia: t("link_foia"), + link_fear: t("link_fear"), + link_ig: t("link_ig"), + link_performance: t("link_performance"), + link_privacy: t("link_privacy"), + logo_alt: t("logo_alt"), + }; const logoImage = ( { {logoImage} - , - }} - /> + {t.rich("identity", { + hhsLink: (chunks) => {chunks}, + })} {IdentifierLinkList} - , - }} - /> + {t.rich("gov_content", { + usaLink: (chunks) => {chunks}, + })} ); diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index 166f844e5..6f26ed4e2 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -10,31 +10,21 @@ import { import { useEffect, useRef, useState } from "react"; import { assetPath } from "src/utils/assetPath"; -import { useFeatureFlags } from "../hooks/useFeatureFlags"; +import { useFeatureFlags } from "src/hooks/useFeatureFlags"; +import { useTranslations } from "next-intl"; type PrimaryLinks = { i18nKey: string; href: string; }[]; -// TODO: Remove during move to app router and next-intl upgrade -type HeaderStrings = { - nav_link_home: string; - nav_link_search?: string; - nav_link_process: string; - nav_link_research: string; - nav_link_newsletter: string; - nav_menu_toggle: string; - title: string; -}; - type Props = { logoPath?: string; - header_strings: HeaderStrings; locale?: string; }; -const Header = ({ header_strings, logoPath, locale }: Props) => { +const Header = ({ logoPath, locale }: Props) => { + const t = useTranslations("Header"); const [isMobileNavExpanded, setIsMobileNavExpanded] = useState(false); const handleMobileNavToggle = () => { setIsMobileNavExpanded(!isMobileNavExpanded); @@ -45,23 +35,23 @@ const Header = ({ header_strings, logoPath, locale }: Props) => { useEffect(() => { primaryLinksRef.current = [ - { i18nKey: "nav_link_home", href: "/" }, - { i18nKey: "nav_link_process", href: "/process" }, - { i18nKey: "nav_link_research", href: "/research" }, - { i18nKey: "nav_link_newsletter", href: "/newsletter" }, + { i18nKey: t("nav_link_home"), href: "/" }, + { i18nKey: t("nav_link_process"), href: "/process" }, + { i18nKey: t("nav_link_research"), href: "/research" }, + { i18nKey: t("nav_link_newsletter"), href: "/newsletter" }, ]; const searchNavLink = { - i18nKey: "nav_link_search", + i18nKey: t("nav_link_search"), href: "/search?status=forecasted,posted", }; if (featureFlagsManager.isFeatureEnabled("showSearchV0")) { primaryLinksRef.current.splice(1, 0, searchNavLink); } - }, [featureFlagsManager]); + }, [featureFlagsManager, t]); const navItems = primaryLinksRef.current.map((link) => ( - {header_strings[link.i18nKey as keyof HeaderStrings]} + {link.i18nKey} )); const language = locale && locale.match("/^es/") ? "spanish" : "english"; @@ -86,14 +76,12 @@ const Header = ({ header_strings, logoPath, locale }: Props) => { /> )} - - {header_strings.title} - + {t("title")} { - const { t } = useTranslation("common", { - keyPrefix: "Hero", - }); + const t = useTranslations("Hero"); return (
    @@ -23,9 +22,9 @@ const Hero = () => { href={ExternalRoutes.GITHUB_REPO} target="_blank" > - {t("github_link")} diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index 7acb26f04..9cce89c04 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -1,50 +1,21 @@ import Footer from "./Footer"; import GrantsIdentifier from "./GrantsIdentifier"; import Header from "./Header"; -import { useTranslation } from "next-i18next"; +import { + useTranslations, + useMessages, + NextIntlClientProvider, +} from "next-intl"; +import pick from "lodash/pick"; type Props = { children: React.ReactNode; + locale: string; }; -const Layout = ({ children }: Props) => { - const { t } = useTranslation("common"); - - // TODO: Remove during move to app router and next-intl upgrade - const header_strings = { - title: t("Header.title"), - nav_menu_toggle: t("Header.nav_menu_toggle"), - nav_link_home: t("Header.nav_link_home"), - nav_link_search: t("Search"), - nav_link_process: t("Header.nav_link_process"), - nav_link_research: t("Header.nav_link_research"), - nav_link_newsletter: t("Header.nav_link_newsletter"), - }; - - const footer_strings = { - agency_name: t("Footer.agency_name"), - agency_contact_center: t("Footer.agency_contact_center"), - telephone: t("Footer.telephone"), - return_to_top: t("Footer.return_to_top"), - link_twitter: t("Footer.link_twitter"), - link_youtube: t("Footer.link_youtube"), - link_blog: t("Footer.link_blog"), - link_newsletter: t("Footer.link_newsletter"), - link_rss: t("Footer.link_rss"), - link_github: t("Footer.link_github"), - logo_alt: t("Footer.logo_alt"), - }; - - const identifier_strings = { - link_about: t("Identifier.link_about"), - link_accessibility: t("Identifier.link_accessibility"), - link_foia: t("Identifier.link_foia"), - link_fear: t("Identifier.link_fear"), - link_ig: t("Identifier.link_ig"), - link_performance: t("Identifier.link_performance"), - link_privacy: t("Identifier.link_privacy"), - logo_alt: t("Identifier.logo_alt"), - }; +export default function Layout({ children, locale }: Props) { + const t = useTranslations(); + const messages = useMessages(); return ( // Stick the footer to the bottom of the page @@ -52,12 +23,15 @@ const Layout = ({ children }: Props) => { {t("Layout.skip_to_main")} -
    + +
    +
    {children}
    -
    - +
    +
    ); -}; - -export default Layout; +} diff --git a/frontend/src/components/USWDSIcon.tsx b/frontend/src/components/USWDSIcon.tsx new file mode 100644 index 000000000..7414d8978 --- /dev/null +++ b/frontend/src/components/USWDSIcon.tsx @@ -0,0 +1,23 @@ +import SpriteSVG from "public/img/uswds-sprite.svg"; + +interface IconProps { + name: string; + className: string; + height?: string; +} + +// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access +const sprite_uri = SpriteSVG.src as string; + +export function USWDSIcon(props: IconProps) { + return ( + + ); +} diff --git a/frontend/src/pages/content/FundingContent.tsx b/frontend/src/components/content/FundingContent.tsx similarity index 93% rename from frontend/src/pages/content/FundingContent.tsx rename to frontend/src/components/content/FundingContent.tsx index 60f0900e4..b72dc07be 100644 --- a/frontend/src/pages/content/FundingContent.tsx +++ b/frontend/src/components/content/FundingContent.tsx @@ -1,12 +1,12 @@ import { nofoPdfs } from "src/constants/nofoPdfs"; -import { useTranslation } from "next-i18next"; +import { useTranslations } from "next-intl"; import { Grid, GridContainer } from "@trussworks/react-uswds"; import NofoImageLink from "../../components/NofoImageLink"; const FundingContent = () => { - const { t } = useTranslation("common", { keyPrefix: "Index" }); + const t = useTranslations("Index"); return (
    @@ -41,7 +41,7 @@ const FundingContent = () => { image={pdf.image} height={pdf.height} width={pdf.width} - alt={t(`${pdf.alt}`)} + alt={pdf.alt} /> ))} diff --git a/frontend/src/pages/content/IndexGoalContent.tsx b/frontend/src/components/content/IndexGoalContent.tsx similarity index 80% rename from frontend/src/pages/content/IndexGoalContent.tsx rename to frontend/src/components/content/IndexGoalContent.tsx index 83d3c4d69..a1e064e6a 100644 --- a/frontend/src/pages/content/IndexGoalContent.tsx +++ b/frontend/src/components/content/IndexGoalContent.tsx @@ -1,11 +1,12 @@ -import { useTranslation } from "next-i18next"; -import Link from "next/link"; -import { Button, Grid, Icon } from "@trussworks/react-uswds"; +import { useTranslations } from "next-intl"; +import Link from "next/link"; +import { Button, Grid } from "@trussworks/react-uswds"; +import { USWDSIcon } from "../USWDSIcon"; import ContentLayout from "src/components/ContentLayout"; const IndexGoalContent = () => { - const { t } = useTranslation("common", { keyPrefix: "Index" }); + const t = useTranslations("Index"); return ( { diff --git a/frontend/src/pages/content/ProcessAndResearchContent.tsx b/frontend/src/components/content/ProcessAndResearchContent.tsx similarity index 77% rename from frontend/src/pages/content/ProcessAndResearchContent.tsx rename to frontend/src/components/content/ProcessAndResearchContent.tsx index 0706f32c3..e07bab385 100644 --- a/frontend/src/pages/content/ProcessAndResearchContent.tsx +++ b/frontend/src/components/content/ProcessAndResearchContent.tsx @@ -1,11 +1,12 @@ -import { useTranslation } from "next-i18next"; +import { useTranslations } from "next-intl"; import Link from "next/link"; -import { Button, Grid, Icon } from "@trussworks/react-uswds"; +import { Button, Grid } from "@trussworks/react-uswds"; +import { USWDSIcon } from "src/components/USWDSIcon"; import ContentLayout from "src/components/ContentLayout"; const ProcessAndResearchContent = () => { - const { t } = useTranslation("common", { keyPrefix: "Index" }); + const t = useTranslations("Index"); return ( { {t("process_and_research.cta_1")} - @@ -44,9 +45,9 @@ const ProcessAndResearchContent = () => { {t("process_and_research.cta_2")} - diff --git a/frontend/src/components/search/SearchResultsList.tsx b/frontend/src/components/search/SearchResultsList.tsx index eeddc716b..bca660db1 100644 --- a/frontend/src/components/search/SearchResultsList.tsx +++ b/frontend/src/components/search/SearchResultsList.tsx @@ -1,7 +1,7 @@ "use client"; import { AgencyNamyLookup } from "src/utils/search/generateAgencyNameLookup"; -import Loading from "../../app/search/loading"; +import Loading from "../../app/[locale]/search/loading"; import SearchErrorAlert from "src/components/search/error/SearchErrorAlert"; import { SearchResponseData } from "../../types/search/searchResponseTypes"; import SearchResultsListItem from "./SearchResultsListItem"; diff --git a/frontend/src/hooks/useSearchFormState.ts b/frontend/src/hooks/useSearchFormState.ts index f3a53bef8..0526effd9 100644 --- a/frontend/src/hooks/useSearchFormState.ts +++ b/frontend/src/hooks/useSearchFormState.ts @@ -4,7 +4,7 @@ import { useRef, useState } from "react"; import { QueryParamData } from "../services/search/searchfetcher/SearchFetcher"; import { SearchAPIResponse } from "../types/search/searchResponseTypes"; -import { updateResults } from "../app/search/actions"; +import { updateResults } from "../app/[locale]/search/actions"; import { useFormState } from "react-dom"; import { useSearchParamUpdater } from "./useSearchParamUpdater"; diff --git a/frontend/src/i18n/messages/en/index.ts b/frontend/src/i18n/messages/en/index.ts index 843d4455d..11a5f900a 100644 --- a/frontend/src/i18n/messages/en/index.ts +++ b/frontend/src/i18n/messages/en/index.ts @@ -229,12 +229,12 @@ export const messages = { { title: "Find", content: - "

    Improve how applicants discover funding opportunities that they’re qualified for and that meet their needs.

    ", + "

    Improve how applicants discover funding opportunities that they’re qualified for and that meet their needs.

    ", }, { title: "Advanced reporting", content: - "

    Improve stakeholders’ capacity to understand, analyze, and assess grants from application to acceptance.

    Make non-confidential Grants.gov data open for public analysis.

    ", + "

    Improve stakeholders’ capacity to understand, analyze, and assess grants from application to acceptance.

    Make non-confidential Grants.gov data open for public analysis.

    ", }, { title: "Apply", @@ -291,9 +291,9 @@ export const messages = { invalid_email: "Enter an email address in the correct format, like name@example.com.", already_subscribed: - "{{email_address}} is already subscribed. If you’re not seeing our emails, check your spam folder and add no-reply@grants.gov to your contacts, address book, or safe senders list. If you continue to not receive our emails, contact simpler@grants.gov.", + " is already subscribed. If you’re not seeing our emails, check your spam folder and add no-reply@grants.gov to your contacts, address book, or safe senders list. If you continue to not receive our emails, contact simpler@grants.gov.", sendy: - "Sorry, an unexpected error in our system occured when trying to save your subscription. If this continues to happen, you may email simpler@grants.gov. Error: {{sendy_error}}", + "Sorry, an unexpected error in our system occured when trying to save your subscription. If this continues to happen, you may email simpler@grants.gov. Error: ", }, }, Newsletter_confirmation: { @@ -323,6 +323,7 @@ export const messages = { "The Simpler.Grants.gov newsletter is powered by the Sendy data service. Personal information is not stored within Simpler.Grants.gov. ", }, ErrorPages: { + page_title: "Page Not Found | Simpler.Grants.gov", page_not_found: { title: "Oops! Page Not Found", message_content_1: diff --git a/frontend/src/middleware.ts b/frontend/src/middleware.ts index 33d8c733b..996176d04 100644 --- a/frontend/src/middleware.ts +++ b/frontend/src/middleware.ts @@ -19,7 +19,7 @@ export const config = { * - _next/image (image optimization files) * - images (static files in public/images/ directory) */ - "/((?!api|_next/static|_next/image|images|site.webmanifest).*)", + "/((?!api|_next/static|_next/image|public|img|uswds|images|robots.txt|site.webmanifest).*)", /** * Fix issue where the pattern above was causing middleware * to not run on the homepage: diff --git a/frontend/src/pages/404.tsx b/frontend/src/pages/404.tsx deleted file mode 100644 index 3543f0e3d..000000000 --- a/frontend/src/pages/404.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; - -import { useTranslation } from "next-i18next"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; -import Link from "next/link"; -import { GridContainer } from "@trussworks/react-uswds"; - -import BetaAlert from "../components/BetaAlert"; - -const PageNotFound: NextPage = () => { - const { t } = useTranslation("common"); - // TODO: Remove during move to app router and next-intl upgrade - const beta_strings = { - alert_title: t("Beta_alert.alert_title"), - alert: t("Beta_alert.alert"), - }; - return ( - <> - - -

    {t("page_not_found.title")}

    -

    - {t("ErrorPages.page_not_found.message_content_1")} -

    - - {t("ErrorPages.page_not_found.visit_homepage_button")} - -
    - - ); -}; - -// Change this to GetServerSideProps if you're using server-side rendering -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default PageNotFound; diff --git a/frontend/src/pages/_app.tsx b/frontend/src/pages/_app.tsx deleted file mode 100644 index 971a5530f..000000000 --- a/frontend/src/pages/_app.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import "../styles/styles.scss"; - -import type { AppProps } from "next/app"; -import { GoogleAnalytics } from "@next/third-parties/google"; -import Head from "next/head"; -import Layout from "../components/Layout"; -import { PUBLIC_ENV } from "src/constants/environments"; -import { appWithTranslation } from "next-i18next"; -import { assetPath } from "src/utils/assetPath"; - -function MyApp({ Component, pageProps }: AppProps) { - return ( - <> - - - {process.env.NEXT_PUBLIC_ENVIRONMENT !== "prod" && ( - - )} - - - - - - - ); -} - -export default appWithTranslation(MyApp); diff --git a/frontend/src/pages/api/hello.ts b/frontend/src/pages/api/hello.ts deleted file mode 100644 index ea77e8f35..000000000 --- a/frontend/src/pages/api/hello.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import type { NextApiRequest, NextApiResponse } from "next"; - -type Data = { - name: string; -}; - -export default function handler( - req: NextApiRequest, - res: NextApiResponse, -) { - res.status(200).json({ name: "John Doe" }); -} diff --git a/frontend/src/pages/content/ProcessIntro.tsx b/frontend/src/pages/content/ProcessIntro.tsx deleted file mode 100644 index af14025e8..000000000 --- a/frontend/src/pages/content/ProcessIntro.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { Trans, useTranslation } from "next-i18next"; -import { Grid } from "@trussworks/react-uswds"; - -import ContentLayout from "src/components/ContentLayout"; - -type IntroBoxes = { - title: string; - content: string; -}; - -const ProcessIntro = () => { - const { t } = useTranslation("common", { keyPrefix: "Process" }); - - const boxes: IntroBoxes[] = t("intro.boxes", { returnObjects: true }); - - return ( - - - -

    - {t("intro.content")} -

    -
    -
    - - - {!Array.isArray(boxes) - ? "" - : boxes.map((box) => { - return ( - -
    -

    {box.title}

    -

    - }} - /> -

    -
    -
    - ); - })} -
    -
    - ); -}; - -export default ProcessIntro; diff --git a/frontend/src/pages/content/ProcessInvolved.tsx b/frontend/src/pages/content/ProcessInvolved.tsx deleted file mode 100644 index 662a4e3b2..000000000 --- a/frontend/src/pages/content/ProcessInvolved.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import { ExternalRoutes } from "src/constants/routes"; - -import { Trans, useTranslation } from "next-i18next"; -import { Grid } from "@trussworks/react-uswds"; - -import ContentLayout from "src/components/ContentLayout"; - -const ProcessInvolved = () => { - const { t } = useTranslation("common", { keyPrefix: "Process" }); - - const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; - - return ( - - - -

    - {t("involved.title_1")} -

    -

    - - ), - }} - /> -

    -
    - -

    - {t("involved.title_2")} -

    -

    - - ), - wiki: ( - - ), - }} - /> -

    -
    -
    -
    - ); -}; - -export default ProcessInvolved; diff --git a/frontend/src/pages/content/ResearchImpact.tsx b/frontend/src/pages/content/ResearchImpact.tsx deleted file mode 100644 index f7278de0a..000000000 --- a/frontend/src/pages/content/ResearchImpact.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { ExternalRoutes } from "src/constants/routes"; - -import { Trans, useTranslation } from "next-i18next"; -import Link from "next/link"; -import { Grid, Icon } from "@trussworks/react-uswds"; - -import ContentLayout from "src/components/ContentLayout"; - -type ImpactBoxes = { - title: string; - content: string; -}; - -const ResearchImpact = () => { - const { t } = useTranslation("common", { - keyPrefix: "Research", - }); - const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; - - const boxes: ImpactBoxes[] = t("impact.boxes", { returnObjects: true }); - - return ( - - -

    {t("impact.paragraph_1")}

    -

    - {t("impact.paragraph_2")} -

    -
    - - {!Array.isArray(boxes) - ? "" - : boxes.map((box) => { - return ( - -
    -

    {box.title}

    -

    - {box.content} -

    -
    -
    - ); - })} -
    - -

    - {t("impact.title_2")} -

    -

    - - ), - newsletter: , - arrowUpRightFromSquare: ( - - ), - }} - /> -

    -
    -
    - ); -}; - -export default ResearchImpact; diff --git a/frontend/src/pages/content/WtGIContent.tsx b/frontend/src/pages/content/WtGIContent.tsx deleted file mode 100644 index 54b4cf5a8..000000000 --- a/frontend/src/pages/content/WtGIContent.tsx +++ /dev/null @@ -1,90 +0,0 @@ -import { ExternalRoutes } from "src/constants/routes"; - -import { Trans, useTranslation } from "next-i18next"; -import { Grid, GridContainer, Icon } from "@trussworks/react-uswds"; - -const WtGIContent = () => { - const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; - const { t } = useTranslation("common", { keyPrefix: "Index" }); - - return ( - -

    - {t("wtgi_title")} -

    - - -

    {t("wtgi_paragraph_1")}

    -
    - -

    - - Join our open‑source community on{" "} - - GitHub - - -

    - - ), - li:
  • , - small: , - repo: ( - - ), - goals: ( - - ), - roadmap: ( - - ), - contribute: ( - - ), - }} - /> -

    - , - }} - /> -

    - - - - ); -}; - -export default WtGIContent; diff --git a/frontend/src/pages/dev/feature-flags.tsx b/frontend/src/pages/dev/feature-flags.tsx deleted file mode 100644 index a24af1eb5..000000000 --- a/frontend/src/pages/dev/feature-flags.tsx +++ /dev/null @@ -1,87 +0,0 @@ -import { NextPage } from "next"; -import { useFeatureFlags } from "src/hooks/useFeatureFlags"; - -import Head from "next/head"; -import React from "react"; -import { Button, Table } from "@trussworks/react-uswds"; - -/** - * Disable this page in production - */ -export function getStaticProps() { - if (process.env.NEXT_PUBLIC_ENVIRONMENT === "prod") { - return { - notFound: true, - }; - } - - return { - props: {}, - }; -} - -/** - * View for managing feature flags - */ -const FeatureFlags: NextPage = () => { - const { featureFlagsManager, mounted, setFeatureFlag } = useFeatureFlags(); - - if (!mounted) { - return null; - } - - return ( - <> - - Manage Feature Flags - -
    -

    Manage Feature Flags

    - - - - - - - - - - {Object.entries(featureFlagsManager.featureFlags).map( - ([featureName, enabled]) => ( - - - - - - ), - )} - -
    StatusFeature FlagActions
    - {enabled ? "Enabled" : "Disabled"} - {featureName} - - -
    -
    - - ); -}; - -export default FeatureFlags; diff --git a/frontend/src/pages/health.tsx b/frontend/src/pages/health.tsx deleted file mode 100644 index efc1978b1..000000000 --- a/frontend/src/pages/health.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; - -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; -import React from "react"; - -const Health: NextPage = () => { - return <>healthy; -}; - -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default Health; diff --git a/frontend/src/pages/index.tsx b/frontend/src/pages/index.tsx deleted file mode 100644 index a77846037..000000000 --- a/frontend/src/pages/index.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; - -import { useTranslation } from "next-i18next"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; - -import BetaAlert from "../components/BetaAlert"; -import PageSEO from "src/components/PageSEO"; -import Hero from "../components/Hero"; -import IndexGoalContent from "./content/IndexGoalContent"; -import ProcessAndResearchContent from "./content/ProcessAndResearchContent"; - -const Home: NextPage = () => { - const { t } = useTranslation("common"); - // TODO: Remove during move to app router and next-intl upgrade - const beta_strings = { - alert_title: t("Beta_alert.alert_title"), - alert: t("Beta_alert.alert"), - }; - - return ( - <> - - - - - - - ); -}; - -// Change this to GetServerSideProps if you're using server-side rendering -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default Home; diff --git a/frontend/src/pages/newsletter/confirmation.tsx b/frontend/src/pages/newsletter/confirmation.tsx deleted file mode 100644 index 3a9abc063..000000000 --- a/frontend/src/pages/newsletter/confirmation.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; -import { NEWSLETTER_CONFIRMATION_CRUMBS } from "src/constants/breadcrumbs"; - -import { Trans, useTranslation } from "next-i18next"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; -import Link from "next/link"; -import { Grid, GridContainer } from "@trussworks/react-uswds"; - -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "../../components/BetaAlert"; - -const NewsletterConfirmation: NextPage = () => { - const { t } = useTranslation("common"); - - // TODO: Remove during move to app router and next-intl upgrade - const beta_strings = { - alert_title: t("Beta_alert.alert_title"), - alert: t("Beta_alert.alert"), - }; - - return ( - <> - - - - - -

    - {t("Newsletter_confirmation.title")} -

    -

    - {t("Newsletter_confirmation.intro")} -

    - - -

    {t("paragraph_1")}

    -
    - -

    - {t("Newsletter_confirmation.heading")} -

    -

    - , - "research-link": , - }} - /> -

    -
    -
    -
    - -

    - {t("Newsletter.disclaimer")} -

    -
    - - ); -}; - -// Change this to GetServerSideProps if you're using server-side rendering -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default NewsletterConfirmation; diff --git a/frontend/src/pages/newsletter/index.tsx b/frontend/src/pages/newsletter/index.tsx deleted file mode 100644 index c49e03f8c..000000000 --- a/frontend/src/pages/newsletter/index.tsx +++ /dev/null @@ -1,276 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; -import { - NEWSLETTER_CONFIRMATION, - NEWSLETTER_CRUMBS, -} from "src/constants/breadcrumbs"; -import { ExternalRoutes } from "src/constants/routes"; - -import { Trans, useTranslation } from "next-i18next"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; -import { useRouter } from "next/router"; -import { useState } from "react"; -import { - Alert, - Button, - ErrorMessage, - FormGroup, - Grid, - GridContainer, - Label, - TextInput, -} from "@trussworks/react-uswds"; - -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "../../components/BetaAlert"; -import { Data } from "../api/subscribe"; - -const Newsletter: NextPage = () => { - const { t } = useTranslation("common"); - // TODO: Remove during move to app router and next-intl upgrade - const beta_strings = { - alert_title: t("Beta_alert.alert_title"), - alert: t("Beta_alert.alert"), - }; - const router = useRouter(); - const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; - - const [formSubmitted, setFormSubmitted] = useState(false); - - const [formData, setFormData] = useState({ - name: "", - LastName: "", - email: "", - hp: "", - }); - - const [sendyError, setSendyError] = useState(""); - const [erroredEmail, setErroredEmail] = useState(""); - - const validateField = (fieldName: string) => { - // returns the string "valid" or the i18n key for the error message - const emailRegex = - /^(\D)+(\w)*((\.(\w)+)?)+@(\D)+(\w)*((\.(\D)+(\w)*)+)?(\.)[a-z]{2,}$/g; - if (fieldName === "name" && formData.name === "") - return "Newsletter.errors.missing_name"; - if (fieldName === "email" && formData.email === "") - return "Newsletter.errors.missing_email"; - if (fieldName === "email" && !emailRegex.test(formData.email)) - return "Newsletter.errors.invalid_email"; - return "valid"; - }; - - const showError = (fieldName: string): boolean => - formSubmitted && validateField(fieldName) !== "valid"; - - const handleInput = (e: React.ChangeEvent) => { - const fieldName = e.target.name; - const fieldValue = e.target.value; - - setFormData((prevState) => ({ - ...prevState, - [fieldName]: fieldValue, - })); - }; - - const submitForm = async () => { - const formURL = "api/subscribe"; - if (validateField("email") !== "valid" || validateField("name") !== "valid") - return; - - const res = await fetch(formURL, { - method: "POST", - body: JSON.stringify(formData), - headers: { - Accept: "application/json", - }, - }); - - if (res.ok) { - const { message } = (await res.json()) as Data; - await router.push({ - pathname: NEWSLETTER_CONFIRMATION.path, - query: { sendy: message }, - }); - return setSendyError(""); - } else { - const { error }: Data = (await res.json()) as Data; - console.error("client error", error); - setErroredEmail(formData.email); - return setSendyError(error || ""); - } - }; - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - setFormSubmitted(true); - submitForm().catch((err) => { - console.error("catch block", err); - }); - }; - - return ( - <> - - - - - -

    - {t("Newsletter.title")} -

    -

    - {t("Newsletter.intro")} -

    - - -

    {t("Newsletter.paragraph_1")}

    - - ), - li:
  • , - }} - /> - - -
    - {sendyError ? ( - - - ), - }} - /> - - ) : ( - <> - )} - - - {showError("name") ? ( - - {t(validateField("name"))} - - ) : ( - <> - )} - - - - - - - {showError("email") ? ( - - {t(validateField("email"))} - - ) : ( - <> - )} - - -
    - - -
    - - -
    - - - -

    {t("disclaimer")}

    -
    - - ); -}; - -// Change this to GetServerSideProps if you're using server-side rendering -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default Newsletter; diff --git a/frontend/src/pages/newsletter/unsubscribe.tsx b/frontend/src/pages/newsletter/unsubscribe.tsx deleted file mode 100644 index 8c25eca76..000000000 --- a/frontend/src/pages/newsletter/unsubscribe.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; -import { NEWSLETTER_UNSUBSCRIBE_CRUMBS } from "src/constants/breadcrumbs"; - -import { Trans, useTranslation } from "next-i18next"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; -import Link from "next/link"; -import { Grid, GridContainer } from "@trussworks/react-uswds"; - -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "../../components/BetaAlert"; - -const NewsletterUnsubscribe: NextPage = () => { - const { t } = useTranslation("common"); - // TODO: Remove during move to app router and next-intl upgrade - const beta_strings = { - alert_title: t("Beta_alert.alert_title"), - alert: t("Beta_alert.alert"), - }; - - return ( - <> - - - - - -

    - {t("Newsletter_unsubscribe.title")} -

    -

    - {t("Newsletter_unsubscribe.intro")} -

    - - -

    - {t("Newsletter_unsubscribe.paragraph_1")} -

    - - {t("Newsletter_unsubscribe.button_resub")} - -
    - -

    - {t("Newsletter_unsubscribe.heading")} -

    -

    - , - "research-link": , - }} - /> -

    -
    -
    -
    - -

    - {t("Newsletter_unsubscribe.disclaimer")} -

    -
    - - ); -}; - -// Change this to GetServerSideProps if you're using server-side rendering -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default NewsletterUnsubscribe; diff --git a/frontend/src/pages/process.tsx b/frontend/src/pages/process.tsx deleted file mode 100644 index 6ebe98a6e..000000000 --- a/frontend/src/pages/process.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; -import { PROCESS_CRUMBS } from "src/constants/breadcrumbs"; - -import { useTranslation } from "next-i18next"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; - -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "../components/BetaAlert"; -import ProcessContent from "./content/ProcessIntro"; -import ProcessInvolved from "./content/ProcessInvolved"; -import ProcessMilestones from "./content/ProcessMilestones"; - -const Process: NextPage = () => { - const { t } = useTranslation("common"); - // TODO: Remove during move to app router and next-intl upgrade - const beta_strings = { - alert_title: t("Beta_alert.alert_title"), - alert: t("Beta_alert.alert"), - }; - - return ( - <> - - - - -
    - -
    - - - ); -}; - -// Change this to GetServerSideProps if you're using server-side rendering -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default Process; diff --git a/frontend/src/pages/research.tsx b/frontend/src/pages/research.tsx deleted file mode 100644 index 01d7c1de5..000000000 --- a/frontend/src/pages/research.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import type { GetStaticProps, NextPage } from "next"; -import { RESEARCH_CRUMBS } from "src/constants/breadcrumbs"; -import ResearchIntro from "src/pages/content/ResearchIntro"; - -import { useTranslation } from "next-i18next"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; - -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "../components/BetaAlert"; -import ResearchArchetypes from "./content/ResearchArchetypes"; -import ResearchImpact from "./content/ResearchImpact"; -import ResearchMethodology from "./content/ResearchMethodology"; -import ResearchThemes from "./content/ResearchThemes"; - -const Research: NextPage = () => { - const { t } = useTranslation("common"); - // TODO: Remove during move to app router and next-intl upgrade - const beta_strings = { - alert_title: t("Beta_alert.alert_title"), - alert: t("Beta_alert.alert"), - }; - - return ( - <> - - - - - -
    - - -
    - - - ); -}; - -// Change this to GetServerSideProps if you're using server-side rendering -export const getStaticProps: GetStaticProps = async ({ locale }) => { - const translations = await serverSideTranslations(locale ?? "en"); - return { props: { ...translations } }; -}; - -export default Research; diff --git a/frontend/stories/components/FundingContent.stories.tsx b/frontend/stories/components/FundingContent.stories.tsx index 95465c0c1..7b00f3ad8 100644 --- a/frontend/stories/components/FundingContent.stories.tsx +++ b/frontend/stories/components/FundingContent.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import FundingContent from "src/pages/content/FundingContent"; +import FundingContent from "src/components/content/FundingContent"; const meta: Meta = { title: "Components/Content/Funding Content", diff --git a/frontend/stories/components/GoalContent.stories.tsx b/frontend/stories/components/GoalContent.stories.tsx index 8d581a32b..0606184c5 100644 --- a/frontend/stories/components/GoalContent.stories.tsx +++ b/frontend/stories/components/GoalContent.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import GoalContent from "src/pages/content/IndexGoalContent"; +import GoalContent from "src/components/content/IndexGoalContent"; const meta: Meta = { title: "Components/Content/Goal Content", diff --git a/frontend/stories/components/ProcessContent.stories.tsx b/frontend/stories/components/ProcessContent.stories.tsx index 736eea64b..4557b76c5 100644 --- a/frontend/stories/components/ProcessContent.stories.tsx +++ b/frontend/stories/components/ProcessContent.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import ProcessContent from "src/pages/content/ProcessIntro"; +import ProcessContent from "src/app/[locale]/process/ProcessIntro"; const meta: Meta = { title: "Components/Content/Process Content", diff --git a/frontend/stories/components/ReaserchImpact.stories.tsx b/frontend/stories/components/ReaserchImpact.stories.tsx index 4d9fb9e4e..5ec6e523a 100644 --- a/frontend/stories/components/ReaserchImpact.stories.tsx +++ b/frontend/stories/components/ReaserchImpact.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import ResearchImpact from "src/pages/content/ResearchImpact"; +import ResearchImpact from "src/app/[locale]/research/ResearchImpact"; const meta: Meta = { title: "Components/Content/Research Impact Content", diff --git a/frontend/stories/components/ReaserchIntro.stories.tsx b/frontend/stories/components/ReaserchIntro.stories.tsx index 1feaa669c..4510f6708 100644 --- a/frontend/stories/components/ReaserchIntro.stories.tsx +++ b/frontend/stories/components/ReaserchIntro.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import ResearchIntro from "src/pages/content/ResearchIntro"; +import ResearchIntro from "src/app/[locale]/research/ResearchIntro"; const meta: Meta = { title: "Components/Content/Research Intro Content", diff --git a/frontend/stories/components/ReaserchThemes.stories.tsx b/frontend/stories/components/ReaserchThemes.stories.tsx index e6da8670d..1eb108e4a 100644 --- a/frontend/stories/components/ReaserchThemes.stories.tsx +++ b/frontend/stories/components/ReaserchThemes.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import ResearchThemes from "src/pages/content/ResearchThemes"; +import ResearchThemes from "src/app/[locale]/research/ResearchThemes"; const meta: Meta = { title: "Components/Content/Research Themes Content", diff --git a/frontend/stories/components/ResearchArchetypes.stories.tsx b/frontend/stories/components/ResearchArchetypes.stories.tsx index 8786dc61d..834ad6183 100644 --- a/frontend/stories/components/ResearchArchetypes.stories.tsx +++ b/frontend/stories/components/ResearchArchetypes.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import ResearchArchetypes from "src/pages/content/ResearchArchetypes"; +import ResearchArchetypes from "src/app/[locale]/research/ResearchArchetypes"; const meta: Meta = { title: "Components/Content/Research Archetypes Content", diff --git a/frontend/stories/components/ResearchMethodology.stories.tsx b/frontend/stories/components/ResearchMethodology.stories.tsx index 47f065d41..0a54bcdee 100644 --- a/frontend/stories/components/ResearchMethodology.stories.tsx +++ b/frontend/stories/components/ResearchMethodology.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import ResearchMethodology from "src/pages/content/ResearchMethodology"; +import ResearchMethodology from "src/app/[locale]/research/ResearchMethodology"; const meta: Meta = { title: "Components/Content/Research Methodology Content", diff --git a/frontend/stories/components/WtGIContent.stories.tsx b/frontend/stories/components/WtGIContent.stories.tsx deleted file mode 100644 index 1c76a0849..000000000 --- a/frontend/stories/components/WtGIContent.stories.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { Meta } from "@storybook/react"; -import WtGIContent from "src/pages/content/WtGIContent"; - -const meta: Meta = { - title: "Components/Content/Ways to Get Involved Content", - component: WtGIContent, -}; -export default meta; - -export const Default = { - parameters: { - design: { - type: "figma", - url: "https://www.figma.com/file/lpKPdyTyLJB5JArxhGjJnE/beta.grants.gov?type=design&node-id=14-1125&mode=design&t=nSr4QJesyQb2OH30-4", - }, - }, -}; diff --git a/frontend/stories/pages/404.stories.tsx b/frontend/stories/pages/404.stories.tsx index b3f1fc877..ee03b30f5 100644 --- a/frontend/stories/pages/404.stories.tsx +++ b/frontend/stories/pages/404.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import PageNotFound from "src/pages/404"; +import PageNotFound from "src/app/not-found"; const meta: Meta = { title: "Pages/404", diff --git a/frontend/stories/pages/Index.stories.tsx b/frontend/stories/pages/Index.stories.tsx index 669c8741e..4afb9c965 100644 --- a/frontend/stories/pages/Index.stories.tsx +++ b/frontend/stories/pages/Index.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import Index from "src/pages/index"; +import Index from "src/app/[locale]/page"; const meta: Meta = { title: "Pages/Home", diff --git a/frontend/stories/pages/process.stories.tsx b/frontend/stories/pages/process.stories.tsx index 114658618..f3776d62e 100644 --- a/frontend/stories/pages/process.stories.tsx +++ b/frontend/stories/pages/process.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import Process from "src/pages/process"; +import Process from "src/app/[locale]/process/page"; const meta: Meta = { title: "Pages/Process", diff --git a/frontend/stories/pages/research.stories.tsx b/frontend/stories/pages/research.stories.tsx index 0d511e6cb..00801f8d5 100644 --- a/frontend/stories/pages/research.stories.tsx +++ b/frontend/stories/pages/research.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import Research from "src/pages/research"; +import Research from "src/app/[locale]/research/page"; const meta: Meta = { title: "Pages/Research", diff --git a/frontend/stories/pages/search.stories.tsx b/frontend/stories/pages/search.stories.tsx index e278ce84e..533c6f483 100644 --- a/frontend/stories/pages/search.stories.tsx +++ b/frontend/stories/pages/search.stories.tsx @@ -1,5 +1,5 @@ import { Meta } from "@storybook/react"; -import Search from "../../src/app/search/page"; +import Search from "../../src/app/[locale]/search/page"; const meta: Meta = { title: "Pages/Search", diff --git a/frontend/tests/components/AppLayout.test.tsx b/frontend/tests/components/AppLayout.test.tsx deleted file mode 100644 index 76ee1a76b..000000000 --- a/frontend/tests/components/AppLayout.test.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { render, screen } from "tests/react-utils"; -import { axe } from "jest-axe"; - -import AppLayout from "src/components/AppLayout"; - -describe("AppLayout", () => { - it("renders children in main section", () => { - render( - -

    child

    -
    , - ); - - const header = screen.getByRole("heading", { name: /child/i, level: 1 }); - - expect(header).toBeInTheDocument(); - }); - - it("passes accessibility scan", async () => { - const { container } = render( - -

    child

    -
    , - ); - const results = await axe(container); - - expect(results).toHaveNoViolations(); - }); -}); diff --git a/frontend/tests/components/BetaAlert.test.tsx b/frontend/tests/components/BetaAlert.test.tsx index 6f2f4635b..7227456f4 100644 --- a/frontend/tests/components/BetaAlert.test.tsx +++ b/frontend/tests/components/BetaAlert.test.tsx @@ -1,17 +1,10 @@ -import { render, screen } from "@testing-library/react"; +import { render, screen } from "tests/react-utils"; import BetaAlert from "src/components/BetaAlert"; -const beta_strings = { - alert_title: - "Attention! Go to www.grants.gov to search and apply for grants.", - alert: - "Simpler.Grants.gov is a work in progress. Thank you for your patience as we build this new website.", -}; - describe("BetaAlert", () => { it("Renders without errors", () => { - render(); + render(); const hero = screen.getByTestId("beta-alert"); expect(hero).toBeInTheDocument(); }); diff --git a/frontend/tests/components/Footer.test.tsx b/frontend/tests/components/Footer.test.tsx index fd2162133..d0c9d4885 100644 --- a/frontend/tests/components/Footer.test.tsx +++ b/frontend/tests/components/Footer.test.tsx @@ -1,31 +1,17 @@ -import { render, screen } from "@testing-library/react"; +import { render, screen } from "tests/react-utils"; import { ExternalRoutes } from "src/constants/routes"; import Footer from "src/components/Footer"; -const footer_strings = { - agency_name: "Grants.gov", - agency_contact_center: "Grants.gov Program Management Office", - telephone: "1-877-696-6775", - return_to_top: "Return to top", - link_twitter: "Twitter", - link_youtube: "YouTube", - link_github: "Github", - link_rss: "RSS", - link_newsletter: "Newsletter", - link_blog: "Blog", - logo_alt: "Grants.gov logo", -}; - describe("Footer", () => { it("Renders without errors", () => { - render(