Skip to content

Commit

Permalink
Merge pull request #196 from Eastern-Research-Group/feature/428_any-r…
Browse files Browse the repository at this point in the history
…eporting-cycle-query

Feature/428 any reporting cycle query
  • Loading branch information
maxdiebold-erg authored Nov 15, 2024
2 parents 465024c + 5097d65 commit 5ad2e63
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
11 changes: 10 additions & 1 deletion app/client/src/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ function FilterFieldInputs({
? sourceState[sourceFieldConfig.id]
: null;
const selectProps = {
additionalOptions: 'additionalOptions' in fieldConfig ? fieldConfig.additionalOptions : [],
apiKey,
apiUrl,
contextFilters: getContextFilters(
Expand Down Expand Up @@ -797,6 +798,7 @@ function SourceSelectFilter(props: SourceSelectFilterProps) {
type FilterFunction = LoadOptions<Option, GroupBase<Option>, unknown>;

function SelectFilter({
additionalOptions,
apiKey,
apiUrl,
contextFilters,
Expand All @@ -819,6 +821,7 @@ function SelectFilter({
// Create the filter function from the HOF
const filterFunc: FilterFunction = useMemo(() => {
return filterOptions({
additionalOptions,
apiKey,
apiUrl,
defaultOption,
Expand Down Expand Up @@ -1363,6 +1366,7 @@ function createSourceReducer(sourceFields: SourceFields) {

// Filters options that require fetching values from the database
function filterDynamicOptions({
additionalOptions = [],
apiKey,
apiUrl,
defaultOption,
Expand All @@ -1374,6 +1378,7 @@ function filterDynamicOptions({
profile,
secondaryFieldName,
}: {
additionalOptions?: Option[];
apiKey: string;
apiUrl: string;
defaultOption?: Option | null;
Expand Down Expand Up @@ -1422,7 +1427,7 @@ function filterDynamicOptions({
return {
options:
!lastLoadedOption && defaultOption // only include default option in first page
? [defaultOption, ...options]
? [defaultOption, ...additionalOptions, ...options]
: options,
hasMore: options.length >= limit,
};
Expand All @@ -1431,6 +1436,7 @@ function filterDynamicOptions({

// Filters options by search input, returning a maximum number of options
function filterOptions({
additionalOptions = [],
apiKey,
apiUrl,
defaultOption,
Expand All @@ -1443,6 +1449,7 @@ function filterOptions({
staticOptions,
secondaryFieldName,
}: {
additionalOptions?: Option[];
apiKey: string;
apiUrl: string;
defaultOption?: Option | null;
Expand All @@ -1462,6 +1469,7 @@ function filterOptions({
);
} else {
return filterDynamicOptions({
additionalOptions,
apiKey,
apiUrl,
defaultOption,
Expand Down Expand Up @@ -1979,6 +1987,7 @@ type RangeFilterProps = {
};

type SelectFilterProps = {
additionalOptions?: Option[];
apiKey: string;
apiUrl: string;
contextFilters: FilterQueryData;
Expand Down
3 changes: 3 additions & 0 deletions app/server/app/content/config/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@
"key": "reportingCycle",
"label": "Reporting Cycle",
"type": "select",
"additionalOptions": [
{ "value": -1, "label": "Any" }
],
"default": { "value": "", "label": "Latest" },
"direction": "desc",
"contextFields": ["organizationId", "region", "state"]
Expand Down
1 change: 1 addition & 0 deletions app/server/app/content/swagger/api-public.json
Original file line number Diff line number Diff line change
Expand Up @@ -4233,6 +4233,7 @@
"in": "query",
"example": 2020,
"explode": true,
"description": "Filter the summary to a specific reporting cycle in terms of the four-digit year the reporting cycle ended (e.g., for the 4/2/2016 – 3/31/2018 reporting cycle, the four-digit reporting cycle is “2018”). If left blank, the service will return the most recent cycle. If -1 is used, the service will return all reporting cycles.",
"schema": {
"type": "integer"
}
Expand Down
25 changes: 16 additions & 9 deletions app/server/app/routes/attains.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,19 @@ function parseCriteria(req, query, profile, queryParams, countOnly = false) {
// so that we can apply the same filters to the subquery
const latestColumn = profile.columns.find((col) => col.default === 'latest');
const subQuery =
latestColumn && !queryParams.filters.hasOwnProperty(latestColumn.alias)
? createLatestSubquery(
req,
profile,
queryParams,
latestColumn.name,
latestColumn.type,
)
: null;
latestColumn &&
queryParams.filters.hasOwnProperty(latestColumn.alias) &&
queryParams.filters[latestColumn.alias] === -1
? null
: latestColumn && !queryParams.filters.hasOwnProperty(latestColumn.alias)
? createLatestSubquery(
req,
profile,
queryParams,
latestColumn.name,
latestColumn.type,
)
: null;

// build select statement of the query
if (!countOnly) {
Expand All @@ -353,6 +357,9 @@ function parseCriteria(req, query, profile, queryParams, countOnly = false) {

// build where clause of the query
profile.columns.forEach((col) => {
if (col.default === 'latest' && queryParams.filters[col.alias] === -1)
return;

const lowArg = 'lowParam' in col && queryParams.filters[col.lowParam];
const highArg = 'highParam' in col && queryParams.filters[col.highParam];
const exactArg = queryParams.filters[col.alias];
Expand Down

0 comments on commit 5ad2e63

Please sign in to comment.