Skip to content

Commit

Permalink
EPMRPP-78737 || Code review fixes - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzmitry Kosarau authored and Dzmitry Kosarau committed Sep 14, 2023
1 parent 56a3192 commit 132d79d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app/src/controllers/filter/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export const fetchUserFiltersSuccessAction = (filters) => ({
payload: filters,
});

export const changeActiveFilterAction = (filterId, fromParsedQuery = false) => ({
export const changeActiveFilterAction = (filterId, meta = {}) => ({
type: CHANGE_ACTIVE_FILTER,
payload: filterId,
meta: { fromParsedQuery },
meta,
});

export const updateFilterConditionsAction = (filterId, conditions) => ({
Expand Down Expand Up @@ -88,7 +88,7 @@ export const createFilterAction = (filter) => ({
export const createFilterFromParsedQueryAction = (filter) => ({
...createFilterAction(filter),
meta: {
fromParsedQuery: true,
redirect: true,
},
});

Expand Down
8 changes: 4 additions & 4 deletions app/src/controllers/filter/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function* updateLaunchesFilter({ payload: filter }) {
);
}

function* changeActiveFilter({ payload: filterId, meta: { fromParsedQuery } }) {
function* changeActiveFilter({ payload: filterId, meta }) {
const activeProject = yield select(activeProjectSelector);
const action = {
type: PROJECT_LAUNCHES_PAGE,
Expand All @@ -116,7 +116,7 @@ function* changeActiveFilter({ payload: filterId, meta: { fromParsedQuery } }) {
},
};

yield put(fromParsedQuery ? redirect(action) : action);
yield put(meta.redirect ? redirect(action) : action);
}

function* resetFilter({ payload: filterId }) {
Expand All @@ -125,7 +125,7 @@ function* resetFilter({ payload: filterId }) {
yield put(updateFilterSuccessAction(savedFilter));
}

function* createFilter({ payload: filter = {}, meta: { fromParsedQuery } = {} }) {
function* createFilter({ payload: filter = {}, meta = {} }) {
const launchFilters = yield select(launchFiltersSelector);
const userId = yield select(userIdSelector);
const lastNewFilterId = launchFilters.reduce(
Expand All @@ -142,7 +142,7 @@ function* createFilter({ payload: filter = {}, meta: { fromParsedQuery } = {} })
owner: userId,
};
yield put(addFilterAction(newFilter));
yield put(changeActiveFilterAction(newFilter.id, fromParsedQuery));
yield put(changeActiveFilterAction(newFilter.id, meta));
}

function* saveNewFilter({ payload: filter }) {
Expand Down
10 changes: 3 additions & 7 deletions app/src/controllers/filter/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import isEqual from 'fast-deep-equal';
import { createQueryParametersSelector, filterIdSelector } from 'controllers/pages';
import { PAGE_KEY, SIZE_KEY } from 'controllers/pagination';
import { SORTING_KEY } from 'controllers/sorting';
import { queryParametersSelector } from 'controllers/launch';
import { isEmptyObject } from 'common/utils';
import { queryParametersSelector } from '../launch/selectors';
import { userFiltersSelector } from '../project/selectors';
import { collectFilterConditions } from './utils';
import { addFilteringFieldToConditions, collectFilterEntities } from './utils';

const domainSelector = (state) => state.filters || {};

Expand Down Expand Up @@ -81,10 +81,6 @@ export const filterFromQuerySelector = createSelector(
return null;
}

return Object.entries(filters).reduce(
(acc, [filterKey, filterValue]) => collectFilterConditions(filterKey, filterValue, acc),

{ conditions: [] },
);
return { conditions: addFilteringFieldToConditions(collectFilterEntities(filters)) };
},
);
20 changes: 10 additions & 10 deletions app/src/controllers/filter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export const updateFilter = (filters, filter, oldId) => {
export const addFilteringFieldToConditions = (conditions = {}) =>
Object.keys(conditions).map((key) => ({ ...conditions[key], filteringField: key }));

export const collectFilterConditions = (filterName, filterValue, filtersCollection) => {
const [, condition, filteringField] = filterName.split('.');
export const collectFilterEntities = (filters) =>
Object.entries(filters).reduce((acc, [filterName, filterValue]) => {
const [, condition, filteringField] = filterName.split('.');

return Object.assign(filtersCollection, {
conditions: filtersCollection.conditions.concat({
filteringField,
value: filterValue,
condition,
}),
});
};
return Object.assign(acc, {
[filteringField]: {
value: filterValue,
condition,
},
});
}, {});

0 comments on commit 132d79d

Please sign in to comment.