make avatar field sortable in the users list

This commit is contained in:
Aine
2024-10-08 12:15:03 +03:00
parent ba485bbb18
commit 0594259ae4
3 changed files with 14 additions and 13 deletions

View File

@@ -25,11 +25,15 @@ run-dev:
stop-dev: stop-dev:
@docker-compose -f docker-compose-dev.yml stop @docker-compose -f docker-compose-dev.yml stop
# register a user in the dev stack
register-user localpart password *admin: register-user localpart password *admin:
docker-compose exec synapse register_new_matrix_user {{ if admin == "1" {"--admin"} else {"--no-admin"} }} -u {{ localpart }} -p {{ password }} -c /config/homeserver.yaml http://localhost:8008 docker-compose exec synapse register_new_matrix_user {{ if admin == "1" {"--admin"} else {"--no-admin"} }} -u {{ localpart }} -p {{ password }} -c /config/homeserver.yaml http://localhost:8008
# run yarn {fix,lint,test} commands
test:
@-yarn run fix
@-yarn run lint
@-yarn run test
# run the app in a production mode # run the app in a production mode
run-prod: build run-prod: build

View File

@@ -1,12 +1,11 @@
import { get } from "lodash"; import { get } from "lodash";
import { Avatar, AvatarProps } from "@mui/material"; import { Avatar, AvatarProps } from "@mui/material";
import { useRecordContext } from "react-admin"; import { FieldProps, useRecordContext } from "react-admin";
import { useState, useEffect, useCallback } from "react"; import { useState, useEffect, useCallback } from "react";
import { fetchAuthenticatedMedia } from "../utils/fetchMedia"; import { fetchAuthenticatedMedia } from "../utils/fetchMedia";
const AvatarField = ({ source, ...rest }: AvatarProps & { source: string, label?: string }) => { const AvatarField = ({ source, ...rest }: AvatarProps & FieldProps) => {
const { alt, classes, sizes, sx, variant } = rest; const { alt, classes, sizes, sx, variant } = rest;
const record = useRecordContext(rest); const record = useRecordContext(rest);
const mxcURL = get(record, source)?.toString(); const mxcURL = get(record, source)?.toString();

View File

@@ -51,6 +51,7 @@ import {
NumberField, NumberField,
useListContext, useListContext,
useNotify, useNotify,
Identifier,
ToolbarClasses, ToolbarClasses,
RaRecord, RaRecord,
ImageInput, ImageInput,
@@ -146,10 +147,6 @@ const UserBulkActionButtons = () => {
); );
}; };
const usersRowClick = (id: Identifier, resource: string, record: RaRecord): string => {
return `/users/${id}`;
};
export const UserList = (props: ListProps) => ( export const UserList = (props: ListProps) => (
<List <List
{...props} {...props}
@@ -159,7 +156,10 @@ export const UserList = (props: ListProps) => (
actions={<UserListActions />} actions={<UserListActions />}
pagination={<UserPagination />} pagination={<UserPagination />}
> >
<Datagrid rowClick={usersRowClick} bulkActionButtons={<UserBulkActionButtons />}> <Datagrid
rowClick={(id: Identifier, resource: string) => `/${resource}/${id}`}
bulkActionButtons={<UserBulkActionButtons />}
>
<AvatarField source="avatar_src" sx={{ height: "40px", width: "40px" }} sortBy="avatar_url" /> <AvatarField source="avatar_src" sx={{ height: "40px", width: "40px" }} sortBy="avatar_url" />
<TextField source="id" sortBy="name" /> <TextField source="id" sortBy="name" />
<TextField source="displayname" /> <TextField source="displayname" />
@@ -211,9 +211,7 @@ const UserEditActions = () => {
export const UserCreate = (props: CreateProps) => ( export const UserCreate = (props: CreateProps) => (
<Create <Create
{...props} {...props}
redirect={(resource: string | undefined, id: Identifier | undefined) => { redirect={(resource: string | undefined, id: Identifier | undefined) => `${resource}/${id}`}
return `users/${id}`;
}}
> >
<SimpleForm> <SimpleForm>
<TextInput source="id" autoComplete="off" validate={validateUser} /> <TextInput source="id" autoComplete="off" validate={validateUser} />