mirror of
https://github.com/strapi/strapi.git
synced 2025-11-19 19:50:46 +00:00
added preview and edit icon
This commit is contained in:
parent
9c8773e861
commit
dadebfa9d7
@ -0,0 +1,53 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { prefixFileUrlWithBackendUrl, pxToRem } from '@strapi/helper-plugin';
|
||||||
|
import { Avatar } from '@strapi/design-system/Avatar';
|
||||||
|
import { Flex } from '@strapi/design-system/Flex';
|
||||||
|
import { Typography } from '@strapi/design-system/Typography';
|
||||||
|
|
||||||
|
const FileWrapper = styled(Flex)`
|
||||||
|
border-radius: 50%;
|
||||||
|
|
||||||
|
span {
|
||||||
|
line-height: 0.6rem;
|
||||||
|
font-size: 0.6rem;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const PreviewCell = ({ alternativeText, fileExtension, mime, name, thumbnailURL, url }) => {
|
||||||
|
const fileURL = prefixFileUrlWithBackendUrl(url);
|
||||||
|
|
||||||
|
if (mime.includes('image')) {
|
||||||
|
const mediaURL = prefixFileUrlWithBackendUrl(thumbnailURL) ?? fileURL;
|
||||||
|
|
||||||
|
return <Avatar src={mediaURL} alt={alternativeText || name} preview />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FileWrapper
|
||||||
|
background="secondary100"
|
||||||
|
height={pxToRem(26)}
|
||||||
|
justifyContent="center"
|
||||||
|
width={pxToRem(26)}
|
||||||
|
>
|
||||||
|
<Typography variant="sigma" textColor="secondary600">
|
||||||
|
{fileExtension}
|
||||||
|
</Typography>
|
||||||
|
</FileWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PreviewCell.defaultProps = {
|
||||||
|
alternativeText: null,
|
||||||
|
thumbnailURL: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
PreviewCell.propTypes = {
|
||||||
|
alternativeText: PropTypes.string,
|
||||||
|
fileExtension: PropTypes.string.isRequired,
|
||||||
|
mime: PropTypes.string.isRequired,
|
||||||
|
name: PropTypes.string.isRequired,
|
||||||
|
thumbnailURL: PropTypes.string,
|
||||||
|
url: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
@ -4,29 +4,38 @@ import { useIntl } from 'react-intl';
|
|||||||
import { getFileExtension } from '@strapi/helper-plugin';
|
import { getFileExtension } from '@strapi/helper-plugin';
|
||||||
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 { Typography } from '@strapi/design-system/Typography';
|
||||||
|
import { IconButton } from '@strapi/design-system/IconButton';
|
||||||
|
import Pencil from '@strapi/icons/Pencil';
|
||||||
|
|
||||||
|
import { PreviewCell } from './PreviewCell';
|
||||||
import { AssetDefinition } from '../../constants';
|
import { AssetDefinition } from '../../constants';
|
||||||
import formatBytes from '../../utils/formatBytes';
|
import { formatBytes, getTrad } from '../../utils';
|
||||||
|
|
||||||
export const TableRows = ({ assets }) => {
|
export const TableRows = ({ assets, onEditAsset }) => {
|
||||||
const { formatDate } = useIntl();
|
const { formatDate, formatMessage } = useIntl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{assets.map((asset) => {
|
{assets.map((asset) => {
|
||||||
// console.log(asset);
|
const { alternativeText, id, name, ext, size, createdAt, url, mime, formats } = asset;
|
||||||
const { id, name, ext, size, createdAt } = asset;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tr key={id}>
|
<Tr key={id}>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>TODO</Typography>
|
<PreviewCell
|
||||||
|
alternativeText={alternativeText}
|
||||||
|
fileExtension={getFileExtension(ext)}
|
||||||
|
mime={mime}
|
||||||
|
name={name}
|
||||||
|
thumbnailURL={formats?.thumbnail?.url}
|
||||||
|
url={url}
|
||||||
|
/>
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{name}</Typography>
|
<Typography>{name}</Typography>
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{getFileExtension(ext)}</Typography>
|
<Typography>{getFileExtension(ext).toUpperCase()}</Typography>
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Typography>{formatBytes(size)}</Typography>
|
<Typography>{formatBytes(size)}</Typography>
|
||||||
@ -34,6 +43,18 @@ export const TableRows = ({ assets }) => {
|
|||||||
<Td>
|
<Td>
|
||||||
<Typography>{formatDate(new Date(createdAt))}</Typography>
|
<Typography>{formatDate(new Date(createdAt))}</Typography>
|
||||||
</Td>
|
</Td>
|
||||||
|
{onEditAsset && (
|
||||||
|
<Td>
|
||||||
|
<IconButton
|
||||||
|
label={formatMessage({
|
||||||
|
id: getTrad('control-card.edit'),
|
||||||
|
defaultMessage: 'Edit',
|
||||||
|
})}
|
||||||
|
icon={<Pencil />}
|
||||||
|
onClick={() => onEditAsset(asset)}
|
||||||
|
/>
|
||||||
|
</Td>
|
||||||
|
)}
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@ -41,6 +62,11 @@ export const TableRows = ({ assets }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TableRows.defaultProps = {
|
||||||
|
onEditAsset: null,
|
||||||
|
};
|
||||||
|
|
||||||
TableRows.propTypes = {
|
TableRows.propTypes = {
|
||||||
assets: PropTypes.arrayOf(AssetDefinition).isRequired,
|
assets: PropTypes.arrayOf(AssetDefinition).isRequired,
|
||||||
|
onEditAsset: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { AssetDefinition } from '../../constants';
|
|||||||
import { tableHeaders } from './utils/tableHeaders';
|
import { tableHeaders } from './utils/tableHeaders';
|
||||||
import { TableRows } from './TableRows';
|
import { TableRows } from './TableRows';
|
||||||
|
|
||||||
export const AssetTableList = ({ assets }) => {
|
export const AssetTableList = ({ assets, onEditAsset }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const headers = tableHeaders.map((header) => ({
|
const headers = tableHeaders.map((header) => ({
|
||||||
@ -19,12 +19,17 @@ export const AssetTableList = ({ assets }) => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DynamicTable contentType="assets" headers={headers} rows={assets}>
|
<DynamicTable withBulkActions contentType="assets" headers={headers} rows={assets}>
|
||||||
<TableRows assets={assets} />
|
<TableRows onEditAsset={onEditAsset} assets={assets} />
|
||||||
</DynamicTable>
|
</DynamicTable>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AssetTableList.defaultProps = {
|
||||||
|
onEditAsset: null,
|
||||||
|
};
|
||||||
|
|
||||||
AssetTableList.propTypes = {
|
AssetTableList.propTypes = {
|
||||||
assets: PropTypes.arrayOf(AssetDefinition).isRequired,
|
assets: PropTypes.arrayOf(AssetDefinition).isRequired,
|
||||||
|
onEditAsset: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -355,7 +355,7 @@ export const MediaLibrary = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<AssetTableList assets={assets} />
|
<AssetTableList assets={assets} onEditAsset={setAssetToEdit} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{assetsData?.pagination && (
|
{assetsData?.pagination && (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user