Add SearchInput to users and rooms

Add filter to search in `user_id` and room name.
This commit is contained in:
dklimpel 2020-05-26 18:41:46 +02:00
parent 0ada5287d7
commit a9477c6d97
3 changed files with 28 additions and 4 deletions

View File

@ -1,12 +1,25 @@
import React from "react"; import React from "react";
import { Datagrid, List, TextField, Pagination } from "react-admin"; import {
Datagrid,
List,
TextField,
Pagination,
Filter,
SearchInput,
} from "react-admin";
const RoomPagination = props => ( const RoomPagination = props => (
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} /> <Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
); );
const RoomFilter = props => (
<Filter {...props}>
<SearchInput source="search_term" alwaysOn />
</Filter>
);
export const RoomList = props => ( export const RoomList = props => (
<List {...props} pagination={<RoomPagination />}> <List {...props} pagination={<RoomPagination />} filters={<RoomFilter />}>
<Datagrid> <Datagrid>
<TextField source="room_id" /> <TextField source="room_id" />
<TextField source="name" /> <TextField source="name" />

View File

@ -29,6 +29,7 @@ import {
regex, regex,
useTranslate, useTranslate,
Pagination, Pagination,
SearchInput,
} from "react-admin"; } from "react-admin";
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices"; import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
@ -38,6 +39,7 @@ const UserPagination = props => (
const UserFilter = props => ( const UserFilter = props => (
<Filter {...props}> <Filter {...props}>
<SearchInput source="user_id" alwaysOn />
<BooleanInput source="guests" alwaysOn /> <BooleanInput source="guests" alwaysOn />
<BooleanInput <BooleanInput
label="resources.users.fields.show_deactivated" label="resources.users.fields.show_deactivated"

View File

@ -86,18 +86,27 @@ function filterNullValues(key, value) {
return value; return value;
} }
function getEncodeURI(value) {
// encodeURI if 'value' is set
if (value) {
return encodeURI(value);
}
return undefined;
}
const dataProvider = { const dataProvider = {
getList: (resource, params) => { getList: (resource, params) => {
console.log("getList " + resource); console.log("getList " + resource);
const { user_id, guests, deactivated } = params.filter; const { user_id, guests, deactivated, search_term } = params.filter;
const { page, perPage } = params.pagination; const { page, perPage } = params.pagination;
const from = (page - 1) * perPage; const from = (page - 1) * perPage;
const query = { const query = {
from: from, from: from,
limit: perPage, limit: perPage,
user_id: user_id, user_id: getEncodeURI(user_id),
guests: guests, guests: guests,
deactivated: deactivated, deactivated: deactivated,
search_term: getEncodeURI(search_term),
}; };
const homeserver = localStorage.getItem("base_url"); const homeserver = localStorage.getItem("base_url");
if (!homeserver || !(resource in resourceMap)) return Promise.reject(); if (!homeserver || !(resource in resourceMap)) return Promise.reject();