Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

VACMS-10851 Find Forms code cleanup #34628

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

Conversation

randimays
Copy link
Contributor

@randimays randimays commented Feb 11, 2025

Are you removing, renaming or moving a folder in this PR?

  • No, I'm not changing any folders (skip to TeamSites and delete the rest of this section)
  • Yes, I'm removing, renaming or moving a folder

⚠️ TeamSites ⚠️

Did you change site-wide styles, platform utilities or other infrastructure?

Summary

Our Find Forms application is two-sided. We have the search results page that is essentially a full-page takeover, but still technically a React widget. Then we have the form detail pages that are almost 100% Drupal, the one exception being the "Download VA Form XXX" link on those pages.

The "Download VA Form XXX" link on both a search result and a form detail page functionally do the same thing. When clicked, they show a modal that warns the user to use Adobe Acrobat to view the PDF, and the modal has a link to download the form. Until now, the difference in the technical implementation is largely that the form detail pages ping the form URL with an HTTP HEAD call to ensure its validity (as URLs can be entered incorrectly in the DB, or forms moved, etc.). For some reason, the form search results download links did not do this check. We don't have the paper trail to explain why this gap existed, but because the data for both pages is from the same source (forms DB), the margin for human error is the same. We should check for URL validity on both pages.

This PR consolidates the code for both types of download links (form search results and form detail pages) to align them to the same functionality:

  1. When clicked, make a HTTP HEAD request to validate the form URL (this only happens when the domain of the browser is the same as the domain of the form URL, e.g. prod form URL and prod VA.gov - locally you won't see this check unless you force it via code)
  2. If the HTTP request comes back ok:
  • open a modal
  • the modal should show a link to download Adobe Acrobat and a link to download the form
  1. If the HTTP request does not come back ok: show the banner to tell the user to email the forms managers for a copy of the form

In addition to code changes in support of getting both sides of the Find Forms app to use mostly the same code, I did a lot of renaming and culling old code that wasn't being used anymore.

Related issue(s)

department-of-veterans-affairs/va.gov-cms#10851

Testing done & screenshots

1. Searching for forms and clicking download with a failed HTTP request

Note: in order to reproduce this scenario, you will need to change src/applications/static-pages/find-forms/api/index.js -> line 21:

if (formPdfIsValid && isSameOrigin) {

to:

if (formPdfIsValid && true) {

This will produce a CORS error trying to make the network call and then you will be able to see the error banner.

  1. Go to /find-forms
  2. Enter search term (I used 1010)
  3. Turn on your Adswerve (Chrome plugin) to track analytics calls
  4. Kick off the search with your dev console open
  5. Validate that you see the view_search_results analytics event with the correct data:

Note that it is expected that the counts differ across environments because the forms data is not consistent across envs.

Screenshot 2025-02-12 at 11 41 05 AM
  1. Validate that the download button under each search result has the correct text: Download VA Form {form number} (PDF) e.g. for the result for Form 10-1086, the button should say Download VA Form 10-1086 (PDF).
  2. Click download button for a search result (I used 10-1086)
  3. Validate the error banner appears to replace the download button:
Screenshot 2025-02-12 at 11 28 13 AM
  1. Inspect the email the forms managers URL to validate that the form URL is correct:
Screenshot 2025-02-12 at 11 28 59 AM
  1. Click download button for a different search result (I used 10-10M)
  2. Validate the same error banner appears to replace the download button
  3. Inspect the email the forms managers URL to validate the correct URL for this banner
  4. Click one of the pagination numbers at the bottom of the page
  5. Verify that you get the appropriate set of results: e.g. if you clicked page 2, you should get the next 10 search results
  6. Click download button for a search result that does not have its own detail page (the title is not a link; my example is from page 2):
Screenshot 2025-02-12 at 11 32 55 AM
2. Looking at a form detail page and clicking download with a failed HTTP request

Note: in order to reproduce this scenario, you will need to change src/applications/static-pages/find-forms/api/index.js -> line 21:

if (formPdfIsValid && isSameOrigin) {

to:

if (formPdfIsValid && true) {

This will produce a CORS error trying to make the network call and then you will be able to see the error banner.

  1. Go to a form detail page (e.g. /find-forms/about-form-10-1086/)
  2. Validate that the download button has the correct text: Download VA Form {form number} (PDF) e.g. for form 10-1086, the button should say Download VA Form 10-1086 (PDF)
  3. Click the download button
  4. Validate the error banner appears to replace the download button:
Screenshot 2025-02-12 at 12 02 36 PM
  1. Inspect the email the forms managers URL to validate that the form URL is correct:
Screenshot 2025-02-12 at 12 03 13 PM
3. Searching for forms and clicking download with a successful HTTP request (modal appears)
  1. Go to /find-forms
  2. Enter search term (I used 1010)
  3. Search
  4. Validate that the download button under each search result has the correct text: Download VA Form {form number} (PDF) e.g. for the result for Form 10-1086, the button should say Download VA Form 10-1086 (PDF).
  5. Click download button for a search result (I used 10-1086)
  6. The modal should appear with two links: one to get Acrobat Reader, and the other should be the download link with the correct text: Download VA Form {form number} (PDF)
  7. When the modal opens, the close button should be focused
  8. Clicking the download link should lead you to the correct production version of the form. For form 10-1086, this would be https://www.va.gov/vaforms/medical/pdf/vha-10-1086.pdf. It should open in the same tab.
  9. When the modal is closed, the page should re-focus the download button that was originally clicked.
4. Looking at a form detail page and clicking download with a successful HTTP request (modal appears)
  1. Go to a form detail page (e.g. /find-forms/about-form-10-1086/)
  2. Validate that the download button has the correct text: Download VA Form {form number} (PDF) e.g. for form 10-1086, the button should say Download VA Form 10-1086 (PDF)
  3. Click the download button
  4. The modal should appear with two links: one to get Acrobat Reader, and the other should be the download link with the correct text: Download VA Form {form number} (PDF)
  5. When the modal opens, the close button should be focused
  6. Clicking the download link should lead you to the correct production version of the form. For form 10-1086, this would be https://www.va.gov/vaforms/medical/pdf/vha-10-1086.pdf. It should open in the same tab.
  7. When the modal is closed, the page should re-focus the download button that was originally clicked.

@va-vfs-bot va-vfs-bot temporarily deployed to master/10851-find-form-code-cleanup/main February 11, 2025 22:11 Inactive
@@ -1,36 +1,35 @@
import PropTypes from 'prop-types';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetized / organized to mirror the structure of the Facility Locator types.

@@ -1,73 +0,0 @@
import cloneDeep from 'lodash/cloneDeep';
Copy link
Contributor Author

@randimays randimays Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a separate file for this code with an index file to import it seemed unnecessary, so I moved this into the index file.

@@ -1,11 +0,0 @@
import * as Sentry from '@sentry/browser';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this out of the download-widget folder and into the main app's helpers folder

@@ -0,0 +1,37 @@
import * as Sentry from '@sentry/browser';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This content was moved in here because now the form detail page and the form search results are both going to check validity of the form URL/PDF before rendering the download modal. If the form is invalid on either page, we need to do Sentry logging.

@@ -1,103 +0,0 @@
import React from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download-widget code was simplified down to a single file.

@@ -1,53 +0,0 @@
import React, { useEffect, useState } from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download-widget code was simplified down to a single file, and now the download widget (on the detail page) shares its PDF code with the search results page.

export const updatePaginationAction = (page = 1, startIndex = 0) => ({
page,
startIndex,
type: UPDATE_PAGINATION,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some of this code directly into SearchForm and then directly connected that component to the fetchFormsApi call to (mostly) mirror the way the download widget is calling it.

@va-vfs-bot va-vfs-bot temporarily deployed to master/10851-find-form-code-cleanup/main February 12, 2025 16:07 Inactive
@randimays randimays changed the title 10851 find form code cleanup VACMS-10851 Find Forms code cleanup Feb 12, 2025
@va-vfs-bot va-vfs-bot temporarily deployed to master/10851-find-form-code-cleanup/main February 12, 2025 17:40 Inactive
const mockRequest = options?.mockRequest || false;
// Form URLs can be entered incorrectly, or the forms themselves can be deleted
// by forms managers. This guards against sending users to 404 pages
export const checkFormValidity = async (form, page) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function represents what is now shared functionality between the search results page and the form detail pages. We need to double check that the form URL coming from the forms DB is a valid URL. If it isn't, we show an error banner with messaging on how to contact the forms managers (instead of the download button that shows the modal).

@@ -44,7 +47,7 @@ const deriveLanguageTranslation = (lang = 'en', whichNode, formName) => {
},
en: {
goToOnlineTool: `Fill out VA Form ${formName} online`,
downloadVaForm: `Download VA Form ${formName}`,
downloadVaForm: `Download VA Form ${formName} (PDF)`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added (PDF) here to make this consistent with the form detail page (Slack thread).

@va-vfs-bot va-vfs-bot temporarily deployed to master/10851-find-form-code-cleanup/main February 13, 2025 21:19 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants