Fixed lint
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
parent
a6f4f6ff77
commit
67db3fdb76
@ -55,10 +55,14 @@ import {
|
|||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
||||||
import { DeviceRemoveButton } from "./devices";
|
import { DeviceRemoveButton } from "./devices";
|
||||||
import { ProtectMediaButton, QuarantineMediaButton, DeleteMediaBulkButton } from "./media";
|
import {
|
||||||
|
ProtectMediaButton,
|
||||||
|
QuarantineMediaButton,
|
||||||
|
DeleteMediaBulkButton,
|
||||||
|
} from "./media";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { TableHead, TableRow, TableCell, Checkbox } from '@material-ui/core';
|
import { TableHead, TableRow, TableCell, Checkbox } from "@material-ui/core";
|
||||||
import classnames from 'classnames';
|
import classnames from "classnames";
|
||||||
|
|
||||||
const redirect = () => {
|
const redirect = () => {
|
||||||
return {
|
return {
|
||||||
@ -321,8 +325,7 @@ const UserTitle = ({ record }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const UserMediaDatagridHeader = props => {
|
||||||
const UserMediaDatagridHeader = (props) => {
|
|
||||||
const {
|
const {
|
||||||
children,
|
children,
|
||||||
classes,
|
classes,
|
||||||
@ -332,115 +335,98 @@ const UserMediaDatagridHeader = (props) => {
|
|||||||
isRowSelectable,
|
isRowSelectable,
|
||||||
} = props;
|
} = props;
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
const {
|
const { currentSort, data, ids, onSelect, selectedIds, setSort } =
|
||||||
currentSort,
|
useListContext(props);
|
||||||
data,
|
|
||||||
ids,
|
|
||||||
onSelect,
|
|
||||||
selectedIds,
|
|
||||||
setSort,
|
|
||||||
} = useListContext(props);
|
|
||||||
|
|
||||||
const updateSortCallback = React.useCallback(
|
const updateSortCallback = React.useCallback(
|
||||||
event => {
|
event => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const newField = event.currentTarget.dataset.field;
|
const newField = event.currentTarget.dataset.field;
|
||||||
const newOrder =
|
const newOrder =
|
||||||
currentSort.field === newField
|
currentSort.field === newField
|
||||||
? currentSort.order === 'ASC'
|
? currentSort.order === "ASC"
|
||||||
? 'DESC'
|
? "DESC"
|
||||||
: 'ASC'
|
: "ASC"
|
||||||
: event.currentTarget.dataset.order;
|
: event.currentTarget.dataset.order;
|
||||||
|
|
||||||
setSort(newField, newOrder);
|
setSort(newField, newOrder);
|
||||||
},
|
},
|
||||||
[currentSort.field, currentSort.order, setSort]
|
[currentSort.field, currentSort.order, setSort]
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateSort = setSort ? updateSortCallback : null;
|
const updateSort = setSort ? updateSortCallback : null;
|
||||||
|
|
||||||
const handleSelectAll = React.useCallback(
|
const handleSelectAll = React.useCallback(
|
||||||
event => {
|
event => {
|
||||||
onSelect(
|
onSelect(
|
||||||
event.target.checked
|
event.target.checked
|
||||||
? ids
|
? ids
|
||||||
.filter(id =>
|
.filter(id =>
|
||||||
isRowSelectable ? isRowSelectable(data[id]) : true
|
isRowSelectable ? isRowSelectable(data[id]) : true
|
||||||
)
|
)
|
||||||
.concat(selectedIds.filter(id => !ids.includes(id)))
|
.concat(selectedIds.filter(id => !ids.includes(id)))
|
||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[data, ids, onSelect, isRowSelectable, selectedIds]
|
[data, ids, onSelect, isRowSelectable, selectedIds]
|
||||||
);
|
);
|
||||||
|
|
||||||
const selectableIds = isRowSelectable
|
const selectableIds = isRowSelectable
|
||||||
? ids.filter(id => isRowSelectable(data[id]))
|
? ids.filter(id => isRowSelectable(data[id]))
|
||||||
: ids;
|
: ids;
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableHead className={classnames(className, classes.thead)}>
|
<TableHead className={classnames(className, classes.thead)}>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={ children.length + 1}>
|
<TableCell colSpan={children.length + 1}>
|
||||||
<BulkActionsToolbar>
|
<BulkActionsToolbar>
|
||||||
<DeleteMediaBulkButton />
|
<DeleteMediaBulkButton />
|
||||||
</BulkActionsToolbar>
|
</BulkActionsToolbar>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow className={classnames(classes.row, classes.headerRow)}>
|
||||||
|
{hasExpand && (
|
||||||
|
<TableCell
|
||||||
|
padding="none"
|
||||||
|
className={classnames(classes.headerCell, classes.expandHeader)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{hasBulkActions && selectedIds && (
|
||||||
|
<TableCell padding="checkbox" className={classes.headerCell}>
|
||||||
|
<Checkbox
|
||||||
|
aria-label={translate("ra.action.select_all", {
|
||||||
|
_: "Select all",
|
||||||
|
})}
|
||||||
|
className="select-all"
|
||||||
|
color="primary"
|
||||||
|
checked={
|
||||||
|
selectedIds.length > 0 &&
|
||||||
|
selectableIds.length > 0 &&
|
||||||
|
selectableIds.every(id => selectedIds.includes(id))
|
||||||
|
}
|
||||||
|
onChange={handleSelectAll}
|
||||||
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
)}
|
||||||
<TableRow className={classnames(classes.row, classes.headerRow)}>
|
{React.Children.map(children, (field, index) =>
|
||||||
{hasExpand && (
|
React.isValidElement(field) ? (
|
||||||
<TableCell
|
<DatagridHeaderCell
|
||||||
padding="none"
|
className={classes.headerCell}
|
||||||
className={classnames(
|
currentSort={currentSort}
|
||||||
classes.headerCell,
|
field={field}
|
||||||
classes.expandHeader
|
isSorting={
|
||||||
)}
|
currentSort.field === (field.props.sortBy || field.props.source)
|
||||||
/>
|
}
|
||||||
)}
|
key={field.props.source || index}
|
||||||
{hasBulkActions && selectedIds && (
|
resource="users_media"
|
||||||
<TableCell
|
updateSort={updateSort}
|
||||||
padding="checkbox"
|
/>
|
||||||
className={classes.headerCell}
|
) : null
|
||||||
>
|
)}
|
||||||
<Checkbox
|
</TableRow>
|
||||||
aria-label={translate('ra.action.select_all', {
|
|
||||||
_: 'Select all',
|
|
||||||
})}
|
|
||||||
className="select-all"
|
|
||||||
color="primary"
|
|
||||||
checked={
|
|
||||||
selectedIds.length > 0 &&
|
|
||||||
selectableIds.length > 0 &&
|
|
||||||
selectableIds.every(id =>
|
|
||||||
selectedIds.includes(id)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onChange={handleSelectAll}
|
|
||||||
/>
|
|
||||||
</TableCell>
|
|
||||||
)}
|
|
||||||
{React.Children.map(children, (field, index) =>
|
|
||||||
React.isValidElement(field) ? (
|
|
||||||
<DatagridHeaderCell
|
|
||||||
className={classes.headerCell}
|
|
||||||
currentSort={currentSort}
|
|
||||||
field={field}
|
|
||||||
isSorting={
|
|
||||||
currentSort.field ===
|
|
||||||
((field.props).sortBy ||
|
|
||||||
(field.props).source)
|
|
||||||
}
|
|
||||||
key={(field.props).source || index}
|
|
||||||
resource="users_media"
|
|
||||||
updateSort={updateSort}
|
|
||||||
/>
|
|
||||||
) : null
|
|
||||||
)}
|
|
||||||
</TableRow>
|
|
||||||
</TableHead>
|
</TableHead>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const UserEdit = props => {
|
export const UserEdit = props => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
@ -604,18 +590,32 @@ export const UserEdit = props => {
|
|||||||
<Datagrid
|
<Datagrid
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
hasBulkActions={true}
|
hasBulkActions={true}
|
||||||
header={<UserMediaDatagridHeader/>}
|
header={<UserMediaDatagridHeader />}
|
||||||
>
|
>
|
||||||
<FunctionField
|
<FunctionField
|
||||||
label="Image"
|
label="Image"
|
||||||
render={record => {
|
render={record => {
|
||||||
let data = {
|
let data = {
|
||||||
title: record.upload_name,
|
title: record.upload_name,
|
||||||
imgURL: `${localStorage.getItem("base_url")}/_matrix/media/v1/thumbnail/${localStorage.getItem("home_server")}/${record.media_id}?width=50&height=50&method=crop`,
|
imgURL: `${localStorage.getItem(
|
||||||
downloadURL: `${localStorage.getItem("base_url")}/_matrix/media/r0/download/${localStorage.getItem("home_server")}/${record.media_id}`,
|
"base_url"
|
||||||
}
|
)}/_matrix/media/v1/thumbnail/${localStorage.getItem(
|
||||||
|
"home_server"
|
||||||
|
)}/${record.media_id}?width=50&height=50&method=crop`,
|
||||||
|
downloadURL: `${localStorage.getItem(
|
||||||
|
"base_url"
|
||||||
|
)}/_matrix/media/r0/download/${localStorage.getItem(
|
||||||
|
"home_server"
|
||||||
|
)}/${record.media_id}`,
|
||||||
|
};
|
||||||
if (record.media_type.startsWith("image")) {
|
if (record.media_type.startsWith("image")) {
|
||||||
return <ImageField record={data} source="imgURL" onClick={() => window.open(data.downloadURL)} />
|
return (
|
||||||
|
<ImageField
|
||||||
|
record={data}
|
||||||
|
source="imgURL"
|
||||||
|
onClick={() => window.open(data.downloadURL)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return "Preview unavailable";
|
return "Preview unavailable";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user