Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the sorting issue in admin portal tables #821

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,24 @@ export default function ListApis() {
const [rowsPerPage, setRowsPerPage] = useState(10);
const [page, setPage] = useState(0);
const [provider, setProvider] = useState('');
const [order, setOrder] = useState('asc');
const [orderBy, setOrderBy] = useState('name');

/**
* API call to get api list
* @returns {Promise}.
*/
function apiCall(pageNo, query = provider) {
function apiCall(pageNo, query = provider, sortBy = orderBy, sortOrder = order) {
setLoading(true);
const restApi = new API();
return restApi
.getApiList({ limit: rowsPerPage, offset: pageNo * rowsPerPage, query })
.getApiList({
limit: rowsPerPage,
offset: pageNo * rowsPerPage,
query,
sortBy,
sortOrder,
})
.then((result) => {
setApiList(result.body.apis);
const { pagination: { total } } = result.body;
Expand All @@ -92,13 +100,13 @@ export default function ListApis() {
apiCall(page).then((result) => {
setApiList(result);
});
}, [page]);
}, [page, rowsPerPage, order, orderBy]);

useEffect(() => {
apiCall(page).then((result) => {
setApiList(result);
});
}, [rowsPerPage]);
function handleRequestSort(event, property) {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
}

function handleChangePage(event, pageNo) {
setPage(pageNo);
Expand Down Expand Up @@ -226,7 +234,11 @@ export default function ListApis() {
{apiList && apiList.length > 0
&& (
<Table id='itest-api-list-table'>
<ApisTableHead />
<ApisTableHead
order={order}
orderBy={orderBy}
onRequestSort={handleRequestSort}
/>
<ApisTableContent
apis={apiList}
page={page}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,24 @@ export default function ListApplications() {
const [rowsPerPage, setRowsPerPage] = useState(10);
const [page, setPage] = useState(0);
const [searchQuery, setSearchQuery] = useState('');
const [order, setOrder] = useState('asc');
const [orderBy, setOrderBy] = useState('name');

/**
* API call to get application list
* @returns {Promise}.
*/
function apiCall(pageNo, user = searchQuery, name = searchQuery) {
function apiCall(pageNo, user = searchQuery, name = searchQuery, sortBy = orderBy, sortOrder = order) {
setLoading(true);
const restApi = new API();
return restApi
.getApplicationList({
limit: rowsPerPage, offset: pageNo * rowsPerPage, user, name,
limit: rowsPerPage,
offset: pageNo * rowsPerPage,
user,
name,
sortBy,
sortOrder,
})
.then((result) => {
setApplicationList(result.body.list);
Expand All @@ -80,13 +87,13 @@ export default function ListApplications() {
apiCall(page).then((result) => {
setApplicationList(result);
});
}, [page]);
}, [page, rowsPerPage, order, orderBy]);

useEffect(() => {
apiCall(page).then((result) => {
setApplicationList(result);
});
}, [rowsPerPage]);
function handleRequestSort(event, property) {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
}

function handleChangePage(event, pageNo) {
setPage(pageNo);
Expand Down Expand Up @@ -220,7 +227,11 @@ export default function ListApplications() {
{applicationList && applicationList.length > 0
&& (
<Table id='itest-application-list-table'>
<ApplicationTableHead />
<ApplicationTableHead
order={order}
orderBy={orderBy}
onRequestSort={handleRequestSort}
/>
<AppsTableContent
apps={applicationList}
page={page}
Expand Down
Loading