diff --git a/jsx/src/App.jsx b/jsx/src/App.jsx index 49058604..d69c53bf 100644 --- a/jsx/src/App.jsx +++ b/jsx/src/App.jsx @@ -4,7 +4,6 @@ import { Provider } from "react-redux"; import { createStore } from "redux"; import { compose } from "recompose"; import { initialState, reducers } from "./Store"; -import { jhapiRequest } from "./util/jhapiUtil"; import withAPI from "./util/withAPI"; import { HashRouter, Switch, Route } from "react-router-dom"; @@ -25,16 +24,28 @@ const App = () => { let api = withAPI()().props; api .updateUsers(user_page * limit, limit) - .then((data) => - store.dispatch({ type: "USER_PAGE", value: { data: data, page: 0 } }) - ) + .then((data) => { + console.log(data); + let { _pagination, items } = data, + { offset, limit } = _pagination; + store.dispatch({ + type: "USER_PAGE", + value: { data: items, page: Math.floor(offset / limit) }, + }); + }) .catch((err) => console.log(err)); api .updateGroups(groups_page * limit, limit) - .then((data) => - store.dispatch({ type: "GROUPS_PAGE", value: { data: data, page: 0 } }) - ) + .then((data) => { + console.log(data); + let { _pagination, items } = data, + { offset, limit } = _pagination; + store.dispatch({ + type: "GROUPS_PAGE", + value: { data: items, page: Math.floor(offset / limit) }, + }); + }) .catch((err) => console.log(err)); }); diff --git a/jsx/src/components/ServerDashboard/ServerDashboard.jsx b/jsx/src/components/ServerDashboard/ServerDashboard.jsx index 94c8e6d3..88947396 100644 --- a/jsx/src/components/ServerDashboard/ServerDashboard.jsx +++ b/jsx/src/components/ServerDashboard/ServerDashboard.jsx @@ -1,5 +1,4 @@ import React, { useState } from "react"; -import regeneratorRuntime from "regenerator-runtime"; import { useSelector, useDispatch } from "react-redux"; import PropTypes from "prop-types"; @@ -90,7 +89,7 @@ const ServerDashboard = (props) => { if (page != user_page) { updateUsers(...slice).then((data) => - dispatchPageUpdate(data, page, name_filter) + dispatchPageUpdate(data.items, page, name_filter) ); } @@ -98,7 +97,7 @@ const ServerDashboard = (props) => { const handleSearch = debounce(async (event) => { // setNameFilter(event.target.value); updateUsers(page * limit, limit, event.target.value).then((data) => - dispatchPageUpdate(data, page, name_filter) + dispatchPageUpdate(data.items, page, name_filter) ); }, 300); @@ -119,7 +118,7 @@ const ServerDashboard = (props) => { if (res.status < 300) { updateUsers(...slice) .then((data) => { - dispatchPageUpdate(data, page, name_filter); + dispatchPageUpdate(data.items, page, name_filter); }) .catch(() => { setIsDisabled(false); @@ -155,7 +154,7 @@ const ServerDashboard = (props) => { if (res.status < 300) { updateUsers(...slice) .then((data) => { - dispatchPageUpdate(data, page, name_filter); + dispatchPageUpdate(data.items, page, name_filter); }) .catch(() => { setErrorAlert(`Failed to update users list.`); @@ -457,7 +456,7 @@ const ServerDashboard = (props) => { .then((res) => { updateUsers(...slice) .then((data) => { - dispatchPageUpdate(data, page, name_filter); + dispatchPageUpdate(data.items, page, name_filter); }) .catch(() => setErrorAlert(`Failed to update users list.`) @@ -493,7 +492,7 @@ const ServerDashboard = (props) => { .then((res) => { updateUsers(...slice) .then((data) => { - dispatchPageUpdate(data, page, name_filter); + dispatchPageUpdate(data.items, page, name_filter); }) .catch(() => setErrorAlert(`Failed to update users list.`) diff --git a/jsx/src/util/jhapiUtil.js b/jsx/src/util/jhapiUtil.js index c8959c10..2578519f 100644 --- a/jsx/src/util/jhapiUtil.js +++ b/jsx/src/util/jhapiUtil.js @@ -6,6 +6,7 @@ export const jhapiRequest = (endpoint, method, data) => { json: true, headers: { "Content-Type": "application/json", + Accept: "application/jupyterhub-pagination+json", }, body: data ? JSON.stringify(data) : null, });