In all pages that use the SingleQuarterDropdown component (which is most of the searches), the default quarter is taken from one of two places:
If the dropdown has been used recently, then there will be a value in local storage that "remembers" the quarter that the user selected last time. This is the best guess as to what the user will want next time.
But if there is no value in local storage, the default value is currently the "top" value in the list, i.e. the same as the value set by the app for START_QTR. (When START_QTR and END_QTR have not been set in the .env file or via dokku config:set, the values are W22 and S22).
It probably makes more sense for the default value (when nothing is in local storage) to be the END_QTR value, rather than the START_QTR value. That's typically the "active" quarter, i.e. the one everyone's most concerned about.
Acceptance Criteria
[ ] When local storage is empty (you can empty it by using your browser's settings to "Clear Local Storage"), the default quarter is always whatever the value of END_QTR is.
[ ] On return visits to the page, the default quarter is the one that was selected on a previous visit to the page (unless local storage has been cleared in the meantime.)
Implementation Suggestions
The code that handles the default quarter in SingleQuarterDropdown is this:
if (!localSearchQuarter) {
localStorage.setItem(controlId, quarters[0].yyyyq);
}
const [quarterState, setQuarterState] = useState(
// Stryker disable next-line all : not sure how to test/mock local storage
quarter.yyyq || localSearchQuarter || quarters[0].yyyyq,
);
Note that value for quarters[0].yyyyq, which is the first thing in the list of quarter passed in, which will typically be START_QTR.
Instead, it would probably make more sense for the end user if the value were the last value in that array.
So the suggested change is to:
set a variable to the index of the last element in the quarters array, e.g. const lastIndex = ... (you figure out what the ... is)
use that variable instead of 0 to index into the quarters list, e.g. quarters[lastIndex].yyyyq
There may be other ways to accomplish this as well.
It might be good, for example, to factor out:
const defaultQuarter = ...
And that use defaultQuarter in place of quarters[0].yyyyq
Summary
In all pages that use the
SingleQuarterDropdown
component (which is most of the searches), the default quarter is taken from one of two places:START_QTR
. (When START_QTR and END_QTR have not been set in the .env file or viadokku config:set
, the values are W22 and S22).It probably makes more sense for the default value (when nothing is in local storage) to be the
END_QTR
value, rather than theSTART_QTR
value. That's typically the "active" quarter, i.e. the one everyone's most concerned about.Acceptance Criteria
Implementation Suggestions
The code that handles the default quarter in
SingleQuarterDropdown
is this:Note that value for
quarters[0].yyyyq,
which is the first thing in the list of quarter passed in, which will typically be START_QTR.Instead, it would probably make more sense for the end user if the value were the last value in that array.
So the suggested change is to:
const lastIndex = ...
(you figure out what the ... is)quarters[lastIndex].yyyyq
There may be other ways to accomplish this as well.
It might be good, for example, to factor out:
And that use
defaultQuarter
in place ofquarters[0].yyyyq