Show room alias or room id in room list if room has no name

Change-Id: Iad769f31347566ccf0b8a978b31f5123553e9dbc
This commit is contained in:
Manuel Stahl 2021-05-05 20:24:15 +02:00
parent 5a5a7143af
commit 229518e456

View file

@ -18,9 +18,11 @@ import {
TabbedShowLayout,
TextField,
TopToolbar,
useRecordContext,
useTranslate,
} from "react-admin";
import get from "lodash/get";
import PropTypes from "prop-types";
import { Tooltip, Typography, Chip } from "@material-ui/core";
import HttpsIcon from "@material-ui/icons/Https";
import NoEncryptionIcon from "@material-ui/icons/NoEncryption";
@ -305,6 +307,20 @@ const RoomFilter = ({ ...props }) => {
);
};
const RoomNameField = props => {
const { source } = props;
const record = useRecordContext(props);
return (
<span>{record[source] || record["canonical_alias"] || record["id"]}</span>
);
};
RoomNameField.propTypes = {
label: PropTypes.string,
record: PropTypes.object,
source: PropTypes.string.isRequired,
};
const FilterableRoomList = ({ roomFilters, dispatch, ...props }) => {
const filter = roomFilters;
const localMembersFilter =
@ -327,7 +343,7 @@ const FilterableRoomList = ({ roomFilters, dispatch, ...props }) => {
sortBy="encryption"
label={<HttpsIcon />}
/>
<TextField source="name" />
<RoomNameField source="name" />
<TextField source="joined_members" />
{localMembersFilter && <TextField source="joined_local_members" />}
{stateEventsFilter && <TextField source="state_events" />}