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

msteele/APPEALS-24727 #19187

Merged
merged 26 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
821d572
APPEALS-24727 Add helper methods and pseudocode
msteele96 Aug 14, 2023
c17c473
APPEALS-24727 Fixed import statement
msteele96 Aug 14, 2023
8366a26
APPEALS-24727 Pass external id into efolderurl field for api call
msteele96 Aug 15, 2023
b1764f8
APPEALS-24727 Refactor debounce
msteele96 Aug 15, 2023
9e1b0a5
APPEALS-24727 Debounce working after useEffect
msteele96 Aug 15, 2023
e7fe1f0
APPEALS-24727 Removed useCallback
msteele96 Aug 15, 2023
081ac75
APPEALS-24727 Added loading styling and prop
msteele96 Aug 15, 2023
6cd7d5f
APPEALS-24727 Valid prop is passed between field and modal properly
msteele96 Aug 17, 2023
db73a28
APPEALS-24727 Moved loading to state value
msteele96 Aug 17, 2023
b039f78
APPEALS-24727 Added error messages and retry button
msteele96 Aug 17, 2023
0efb78d
APPEALS-24727 Removed code used for testing
msteele96 Aug 17, 2023
1d881f0
APPEALS-24727 Update style to fix CC issue
msteele96 Aug 22, 2023
e96754a
APPEALS-24727 Update Jest test
msteele96 Aug 22, 2023
c061300
APPEALS-24727 Linting fix
msteele96 Aug 22, 2023
cceef2a
Merge branch 'master' into msteele/APPEALS-24727
msteele96 Aug 22, 2023
0fb676d
Merge branch 'master' into msteele/APPEALS-24727
msteele96 Aug 22, 2023
a130646
APPEALS-24727 Update validateForm to make sure efolderurl is valid no…
msteele96 Aug 22, 2023
610241e
APPEALS-24727 Update wording of label and corresponding tests
msteele96 Aug 22, 2023
f5aaee5
APPEALS-24727 linting fix
msteele96 Aug 22, 2023
7878988
Merge branch 'feature/APPEALS-21339' into msteele/APPEALS-24727
msteele96 Aug 23, 2023
005a886
APPEALS-24727 refactor to fix bug, last jest test failing
msteele96 Aug 24, 2023
e4c65ec
APPEALS-24727 Fix jest test and remove console log
msteele96 Aug 25, 2023
529d557
APPEALS-24727 Fixed flickering
msteele96 Aug 25, 2023
4411683
APPEALS-24727 Added ignore line for linter
msteele96 Aug 25, 2023
1e03765
Merge branch 'feature/APPEALS-21339' into msteele/APPEALS-24727
msteele96 Aug 25, 2023
4595025
APPEALS-24727 Removed unnecessary props and comments. Refactored retr…
msteele96 Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/COPY.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@
"CREATE_MAIL_TASK_TITLE": "Create new mail task",
"MAIL_TASK_DROPDOWN_TYPE_SELECTOR_LABEL": "Select correspondence type",
"MAIL_TASK_CREATION_SUCCESS_MESSAGE": "Created %s task",
"EFOLDER_DOCUMENT_NOT_FOUND": "This document could not be found in eFolder.",
"EFOLDER_INVALID_LINK_FORMAT": "This link format is invalid.",
"EFOLDER_CONNECTION_ERROR": "Error contacting VBMS, please click 'Retry'",
"SELF_ASSIGNED_MAIL_TASK_CREATION_SUCCESS_TITLE": "You have successfully created a new %s mail task",
"SELF_ASSIGNED_MAIL_TASK_CREATION_SUCCESS_MESSAGE": "This task will remain in your Queue. Assign or take action on this at any time through your actions dropdown.",
"CASE_TIMELINE_HEADER": "Below is the history of this case.",
Expand Down
54 changes: 33 additions & 21 deletions client/app/components/TextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const TextField = (props) => {
inputStyling,
inputProps,
inputRef,
loading
} = props;

