Merge remote-tracking branch 'origin/Fix/View'

This commit is contained in:
a.bouhuolia
2020-12-17 01:21:34 +02:00
20 changed files with 242 additions and 313 deletions

View File

@@ -12,12 +12,13 @@ export const editItem = ({ id, form }) => {
export const fetchItems = ({ query }) => {
return (dispatch, getState) =>
new Promise((resolve, reject) => {
const pageQuery = getState().items.tableQuery;
let pageQuery = getState().items.tableQuery;
dispatch({
type: t.ITEMS_TABLE_LOADING,
payload: { loading: true },
});
ApiService.get(`items`, { params: { ...pageQuery, ...query } })
.then((response) => {
dispatch({
@@ -27,16 +28,18 @@ export const fetchItems = ({ query }) => {
dispatch({
type: t.ITEMS_PAGE_SET,
items: response.data.items,
customViewId: response.data?.filter_meta?.view?.custom_view_id,
customViewId:
response.data?.filter_meta?.view?.custom_view_id || -1,
paginationMeta: response.data.pagination,
});
dispatch({
type: t.ITEMS_PAGINATION_SET,
payload: {
pagination: response.data.pagination,
customViewId: response.data.customViewId || -1,
}
})
customViewId:
response.data?.filter_meta?.view?.custom_view_id || -1,
},
});
dispatch({
type: t.ITEMS_TABLE_LOADING,
payload: { loading: false },
@@ -44,9 +47,6 @@ export const fetchItems = ({ query }) => {
resolve(response);
})
.catch((error) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
reject(error);
});
});

View File

@@ -1,9 +1,6 @@
import { paginationLocationQuery } from "store/selectors";
import { paginationLocationQuery } from 'store/selectors';
import { createSelector } from 'reselect';
import {
pickItemsFromIds,
defaultPaginationMeta,
} from 'store/selectors';
import { pickItemsFromIds, defaultPaginationMeta } from 'store/selectors';
const itemsTableQuerySelector = (state) => state.items.tableQuery;
@@ -20,10 +17,11 @@ const itemsPaginationSelector = (state, props) => {
const viewId = state.items.currentViewId;
return state.items.views?.[viewId]?.paginationMeta;
};
const customersCurrentViewIdSelector = (state) => state.customers.currentViewId;
const itemsCurrentViewIdSelector = (state) => {
return state.items.currentViewId;
};
// Get items table query marged with location query.
export const getItemsTableQueryFactory = () =>
export const getItemsTableQueryFactory = () =>
createSelector(
paginationLocationQuery,
itemsTableQuerySelector,
@@ -31,39 +29,33 @@ export const getItemsTableQueryFactory = () =>
return {
...locationQuery,
...tableQuery,
}
};
},
);
// Retrieve items current page and view.
export const getItemsCurrentPageFactory = () =>
export const getItemsCurrentPageFactory = () =>
createSelector(
itemsDataSelector,
itemsCurrentPageSelector,
(items, itemsIdsCurrentPage) => {
return typeof itemsIdsCurrentPage === 'object'
? pickItemsFromIds(items, itemsIdsCurrentPage.ids) || []
: [];
? pickItemsFromIds(items, itemsIdsCurrentPage.ids) || []
: [];
},
);
// Retrieve items pagination meta.
export const getItemsPaginationMetaFactory = () =>
createSelector(
itemsPaginationSelector,
(itemsPagination) => {
return {
...defaultPaginationMeta(),
...itemsPagination,
};
}
);
export const getItemsPaginationMetaFactory = () =>
createSelector(itemsPaginationSelector, (itemsPagination) => {
return {
...defaultPaginationMeta(),
...itemsPagination,
};
});
// Retrieve items current view id.
export const getItemsCurrentViewIdFactory = () =>
createSelector(
customersCurrentViewIdSelector,
(currentViewId) => {
return currentViewId;
}
);
export const getItemsCurrentViewIdFactory = () =>
createSelector(itemsCurrentViewIdSelector, (currentViewId) => {
return currentViewId;
});