Skip to content

Commit

Permalink
[WIP] Alert for VVA and VBMS document list retrievals (#8276)
Browse files Browse the repository at this point in the history
Resolves #6049

### Description
Added error in the document list for when the was never a response from VBMS or VVA. Added a similar warning for when the last response was older than the eFolder cache limit. Reimplemented retrieval timestamps.
  • Loading branch information
hschallhorn authored and va-bot committed Dec 21, 2018
1 parent aeba22a commit b4aa4f6
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/services/document_fetcher.rb
Expand Up @@ -42,7 +42,7 @@ def manifest_vva_fetched_at=(fetched_at)
end

def fetched_at_format
"%D %l:%M%P %Z"
"%D %l:%M%P %Z %z"
end

def save!
Expand Down
56 changes: 56 additions & 0 deletions client/app/reader/LastRetrievalAlert.jsx
@@ -0,0 +1,56 @@
import _ from 'lodash';
import moment from 'moment';
import React from 'react';
import { connect } from 'react-redux';
import Alert from '../components/Alert';
import { css } from 'glamor';

const CACHE_TIMEOUT_HOURS = 3;

const alertStyling = css({
marginBottom: '20px'
});

class LastRetrievalAlert extends React.PureComponent {

render() {

// Check that document manifests have been recieved from VVA and VBMS
if (!this.props.manifestVbmsFetchedAt || !this.props.manifestVvaFetchedAt) {
return <div {...alertStyling}>
<Alert title="Error" type="error">
Some of {this.props.appeal.veteran_full_name}'s documents are not available at the moment due to
a loading error from VBMS or VVA. As a result, you may be viewing a partial list of claims folder documents.
<br />
<br />
Please refresh your browser at a later point to view a complete list of documents in the claims
folder.
</Alert>
</div>;
}

const staleCacheTime = moment().subtract(CACHE_TIMEOUT_HOURS, 'h'),
vbmsManifestTimestamp = moment(this.props.manifestVbmsFetchedAt, 'MM/DD/YY HH:mma Z'),
vvaManifestTimestamp = moment(this.props.manifestVvaFetchedAt, 'MM/DD/YY HH:mma Z');

// Check that manifest results are fresh
if (vbmsManifestTimestamp.isBefore(staleCacheTime) || vvaManifestTimestamp.isBefore(staleCacheTime)) {
const now = moment(),
vbmsDiff = now.diff(vbmsManifestTimestamp, 'hours'),
vvaDiff = now.diff(vvaManifestTimestamp, 'hours');

return <div {...alertStyling}>
<Alert title="Warning" type="warning">
We last synced with VBMS and VVA {Math.max(vbmsDiff, vvaDiff)} hours ago. If you'd like to check for new
documents, refresh the page.
</Alert>
</div>;
}

return null;
}
}

export default connect(
(state) => _.pick(state.documentList, ['manifestVvaFetchedAt', 'manifestVbmsFetchedAt'])
)(LastRetrievalAlert);
20 changes: 13 additions & 7 deletions client/app/reader/LastRetrievalInfo.jsx
Expand Up @@ -4,15 +4,21 @@ import { connect } from 'react-redux';

class UnconnectedLastRetrievalInfo extends React.PureComponent {
render() {
if (!this.props.manifestVbmsFetchedAt) {
return null;
}

return [
<div id="vbms-manifest-retrieved-at" key="vbms">Last VBMS retrieval: {this.props.manifestVbmsFetchedAt}</div>,
this.props.manifestVbmsFetchedAt ?
<div id="vbms-manifest-retrieved-at" key="vbms">
Last VBMS retrieval: {this.props.manifestVbmsFetchedAt.slice(0, -5)}
</div> :
<div className="cf-red-text" key="vbms">
Unable to display VBMS documents at this time
</div>,
this.props.manifestVvaFetchedAt ?
<div id="vva-manifest-retrieved-at" key="vva">Last VVA retrieval: {this.props.manifestVvaFetchedAt}</div> :
<div className="cf-red-text" key="vva">Unable to display VVA documents at this time</div>
<div id="vva-manifest-retrieved-at" key="vva">
Last VVA retrieval: {this.props.manifestVvaFetchedAt.slice(0, -5)}
</div> :
<div className="cf-red-text" key="vva">
Unable to display VVA documents at this time
</div>
];
}
}
Expand Down
9 changes: 6 additions & 3 deletions client/app/reader/PdfListView.jsx
Expand Up @@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import _ from 'lodash';

import BackToQueueLink from './BackToQueueLink';
import LastRetrievalAlert from './LastRetrievalAlert';
import LastRetrievalInfo from './LastRetrievalInfo';
import AppSegment from '@department-of-veterans-affairs/caseflow-frontend-toolkit/components/AppSegment';
import DocumentListHeader from './DocumentListHeader';
Expand Down Expand Up @@ -59,14 +60,15 @@ export class PdfListView extends React.Component {
}

return <div>
{ this.props.queueRedirectUrl && <BackToQueueLink
{this.props.queueRedirectUrl && <BackToQueueLink
queueRedirectUrl={this.props.queueRedirectUrl}
queueTaskType={this.props.queueTaskType}
veteranFullName={this.props.appeal.veteran_full_name}
vbmsId={this.props.appeal.vbms_id} /> }
vbmsId={this.props.appeal.vbms_id} />}
<AppSegment filledBackground>
<div className="section--document-list">
<ClaimsFolderDetails appeal={this.props.appeal} documents={this.props.documents} />
<LastRetrievalAlert appeal={this.props.appeal} />
<DocumentListHeader
documents={this.props.documents}
noDocuments={noDocuments}
Expand All @@ -80,7 +82,8 @@ export class PdfListView extends React.Component {
}

const mapStateToProps = (state, props) => {
return { documents: getFilteredDocuments(state),
return {
documents: getFilteredDocuments(state),
..._.pick(state.documentList, 'docFilterCriteria', 'viewingDocumentsOrComments'),
appeal: _.find(state.caseSelect.assignments, { vacols_id: props.match.params.vacolsId }) ||
state.pdfViewer.loadedAppeal,
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/vbms.rb
@@ -1 +1,6 @@
VBMSService = (!ApplicationController.dependencies_faked? ? ExternalApi::VBMSService : Fakes::VBMSService)

if ApplicationController.dependencies_faked?
VBMSService.manifest_vbms_fetched_at = Time.zone.now
VBMSService.manifest_vva_fetched_at = Time.zone.now
end
26 changes: 24 additions & 2 deletions spec/feature/reader/reader_spec.rb
Expand Up @@ -235,19 +235,41 @@ def add_comment(text)
end

context "When both document source manifest retrieval times are set" do
scenario "Both times display on the page" do
scenario "Both times display on the page and there are no document alerts" do
visit "/reader/appeal/#{appeal.vacols_id}/documents"
expect(find("#vbms-manifest-retrieved-at").text).to have_content(vbms_ts_string)
expect(find("#vva-manifest-retrieved-at").text).to have_content(vva_ts_string)
expect(page).to_not have_css(".section--document-list .usa-alert")
end
end

context "When VVA manifest retrieval time is older, but within the eFolder cache limit" do
let(:vva_fetched_ts) { Time.zone.now - 2.hours }
scenario "Both times display on the page and there are no document alerts" do
visit "/reader/appeal/#{appeal.vacols_id}/documents"
expect(find("#vbms-manifest-retrieved-at").text).to have_content(vbms_ts_string)
expect(find("#vva-manifest-retrieved-at").text).to have_content(vva_ts_string)
expect(page).to_not have_css(".section--document-list .usa-alert")
end
end

context "When VVA manifest retrieval time is olde and outside of the eFolder cache limit" do
let(:vva_fetched_ts) { Time.zone.now - 4.hours }
scenario "Both times display on the page and a warning alert is shown" do
visit "/reader/appeal/#{appeal.vacols_id}/documents"
expect(find("#vbms-manifest-retrieved-at").text).to have_content(vbms_ts_string)
expect(find("#vva-manifest-retrieved-at").text).to have_content(vva_ts_string)
expect(find(".section--document-list .usa-alert-warning").text).to have_content("4 hours ago")
end
end

context "When VVA manifest retrieval time is nil" do
let(:vva_fetched_ts) { nil }
scenario "Only VBMS time displays on the page" do
scenario "Only VBMS time displays on the page and error alert is shown" do
visit "/reader/appeal/#{appeal.vacols_id}/documents"
expect(find("#vbms-manifest-retrieved-at").text).to have_content(vbms_ts_string)
expect(page).to_not have_css("#vva-manifest-retrieved-at")
expect(page).to have_css(".section--document-list .usa-alert-error")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/services/document_fetcher_spec.rb
Expand Up @@ -13,7 +13,7 @@
let(:service_manifest_vbms_fetched_at) { Time.zone.local(1989, "nov", 23, 8, 2, 55) }
let(:service_manifest_vva_fetched_at) { Time.zone.local(1989, "dec", 13, 20, 15, 1) }

let(:fetched_at_format) { "%D %l:%M%P %Z" }
let(:fetched_at_format) { "%D %l:%M%P %Z %z" }
let!(:efolder_fetched_at_format) { "%FT%T.%LZ" }
let(:doc_struct) do
{
Expand Down
5 changes: 3 additions & 2 deletions spec/services/external_api/efolder_service_spec.rb
Expand Up @@ -36,8 +36,9 @@
let(:user) { Generators::User.create }
let(:appeal) { Generators::LegacyAppeal.build }
let(:vbms_id) { appeal.sanitized_vbms_id.to_s }
let(:manifest_vbms_fetched_at) { Time.zone.now.strftime("%D %l:%M%P %Z") }
let(:manifest_vva_fetched_at) { Time.zone.now.strftime("%D %l:%M%P %Z") }
let(:fetched_at_format) { "%D %l:%M%P %Z %z" }
let(:manifest_vbms_fetched_at) { Time.zone.now.strftime(fetched_at_format) }
let(:manifest_vva_fetched_at) { Time.zone.now.strftime(fetched_at_format) }
let(:expected_response) { construct_response(records, sources) }

subject { ExternalApi::EfolderService.generate_efolder_request(vbms_id, user) }
Expand Down

0 comments on commit b4aa4f6

Please sign in to comment.