Replace ({ record }) with useRecordContext() (#236)

* replace `({ record })` with `useRecordContext()`

* code style

Co-authored-by: Michael Albert <37796947+awesome-michael@users.noreply.github.com>
This commit is contained in:
Dirk Klimpel 2023-01-24 16:36:08 +01:00 committed by GitHub
parent 8501f19a03
commit 74f77e6988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 9 deletions

View File

@ -19,6 +19,7 @@ import {
useMutation, useMutation,
useNotify, useNotify,
useTranslate, useTranslate,
useRecordContext,
useRefresh, useRefresh,
useUnselectAll, useUnselectAll,
} from "react-admin"; } from "react-admin";
@ -105,7 +106,8 @@ export const RoomDirectoryBulkSaveButton = ({ selectedIds }) => {
); );
}; };
export const RoomDirectorySaveButton = ({ record }) => { export const RoomDirectorySaveButton = props => {
const record = useRecordContext();
const notify = useNotify(); const notify = useNotify();
const refresh = useRefresh(); const refresh = useRefresh();
const [create, { loading }] = useCreate("room_directory"); const [create, { loading }] = useCreate("room_directory");

View File

@ -9,6 +9,7 @@ import {
useCreate, useCreate,
useMutation, useMutation,
useNotify, useNotify,
useRecordContext,
useTranslate, useTranslate,
useUnselectAll, useUnselectAll,
} from "react-admin"; } from "react-admin";
@ -64,7 +65,8 @@ const ServerNoticeDialog = ({ open, loading, onClose, onSend }) => {
); );
}; };
export const ServerNoticeButton = ({ record }) => { export const ServerNoticeButton = props => {
const record = useRecordContext();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const notify = useNotify(); const notify = useNotify();
const [create, { loading }] = useCreate("servernotices"); const [create, { loading }] = useCreate("servernotices");

View File

@ -1,5 +1,12 @@
import React, { Fragment, useState } from "react"; import React, { Fragment, useState } from "react";
import { Button, useDelete, useNotify, Confirm, useRefresh } from "react-admin"; import {
Button,
useDelete,
useNotify,
Confirm,
useRecordContext,
useRefresh,
} from "react-admin";
import ActionDelete from "@material-ui/icons/Delete"; import ActionDelete from "@material-ui/icons/Delete";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import { alpha } from "@material-ui/core/styles/colorManipulator"; import { alpha } from "@material-ui/core/styles/colorManipulator";
@ -22,7 +29,7 @@ const useStyles = makeStyles(
); );
export const DeviceRemoveButton = props => { export const DeviceRemoveButton = props => {
const { record } = props; const record = useRecordContext();
const classes = useStyles(props); const classes = useStyles(props);
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const refresh = useRefresh(); const refresh = useRefresh();

View File

@ -14,6 +14,7 @@ import {
useCreate, useCreate,
useDelete, useDelete,
useNotify, useNotify,
useRecordContext,
useRefresh, useRefresh,
useTranslate, useTranslate,
} from "react-admin"; } from "react-admin";
@ -154,7 +155,7 @@ export const DeleteMediaButton = props => {
}; };
export const ProtectMediaButton = props => { export const ProtectMediaButton = props => {
const { record } = props; const record = useRecordContext();
const translate = useTranslate(); const translate = useTranslate();
const refresh = useRefresh(); const refresh = useRefresh();
const notify = useNotify(); const notify = useNotify();
@ -250,7 +251,7 @@ export const ProtectMediaButton = props => {
}; };
export const QuarantineMediaButton = props => { export const QuarantineMediaButton = props => {
const { record } = props; const record = useRecordContext();
const translate = useTranslate(); const translate = useTranslate();
const refresh = useRefresh(); const refresh = useRefresh();
const notify = useNotify(); const notify = useNotify();

View File

@ -87,7 +87,8 @@ const EncryptionField = ({ source, record = {}, emptyText }) => {
); );
}; };
const RoomTitle = ({ record }) => { const RoomTitle = props => {
const record = useRecordContext();
const translate = useTranslate(); const translate = useTranslate();
var name = ""; var name = "";
if (record) { if (record) {
@ -354,7 +355,7 @@ const RoomFilter = ({ ...props }) => {
const RoomNameField = props => { const RoomNameField = props => {
const { source } = props; const { source } = props;
const record = useRecordContext(props); const record = useRecordContext();
return ( return (
<span>{record[source] || record["canonical_alias"] || record["id"]}</span> <span>{record[source] || record["canonical_alias"] || record["id"]}</span>
); );

View File

@ -39,6 +39,7 @@ import {
maxLength, maxLength,
regex, regex,
required, required,
useRecordContext,
useTranslate, useTranslate,
Pagination, Pagination,
CreateButton, CreateButton,
@ -329,7 +330,8 @@ export const UserCreate = props => (
</Create> </Create>
); );
const UserTitle = ({ record }) => { const UserTitle = props => {
const record = useRecordContext();
const translate = useTranslate(); const translate = useTranslate();
return ( return (
<span> <span>