Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files with computed name #607

Open
wants to merge 2 commits into
base: fix-login-button-603
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/form/Attributes/File/Cell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import BaseCell from 'form/Attributes/common/Base/Cell';

const BaseValuesRenderer = ({nodes}) => (
<TextBase numberOfLines={1}>
{nodes?.map(node => node?.value?.fileName).join(', ')}
{nodes
?.map(node => {
const {fileName: fileNameUuid, fileNameCalculated} =
node?.value?.fileName;
Comment on lines +10 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one looks wrong, it should be:
const {fileName: fileNameUuid, fileNameCalculated} =
node?.value ?? {}

const fileName = fileNameCalculated || fileNameUuid;
return fileName;
})
.join(', ')}
</TextBase>
);

Expand Down
2 changes: 1 addition & 1 deletion src/form/Attributes/File/Preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const NodeValueRender = ({node = false, nodeDef}) => {
return (
<>
<Container>
{node?.value ? (
{node?.value && node?.value?.fileName ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be simply node?.value?.fileName

Copy link
Member

@SteRiccio SteRiccio Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are also helper methods in arena-core for this, e.g. NodeValues.getFileName

<>
<FilePreview node={node} nodeDef={nodeDef} />
<DeleteFileButton
Expand Down
11 changes: 8 additions & 3 deletions src/form/Attributes/File/components/Preview/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ const ImageStats = ({file}) => {
}, [file]);

return (
<TextBase type="secondaryLight">
{fileSizeMB} KB · ({file.meta.width} x {file.meta.height} px)
</TextBase>
<View>
<TextBase type="secondaryLight">
{file.meta.fileNameCalculated || file.meta.fileName}
</TextBase>
<TextBase type="secondaryLight">
{fileSizeMB} KB · ({file.meta.width} x {file.meta.height} px)
</TextBase>
</View>
);
};

Expand Down
10 changes: 8 additions & 2 deletions src/form/Attributes/File/hooks/useFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ const useFile = ({nodeDef, node, isImage = false}) => {
fileUuid: node?.value?.fileUuid || uuidv4(),
};

const fileKeys = ['fileName', 'fileSize', 'fileUuid', 'uri'];
const fileKeys = [
'fileName',
'fileSize',
'fileUuid',
'uri',
'fileNameCalculated',
];
const fileValueFiltered = Object.keys(value).reduce((acc, key) => {
if (fileKeys.includes(key)) {
acc[key] = value[key];
Expand Down Expand Up @@ -59,7 +65,7 @@ const useFile = ({nodeDef, node, isImage = false}) => {
const deleteFile = useCallback(() => {
handleDelete({
node,
label: node?.value?.fileName,
label: node?.value?.fileNameCalculated,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, if fileNameCalculated is missing it should default to something else

requestConfirm: true,
isImage: true,
});
Expand Down
3 changes: 3 additions & 0 deletions src/form/Attributes/File/hooks/useImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ const getFilesFromImage = image => {
const name =
image?.filename || (image?.path || '').split('/').pop() || '---.png';

const fileNameCalculated = image?.fileNameCalculated || name;

return [
{
...image,
name,
fileNameCalculated,
size: image?.size,
type: image?.mime,
uri: image?.path, // image.sourceURL - /private/var/mobile || file:///var/mobile/Media
Expand Down
Loading