Merge branch 'master' into add_mui5

This commit is contained in:
Dirk Klimpel 2023-01-24 15:59:39 +01:00 committed by GitHub
commit 73952aa9eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 47 deletions

View File

@ -169,7 +169,7 @@ const LoginPage = ({ theme }) => {
: typeof error === "undefined" || !error.message : typeof error === "undefined" || !error.message
? "ra.auth.sign_in_error" ? "ra.auth.sign_in_error"
: error.message, : error.message,
"warning" { type: "warning" }
); );
}); });
}; };

View File

@ -86,7 +86,9 @@ export const RoomDirectoryBulkSaveButton = ({ selectedIds }) => {
refresh(); refresh();
}, },
onFailure: error => onFailure: error =>
notify("resources.room_directory.action.send_failure", "error"), notify("resources.room_directory.action.send_failure", {
type: "error",
}),
} }
); );
}; };
@ -118,7 +120,9 @@ export const RoomDirectorySaveButton = ({ record }) => {
refresh(); refresh();
}, },
onFailure: error => onFailure: error =>
notify("resources.room_directory.action.send_failure", "error"), notify("resources.room_directory.action.send_failure", {
type: "error",
}),
} }
); );
}; };

View File

@ -83,7 +83,9 @@ export const ServerNoticeButton = ({ record }) => {
handleDialogClose(); handleDialogClose();
}, },
onFailure: () => onFailure: () =>
notify("resources.servernotices.action.send_failure", "error"), notify("resources.servernotices.action.send_failure", {
type: "error",
}),
} }
); );
}; };
@ -129,7 +131,9 @@ export const ServerNoticeBulkButton = ({ selectedIds }) => {
handleDialogClose(); handleDialogClose();
}, },
onFailure: error => onFailure: error =>
notify("resources.servernotices.action.send_failure", "error"), notify("resources.servernotices.action.send_failure", {
type: "error",
}),
} }
); );
}; };

View File

@ -1,11 +1,5 @@
import React, { Fragment, useState } from "react"; import React, { Fragment, useState } from "react";
import { import { Button, useDelete, useNotify, Confirm, useRefresh } from "react-admin";
Button,
useMutation,
useNotify,
Confirm,
useRefresh,
} from "react-admin";
import ActionDelete from "@mui/icons-material/Delete"; import ActionDelete from "@mui/icons-material/Delete";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import { alpha } from "@mui/material/styles"; import { alpha } from "@mui/material/styles";
@ -34,7 +28,7 @@ export const DeviceRemoveButton = props => {
const refresh = useRefresh(); const refresh = useRefresh();
const notify = useNotify(); const notify = useNotify();
const [removeDevice, { loading }] = useMutation(); const [removeDevice, { isLoading }] = useDelete("devices");
if (!record) return null; if (!record) return null;
@ -43,21 +37,15 @@ export const DeviceRemoveButton = props => {
const handleConfirm = () => { const handleConfirm = () => {
removeDevice( removeDevice(
{ { payload: { id: record.id, user_id: record.user_id } },
type: "delete",
resource: "devices",
payload: {
id: record.id,
user_id: record.user_id,
},
},
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.devices.action.erase.success"); notify("resources.devices.action.erase.success");
refresh(); refresh();
}, },
onFailure: () => onFailure: () => {
notify("resources.devices.action.erase.failure", "error"), notify("resources.devices.action.erase.failure", { type: "error" });
},
} }
); );
setOpen(false); setOpen(false);
@ -74,7 +62,7 @@ export const DeviceRemoveButton = props => {
</Button> </Button>
<Confirm <Confirm
isOpen={open} isOpen={open}
loading={loading} loading={isLoading}
onConfirm={handleConfirm} onConfirm={handleConfirm}
onClose={handleDialogClose} onClose={handleDialogClose}
title="resources.devices.action.erase.title" title="resources.devices.action.erase.title"

View File

@ -129,7 +129,9 @@ export const DeleteMediaButton = props => {
handleDialogClose(); handleDialogClose();
}, },
onFailure: () => onFailure: () =>
notify("resources.delete_media.action.send_failure", "error"), notify("resources.delete_media.action.send_failure", {
type: "error",
}),
} }
); );
}; };
@ -172,7 +174,9 @@ export const ProtectMediaButton = props => {
refresh(); refresh();
}, },
onFailure: () => onFailure: () =>
notify("resources.protect_media.action.send_failure", "error"), notify("resources.protect_media.action.send_failure", {
type: "error",
}),
} }
); );
}; };
@ -186,7 +190,9 @@ export const ProtectMediaButton = props => {
refresh(); refresh();
}, },
onFailure: () => onFailure: () =>
notify("resources.protect_media.action.send_failure", "error"), notify("resources.protect_media.action.send_failure", {
type: "error",
}),
} }
); );
}; };
@ -264,7 +270,9 @@ export const QuarantineMediaButton = props => {
refresh(); refresh();
}, },
onFailure: () => onFailure: () =>
notify("resources.quarantine_media.action.send_failure", "error"), notify("resources.quarantine_media.action.send_failure", {
type: "error",
}),
} }
); );
}; };
@ -278,7 +286,9 @@ export const QuarantineMediaButton = props => {
refresh(); refresh();
}, },
onFailure: () => onFailure: () =>
notify("resources.quarantine_media.action.send_failure", "error"), notify("resources.quarantine_media.action.send_failure", {
type: "error",
}),
} }
); );
}; };

