@applica-software-guru/react-admin 1.5.257 → 1.5.259
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ra-fields/AttachmentField.d.ts +4 -4
- package/dist/components/ra-fields/AttachmentField.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +1 -1
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +1037 -1037
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +1 -1
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ra-fields/AttachmentField.tsx +9 -8
- package/src/components/ra-inputs/AttachmentInput.tsx +1 -1
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
6
6
|
import { useDataProvider, useRecordContext, useResourceContext, useTranslate } from 'react-admin';
|
|
7
7
|
|
|
8
8
|
function AttachmentField({
|
|
9
|
-
entityId,
|
|
9
|
+
entityId: _entityId,
|
|
10
10
|
property,
|
|
11
11
|
disabled,
|
|
12
12
|
showUser = false,
|
|
13
13
|
userResource = 'entities/user',
|
|
14
|
-
|
|
14
|
+
resource: _resource,
|
|
15
15
|
...props
|
|
16
16
|
}: AttachmentFieldProps): JSX.Element {
|
|
17
17
|
const [user, setUser] = useState<any>(null);
|
|
@@ -23,16 +23,17 @@ function AttachmentField({
|
|
|
23
23
|
e.preventDefault();
|
|
24
24
|
e.stopPropagation();
|
|
25
25
|
const item = get(record, props?.source);
|
|
26
|
-
const entity =
|
|
26
|
+
const entity = _resource || resource.replace('entities/', '');
|
|
27
|
+
const entityId = _entityId || record?.id;
|
|
27
28
|
const attachment = await dataProvider.getFile(
|
|
28
|
-
`/attachments/${entity}/${entityId
|
|
29
|
+
`/attachments/${entity}/${entityId}/${property || props?.source}/${item?.id || record?.id}`
|
|
29
30
|
);
|
|
30
31
|
const link = document.createElement('a');
|
|
31
32
|
link.href = attachment;
|
|
32
33
|
link.download = get(record, props?.title || props?.source);
|
|
33
34
|
link.click();
|
|
34
35
|
},
|
|
35
|
-
[dataProvider, record,
|
|
36
|
+
[dataProvider, record, _entityId, resource, _resource, property, props?.source, props?.title]
|
|
36
37
|
);
|
|
37
38
|
const _record = useMemo(
|
|
38
39
|
() => ({
|
|
@@ -91,10 +92,10 @@ type AttachmentFieldProps = BaseAttachmentFieldProps & {
|
|
|
91
92
|
*/
|
|
92
93
|
showUser?: boolean;
|
|
93
94
|
/**
|
|
94
|
-
* When the AttachmentInput is used inside a nested form, you can specify the root
|
|
95
|
-
* If not specified, the default value is the current
|
|
95
|
+
* When the AttachmentInput is used inside a nested form, you can specify the root resource to use for the REST calls.
|
|
96
|
+
* If not specified, the default value is the current resource passed by context.
|
|
96
97
|
*/
|
|
97
|
-
|
|
98
|
+
resource?: string;
|
|
98
99
|
};
|
|
99
100
|
|
|
100
101
|
export { AttachmentField };
|
|
@@ -68,7 +68,7 @@ function AttachmentInput({
|
|
|
68
68
|
{/** @ts-ignore */}
|
|
69
69
|
<StyledFileInput type={type} multiple={multiple} disabled={disabled}>
|
|
70
70
|
{/* @ts-ignore */}
|
|
71
|
-
{React.cloneElement(children, { ...children.props
|
|
71
|
+
{React.cloneElement(children, { entityId, property, ...children.props })}
|
|
72
72
|
</StyledFileInput>
|
|
73
73
|
</LabeledInput>
|
|
74
74
|
);
|