feat: datatables pagination.

This commit is contained in:
Ahmed Bouhuolia
2020-11-16 13:36:14 +02:00
parent 6d4b3164a8
commit 13dd14b9d4
76 changed files with 1160 additions and 1315 deletions

View File

@@ -30,13 +30,17 @@ export const fetchItems = ({ query }) => {
customViewId: response.data?.filter_meta?.view?.custom_view_id,
paginationMeta: response.data.pagination,
});
dispatch({
type: t.ITEMS_PAGINATION_SET,
payload: {
pagination: response.data.pagination,
customViewId: response.data.customViewId || -1,
}
})
dispatch({
type: t.ITEMS_TABLE_LOADING,
payload: { loading: false },
});
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {

View File

@@ -1,7 +1,10 @@
import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit';
import { getItemsViewPages } from 'store/items/items.selectors';
import { createTableQueryReducers } from 'store/queryReducers';
import {
viewPaginationSetReducer,
createTableQueryReducers,
} from 'store/journalNumber.reducer';
const initialState = {
items: {},
@@ -9,12 +12,15 @@ const initialState = {
itemsRelation: {},
currentPage: 1,
currentViewId: -1,
tableQuery: {},
bulkActions: {},
loading: false,
tableQuery: {
page_size: 12,
page: 1,
},
};
const itemsReducer = createReducer(initialState, {
export default createReducer(initialState, {
[t.ITEMS_SET]: (state, action) => {
const _items = {};
@@ -111,9 +117,10 @@ const itemsReducer = createReducer(initialState, {
});
state.items = items;
},
});
export default createTableQueryReducers('items', itemsReducer);
...viewPaginationSetReducer(t.ITEMS_PAGINATION_SET),
...createTableQueryReducers('ITEMS'),
});
export const getItemById = (state, id) => {
return state.items.items[id];

View File

@@ -2,12 +2,13 @@ export default {
ITEMS_SET: 'ITEMS_SET',
ITEM_SET: 'ITEM_SET',
ITEMS_PAGE_SET: 'ITEMS_PAGE_SET',
ITEMS_PAGINATION_SET: 'ITEMS_PAGINATION_SET',
ITEM_DELETE: 'ITEM_DELETE',
ITEM_BULK_ACTION_ADD: 'ITEM_BULK_ACTION_ADD',
ITEM_BULK_ACTION_REMOVE: 'ITEM_BULK_ACTION_REMOVE',
ITEMS_TABLE_QUERY_SET: 'ITEMS_TABLE_QUERY_SET',
ITEMS_TABLE_QUERIES_ADD: 'ITEMS_TABLE_QUERIES_ADD',
ITEMS_TABLE_QUERY_SET: 'ITEMS/TABLE_QUERY_SET',
ITEMS_TABLE_QUERIES_ADD: 'ITEMS/TABLE_QUERIES_ADD',
ITEMS_TABLE_LOADING: 'ITEMS_TABLE_LOADING',
ITEMS_SET_CURRENT_VIEW: 'ITEMS_SET_CURRENT_VIEW',