View File

@ -41,14 +41,16 @@ const resourceMap = {
data: "users", data: "users",
total: json => json.total, total: json => json.total,
create: data => ({ create: data => ({
endpoint: `/_synapse/admin/v2/users/@${data.id}:${localStorage.getItem( endpoint: `/_synapse/admin/v2/users/@${encodeURIComponent(
"home_server" data.id
)}`, )}:${localStorage.getItem("home_server")}`,
body: data, body: data,
method: "PUT", method: "PUT",
}), }),
delete: params => ({ delete: params => ({
endpoint: `/_synapse/admin/v1/deactivate/${params.id}`, endpoint: `/_synapse/admin/v1/deactivate/${encodeURIComponent(
params.id
)}`,
body: { erase: true }, body: { erase: true },
method: "POST", method: "POST",
}), }),
@ -92,10 +94,12 @@ const resourceMap = {
return json.total; return json.total;
}, },
reference: id => ({ reference: id => ({
endpoint: `/_synapse/admin/v2/users/${id}/devices`, endpoint: `/_synapse/admin/v2/users/${encodeURIComponent(id)}/devices`,
}), }),
delete: params => ({ delete: params => ({
endpoint: `/_synapse/admin/v2/users/${params.user_id}/devices/${params.id}`, endpoint: `/_synapse/admin/v2/users/${encodeURIComponent(
params.user_id
)}/devices/${params.id}`,
}), }),
}, },
connections: { connections: {
@ -137,7 +141,7 @@ const resourceMap = {
id: p.pushkey, id: p.pushkey,
}), }),
reference: id => ({ reference: id => ({
endpoint: `/_synapse/admin/v1/users/${id}/pushers`, endpoint: `/_synapse/admin/v1/users/${encodeURIComponent(id)}/pushers`,
}), }),
data: "pushers", data: "pushers",
total: json => { total: json => {
@ -149,7 +153,9 @@ const resourceMap = {
id: jr, id: jr,
}), }),
reference: id => ({ reference: id => ({
endpoint: `/_synapse/admin/v1/users/${id}/joined_rooms`, endpoint: `/_synapse/admin/v1/users/${encodeURIComponent(
id
)}/joined_rooms`,
}), }),
data: "joined_rooms", data: "joined_rooms",
total: json => { total: json => {
@ -162,7 +168,7 @@ const resourceMap = {
id: um.media_id, id: um.media_id,
}), }),
reference: id => ({ reference: id => ({
endpoint: `/_synapse/admin/v1/users/${id}/media`, endpoint: `/_synapse/admin/v1/users/${encodeURIComponent(id)}/media`,
}), }),
data: "media", data: "media",
total: json => { total: json => {
@ -355,9 +361,11 @@ const dataProvider = {
const res = resourceMap[resource]; const res = resourceMap[resource];
const endpoint_url = homeserver + res.path; const endpoint_url = homeserver + res.path;
return jsonClient(`${endpoint_url}/${params.id}`).then(({ json }) => ({ return jsonClient(`${endpoint_url}/${encodeURIComponent(params.id)}`).then(
data: res.map(json), ({ json }) => ({
})); data: res.map(json),
})
);
}, },
getMany: (resource, params) => { getMany: (resource, params) => {
@ -369,7 +377,9 @@ const dataProvider = {
const endpoint_url = homeserver + res.path; const endpoint_url = homeserver + res.path;
return Promise.all( return Promise.all(
params.ids.map(id => jsonClient(`${endpoint_url}/${id}`)) params.ids.map(id =>
jsonClient(`${endpoint_url}/${encodeURIComponent(id)}`)
)
).then(responses => ({ ).then(responses => ({
data: responses.map(({ json }) => res.map(json)), data: responses.map(({ json }) => res.map(json)),
total: responses.length, total: responses.length,
@ -410,7 +420,7 @@ const dataProvider = {
const res = resourceMap[resource]; const res = resourceMap[resource];
const endpoint_url = homeserver + res.path; const endpoint_url = homeserver + res.path;
return jsonClient(`${endpoint_url}/${params.data.id}`, { return jsonClient(`${endpoint_url}/${encodeURIComponent(params.data.id)}`, {
method: "PUT", method: "PUT",
body: JSON.stringify(params.data, filterNullValues), body: JSON.stringify(params.data, filterNullValues),
}).then(({ json }) => ({ }).then(({ json }) => ({
@ -427,10 +437,13 @@ const dataProvider = {
const endpoint_url = homeserver + res.path; const endpoint_url = homeserver + res.path;
return Promise.all( return Promise.all(
params.ids.map(id => jsonClient(`${endpoint_url}/${id}`), { params.ids.map(
method: "PUT", id => jsonClient(`${endpoint_url}/${encodeURIComponent(id)}`),
body: JSON.stringify(params.data, filterNullValues), {
}) method: "PUT",
body: JSON.stringify(params.data, filterNullValues),
}
)
).then(responses => ({ ).then(responses => ({
data: responses.map(({ json }) => json), data: responses.map(({ json }) => json),
})); }));