Use data.items to display users

This commit is contained in:
Nathan Barber
2022-08-03 10:59:38 -04:00
parent 562a24b651
commit 33d4f382d5
3 changed files with 25 additions and 14 deletions

View File

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

View File

@@ -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.`)

View File

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