Enhance FileList and ObjectProperty components by adding maxWidth prop for improved layout control. Update rendering logic in FileList to accommodate card and minimal states, ensuring better responsiveness. Adjust PropertyChanges to maintain consistent styling with new width settings.

This commit is contained in:
Tom Butcher 2026-07-23 23:24:48 +01:00
parent 83f5b20168
commit deec609d54
3 changed files with 75 additions and 50 deletions

View File

@ -24,7 +24,8 @@ const FileList = ({
showDownload = true, showDownload = true,
defaultPreviewOpen = false, defaultPreviewOpen = false,
minimal = false, minimal = false,
card = true card = true,
maxWidth = '100%'
}) => { }) => {
const { fetchFileContent, flushFile } = useContext(ApiServerContext) const { fetchFileContent, flushFile } = useContext(ApiServerContext)
const navigate = useNavigate() const navigate = useNavigate()
@ -63,12 +64,23 @@ const FileList = ({
const filesToRender = multiple ? files : [files] const filesToRender = multiple ? files : [files]
const renderFileContent = (file) => ( const renderFileContent = (file) => (
<Flex vertical gap='10px' style={{ maxWidth: '100%', minWidth: 0 }}> <Flex
vertical
gap='10px'
style={{ maxWidth: '100%', minWidth: 0, width: card ? '100%' : 'fit-content' }}
>
<Flex <Flex
justify={card ? 'space-between' : 'start'} justify={card ? 'space-between' : 'start'}
style={{ maxWidth: '100%', minWidth: 0 }} align='center'
gap='small'
wrap={false}
style={{ maxWidth: '100%', minWidth: 0, width: card ? '100%' : 'fit-content' }}
> >
<Flex gap={'small'} align='center' style={{ minWidth: 0 }}> <Flex
gap={'small'}
align='center'
style={{ minWidth: 0, flex: '0 1 auto', overflow: 'hidden' }}
>
<FileIcon <FileIcon
style={{ margin: 0, fontSize: card == true ? '24px' : '16px' }} style={{ margin: 0, fontSize: card == true ? '24px' : '16px' }}
/> />
@ -76,50 +88,52 @@ const FileList = ({
<Text style={{ marginTop: '1px', minWidth: 0 }} ellipsis> <Text style={{ marginTop: '1px', minWidth: 0 }} ellipsis>
{file.name || file.filename || 'Unknown file'} {file.name || file.filename || 'Unknown file'}
</Text> </Text>
<Tag>{file.extension}</Tag> {file.extension && <Tag style={{ margin: 0 }}>{file.extension}</Tag>}
</Flex>
<Flex gap={'small'} align='center'>
{showDownload && !minimal && (
<Button
icon={<DownloadIcon />}
size='small'
type='text'
onClick={() => handleDownload(file)}
/>
)}
{showPreview && !minimal && (
<Button
icon={previewOpen ? <EyeSlashIcon /> : <EyeIcon />}
size='small'
type='text'
onClick={() => {
if (previewOpen == true) {
setPreviewOpen(false)
} else {
setPreviewOpen(true)
}
}}
/>
)}
{showInfo && !minimal && (
<Button
icon={<InfoCircleIcon />}
size='small'
type='text'
onClick={() => {
navigate(infoAction.url(file._id))
}}
/>
)}
{editing && !minimal && (
<Button
icon={<BinIcon />}
size='small'
type='text'
onClick={() => handleRemove(file)}
/>
)}
</Flex> </Flex>
{!minimal && (
<Flex gap={'small'} align='center'>
{showDownload && (
<Button
icon={<DownloadIcon />}
size='small'
type='text'
onClick={() => handleDownload(file)}
/>
)}
{showPreview && (
<Button
icon={previewOpen ? <EyeSlashIcon /> : <EyeIcon />}
size='small'
type='text'
onClick={() => {
if (previewOpen == true) {
setPreviewOpen(false)
} else {
setPreviewOpen(true)
}
}}
/>
)}
{showInfo && (
<Button
icon={<InfoCircleIcon />}
size='small'
type='text'
onClick={() => {
navigate(infoAction.url(file._id))
}}
/>
)}
{editing && (
<Button
icon={<BinIcon />}
size='small'
type='text'
onClick={() => handleRemove(file)}
/>
)}
</Flex>
)}
</Flex> </Flex>
{previewOpen && !minimal ? ( {previewOpen && !minimal ? (
<> <>
@ -130,8 +144,16 @@ const FileList = ({
</Flex> </Flex>
) )
const rootStyle = {
minWidth: 0,
maxWidth,
...(card
? { width: '100%' }
: { width: 'fit-content', alignSelf: 'flex-start' })
}
return ( return (
<div style={{ width: '100%' }}> <div style={rootStyle}>
{filesToRender.map((file, index) => { {filesToRender.map((file, index) => {
const key = file._id || file.id || index const key = file._id || file.id || index
const style = { const style = {
@ -176,7 +198,8 @@ FileList.propTypes = {
showDownload: PropTypes.bool, showDownload: PropTypes.bool,
defaultPreviewOpen: PropTypes.bool, defaultPreviewOpen: PropTypes.bool,
card: PropTypes.bool, card: PropTypes.bool,
minimal: PropTypes.bool minimal: PropTypes.bool,
maxWidth: PropTypes.string
} }
export default FileList export default FileList

View File

@ -616,6 +616,7 @@ const ObjectProperty = ({
minimal={minimal} minimal={minimal}
multiple={false} multiple={false}
card={false} card={false}
maxWidth={maxWidth}
defaultPreviewOpen={previewOpen} defaultPreviewOpen={previewOpen}
showPreview={showPreview} showPreview={showPreview}
showInfo={showHyperlink} showInfo={showHyperlink}
@ -630,6 +631,7 @@ const ObjectProperty = ({
files={value} files={value}
minimal={minimal} minimal={minimal}
multiple={true} multiple={true}
maxWidth={maxWidth}
defaultPreviewOpen={previewOpen} defaultPreviewOpen={previewOpen}
showPreview={showPreview} showPreview={showPreview}
showInfo={showHyperlink} showInfo={showHyperlink}

View File

@ -53,7 +53,7 @@ const PropertyChanges = ({ type, value }) => {
} }
return ( return (
<Descriptions.Item key={key} label={changeProperty.label}> <Descriptions.Item key={key} label={changeProperty.label}>
<Flex gap={'small'}> <Flex gap={'small'} style={{ minWidth: 0, width: '100%' }}>
{value?.old ? ( {value?.old ? (
<ObjectProperty <ObjectProperty
{...changeProperty} {...changeProperty}