Allow changing playlist's owner. Relates to #698
This commit is contained in:
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
|
|||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { setOmittedFields, setToggleableFields } from '../actions'
|
import { setOmittedFields, setToggleableFields } from '../actions'
|
||||||
|
|
||||||
|
// TODO Refactor
|
||||||
export const useSelectedFields = ({
|
export const useSelectedFields = ({
|
||||||
resource,
|
resource,
|
||||||
columns,
|
columns,
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import {
|
|||||||
BooleanInput,
|
BooleanInput,
|
||||||
required,
|
required,
|
||||||
useTranslate,
|
useTranslate,
|
||||||
|
usePermissions,
|
||||||
|
ReferenceInput,
|
||||||
|
SelectInput,
|
||||||
} from 'react-admin'
|
} from 'react-admin'
|
||||||
import { isSmartPlaylist, isWritable, Title } from '../common'
|
import { isSmartPlaylist, isWritable, Title } from '../common'
|
||||||
|
|
||||||
@@ -29,10 +32,26 @@ const PlaylistTitle = ({ record }) => {
|
|||||||
|
|
||||||
const PlaylistEditForm = (props) => {
|
const PlaylistEditForm = (props) => {
|
||||||
const { record } = props
|
const { record } = props
|
||||||
|
const { permissions } = usePermissions()
|
||||||
return (
|
return (
|
||||||
<SimpleForm redirect="list" variant={'outlined'} {...props}>
|
<SimpleForm redirect="list" variant={'outlined'} {...props}>
|
||||||
<TextInput source="name" validate={required()} />
|
<TextInput source="name" validate={required()} />
|
||||||
<TextInput multiline source="comment" />
|
<TextInput multiline source="comment" />
|
||||||
|
{permissions === 'admin' ? (
|
||||||
|
<ReferenceInput
|
||||||
|
source="ownerId"
|
||||||
|
reference="user"
|
||||||
|
perPage={0}
|
||||||
|
sort={{ field: 'name', order: 'ASC' }}
|
||||||
|
>
|
||||||
|
<SelectInput
|
||||||
|
label={'resources.playlist.fields.ownerName'}
|
||||||
|
optionText="userName"
|
||||||
|
/>
|
||||||
|
</ReferenceInput>
|
||||||
|
) : (
|
||||||
|
<TextField source="ownerName" />
|
||||||
|
)}
|
||||||
<BooleanInput
|
<BooleanInput
|
||||||
source="public"
|
source="public"
|
||||||
disabled={!isWritable(record.ownerId) || isSmartPlaylist(record)}
|
disabled={!isWritable(record.ownerId) || isSmartPlaylist(record)}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import {
|
|||||||
EditButton,
|
EditButton,
|
||||||
Filter,
|
Filter,
|
||||||
NumberField,
|
NumberField,
|
||||||
|
ReferenceInput,
|
||||||
SearchInput,
|
SearchInput,
|
||||||
|
SelectInput,
|
||||||
TextField,
|
TextField,
|
||||||
useUpdate,
|
useUpdate,
|
||||||
useNotify,
|
useNotify,
|
||||||
@@ -27,6 +29,15 @@ import PlaylistListActions from './PlaylistListActions'
|
|||||||
const PlaylistFilter = (props) => (
|
const PlaylistFilter = (props) => (
|
||||||
<Filter {...props} variant={'outlined'}>
|
<Filter {...props} variant={'outlined'}>
|
||||||
<SearchInput source="q" alwaysOn />
|
<SearchInput source="q" alwaysOn />
|
||||||
|
<ReferenceInput
|
||||||
|
source="owner_id"
|
||||||
|
reference="user"
|
||||||
|
perPage={0}
|
||||||
|
sort={{ field: 'name', order: 'ASC' }}
|
||||||
|
alwaysOn
|
||||||
|
>
|
||||||
|
<SelectInput optionText="name" />
|
||||||
|
</ReferenceInput>
|
||||||
</Filter>
|
</Filter>
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,8 +79,8 @@ const PlaylistList = (props) => {
|
|||||||
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
|
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
|
||||||
useResourceRefresh('playlist')
|
useResourceRefresh('playlist')
|
||||||
|
|
||||||
const toggleableFields = useMemo(() => {
|
const toggleableFields = useMemo(
|
||||||
return {
|
() => ({
|
||||||
ownerName: <TextField source="ownerName" />,
|
ownerName: <TextField source="ownerName" />,
|
||||||
songCount: isDesktop && <NumberField source="songCount" />,
|
songCount: isDesktop && <NumberField source="songCount" />,
|
||||||
duration: isDesktop && <DurationField source="duration" />,
|
duration: isDesktop && <DurationField source="duration" />,
|
||||||
@@ -79,8 +90,9 @@ const PlaylistList = (props) => {
|
|||||||
public: !isXsmall && (
|
public: !isXsmall && (
|
||||||
<TogglePublicInput source="public" sortByOrder={'DESC'} />
|
<TogglePublicInput source="public" sortByOrder={'DESC'} />
|
||||||
),
|
),
|
||||||
}
|
}),
|
||||||
}, [isDesktop, isXsmall])
|
[isDesktop, isXsmall]
|
||||||
|
)
|
||||||
|
|
||||||
const columns = useSelectedFields({
|
const columns = useSelectedFields({
|
||||||
resource: 'playlist',
|
resource: 'playlist',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, { cloneElement } from 'react'
|
||||||
import {
|
import {
|
||||||
sanitizeListRestProps,
|
sanitizeListRestProps,
|
||||||
TopToolbar,
|
TopToolbar,
|
||||||
@@ -14,6 +14,7 @@ const PlaylistListActions = ({ className, ...rest }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
|
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
|
||||||
|
{cloneElement(rest.filters, { context: 'button' })}
|
||||||
<CreateButton basePath="/playlist">
|
<CreateButton basePath="/playlist">
|
||||||
{translate('ra.action.create')}
|
{translate('ra.action.create')}
|
||||||
</CreateButton>
|
</CreateButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user