mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 06:50:51 +00:00
feedback fixes
This commit is contained in:
parent
bd177a0215
commit
a04305a2bb
@ -54,7 +54,7 @@ export const PreviewCell = ({ alternativeText, fileExtension, mime, thumbnailURL
|
|||||||
PreviewCell.defaultProps = {
|
PreviewCell.defaultProps = {
|
||||||
alternativeText: null,
|
alternativeText: null,
|
||||||
fileExtension: '',
|
fileExtension: '',
|
||||||
mime: null,
|
mime: '',
|
||||||
thumbnailURL: null,
|
thumbnailURL: null,
|
||||||
url: null,
|
url: null,
|
||||||
};
|
};
|
||||||
|
@ -5,10 +5,10 @@ import { getFileExtension } from '@strapi/helper-plugin';
|
|||||||
import { BaseCheckbox } from '@strapi/design-system/BaseCheckbox';
|
import { BaseCheckbox } from '@strapi/design-system/BaseCheckbox';
|
||||||
import { IconButton } from '@strapi/design-system/IconButton';
|
import { IconButton } from '@strapi/design-system/IconButton';
|
||||||
import { Tbody, Td, Tr } from '@strapi/design-system/Table';
|
import { Tbody, Td, Tr } from '@strapi/design-system/Table';
|
||||||
import { Typography } from '@strapi/design-system/Typography';
|
|
||||||
import Pencil from '@strapi/icons/Pencil';
|
import Pencil from '@strapi/icons/Pencil';
|
||||||
|
|
||||||
import { PreviewCell } from './PreviewCell';
|
import { PreviewCell } from './PreviewCell';
|
||||||
|
import { TextCell } from './TextCell';
|
||||||
import { AssetDefinition, FolderDefinition } from '../../constants';
|
import { AssetDefinition, FolderDefinition } from '../../constants';
|
||||||
import { formatBytes, getTrad } from '../../utils';
|
import { formatBytes, getTrad } from '../../utils';
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ export const TableRows = ({ onEditAsset, onEditFolder, onSelectOne, rows, select
|
|||||||
mime,
|
mime,
|
||||||
formats,
|
formats,
|
||||||
type,
|
type,
|
||||||
} = element || {};
|
} = element;
|
||||||
|
|
||||||
const isSelected = !!selected.find((currentRow) => currentRow.id === id);
|
const isSelected = !!selected.find((currentRow) => currentRow.id === id);
|
||||||
|
|
||||||
@ -61,19 +61,19 @@ export const TableRows = ({ onEditAsset, onEditFolder, onSelectOne, rows, select
|
|||||||
/>
|
/>
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{name}</Typography>
|
<TextCell content={name} />
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{ext ? getFileExtension(ext).toUpperCase() : '-'}</Typography>
|
<TextCell content={ext && getFileExtension(ext).toUpperCase()} />
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{size ? formatBytes(size) : '-'}</Typography>
|
<TextCell content={size && formatBytes(size)} />
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{formatDate(new Date(createdAt))}</Typography>
|
<TextCell content={formatDate(new Date(createdAt))} />
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{formatDate(new Date(updatedAt))}</Typography>
|
<TextCell content={formatDate(new Date(updatedAt))} />
|
||||||
</Td>
|
</Td>
|
||||||
{((type === 'asset' && onEditAsset) || (type === 'folder' && onEditFolder)) && (
|
{((type === 'asset' && onEditAsset) || (type === 'folder' && onEditFolder)) && (
|
||||||
<Td>
|
<Td>
|
||||||
@ -99,11 +99,12 @@ export const TableRows = ({ onEditAsset, onEditFolder, onSelectOne, rows, select
|
|||||||
TableRows.defaultProps = {
|
TableRows.defaultProps = {
|
||||||
onEditAsset: null,
|
onEditAsset: null,
|
||||||
onEditFolder: null,
|
onEditFolder: null,
|
||||||
|
rows: [],
|
||||||
selected: [],
|
selected: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
TableRows.propTypes = {
|
TableRows.propTypes = {
|
||||||
rows: PropTypes.arrayOf(AssetDefinition, FolderDefinition).isRequired,
|
rows: PropTypes.arrayOf(AssetDefinition, FolderDefinition),
|
||||||
onEditAsset: PropTypes.func,
|
onEditAsset: PropTypes.func,
|
||||||
onEditFolder: PropTypes.func,
|
onEditFolder: PropTypes.func,
|
||||||
onSelectOne: PropTypes.func.isRequired,
|
onSelectOne: PropTypes.func.isRequired,
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Typography } from '@strapi/design-system/Typography';
|
||||||
|
|
||||||
|
export const TextCell = ({ content }) => {
|
||||||
|
if (content) {
|
||||||
|
return <Typography>{content}</Typography>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Typography>-</Typography>;
|
||||||
|
};
|
||||||
|
|
||||||
|
TextCell.defaultProps = {
|
||||||
|
content: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
TextCell.propTypes = {
|
||||||
|
content: PropTypes.string,
|
||||||
|
};
|
@ -14,6 +14,7 @@ import { TableRows } from './TableRows';
|
|||||||
export const TableList = ({
|
export const TableList = ({
|
||||||
assetCount,
|
assetCount,
|
||||||
folderCount,
|
folderCount,
|
||||||
|
indeterminate,
|
||||||
onEditAsset,
|
onEditAsset,
|
||||||
onEditFolder,
|
onEditFolder,
|
||||||
onSelectAll,
|
onSelectAll,
|
||||||
@ -34,7 +35,7 @@ export const TableList = ({
|
|||||||
id: getTrad('bulk.select.label'),
|
id: getTrad('bulk.select.label'),
|
||||||
defaultMessage: 'Select all folders & assets',
|
defaultMessage: 'Select all folders & assets',
|
||||||
})}
|
})}
|
||||||
indeterminate={selected?.length > 0 && selected?.length !== assetCount + folderCount}
|
indeterminate={indeterminate}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (e.target.checked) {
|
if (e.target.checked) {
|
||||||
trackUsage('didSelectAllMediaLibraryElements');
|
trackUsage('didSelectAllMediaLibraryElements');
|
||||||
@ -79,6 +80,7 @@ export const TableList = ({
|
|||||||
TableList.defaultProps = {
|
TableList.defaultProps = {
|
||||||
assetCount: 0,
|
assetCount: 0,
|
||||||
folderCount: 0,
|
folderCount: 0,
|
||||||
|
indeterminate: false,
|
||||||
onEditAsset: null,
|
onEditAsset: null,
|
||||||
onEditFolder: null,
|
onEditFolder: null,
|
||||||
rows: [],
|
rows: [],
|
||||||
@ -88,6 +90,7 @@ TableList.defaultProps = {
|
|||||||
TableList.propTypes = {
|
TableList.propTypes = {
|
||||||
assetCount: PropTypes.number,
|
assetCount: PropTypes.number,
|
||||||
folderCount: PropTypes.number,
|
folderCount: PropTypes.number,
|
||||||
|
indeterminate: PropTypes.bool,
|
||||||
onEditAsset: PropTypes.func,
|
onEditAsset: PropTypes.func,
|
||||||
onEditFolder: PropTypes.func,
|
onEditFolder: PropTypes.func,
|
||||||
onSelectAll: PropTypes.func.isRequired,
|
onSelectAll: PropTypes.func.isRequired,
|
||||||
|
@ -29,7 +29,7 @@ const ComponentFixture = (props) => {
|
|||||||
|
|
||||||
const setup = (props) => render(<ComponentFixture {...props} />);
|
const setup = (props) => render(<ComponentFixture {...props} />);
|
||||||
|
|
||||||
describe('AssetTableList | PreviewCell', () => {
|
describe('TableList | PreviewCell', () => {
|
||||||
describe('rendering images', () => {
|
describe('rendering images', () => {
|
||||||
it('should render an image with thumbnail if available', () => {
|
it('should render an image with thumbnail if available', () => {
|
||||||
const { getByRole } = setup();
|
const { getByRole } = setup();
|
||||||
|
@ -58,7 +58,7 @@ const ComponentFixture = (props) => {
|
|||||||
|
|
||||||
const setup = (props) => render(<ComponentFixture {...props} />);
|
const setup = (props) => render(<ComponentFixture {...props} />);
|
||||||
|
|
||||||
describe('AssetTableList | TableRows', () => {
|
describe('TableList | TableRows', () => {
|
||||||
describe('rendering assets', () => {
|
describe('rendering assets', () => {
|
||||||
it('should properly render every asset attribute', () => {
|
it('should properly render every asset attribute', () => {
|
||||||
const { getByRole, getByText } = setup();
|
const { getByRole, getByText } = setup();
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react';
|
||||||
|
import { ThemeProvider, lightTheme } from '@strapi/design-system';
|
||||||
|
|
||||||
|
import { TextCell } from '../TextCell';
|
||||||
|
|
||||||
|
const ComponentFixture = (props) => (
|
||||||
|
<ThemeProvider theme={lightTheme}>
|
||||||
|
<TextCell {...props} />
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const setup = (props) => render(<ComponentFixture {...props} />);
|
||||||
|
|
||||||
|
describe('TableList | TextCell', () => {
|
||||||
|
it('should render content', () => {
|
||||||
|
const { getByText } = setup({ content: 'michka' });
|
||||||
|
|
||||||
|
expect(getByText('michka')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render a default content', () => {
|
||||||
|
const { getByText } = setup();
|
||||||
|
|
||||||
|
expect(getByText('-')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
@ -86,7 +86,7 @@ export const MediaLibrary = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: folders,
|
data: foldersData,
|
||||||
isLoading: foldersLoading,
|
isLoading: foldersLoading,
|
||||||
errors: foldersError,
|
errors: foldersError,
|
||||||
} = useFolders({
|
} = useFolders({
|
||||||
@ -107,8 +107,9 @@ export const MediaLibrary = () => {
|
|||||||
push(pathname);
|
push(pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const folders = foldersData ?? [];
|
||||||
const folderCount = folders?.length || 0;
|
const folderCount = folders?.length || 0;
|
||||||
const assets = assetsData?.results;
|
const assets = assetsData?.results || [];
|
||||||
const assetCount = assets?.length ?? 0;
|
const assetCount = assets?.length ?? 0;
|
||||||
const isLoading = isCurrentFolderLoading || foldersLoading || permissionsLoading || assetsLoading;
|
const isLoading = isCurrentFolderLoading || foldersLoading || permissionsLoading || assetsLoading;
|
||||||
const [showUploadAssetDialog, setShowUploadAssetDialog] = useState(false);
|
const [showUploadAssetDialog, setShowUploadAssetDialog] = useState(false);
|
||||||
@ -116,6 +117,8 @@ export const MediaLibrary = () => {
|
|||||||
const [assetToEdit, setAssetToEdit] = useState(undefined);
|
const [assetToEdit, setAssetToEdit] = useState(undefined);
|
||||||
const [folderToEdit, setFolderToEdit] = useState(undefined);
|
const [folderToEdit, setFolderToEdit] = useState(undefined);
|
||||||
const [selected, { selectOne, selectAll }] = useSelectionState(['type', 'id'], []);
|
const [selected, { selectOne, selectAll }] = useSelectionState(['type', 'id'], []);
|
||||||
|
const indeterminateBulkSelect =
|
||||||
|
selected?.length > 0 && selected?.length !== assetCount + folderCount;
|
||||||
const toggleUploadAssetDialog = () => setShowUploadAssetDialog((prev) => !prev);
|
const toggleUploadAssetDialog = () => setShowUploadAssetDialog((prev) => !prev);
|
||||||
const toggleEditFolderDialog = ({ created = false } = {}) => {
|
const toggleEditFolderDialog = ({ created = false } = {}) => {
|
||||||
// folders are only displayed on the first page, therefore
|
// folders are only displayed on the first page, therefore
|
||||||
@ -183,9 +186,7 @@ export const MediaLibrary = () => {
|
|||||||
id: getTrad('bulk.select.label'),
|
id: getTrad('bulk.select.label'),
|
||||||
defaultMessage: 'Select all folders & assets',
|
defaultMessage: 'Select all folders & assets',
|
||||||
})}
|
})}
|
||||||
indeterminate={
|
indeterminate={indeterminateBulkSelect}
|
||||||
selected?.length > 0 && selected?.length !== assetCount + folderCount
|
|
||||||
}
|
|
||||||
value={
|
value={
|
||||||
(assetCount > 0 || folderCount > 0) &&
|
(assetCount > 0 || folderCount > 0) &&
|
||||||
selected.length === assetCount + folderCount
|
selected.length === assetCount + folderCount
|
||||||
@ -196,9 +197,7 @@ export const MediaLibrary = () => {
|
|||||||
}
|
}
|
||||||
selectAll([
|
selectAll([
|
||||||
...assets.map((asset) => ({ ...asset, type: 'asset' })),
|
...assets.map((asset) => ({ ...asset, type: 'asset' })),
|
||||||
...(folders
|
...folders.map((folder) => ({ ...folder, type: 'folder' })),
|
||||||
? folders.map((folder) => ({ ...folder, type: 'folder' }))
|
|
||||||
: []),
|
|
||||||
]);
|
]);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -243,14 +242,22 @@ export const MediaLibrary = () => {
|
|||||||
<TableList
|
<TableList
|
||||||
assetCount={assetCount}
|
assetCount={assetCount}
|
||||||
folderCount={folderCount}
|
folderCount={folderCount}
|
||||||
|
indeterminate={indeterminateBulkSelect}
|
||||||
onEditAsset={setAssetToEdit}
|
onEditAsset={setAssetToEdit}
|
||||||
onEditFolder={handleEditFolder}
|
onEditFolder={handleEditFolder}
|
||||||
onSelectOne={selectOne}
|
onSelectOne={selectOne}
|
||||||
onSelectAll={selectAll}
|
onSelectAll={selectAll}
|
||||||
rows={[
|
rows={
|
||||||
...(folders ? folders.map((folder) => ({ ...folder, type: 'folder' })) : []),
|
// TODO: remove when fixed on DS side
|
||||||
...(assets ? assets.map((asset) => ({ ...asset, type: 'asset' })) : []),
|
// when number of rows in Table changes, the keyboard tab from a row to another
|
||||||
]}
|
// is not working for 1st and last column
|
||||||
|
!assetsLoading && !foldersLoading
|
||||||
|
? [
|
||||||
|
...folders.map((folder) => ({ ...folder, type: 'folder' })),
|
||||||
|
...assets.map((asset) => ({ ...asset, type: 'asset' })),
|
||||||
|
]
|
||||||
|
: []
|
||||||
|
}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user