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, TabbedShowLayout,
TextField, TextField,
TopToolbar, TopToolbar,
useRecordContext,
useTranslate, useTranslate,
} from "react-admin"; } from "react-admin";
import get from "lodash/get"; import get from "lodash/get";
import PropTypes from "prop-types";
import { Tooltip, Typography, Chip } from "@material-ui/core"; import { Tooltip, Typography, Chip } from "@material-ui/core";
import HttpsIcon from "@material-ui/icons/Https"; import HttpsIcon from "@material-ui/icons/Https";
import NoEncryptionIcon from "@material-ui/icons/NoEncryption"; 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 FilterableRoomList = ({ roomFilters, dispatch, ...props }) => {
const filter = roomFilters; const filter = roomFilters;
const localMembersFilter = const localMembersFilter =
@ -327,7 +343,7 @@ const FilterableRoomList = ({ roomFilters, dispatch, ...props }) => {
sortBy="encryption" sortBy="encryption"
label={<HttpsIcon />} label={<HttpsIcon />}
/> />
<TextField source="name" /> <RoomNameField source="name" />
<TextField source="joined_members" /> <TextField source="joined_members" />
{localMembersFilter && <TextField source="joined_local_members" />} {localMembersFilter && <TextField source="joined_local_members" />}
{stateEventsFilter && <TextField source="state_events" />} {stateEventsFilter && <TextField source="state_events" />}