- added filter for the table of calls with pagination;
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React, { useEffect, useState, useCallback } from 'react';
|
import React, { useEffect, useState, useCallback } from 'react';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { FilterMatchMode } from 'primereact/api';
|
||||||
|
|
||||||
import translationStrings from '../../../../translationStringsForComponents';
|
import translationStrings from '../../../../translationStringsForComponents';
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ import { Dropdown } from 'primereact/dropdown';
|
|||||||
import { Tag } from 'primereact/tag';
|
import { Tag } from 'primereact/tag';
|
||||||
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
||||||
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
||||||
|
import { isEmpty, pathOr } from 'ramda';
|
||||||
|
|
||||||
const LatestBandiTableAsync = () => {
|
const LatestBandiTableAsync = () => {
|
||||||
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
||||||
@@ -29,7 +31,7 @@ const LatestBandiTableAsync = () => {
|
|||||||
sortOrder: null,
|
sortOrder: null,
|
||||||
filters: {
|
filters: {
|
||||||
name: { value: '', matchMode: 'contains' },
|
name: { value: '', matchMode: 'contains' },
|
||||||
status: { value: '', matchMode: 'contains' }
|
status: { value: '', matchMode: 'equals' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const statuses = ['PUBLISH'];
|
const statuses = ['PUBLISH'];
|
||||||
@@ -50,6 +52,13 @@ const LatestBandiTableAsync = () => {
|
|||||||
globalFilters: {
|
globalFilters: {
|
||||||
page: lazyState.page ? lazyState.page + 1 : 1,
|
page: lazyState.page ? lazyState.page + 1 : 1,
|
||||||
limit: lazyState.rows,
|
limit: lazyState.rows,
|
||||||
|
filters: Object.keys(lazyState.filters).reduce((acc, cur) => {
|
||||||
|
const value = pathOr('', ['filters', cur, 'value'], lazyState);
|
||||||
|
if (!isEmpty(value)) {
|
||||||
|
acc[cur] = lazyState.filters[cur];
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
sortBy
|
sortBy
|
||||||
},
|
},
|
||||||
status: statuses
|
status: statuses
|
||||||
@@ -57,32 +66,36 @@ const LatestBandiTableAsync = () => {
|
|||||||
}, [lazyState]);
|
}, [lazyState]);
|
||||||
|
|
||||||
const onPage = (event) => {
|
const onPage = (event) => {
|
||||||
console.log('onPage', event);
|
//console.log('onPage', event);
|
||||||
setLazyState(event);
|
setLazyState(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSort = (event) => {
|
const onSort = (event) => {
|
||||||
console.log('onSort', event);
|
//console.log('onSort', event);
|
||||||
|
event['first'] = 0;
|
||||||
|
event['page'] = 0;
|
||||||
setLazyState(event);
|
setLazyState(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onFilter = useCallback((event) => {
|
const onFilter = useCallback((event) => {
|
||||||
console.log('onFilter', event);
|
//console.log('onFilter', event);
|
||||||
event['first'] = 0;
|
event['first'] = 0;
|
||||||
|
event['page'] = 0;
|
||||||
setLazyState(event);
|
setLazyState(event);
|
||||||
}, [lazyState]);
|
}, [lazyState]);
|
||||||
|
|
||||||
const getCallback = (data) => {
|
const getCallback = (resp) => {
|
||||||
if (data.status === 'SUCCESS') {
|
if (resp.status === 'SUCCESS') {
|
||||||
const { body, totalRecords, currentPage, totalPages, pageSize } = data.data;
|
const { body, totalRecords,
|
||||||
|
//currentPage, totalPages, pageSize
|
||||||
|
} = resp.data;
|
||||||
setTotalRecordsNum(totalRecords);
|
setTotalRecordsNum(totalRecords);
|
||||||
//const newItems = body.filter(o => o.status === 'PUBLISH');
|
|
||||||
setItems(getFormattedBandiData(body));
|
setItems(getFormattedBandiData(body));
|
||||||
}
|
}
|
||||||
setLocalAsyncRequest(false);
|
setLocalAsyncRequest(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const errGetCallbacks = (data) => {
|
const errGetCallbacks = () => {
|
||||||
setLocalAsyncRequest(false);
|
setLocalAsyncRequest(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,22 +155,21 @@ const LatestBandiTableAsync = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('lazyState', lazyState)
|
//console.log('lazyState', lazyState)
|
||||||
/*const paginationQuery = getPaginationQuery();
|
|
||||||
console.log('paginationQuery', paginationQuery)*/
|
|
||||||
setLocalAsyncRequest(true);
|
setLocalAsyncRequest(true);
|
||||||
const paginationQuery = getPaginationQuery();
|
const paginationQuery = getPaginationQuery();
|
||||||
console.log('paginationQuery', paginationQuery)
|
//console.log('paginationQuery', paginationQuery)
|
||||||
|
|
||||||
BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks);
|
BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks);
|
||||||
}, [lazyState]);
|
}, [lazyState]);
|
||||||
|
|
||||||
useEffect(() => {
|
/*useEffect(() => {
|
||||||
if (!localAsyncRequest) {
|
if (!localAsyncRequest) {
|
||||||
setLocalAsyncRequest(true);
|
setLocalAsyncRequest(true);
|
||||||
const paginationQuery = getPaginationQuery();
|
const paginationQuery = getPaginationQuery();
|
||||||
BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks);
|
BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);*/
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="appPageSection__table">
|
<div className="appPageSection__table">
|
||||||
@@ -170,7 +182,8 @@ const LatestBandiTableAsync = () => {
|
|||||||
emptyMessage={translationStrings.emptyMessage}>
|
emptyMessage={translationStrings.emptyMessage}>
|
||||||
<Column field="name"
|
<Column field="name"
|
||||||
sortable
|
sortable
|
||||||
filterField="name" filter filterMatchModeOptions={['contains']}
|
filterField="name" filter
|
||||||
|
filterMatchModeOptions={[{ label: 'Contiene', value: FilterMatchMode.CONTAINS }]}
|
||||||
header={__('Nome Bando', 'gepafin')}
|
header={__('Nome Bando', 'gepafin')}
|
||||||
style={{ minWidth: '8rem' }}/>
|
style={{ minWidth: '8rem' }}/>
|
||||||
<Column header={__('Data Pubblicazione', 'gepafin')}
|
<Column header={__('Data Pubblicazione', 'gepafin')}
|
||||||
@@ -180,7 +193,8 @@ const LatestBandiTableAsync = () => {
|
|||||||
style={{ minWidth: '8rem' }}
|
style={{ minWidth: '8rem' }}
|
||||||
body={dateEndBodyTemplate}/>
|
body={dateEndBodyTemplate}/>
|
||||||
<Column field="status"
|
<Column field="status"
|
||||||
filterElement={statusFilterTemplate} filter filterMatchModeOptions={['contains']}
|
filterElement={statusFilterTemplate} filter
|
||||||
|
filterMatchModeOptions={[{ label: 'Uguale a', value: FilterMatchMode.EQUALS }]}
|
||||||
header={__('Stato', 'gepafin')}
|
header={__('Stato', 'gepafin')}
|
||||||
style={{ minWidth: '7rem' }}
|
style={{ minWidth: '7rem' }}
|
||||||
body={statusBodyTemplate} />
|
body={statusBodyTemplate} />
|
||||||
|
|||||||
Reference in New Issue
Block a user