mirror of
https://github.com/strapi/strapi.git
synced 2025-11-24 22:21:38 +00:00
Merge pull request #14974 from strapi/ML-listview/permissions
[features][ML listview] Permissions checboxes
This commit is contained in:
commit
7c4b0e1bd1
@ -19,7 +19,14 @@ import { CellContent } from './CellContent';
|
|||||||
import { AssetDefinition, FolderDefinition, tableHeaders as cells } from '../../constants';
|
import { AssetDefinition, FolderDefinition, tableHeaders as cells } from '../../constants';
|
||||||
import { getFolderURL, getTrad } from '../../utils';
|
import { getFolderURL, getTrad } from '../../utils';
|
||||||
|
|
||||||
export const TableRows = ({ onEditAsset, onEditFolder, onSelectOne, rows, selected }) => {
|
export const TableRows = ({
|
||||||
|
canUpdate,
|
||||||
|
onEditAsset,
|
||||||
|
onEditFolder,
|
||||||
|
onSelectOne,
|
||||||
|
rows,
|
||||||
|
selected,
|
||||||
|
}) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const [{ query }] = useQueryParams();
|
const [{ query }] = useQueryParams();
|
||||||
@ -57,6 +64,7 @@ export const TableRows = ({ onEditAsset, onEditFolder, onSelectOne, rows, select
|
|||||||
},
|
},
|
||||||
{ name }
|
{ name }
|
||||||
)}
|
)}
|
||||||
|
disabled={!canUpdate}
|
||||||
onValueChange={() => onSelectOne(element)}
|
onValueChange={() => onSelectOne(element)}
|
||||||
checked={isSelected}
|
checked={isSelected}
|
||||||
/>
|
/>
|
||||||
@ -115,11 +123,13 @@ export const TableRows = ({ onEditAsset, onEditFolder, onSelectOne, rows, select
|
|||||||
};
|
};
|
||||||
|
|
||||||
TableRows.defaultProps = {
|
TableRows.defaultProps = {
|
||||||
|
canUpdate: false,
|
||||||
rows: [],
|
rows: [],
|
||||||
selected: [],
|
selected: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
TableRows.propTypes = {
|
TableRows.propTypes = {
|
||||||
|
canUpdate: PropTypes.bool,
|
||||||
rows: PropTypes.arrayOf(AssetDefinition, FolderDefinition),
|
rows: PropTypes.arrayOf(AssetDefinition, FolderDefinition),
|
||||||
onEditAsset: PropTypes.func.isRequired,
|
onEditAsset: PropTypes.func.isRequired,
|
||||||
onEditFolder: PropTypes.func.isRequired,
|
onEditFolder: PropTypes.func.isRequired,
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import { TableRows } from './TableRows';
|
|||||||
|
|
||||||
export const TableList = ({
|
export const TableList = ({
|
||||||
assetCount,
|
assetCount,
|
||||||
|
canUpdate,
|
||||||
folderCount,
|
folderCount,
|
||||||
indeterminate,
|
indeterminate,
|
||||||
onChangeSort,
|
onChangeSort,
|
||||||
@ -46,6 +47,7 @@ export const TableList = ({
|
|||||||
id: getTrad('bulk.select.label'),
|
id: getTrad('bulk.select.label'),
|
||||||
defaultMessage: 'Select all folders & assets',
|
defaultMessage: 'Select all folders & assets',
|
||||||
})}
|
})}
|
||||||
|
disabled={!canUpdate}
|
||||||
indeterminate={indeterminate}
|
indeterminate={indeterminate}
|
||||||
onChange={(e) => onSelectAll(e, rows)}
|
onChange={(e) => onSelectAll(e, rows)}
|
||||||
value={
|
value={
|
||||||
@ -108,6 +110,7 @@ export const TableList = ({
|
|||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<TableRows
|
<TableRows
|
||||||
|
canUpdate={canUpdate}
|
||||||
onEditAsset={onEditAsset}
|
onEditAsset={onEditAsset}
|
||||||
onEditFolder={onEditFolder}
|
onEditFolder={onEditFolder}
|
||||||
rows={rows}
|
rows={rows}
|
||||||
@ -120,6 +123,7 @@ export const TableList = ({
|
|||||||
|
|
||||||
TableList.defaultProps = {
|
TableList.defaultProps = {
|
||||||
assetCount: 0,
|
assetCount: 0,
|
||||||
|
canUpdate: false,
|
||||||
folderCount: 0,
|
folderCount: 0,
|
||||||
indeterminate: false,
|
indeterminate: false,
|
||||||
onChangeSort: null,
|
onChangeSort: null,
|
||||||
@ -132,6 +136,7 @@ TableList.defaultProps = {
|
|||||||
|
|
||||||
TableList.propTypes = {
|
TableList.propTypes = {
|
||||||
assetCount: PropTypes.number,
|
assetCount: PropTypes.number,
|
||||||
|
canUpdate: PropTypes.bool,
|
||||||
folderCount: PropTypes.number,
|
folderCount: PropTypes.number,
|
||||||
indeterminate: PropTypes.bool,
|
indeterminate: PropTypes.bool,
|
||||||
onChangeSort: PropTypes.func,
|
onChangeSort: PropTypes.func,
|
||||||
|
|||||||
@ -13,6 +13,7 @@ jest.mock('@strapi/helper-plugin', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const PROPS_FIXTURE = {
|
const PROPS_FIXTURE = {
|
||||||
|
canUpdate: false,
|
||||||
rows: [
|
rows: [
|
||||||
{
|
{
|
||||||
alternativeText: 'alternative text',
|
alternativeText: 'alternative text',
|
||||||
@ -100,6 +101,21 @@ describe('TableList', () => {
|
|||||||
expect(onChangeSortSpy).toHaveBeenCalledWith('name:ASC');
|
expect(onChangeSortSpy).toHaveBeenCalledWith('name:ASC');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call onSelectAll callback when bulk selecting', () => {
|
||||||
|
const onSelectAllSpy = jest.fn();
|
||||||
|
const { getByRole } = setup({ onSelectAll: onSelectAllSpy });
|
||||||
|
|
||||||
|
fireEvent.click(getByRole('checkbox', { name: 'Select all folders & assets' }));
|
||||||
|
|
||||||
|
expect(onSelectAllSpy).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should disable bulk select when users do not have update permissions', () => {
|
||||||
|
const { getByRole } = setup({ canUpdate: false });
|
||||||
|
|
||||||
|
expect(getByRole('checkbox', { name: 'Select all folders & assets' })).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should render assets', () => {
|
it('should render assets', () => {
|
||||||
const { getByText } = setup();
|
const { getByText } = setup();
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ jest.mock('@strapi/helper-plugin', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const PROPS_FIXTURE = {
|
const PROPS_FIXTURE = {
|
||||||
|
canUpdate: true,
|
||||||
rows: [
|
rows: [
|
||||||
{
|
{
|
||||||
alternativeText: 'alternative text',
|
alternativeText: 'alternative text',
|
||||||
@ -103,6 +104,12 @@ describe('TableList | TableRows', () => {
|
|||||||
expect(getByRole('checkbox', { name: 'Select michka asset', hidden: true })).toBeChecked();
|
expect(getByRole('checkbox', { name: 'Select michka asset', hidden: true })).toBeChecked();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should disable select asset checkbox when users do not have the permission to update', () => {
|
||||||
|
const { getByRole } = setup({ canUpdate: false });
|
||||||
|
|
||||||
|
expect(getByRole('checkbox', { name: 'Select michka asset', hidden: true })).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should call onEditAsset callback', () => {
|
it('should call onEditAsset callback', () => {
|
||||||
const onEditAssetSpy = jest.fn();
|
const onEditAssetSpy = jest.fn();
|
||||||
const { getByRole } = setup({ onEditAsset: onEditAssetSpy });
|
const { getByRole } = setup({ onEditAsset: onEditAssetSpy });
|
||||||
@ -154,6 +161,14 @@ describe('TableList | TableRows', () => {
|
|||||||
expect(getByRole('checkbox', { name: 'Select folder 1 folder', hidden: true })).toBeChecked();
|
expect(getByRole('checkbox', { name: 'Select folder 1 folder', hidden: true })).toBeChecked();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should disable select folder checkbox when users do not have the permission to update', () => {
|
||||||
|
const { getByRole } = setup({ rows: [FOLDER_FIXTURE], canUpdate: false });
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getByRole('checkbox', { name: 'Select folder 1 folder', hidden: true })
|
||||||
|
).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should not display size and ext', () => {
|
it('should not display size and ext', () => {
|
||||||
const { getAllByText } = setup({ rows: [FOLDER_FIXTURE] });
|
const { getAllByText } = setup({ rows: [FOLDER_FIXTURE] });
|
||||||
|
|
||||||
|
|||||||
@ -273,6 +273,7 @@ export const MediaLibrary = () => {
|
|||||||
{canRead && !isGridView && (assetCount > 0 || folderCount > 0) && (
|
{canRead && !isGridView && (assetCount > 0 || folderCount > 0) && (
|
||||||
<TableList
|
<TableList
|
||||||
assetCount={assetCount}
|
assetCount={assetCount}
|
||||||
|
canUpdate={canUpdate}
|
||||||
folderCount={folderCount}
|
folderCount={folderCount}
|
||||||
indeterminate={indeterminateBulkSelect}
|
indeterminate={indeterminateBulkSelect}
|
||||||
onChangeSort={handleChangeSort}
|
onChangeSort={handleChangeSort}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user