fix: View.

This commit is contained in:
elforjani3
2020-12-07 22:37:15 +02:00
parent cff7575326
commit e398b8c239
20 changed files with 273 additions and 342 deletions

View File

@@ -1,6 +1,10 @@
import { createSelector } from 'reselect';
import { repeat } from 'lodash';
import { pickItemsFromIds, getItemById } from 'store/selectors';
import {
pickItemsFromIds,
getItemById,
paginationLocationQuery,
} from 'store/selectors';
import { flatToNestedArray, treeToList } from 'utils';
const accountsViewsSelector = (state) => state.accounts.views;
@@ -8,6 +12,16 @@ const accountsDataSelector = (state) => state.accounts.items;
const accountsCurrentViewSelector = (state) => state.accounts.currentViewId;
const accountIdPropSelector = (state, props) => props.accountId;
const accountsListSelector = (state) => state.accounts.listTree;
const accountsTableQuery = (state, props) => state.accounts.tableQuery;
export const getAccountsTableQuery = createSelector(
accountsTableQuery,
(tableQuery) => {
return {
...tableQuery,
};
},
);
export const getAccountsItems = createSelector(
accountsViewsSelector,
@@ -42,12 +56,13 @@ export const getAccountsListFactory = () =>
return {
...account,
htmlName: (depth > 1)
? (`${repeat(spaceChar, (depth - 1) * 2)}${account.name}`) :
account.name,
htmlName:
depth > 1
? `${repeat(spaceChar, (depth - 1) * 2)}${account.name}`
: account.name,
depth,
};
}
},
});
},
);

View File

@@ -14,8 +14,10 @@ export default {
ACCOUNTS_SET_CURRENT_VIEW: 'ACCOUNTS_SET_CURRENT_VIEW',
ACCOUNTS_TABLE_QUERY_SET: 'ACCOUNTS_TABLE_QUERY_SET',
ACCOUNTS_TABLE_QUERIES_SET: 'ACCOUNTS_TABLE_QUERIES_SET',
ACCOUNTS_TABLE_QUERY_SET: 'ACCOUNTS/TABLE_QUERY_SET',
ACCOUNTS_TABLE_QUERIES_SET: 'ACCOUNTS/TABLE_QUERIES_SET',
ACCOUNTS_TABLE_QUERIES_ADD:'ACCOUNTS/TABLE_QUERIES_ADD',
ACCOUNTS_TABLE_LOADING: 'ACCOUNTS_TABLE_LOADING',

View File

@@ -20,21 +20,23 @@ export const fetchExpensesTable = ({ query } = {}) => {
payload: {
expenses: response.data.expenses,
pagination: response.data.pagination,
customViewId: response.data.customViewId || -1,
},
customViewId:
response.data?.filter_meta?.view?.custom_view_id || -1,
},
});
dispatch({
type: t.EXPENSES_ITEMS_SET,
payload: {
expenses: response.data.expenses,
}
},
});
dispatch({
type: t.EXPENSES_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.EXPENSES_TABLE_LOADING,
@@ -54,7 +56,7 @@ export const fetchExpense = ({ id }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.get(`expenses/${id}`)
.then((response) => {
.then((response) => {
dispatch({
type: t.EXPENSE_SET,
payload: {

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;
});

View File

@@ -129,7 +129,7 @@ export const fetchManualJournalsTable = ({ query } = {}) => {
payload: {
manualJournals: response.data.manual_journals,
customViewId:
response.data.manual_journals?.viewMeta?.customViewId || -1,
response.data?.filter_meta?.view?.custom_view_id || -1,
pagination: response.data.pagination,
},
});
@@ -140,23 +140,25 @@ export const fetchManualJournalsTable = ({ query } = {}) => {
...manualJournal,
entries: manualJournal.entries.map((entry) => ({
...omit(entry, ['account']),
}))
})),
})),
]
],
});
dispatch({
type: t.MANUAL_JOURNALS_PAGINATION_SET,
payload: {
pagination: response.data.pagination,
customViewId:
response.data.manual_journals?.viewMeta?.customViewId || -1,
response.data?.filter_meta?.view?.custom_view_id || -1,
},
});
dispatch({
type: t.ACCOUNTS_ITEMS_SET,
accounts: flatten(response.data.manual_journals?.map(
journal => journal?.entries.map(entry => entry.account),
)),
accounts: flatten(
response.data.manual_journals?.map((journal) =>
journal?.entries.map((entry) => entry.account),
),
),
});
dispatch({
type: t.MANUAL_JOURNALS_TABLE_LOADING,