Skip to content

Commit

Permalink
New function to parse date range filters, fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Castillo <[email protected]>
  • Loading branch information
tomrndom committed Jul 8, 2024
1 parent f497683 commit 547c499
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 42 deletions.
15 changes: 3 additions & 12 deletions src/actions/attendee-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
escapeFilterValue,
getCSV
} from "openstack-uicore-foundation/lib/utils/actions";
import {checkOrFilter, getAccessTokenSafely, isNumericString} from '../utils/methods';
import {checkOrFilter, getAccessTokenSafely, isNumericString, parseDateRangeFilter} from '../utils/methods';

export const REQUEST_ATTENDEES = 'REQUEST_ATTENDEES';
export const RECEIVE_ATTENDEES = 'RECEIVE_ATTENDEES';
Expand Down Expand Up @@ -145,17 +145,8 @@ const parseFilters = (filters, term = null) => {
filter.push('badge_type_id=='+filters.badgeTypeFilter.join('||'));
}

if (filters.checkinDateFilter && filters.checkinDateFilter.some(e => e !== null)) {
if(filters.checkinDateFilter.every(e => e !== null )) {
// added between operator []
filter.push(`summit_hall_checked_in_date[]${filters.checkinDateFilter[0]}&&${filters.checkinDateFilter[1]}`);
} else {
filter.push(`
${filters.checkinDateFilter[0] !== null ?
`summit_hall_checked_in_date>=${filters.checkinDateFilter[0]}` : ``}
${filters.checkinDateFilter[1] !== null ?
`summit_hall_checked_in_date<=${filters.checkinDateFilter[1]}` : ``}`);
}
if (filters.checkinDateFilter) {
parseDateRangeFilter(filter, filters.checkinDateFilter, 'summit_hall_checked_in_date');
}

if (filters.notes) {
Expand Down
42 changes: 12 additions & 30 deletions src/actions/event-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
fetchErrorHandler
} from "openstack-uicore-foundation/lib/utils/actions";
import {epochToMomentTimeZone} from "openstack-uicore-foundation/lib/utils/methods";
import {checkOrFilter, getAccessTokenSafely, isNumericString} from '../utils/methods';
import {checkOrFilter, getAccessTokenSafely, isNumericString, parseDateRangeFilter} from '../utils/methods';
import {getQAUsersBySummitEvent} from "./user-chat-roles-actions";
import {getAuditLog} from "./audit-log-actions";

Expand Down Expand Up @@ -969,39 +969,21 @@ const parseFilters = (filters, term = null) => {
filter.push(`published==${filters.published_filter === 'published' ? '1' : '0'}`);
}

if (filters.start_date_filter && filters.start_date_filter.some(e => e !== null)) {
if(filters.start_date_filter.every(e => e !== null )) {
filter.push(`start_date[]${filters.start_date_filter[0]}&&${filters.start_date_filter[1]}`);
} else {
filter.push(`${filters.start_date_filter[0] !== null ? `start_date>=${filters.start_date_filter[0]}` : ``}${filters.start_date_filter[1] !== null ? `start_date<=${filters.start_date_filter[1]}` : ``}`);
}
}

if (filters.start_date_filter) {
parseDateRangeFilter(filter, filters.start_date_filter, 'start_date');
}

if (filters.end_date_filter && filters.end_date_filter.some(e => e !== null)) {
if(filters.end_date_filter.every(e => e !== null )) {
// between
filter.push(`end_date[]${filters.end_date_filter[0]}&&${filters.end_date_filter[1]}`);
} else {
filter.push(`${filters.end_date_filter[0] !== null ? `end_date>=${filters.end_date_filter[0]}` : ``}${filters.end_date_filter[1] !== null ? `end_date<=${filters.end_date_filter[1]}` : ``}`);
}
if (filters.end_date_filter) {
parseDateRangeFilter(filter, filters.end_date_filter, 'end_date');
}

if (filters.created_filter && filters.created_filter.some(e => e !== null)) {
if(filters.created_filter.every(e => e !== null )) {
// between
filter.push(`created[]${filters.created_filter[0]}&&${filters.created_filter[1]}`);
} else {
filter.push(`${filters.created_filter[0] !== null ? `created>=${filters.created_filter[0]}` : ``}${filters.created_filter[1] !== null ? `created<=${filters.created_filter[1]}` : ``}`);
}
}
if (filters.created_filter) {
parseDateRangeFilter(filter, filters.created_filter, 'created');
}

if (filters.modified_filter && filters.modified_filter.some(e => e !== null)) {
if(filters.modified_filter.every(e => e !== null )) {
// between
filter.push(`last_edited[]${filters.modified_filter[0]}&&${filters.modified_filter[1]}`);
} else {
filter.push(`${filters.modified_filter[0] !== null ? `last_edited>=${filters.modified_filter[0]}` : ``}${filters.modified_filter[1] !== null ? `last_edited<=${filters.modified_filter[1]}` : ``}`);
}
if (filters.modified_filter) {
parseDateRangeFilter(filter, filters.modified_filter, 'last_edited');
}

if (filters.duration_filter) {
Expand Down
10 changes: 10 additions & 0 deletions src/utils/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,13 @@ export const htmlToString = (html) => {
}

export const capitalize = string => string ? string.charAt(0).toUpperCase() + string.slice(1) : '';

export const parseDateRangeFilter = (filterObject, filterToParse, filterName) => {
if (filterToParse && filterToParse.some(e => e !== null)) {
if(filterToParse.every(e => e !== null && e !==0 )) {
filterObject.push(`${filterName}[]${filterToParse[0]}&&${filterToParse[1]}`);
} else {
filterObject.push(`${filterToParse[0] !== null && filterToParse[0] !== 0 ? `${filterName}>=${filterToParse[0]}` : ``}${filterToParse[1] !== null && filterToParse[1] !== 0 ? `${filterName}<=${filterToParse[1]}` : ``}`);
}
}
}

0 comments on commit 547c499

Please sign in to comment.