Make it possible to adjust transformedFile object shape in ImageInput, FileInput
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu bằng cách đọc các entry point ImageInput và FileInput, tập trung vào cách các đối tượng transformedFile được tạo và cách afterRead, parse và format tương tác trong quá trình lưu. Tái hiện ví dụ với các trường src và title tùy chỉnh, sau đó xác minh rằng một phép biến đổi có thể cấu hình vẫn giữ nguyên cấu trúc tùy chỉnh cho cả tệp đơn lẻ và nhiều tệp, đồng thời vẫn chính xác sau khi lưu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is your feature request related to a problem? Please describe.
My api uses a different attribute names for file url (src) and title.
I tried to use afterRead lifecyclecallback, but it did not worked all the time (after save it used the original object)
I introduced new attributes to my api, but i don't find it ideal
I create a local version of transformFiles which did the trick, but multiple is used as an inside variable, the code look and feel was not nice anymore
Describe the solution you'd like
It would be nice, if we could adjust the shape of the transformedFile with a callback function, than it could be lined up easily with api, and would be even easy to add more variables to it.
const transform = (file, preview) =>{
return {
rawFile: file,
contentUrl: preview,
title: file.name,
};
}
// turn a browser dropped file structure into expected structure
const transformFile = file => {
if (!(file instanceof File)) {
return file;
}
const preview = URL.createObjectURL(file);
const transformedFile = transform(file, preview);
return transformedFile;
};
const transformFiles = (files: any[]) => {
if (!files) {
return multiple ? [] : null;
}
if (Array.isArray(files)) {
return files.map(transformFile);
}
return transformFile(files);
};
Describe alternatives you've considered
Maybe if afterRead would be fixed, that could give a nice solution as well.
Additional context
My solution now:
const ConfigWatermarkForm = () => {
const multiple = false;
// turn a browser dropped file structure into expected structure
const transformFile = file => {
if (!(file instanceof File)) {
return file;
}
const preview = URL.createObjectURL(file);
const transformedFile = {
rawFile: file,
contentUrl: preview,
title: file.name,
};
return transformedFile;
};
const transformFiles = (files: any[]) => {
if (!files) {
return multiple ? [] : null;
}
if (Array.isArray(files)) {
return files.map(transformFile);
}
return transformFile(files);
};
return (
<SimpleForm>
<TextInput source="name"/>
<DateInput source="activeFrom"/>
<DateInput source="activeTo"/>
<ReferenceArrayInput
reference={ResourceNameEnum.ConfigWatermarkAlloweds}
source="allowed"
/>
<ImageInput source="topConfigWatermarkMediaObject" parse={transformFiles} format={transformFiles}>
<ImageField source="contentUrl" title="title"/>
</ImageInput>
<ImageInput source="bottomConfigWatermarkMediaObject" parse={transformFiles} format={transformFiles}>
<ImageField source="contentUrl" title="title"/>
</ImageInput>
</SimpleForm>
);
};
export default ConfigWatermarkForm;
Preferred solution would be:
const ConfigWatermarkForm = () => {
const transform = (file, preview) =>{
return {
rawFile: file,
contentUrl: preview,
title: file.name,
};
}
return (
<SimpleForm>
<TextInput source="name"/>
<DateInput source="activeFrom"/>
<DateInput source="activeTo"/>
<ReferenceArrayInput
reference={ResourceNameEnum.ConfigWatermarkAlloweds}
source="allowed"
/>
<ImageInput source="topConfigWatermarkMediaObject" transform={transform}>
<ImageField source="contentUrl" title="title"/>
</ImageInput>
<ImageInput source="bottomConfigWatermarkMediaObject" transform={transform}>
<ImageField source="contentUrl" title="title"/>
</ImageInput>
</SimpleForm>
);
};
export default ConfigWatermarkForm;
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 5.5k
- Merge trung bình
- 1 ngày 3 phút
- Pull request đã merge (30 ngày)
- 32
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của marmelab/react-admin
-
Blank page after logout when the app re-renders `<Admin>` during `authProvider.logout()`Có thể đã có người làm @uchiha-suraj đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
marmelab/react-admin#11431 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Pagination: page button aria-labels are not translated on small screensCó thể đã có người làm @Singmin đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
marmelab/react-admin#11427 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add emptyText property to SelectArrayInputCó thể đã có người làm @kwitykwity đã nhận 61 ngày trước. Đang mởenhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
marmelab/react-admin#10454 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 Hơn một tuần Mức phù hợp với người mới 38/100
marmelab/react-admin#11426 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ra-data-graphql-simple: outdated graphql-ast-types-browser dependency causes npm peer warningsCó thể làm lại được @bipul724 đã nhận 14 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
marmelab/react-admin#11395 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của marmelab/react-admin
Issue tương tự
-
bug low priority
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
laaielichter/Godotwright#81 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
gebied: infra
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
VincentSmedinga/sc-heerenveen-fansite#538 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
CI grants a token it does not need, never cancels superseded runs, and cannot fail on lint warningsĐang mởgood first issue help wanted type:infrastructure type:security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Open-Glassbeetle/glassbeetle#247 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày