@performant-software/shared-components 0.5.6 → 0.5.9
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/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/main.css +155 -1
- package/package.json +2 -2
- package/src/components/EditContainer.js +2 -2
- package/src/index.js +1 -0
- package/src/utils/Hooks.js +24 -0
- package/test/services/BaseSerivce.spec.js +16 -0
- package/test/{api → transforms}/Attachments.spec.js +1 -1
- package/types/components/EditContainer.js.flow +2 -2
- package/types/index.js.flow +2 -2
- package/types/services/BaseService.js.flow +10 -1
- package/types/utils/Browser.js.flow +5 -1
- package/types/utils/Hooks.js.flow +24 -0
- package/types/utils/Object.js.flow +7 -3
- package/types/api/Attachments.js.flow +0 -28
- package/types/api/BaseService.js.flow +0 -144
- package/types/api/BaseTransform.js.flow +0 -55
- package/types/api/FormDataTransform.js.flow +0 -30
- package/types/api/NestedAttributesTransform.js.flow +0 -63
- package/types/utils/Utility.js.flow +0 -14
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import _ from 'underscore';
|
|
4
|
-
import StringUtils from '../utils/String';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Class for handling transforming nested attributes of a parent object. This class will handle transforming the
|
|
8
|
-
* object into a payload to be sent to a POST/PUT request on an API. This class currently supports transforming into
|
|
9
|
-
* a plain Javascript object or a FormData object.
|
|
10
|
-
*/
|
|
11
|
-
class NestedAttributesTransform {
|
|
12
|
-
/**
|
|
13
|
-
* Constructs a new BaseTransform object. This constructor should never be used directly.
|
|
14
|
-
*/
|
|
15
|
-
constructor() {
|
|
16
|
-
if (this.constructor === NestedAttributesTransform) {
|
|
17
|
-
throw new TypeError('Abstract class "NestedAttributesTransform" cannot be instantiated directly.');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Returns the array of payload keys.
|
|
23
|
-
*
|
|
24
|
-
* @returns {*[]}
|
|
25
|
-
*/
|
|
26
|
-
getPayloadKeys() {
|
|
27
|
-
// Implemented in sub-class.
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Appends the passed record's collection to the form data.
|
|
33
|
-
*
|
|
34
|
-
* @param formData
|
|
35
|
-
* @param prefix
|
|
36
|
-
* @param record
|
|
37
|
-
* @param collection
|
|
38
|
-
*/
|
|
39
|
-
toFormData(formData: FormData, prefix: string, record: any, collection: string) {
|
|
40
|
-
_.each(record[collection], (item, index) => {
|
|
41
|
-
_.each(this.getPayloadKeys(), (key) => {
|
|
42
|
-
formData.append(`${prefix}[${collection}][${index}][${key}]`, StringUtils.toString(item[key]));
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Transforms the passed record's collection to a payload object.
|
|
49
|
-
*
|
|
50
|
-
* @param record
|
|
51
|
-
* @param collection
|
|
52
|
-
*
|
|
53
|
-
* @returns {{[p: string]: *}}
|
|
54
|
-
*/
|
|
55
|
-
toPayload(record: any, collection: string) {
|
|
56
|
-
return {
|
|
57
|
-
[collection]: _.map(record[collection],
|
|
58
|
-
(item, index) => ({ ..._.pick(item, this.getPayloadKeys()), order: index }))
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export default NestedAttributesTransform;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns true if passed value is a promise (i.e, has a .then method)
|
|
5
|
-
*
|
|
6
|
-
* @param *
|
|
7
|
-
*
|
|
8
|
-
* @returns {boolean}
|
|
9
|
-
*/
|
|
10
|
-
const isPromise = (value: any) => !!value && typeof value === 'object' && typeof value.then === 'function';
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
isPromise
|
|
14
|
-
};
|