const textInputClass = className.
Expand Down Expand Up @@ -78,27 +79,37 @@ export const TextField = (props) => {
{props.fixedInput ? (
<p>{value}</p>
) : (
<input
ref={inputRef}
className={className}
name={name}
id={name}
onChange={handleChange}
onKeyPress={onKeyPress}
onBlur={handleBlur}
type={type}
defaultValue={defaultValue}
value={adjustedVal}
readOnly={readOnly}
placeholder={placeholder}
title={title}
maxLength={maxLength}
max={max}
autoComplete={autoComplete}
{...inputProps}
{...ariaLabelObj}
{...inputStyling}
/>
<div className="input-container">
<input
ref={inputRef}
className={className}
name={name}
id={name}
onChange={handleChange}
onKeyPress={onKeyPress}
onBlur={handleBlur}
type={type}
defaultValue={defaultValue}
value={adjustedVal}
readOnly={readOnly}
placeholder={placeholder}
title={title}
maxLength={maxLength}
max={max}
autoComplete={autoComplete}
{...inputProps}
{...ariaLabelObj}
{...inputStyling}
/>

{ loading &&
<span className="cf-loading-icon-container">
<span className="cf-loading-icon-front">
<span className="cf-loading-icon-back" />
</span>
</span>
}
</div>
)}

{validationError && (
Expand Down Expand Up @@ -181,6 +192,7 @@ TextField.propTypes = {
optional: PropTypes.bool.isRequired,
type: PropTypes.string,
validationError: PropTypes.string,
loading: PropTypes.bool,

/**
* The value of the `input` element; required for a controlled component
Expand Down
9 changes: 5 additions & 4 deletions client/app/queue/CreateMailTaskDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ export class CreateMailTaskDialog extends React.Component {
this.state = {
selectedValue: null,
instructions: '',
eFolderUrl: ''
eFolderUrl: '',
eFolderUrlValid: false
};
}

validateForm = () => {
const instructionsAndValue = () => this.state.selectedValue !== null && this.state.instructions !== '';

if (this.isHearingRequestMailTask()) {
return instructionsAndValue() && this.state.eFolderUrl !== '';
return instructionsAndValue() && this.state.eFolderUrlValid === true;
}

return instructionsAndValue();
Expand Down Expand Up @@ -132,9 +133,9 @@ export class CreateMailTaskDialog extends React.Component {
{
this.isHearingRequestMailTask() &&
<EfolderUrlField
appealId={this.props.appealId}
requestType={this.state.selectedValue}
onChange={(value) => this.setState({ eFolderUrl: value })}
value={this.state.eFolderUrl}
onChange={(value, valid) => this.setState({ eFolderUrl: value, eFolderUrlValid: valid })}
/>
}
<TextareaField
Expand Down
110 changes: 98 additions & 12 deletions client/app/queue/components/EfolderUrlField.jsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,123 @@
import React, {
useCallback,
useState,
useTransition
} from 'react';
import React, { useEffect, useState, useRef } from 'react';
import PropTypes from 'prop-types';
import { debounce } from 'lodash';

import COPY from '../../../COPY';
import Button from '../../components/Button';
import TextField from '../../components/TextField';
import ApiUtil from '../../util/ApiUtil';

const EfolderUrlField = (props) => {

const [url, setUrl] = useState('');
const [valid, setValid] = useState(false);
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const valueRef = useRef(url);

const extractRequestType = () => (
props.requestType.replace('Hearing', '').replace('RequestMailTask', '').
toLowerCase()
);

const handleChange = (value) => {
props?.onChange?.(value);
const efolderLinkRegexMatch = (inputValue) => {
return inputValue.match(/https:\/\/vefs-claimevidence.*\.bip\.va\.gov\/file\/\S{8}-\S{4}-\S{4}-\S{4}-\S{12}/)?.[0] === inputValue.split('?')[0]; // eslint-disable-line
};

const captureDocumentSeriesId = (validUrl) => {
return validUrl.match(/\S{8}-\S{4}-\S{4}-\S{4}-\S{12}/)?.[0];
};

const checkIfDocumentExists = async () => {
setLoading(true);
const seriesId = captureDocumentSeriesId(url);
Comment on lines +31 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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

Whenever the "Retry" button is pressed, will this function's invocation allow for the parent component's state to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just updated the onclick of the retry button with the rest of the functionality from the debounce

const appealId = props.appealId;

let apiValidity = false;

await ApiUtil.get(`/appeals/${appealId}/document/${seriesId}`).
then((response) => {
if (response.body.document_presence === true) {
apiValidity = true;
setError('');
} else {
apiValidity = false;
setValid(false);
setError(COPY.EFOLDER_DOCUMENT_NOT_FOUND);
}
}).
catch(() => {
apiValidity = false;
setError(COPY.EFOLDER_CONNECTION_ERROR);
}).
finally(() => {
setLoading(false);
});

return apiValidity;
};

const handleDebounce = debounce(async (value) => {
if (valueRef.current === value) {
props?.onChange?.(url, valid);

return;
}

let newValidity;

if (efolderLinkRegexMatch(value)) {
newValidity = await checkIfDocumentExists();
} else {
newValidity = false;
setError(COPY.EFOLDER_INVALID_LINK_FORMAT);
}
valueRef.current = value;
props?.onChange?.(url, newValidity);
setValid(newValidity);
}, 500);

const retryOnClick = async () => {
const retryValidity = await checkIfDocumentExists();

setValid(retryValidity);
props?.onChange?.(url, retryValidity);
};

useEffect(() => {
props?.onChange?.(url, false);
handleDebounce(url);

return () => {
handleDebounce.cancel();
};
}, [url, valid]);

return <>
<TextField
label={`Include Caseflow Reader document hyperlink to request a hearing ${extractRequestType()}`}
label={`Include eFolder document hyperlink to request a hearing ${extractRequestType()}`}
name="eFolderUrlField"
value={props.value}
onChange={handleChange}
errorMessage={props.errorMessage}
value={url}
onChange={(newUrl) => setUrl(newUrl)}
errorMessage={error}
loading={loading}
/>

{
error === COPY.EFOLDER_CONNECTION_ERROR &&
<Button
onClick={retryOnClick}
linkStyling
classNames={['cf-push-right', 'cf-retry']}>
Retry
</Button>
}
</>;
};

EfolderUrlField.propTypes = {
appealId: PropTypes.string.isRequired,
requestType: PropTypes.string,
value: PropTypes.string,
errorMessage: PropTypes.string
};

Expand Down
44 changes: 44 additions & 0 deletions client/app/styles/_commons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ svg title {
table {
margin: 0 0 2em;
}

.cf-retry {
margin-top: -1.5em;
}
}

.cf-modal-close {
Expand Down Expand Up @@ -1254,6 +1258,46 @@ button {
}
}

.input-container {
display: inline-block;
position: relative;
width: 100%;

.cf-loading-icon-container {
position: absolute;
padding-right: 23px;
top: 30%;
left: 90%;

.cf-loading-icon-back,
.cf-loading-icon-front {
&::after {
content: ' ';
// container for preloaded images was 0x0, but now...
// scss-lint:disable ImportantRule
width: 20px !important;
height: 20px !important;
// scss-lint:enable ImportantRule
box-sizing: border-box;
font-size: 99em;
position: absolute;
right: 0;
top: -0.1rem;
@include animation(spin 5s linear infinite);
background: url(#{$image-url}/icons/loading-pill.svg) center center no-repeat;
}
}

.cf-loading-icon-front {
&::after {
@include animation(backwardspin 5s linear infinite);
background: url(#{$image-url}/icons/loading-pill.svg) center center no-repeat;
opacity: 0.5;
}
}
}
}

.usa-accordion-button {
background-image: url(#{$image-path}/minus.svg);

Expand Down
Loading
Loading