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

TYLERB/preserve-completed-date-filter #23605

Open
wants to merge 6 commits into
base: feature/APPEALS-53424
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 39 additions & 17 deletions client/app/nonComp/components/NonCompTabs.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useMemo, useState } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';

Expand All @@ -14,16 +14,7 @@ import moment from 'moment';

const NonCompTabsUnconnected = (props) => {
const [localFilter, setFilter] = useLocalFilterStorage('nonCompFilter', []);

// A callback function to send down to QueueTable to add filters to local storage when the get parameters are updated
const onHistoryUpdate = (urlString) => {
const url = new URL(urlString);
const params = new URLSearchParams(url.search);
const filterParams = params.getAll(`${QUEUE_CONFIG.FILTER_COLUMN_REQUEST_PARAM}[]`);

setFilter(filterParams);
};

const [savedCompletedDateFilter, setSavedCompletedDateFilter] = useState('');
const isVhaBusinessLine = props.businessLineUrl === 'vha';
const queryParams = new URLSearchParams(window.location.search);
const currentTabName = queryParams.get(QUEUE_CONFIG.TAB_NAME_REQUEST_PARAM) || 'in_progress';
Expand All @@ -46,6 +37,26 @@ const NonCompTabsUnconnected = (props) => {
const findTab = tabArray.findIndex((tabName) => tabName === currentTabName);
const getTabByIndex = findTab === -1 ? 0 : findTab;

// A callback function to send down to QueueTable to add filters to local storage when the get parameters are updated
const onHistoryUpdate = (urlString) => {
const url = new URL(urlString);
const params = new URLSearchParams(url.search);
const filterParams = params.getAll(`${QUEUE_CONFIG.FILTER_COLUMN_REQUEST_PARAM}[]`);

// Completed date filter preservation is different since the column is not shared between tabs
const completedDateFilter = filterParams.find((value) => value.includes('col=completedDateColumn'));
const tabFromParams = params.get(QUEUE_CONFIG.TAB_NAME_REQUEST_PARAM);

if (completedDateFilter) {
setSavedCompletedDateFilter(completedDateFilter);
} else if (!completedDateFilter && tabFromParams === 'completed') {
// Since it is still in the completed tab without a filter, assume it was cleared
setSavedCompletedDateFilter('cleared');
}

setFilter(filterParams);
};

// Derive the different tab task counts from the task filters.
const taskCounts = useMemo(() => (
mapValues(props.taskFilterDetails, (obj) => sumBy(Object.values(obj)))
Expand Down Expand Up @@ -93,15 +104,26 @@ const NonCompTabsUnconnected = (props) => {
const completedTabPaginationOptions = cloneDeep(tabPaginationOptions);

if (isVhaBusinessLine) {
const containsCompletedDateFilter = completedTabPaginationOptions['filter[]'].
some((item) => item.includes('col=completedDateColumn'));
if (savedCompletedDateFilter) {
if (savedCompletedDateFilter === 'cleared') {
// Filter was cleared so don't set a filter now
} else {
// It's an existing filter so add it to the filters like normally
completedTabPaginationOptions['filter[]'].push(savedCompletedDateFilter);
}
} else {
// Sets the last 7 days filter on first swap to the completed tasks tab if the temp date filter is not set
const containsCompletedDateFilter = completedTabPaginationOptions['filter[]'].
some((item) => item.includes('col=completedDateColumn'));

if (!containsCompletedDateFilter) {
const sevenDaysAgoString = moment().subtract(7, 'days').
format('YYYY-MM-DD');
if (!containsCompletedDateFilter) {
const sevenDaysAgoString = moment().subtract(7, 'days').
format('YYYY-MM-DD');

completedTabPaginationOptions['filter[]'].push(`col=completedDateColumn&val=last7,${sevenDaysAgoString},`);
completedTabPaginationOptions['filter[]'].push(`col=completedDateColumn&val=last7,${sevenDaysAgoString},`);
}
}

}

const ALL_TABS = {
Expand Down
9 changes: 9 additions & 0 deletions spec/feature/non_comp/reviews_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,15 @@ def current_table_rows
expect(page).to have_content("Cases completed (Last 30 Days)")
expect(page).to have_content("Date Completed (1)")
expect(page).to have_content("Viewing 1-3 of 3 total")

# Verify that the filter is preserved between tabs
click_on "Incomplete Tasks"
expect(page).to have_content(COPY::VHA_INCOMPLETE_TAB_DESCRIPTION)

click_on "Completed Tasks"
expect(page).to have_content("Cases completed (Last 30 Days)")
expect(page).to have_content("Date Completed (1)")
expect(page).to have_content("Viewing 1-3 of 3 total")
end
end

Expand Down
Loading