Skip to content

Commit

Permalink
EPMRPP-91556 || fix last run date
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazarQSO committed Dec 10, 2024
1 parent 9e4fb47 commit 2f5cb38
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
48 changes: 48 additions & 0 deletions app/src/components/filterEntities/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

import moment from 'moment/moment';
import { getMinutesFromTimestamp } from 'common/utils';
import { LAST_RUN_DATE_FILTER_NAME } from 'components/main/filterButton';

export function bindDefaultValue(key, options = {}) {
const { filterValues } = this.props;
if (key in filterValues) {
Expand All @@ -25,3 +29,47 @@ export function bindDefaultValue(key, options = {}) {
...options,
};
}

const getFormattedDate = (value) => {
const utcString = moment().format('ZZ');
const calculateStartDate = (days) =>
moment()
.startOf('day')
.subtract(days - 1, 'days')
.valueOf();
const endOfToday = moment()
.add(1, 'days')
.startOf('day')
.valueOf();
let start = null;
switch (value) {
case 'today':
start = calculateStartDate(1);
break;
case 'last2days':
start = calculateStartDate(2);
break;
case 'last7days':
start = calculateStartDate(7);
break;
case 'last30days':
start = calculateStartDate(30);
break;
default:
break;
}
return `${getMinutesFromTimestamp(start)};${getMinutesFromTimestamp(endOfToday)};${utcString}`;
};

export const updateFormatDate = (filtersParams) => {
const { search_criteria: searchCriteria } = filtersParams;

const lastRunDateFilterIndex = Object.values(searchCriteria).findIndex(
(el) => el.filter_key === LAST_RUN_DATE_FILTER_NAME,
);
if (lastRunDateFilterIndex !== -1) {
searchCriteria[lastRunDateFilterIndex].value = getFormattedDate(
searchCriteria[lastRunDateFilterIndex].value,
);
}
};
3 changes: 2 additions & 1 deletion app/src/controllers/instance/organizations/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { takeEvery, all, put, select } from 'redux-saga/effects';
import { URLS } from 'common/urls';
import { showDefaultErrorNotification } from 'controllers/notification';
import { fetchDataAction } from 'controllers/fetch';
import { updateFormatDate } from 'components/filterEntities/utils';
import { filterQuerySelector, querySelector } from './selectors';
import { FETCH_ORGANIZATIONS, FETCH_FILTERED_ORGANIZATIONS, NAMESPACE } from './constants';

Expand All @@ -37,7 +38,7 @@ function* watchFetchOrganizations() {

function* fetchFilteredOrganizations() {
const filtersParams = yield select(filterQuerySelector);

updateFormatDate(filtersParams);
yield put(
fetchDataAction(NAMESPACE)(URLS.organizationSearches(), {
method: 'post',
Expand Down
2 changes: 2 additions & 0 deletions app/src/controllers/organization/projects/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { URLS } from 'common/urls';
import { fetch } from 'common/utils';
import { hideModalAction } from 'controllers/modal';
import { NOTIFICATION_TYPES, showNotification } from 'controllers/notification';
import { updateFormatDate } from 'components/filterEntities/utils';
import {
CREATE_PROJECT,
FETCH_ORGANIZATION_PROJECTS,
Expand Down Expand Up @@ -121,6 +122,7 @@ function* watchDeleteProject() {
function* fetchFilteredProjects() {
const activeOrganizationId = yield select(activeOrganizationIdSelector);
const filtersParams = yield select(filterQuerySelector);
updateFormatDate(filtersParams);

yield put(
fetchDataAction(NAMESPACE)(URLS.organizationProjectsSearches(activeOrganizationId), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from 'components/main/filterButton';
import { FilterButton } from 'components/main/filterButton/filterButton';
import { fetchFilteredOrganizationsAction } from 'controllers/instance/organizations';
import { CONDITION_BETWEEN } from 'components/filterEntities/constants';
import { messages } from './messages';

export const OrganizationsFilter = ({
Expand All @@ -50,6 +51,7 @@ export const OrganizationsFilter = ({
value: timeRange[0].value,
title: formatMessage(messages.lastRunDate),
options: timeRange,
condition: CONDITION_BETWEEN.toUpperCase(),
placeholder: formatMessage(messages.lastRunDatePlaceholder),
},
[LAUNCHES_FILTER_NAME]: {
Expand Down

0 comments on commit 2f5cb38

Please sign in to comment.