@performant-software/shared-components 0.5.4 → 0.5.7

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/main.css CHANGED
@@ -8,4 +8,158 @@
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
10
  *
11
- */.hg-theme-default{width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;box-sizing:border-box;overflow:hidden;touch-action:manipulation;font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;background-color:#ececec;padding:5px;border-radius:5px}.hg-theme-default .hg-button span{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;outline:0;font-size:inherit}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5;cursor:pointer;display:flex;align-items:center;justify-content:center;-webkit-tap-highlight-color:rgba(0,0,0,0)}.hg-theme-default .hg-button.hg-standardBtn{width:20px}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;align-items:center;display:flex;justify-content:center}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}.hg-candidate-box{display:inline-flex;border-radius:5px;position:absolute;background:#ececec;border-bottom:2px solid #b5b5b5;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;max-width:272px;transform:translateY(-100%);margin-top:-10px}ul.hg-candidate-box-list{display:flex;list-style:none;padding:0;margin:0;flex:1}li.hg-candidate-box-list-item{height:40px;width:40px;display:flex;align-items:center;justify-content:center}li.hg-candidate-box-list-item:hover{background:rgba(0,0,0,.03);cursor:pointer}li.hg-candidate-box-list-item:active{background:rgba(0,0,0,.1)}.hg-candidate-box-prev:before{content:"◄"}.hg-candidate-box-next:before{content:"►"}.hg-candidate-box-next,.hg-candidate-box-prev{display:flex;align-items:center;padding:0 10px;background:#d0d0d0;color:#969696;cursor:pointer}.hg-candidate-box-next{border-top-right-radius:5px;border-bottom-right-radius:5px}.hg-candidate-box-prev{border-top-left-radius:5px;border-bottom-left-radius:5px}.hg-candidate-box-btn-active{color:#444}
11
+ */
12
+ .hg-theme-default {
13
+ width: 100%;
14
+ -webkit-user-select: none;
15
+ -moz-user-select: none;
16
+ -ms-user-select: none;
17
+ user-select: none;
18
+ box-sizing: border-box;
19
+ overflow: hidden;
20
+ touch-action: manipulation;
21
+ font-family: HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;
22
+ background-color: #ececec;
23
+ padding: 5px;
24
+ border-radius: 5px;
25
+ }
26
+ .hg-theme-default .hg-button span {
27
+ pointer-events: none;
28
+ }
29
+ .hg-theme-default button.hg-button {
30
+ border-width: 0;
31
+ outline: 0;
32
+ font-size: inherit;
33
+ }
34
+ .hg-theme-default .hg-button {
35
+ display: inline-block;
36
+ flex-grow: 1;
37
+ }
38
+ .hg-theme-default .hg-row {
39
+ display: flex;
40
+ }
41
+ .hg-theme-default .hg-row:not(:last-child) {
42
+ margin-bottom: 5px;
43
+ }
44
+ .hg-theme-default .hg-row .hg-button-container,
45
+ .hg-theme-default .hg-row .hg-button:not(:last-child) {
46
+ margin-right: 5px;
47
+ }
48
+ .hg-theme-default .hg-row > div:last-child {
49
+ margin-right: 0;
50
+ }
51
+ .hg-theme-default .hg-row .hg-button-container {
52
+ display: flex;
53
+ }
54
+ .hg-theme-default .hg-button {
55
+ box-shadow: 0 0 3px -1px rgba(0, 0, 0, 0.3);
56
+ height: 40px;
57
+ border-radius: 5px;
58
+ box-sizing: border-box;
59
+ padding: 5px;
60
+ background: #fff;
61
+ border-bottom: 1px solid #b5b5b5;
62
+ cursor: pointer;
63
+ display: flex;
64
+ align-items: center;
65
+ justify-content: center;
66
+ -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
67
+ }
68
+ .hg-theme-default .hg-button.hg-standardBtn {
69
+ width: 20px;
70
+ }
71
+ .hg-theme-default .hg-button.hg-activeButton {
72
+ background: #efefef;
73
+ }
74
+ .hg-theme-default.hg-layout-numeric .hg-button {
75
+ width: 33.3%;
76
+ height: 60px;
77
+ align-items: center;
78
+ display: flex;
79
+ justify-content: center;
80
+ }
81
+ .hg-theme-default .hg-button.hg-button-numpadadd,
82
+ .hg-theme-default .hg-button.hg-button-numpadenter {
83
+ height: 85px;
84
+ }
85
+ .hg-theme-default .hg-button.hg-button-numpad0 {
86
+ width: 105px;
87
+ }
88
+ .hg-theme-default .hg-button.hg-button-com {
89
+ max-width: 85px;
90
+ }
91
+ .hg-theme-default .hg-button.hg-standardBtn.hg-button-at {
92
+ max-width: 45px;
93
+ }
94
+ .hg-theme-default .hg-button.hg-selectedButton {
95
+ background: rgba(5, 25, 70, 0.53);
96
+ color: #fff;
97
+ }
98
+ .hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"] {
99
+ max-width: 82px;
100
+ }
101
+ .hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"] {
102
+ max-width: 60px;
103
+ }
104
+ .hg-candidate-box {
105
+ display: inline-flex;
106
+ border-radius: 5px;
107
+ position: absolute;
108
+ background: #ececec;
109
+ border-bottom: 2px solid #b5b5b5;
110
+ -webkit-user-select: none;
111
+ -moz-user-select: none;
112
+ -ms-user-select: none;
113
+ user-select: none;
114
+ max-width: 272px;
115
+ transform: translateY(-100%);
116
+ margin-top: -10px;
117
+ }
118
+ ul.hg-candidate-box-list {
119
+ display: flex;
120
+ list-style: none;
121
+ padding: 0;
122
+ margin: 0;
123
+ flex: 1;
124
+ }
125
+ li.hg-candidate-box-list-item {
126
+ height: 40px;
127
+ width: 40px;
128
+ display: flex;
129
+ align-items: center;
130
+ justify-content: center;
131
+ }
132
+ li.hg-candidate-box-list-item:hover {
133
+ background: rgba(0, 0, 0, 0.03);
134
+ cursor: pointer;
135
+ }
136
+ li.hg-candidate-box-list-item:active {
137
+ background: rgba(0, 0, 0, 0.1);
138
+ }
139
+ .hg-candidate-box-prev:before {
140
+ content: "◄";
141
+ }
142
+ .hg-candidate-box-next:before {
143
+ content: "►";
144
+ }
145
+ .hg-candidate-box-next,
146
+ .hg-candidate-box-prev {
147
+ display: flex;
148
+ align-items: center;
149
+ padding: 0 10px;
150
+ background: #d0d0d0;
151
+ color: #969696;
152
+ cursor: pointer;
153
+ }
154
+ .hg-candidate-box-next {
155
+ border-top-right-radius: 5px;
156
+ border-bottom-right-radius: 5px;
157
+ }
158
+ .hg-candidate-box-prev {
159
+ border-top-left-radius: 5px;
160
+ border-bottom-left-radius: 5px;
161
+ }
162
+ .hg-candidate-box-btn-active {
163
+ color: #444;
164
+ }
165
+
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@performant-software/shared-components",
3
- "version": "0.5.4",
3
+ "version": "0.5.7",
4
4
  "description": "A package of shared, framework agnostic, components.",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",
7
- "style": "./build/styles.css",
7
+ "style": "./build/main.css",
8
8
  "scripts": {
9
9
  "build": "webpack --mode production && flow-copy-source -v src types"
10
10
  },
@@ -28,7 +28,7 @@
28
28
  "react-dom": ">= 16.13.1 < 18.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@performant-software/webpack-config": "^0.5.4",
31
+ "@performant-software/webpack-config": "^0.5.7",
32
32
  "react": "^17.0.2",
33
33
  "react-dom": "^17.0.2"
34
34
  }
package/src/index.js CHANGED
@@ -22,7 +22,7 @@ export { default as FormDataTransform } from './transforms/FormDataTransform';
22
22
  export { default as NestedAttributesTransform } from './transforms/NestedAttributesTransform';
23
23
 
24
24
  // Utils
25
- export * as Browser from './utils/Browser';
25
+ export { default as Browser } from './utils/Browser';
26
26
  export { default as Calendar } from './utils/Calendar';
27
27
  export { default as Date } from './utils/Date';
28
28
  export { default as useDragDrop } from './utils/DragDrop';
@@ -31,7 +31,6 @@ export { default as Map } from './utils/Map';
31
31
  export { default as Object } from './utils/Object';
32
32
  export { default as String } from './utils/String';
33
33
  export { default as Timer } from './utils/Timer';
34
- export { default as Utility } from './utils/Utility'; // TODO: Rename me
35
34
 
36
35
  // Types
37
36
  export type { EditContainerProps as EditModalProps } from './components/EditContainer'; // Backwards compatability
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
 
3
- import axios, { type AxiosResponse } from 'axios';
3
+ import axios, { type AxiosResponse, type AxiosStatic } from 'axios';
4
4
 
5
5
  /**
6
6
  * Base class for making API calls. This class uses Axios under the hood and a customizable transform class for
@@ -102,6 +102,15 @@ class BaseService {
102
102
 
103
103
  // protected
104
104
 
105
+ /**
106
+ * Returns the axios instance.
107
+ *
108
+ * @returns {AxiosStatic}
109
+ */
110
+ getAxios(): AxiosStatic {
111
+ return axios;
112
+ }
113
+
105
114
  /**
106
115
  * Returns the API base URL string.
107
116
  */
@@ -5,4 +5,8 @@
5
5
  *
6
6
  * @returns {boolean}
7
7
  */
8
- export const isBrowser = () => (typeof window !== 'undefined');
8
+ const isBrowser = () => (typeof window !== 'undefined');
9
+
10
+ export default {
11
+ isBrowser
12
+ };
@@ -31,7 +31,7 @@ const WHITESPACE_REGEX = /\s\s+/g;
31
31
  *
32
32
  * @returns {boolean|*}
33
33
  */
34
- export const isEmpty = (value: any) => {
34
+ const isEmpty = (value: any) => {
35
35
  // If the value is an object or array, use underscore's isEmpty check.
36
36
  if (_.isObject(value) || _.isArray(value)) {
37
37
  return _.isEmpty(value);
@@ -49,7 +49,7 @@ export const isEmpty = (value: any) => {
49
49
  *
50
50
  * @returns {boolean}
51
51
  */
52
- export const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
52
+ const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
53
53
  const options = _.defaults(userOptions, DEFAULT_OPTIONS);
54
54
 
55
55
  // Check equality, consider empty strings and "null" values as equal
@@ -109,6 +109,10 @@ export const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
109
109
  return false;
110
110
  };
111
111
 
112
- export default {
112
+ const isPromise = (value: any) => !!value && typeof value === 'object' && typeof value.then === 'function';
113
113
 
114
+ export default {
115
+ isEmpty,
116
+ isEqual,
117
+ isPromise
114
118
  };
@@ -0,0 +1,16 @@
1
+ import axios from 'axios';
2
+ import BaseService from '../../src/services/BaseService';
3
+
4
+ jest.mock('axios');
5
+
6
+ class TestClass extends BaseService {
7
+
8
+ }
9
+
10
+ describe('getAxios', () => {
11
+ it('should return the default axios instance', () => {
12
+ const test = new TestClass();
13
+ const instance = test.getAxios();
14
+ expect(instance).toBe(axios);
15
+ });
16
+ });
@@ -1,4 +1,4 @@
1
- import Attachments from '../../src/api/Attachments';
1
+ import Attachments from '../../src/transforms/Attachments';
2
2
 
3
3
  describe('toPayload', () => {
4
4
  test('toPayload adds the attachment, if provided', () => {
@@ -22,7 +22,7 @@ export { default as FormDataTransform } from './transforms/FormDataTransform';
22
22
  export { default as NestedAttributesTransform } from './transforms/NestedAttributesTransform';
23
23
 
24
24
  // Utils
25
- export * as Browser from './utils/Browser';
25
+ export { default as Browser } from './utils/Browser';
26
26
  export { default as Calendar } from './utils/Calendar';
27
27
  export { default as Date } from './utils/Date';
28
28
  export { default as useDragDrop } from './utils/DragDrop';
@@ -31,7 +31,6 @@ export { default as Map } from './utils/Map';
31
31
  export { default as Object } from './utils/Object';
32
32
  export { default as String } from './utils/String';
33
33
  export { default as Timer } from './utils/Timer';
34
- export { default as Utility } from './utils/Utility'; // TODO: Rename me
35
34
 
36
35
  // Types
37
36
  export type { EditContainerProps as EditModalProps } from './components/EditContainer'; // Backwards compatability
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
 
3
- import axios, { type AxiosResponse } from 'axios';
3
+ import axios, { type AxiosResponse, type AxiosStatic } from 'axios';
4
4
 
5
5
  /**
6
6
  * Base class for making API calls. This class uses Axios under the hood and a customizable transform class for
@@ -102,6 +102,15 @@ class BaseService {
102
102
 
103
103
  // protected
104
104
 
105
+ /**
106
+ * Returns the axios instance.
107
+ *
108
+ * @returns {AxiosStatic}
109
+ */
110
+ getAxios(): AxiosStatic {
111
+ return axios;
112
+ }
113
+
105
114
  /**
106
115
  * Returns the API base URL string.
107
116
  */
@@ -5,4 +5,8 @@
5
5
  *
6
6
  * @returns {boolean}
7
7
  */
8
- export const isBrowser = () => (typeof window !== 'undefined');
8
+ const isBrowser = () => (typeof window !== 'undefined');
9
+
10
+ export default {
11
+ isBrowser
12
+ };
@@ -31,7 +31,7 @@ const WHITESPACE_REGEX = /\s\s+/g;
31
31
  *
32
32
  * @returns {boolean|*}
33
33
  */
34
- export const isEmpty = (value: any) => {
34
+ const isEmpty = (value: any) => {
35
35
  // If the value is an object or array, use underscore's isEmpty check.
36
36
  if (_.isObject(value) || _.isArray(value)) {
37
37
  return _.isEmpty(value);
@@ -49,7 +49,7 @@ export const isEmpty = (value: any) => {
49
49
  *
50
50
  * @returns {boolean}
51
51
  */
52
- export const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
52
+ const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
53
53
  const options = _.defaults(userOptions, DEFAULT_OPTIONS);
54
54
 
55
55
  // Check equality, consider empty strings and "null" values as equal
@@ -109,6 +109,10 @@ export const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
109
109
  return false;
110
110
  };
111
111
 
112
- export default {
112
+ const isPromise = (value: any) => !!value && typeof value === 'object' && typeof value.then === 'function';
113
113
 
114
+ export default {
115
+ isEmpty,
116
+ isEqual,
117
+ isPromise
114
118
  };
@@ -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
- };
@@ -1,28 +0,0 @@
1
- // @flow
2
-
3
- /**
4
- * Helper class for handling binary data. This class should be used in conjunction with the FormDataTransform.
5
- */
6
- class Attachments {
7
- /**
8
- * Appends the attachment for the passed record to the passed form data. If the attachment is not present, the
9
- * "*_remove" attribute will be appended if the attachment has been removed.
10
- *
11
- * @param formData
12
- * @param prefix
13
- * @param record
14
- * @param name
15
- */
16
- toPayload(formData: FormData, prefix: string, record: any, name: string) {
17
- const attachment = record[name];
18
- const removeAttribute = `${name}_remove`;
19
-
20
- if (attachment) {
21
- formData.append(`${prefix}[${name}]`, attachment);
22
- } else if (record[removeAttribute]) {
23
- formData.append(`${prefix}[${removeAttribute}]`, record[removeAttribute]);
24
- }
25
- }
26
- }
27
-
28
- export default new Attachments();
@@ -1,144 +0,0 @@
1
- // @flow
2
-
3
- import axios, { type AxiosResponse, type AxiosStatic } from 'axios';
4
-
5
- /**
6
- * Base class for making API calls. This class uses Axios under the hood and a customizable transform class for
7
- * PUT/POST requests.
8
- */
9
- class BaseService {
10
- /**
11
- * Constructs a new BaseService object. This constructor should never be used directly.
12
- */
13
- constructor() {
14
- if (this.constructor === BaseService) {
15
- throw new TypeError('Abstract class "BaseService" cannot be instantiated directly.');
16
- }
17
- }
18
-
19
- /**
20
- * Calls the POST /api/<resource>/ endpoint with the passed item.
21
- *
22
- * @param item
23
- *
24
- * @returns {Promise<AxiosResponse<T>>}
25
- */
26
- create(item: any): Promise<AxiosResponse> {
27
- const transform = this.getTransform();
28
- return this.getAxios().post(this.getBaseUrl(), transform.toPayload(item), this.getConfig());
29
- }
30
-
31
- /**
32
- * Calls the DELETE /api/<resource>/:id endpoint for the passed item.
33
- *
34
- * @param item
35
- *
36
- * @returns {Promise<AxiosResponse<T>>}
37
- */
38
- delete(item: any) {
39
- return this.getAxios().delete(`${this.getBaseUrl()}/${item.id}`);
40
- }
41
-
42
- /**
43
- * Calls the GET /api/<resource>/ endpoint.
44
- *
45
- * @returns {Promise<AxiosResponse<T>>}
46
- */
47
- fetchAll(params: any) {
48
- return this.getAxios().get(this.getBaseUrl(), { params });
49
- }
50
-
51
- /**
52
- * Calls the GET /api/<resource>/:id endpoint.
53
- *
54
- * @returns {Promise<AxiosResponse<T>>}
55
- */
56
- fetchOne(id: number) {
57
- return this.getAxios().get(`${this.getBaseUrl()}/${id}`);
58
- }
59
-
60
- /**
61
- * Calls the create/update API endpoint for the passed item.
62
- *
63
- * @param item
64
- *
65
- * @returns {Promise<AxiosResponse<T>>}
66
- */
67
- save(item: any) {
68
- return item.id ? this.update(item) : this.create(item);
69
- }
70
-
71
- /**
72
- * Calls the POST /api/<resource>/search endpoint.
73
- *
74
- * @param params
75
- *
76
- * @returns {Promise<AxiosResponse<T>>}
77
- */
78
- search(params: any) {
79
- return this.getAxios().post(`${this.getBaseUrl()}/search`, params);
80
- }
81
-
82
- /**
83
- * Calls the PUT /api/<resource>/:id endpoint with the passed item.
84
- *
85
- * @param item
86
- *
87
- * @returns {Promise<AxiosResponse<T>>}
88
- */
89
- update(item: any) {
90
- const transform = this.getTransform();
91
- return this.getAxios().put(`${this.getBaseUrl()}/${item.id}`, transform.toPayload(item), this.getConfig());
92
- }
93
-
94
- // protected
95
-
96
- /**
97
- * Returns the API base URL string.
98
- */
99
- getBaseUrl(): string {
100
- // Implemented in concrete classes.
101
- return '';
102
- }
103
-
104
- /**
105
- * Returns the config properties for POST/PUT requests.
106
- *
107
- * @returns {null}
108
- */
109
- getConfig() {
110
- // Implemented in concrete classes
111
- return null;
112
- }
113
-
114
- /**
115
- * Returns the axios instance object to use for API calls.
116
- *
117
- * @returns {null}
118
- */
119
- getInstance() {
120
- // Implemented in concrete classes
121
- return null;
122
- }
123
-
124
- /**
125
- * Returns the transform object. This class will be used to generate the object sent on POST/PUT requests.
126
- */
127
- getTransform() {
128
- // Implemented in concrete classes.
129
- return {};
130
- }
131
-
132
- // private
133
-
134
- /**
135
- * Returns the axios instance to use for API calls.
136
- *
137
- * @returns {*|AxiosStatic}
138
- */
139
- getAxios(): AxiosStatic {
140
- return this.getInstance() || axios;
141
- }
142
- }
143
-
144
- export default BaseService;
@@ -1,55 +0,0 @@
1
- // @flow
2
-
3
- import _ from 'underscore';
4
-
5
- /**
6
- * Class for handling transforming objects for PUT/POST requests. This class transforms records into
7
- * plain Javascript objects.
8
- */
9
- class BaseTransform {
10
- /**
11
- * Constructs a new BaseTransform object. This constructor should never be used directly.
12
- */
13
- constructor() {
14
- if (this.constructor === BaseTransform) {
15
- throw new TypeError('Abstract class "BaseTransform" cannot be instantiated directly.');
16
- }
17
- }
18
-
19
- // protected
20
-
21
- /**
22
- * Returns the parameter name.
23
- *
24
- * @returns {string}
25
- */
26
- getParameterName(): string {
27
- // Implemented in sub-class
28
- return '';
29
- }
30
-
31
- /**
32
- * Returns the array of payload keys.
33
- *
34
- * @returns {*[]}
35
- */
36
- getPayloadKeys(): Array<string> {
37
- // Implemented in sub-class
38
- return [];
39
- }
40
-
41
- /**
42
- * Returns the object for POST/PUT requests as a plain Javascript object.
43
- *
44
- * @param item
45
- *
46
- * @returns any
47
- */
48
- toPayload(item: any): any {
49
- return {
50
- [this.getParameterName()]: _.pick(item, this.getPayloadKeys())
51
- };
52
- }
53
- }
54
-
55
- export default BaseTransform;
@@ -1,30 +0,0 @@
1
- // @flow
2
-
3
- import _ from 'underscore';
4
- import BaseTransform from './BaseTransform';
5
- import StringUtils from '../utils/String';
6
-
7
- /**
8
- * Class for handling transforming records for PUT/POST requests. This class transforms objects in FormData. This
9
- * class is useful if your model contains binary data to be uploaded.
10
- */
11
- class FormDataTransform extends BaseTransform {
12
- /**
13
- * Converts the passed records to a formData object to be sent on PUT/POST requests.
14
- *
15
- * @param record
16
- *
17
- * @returns {FormData}
18
- */
19
- toPayload(record: any) {
20
- const formData = new FormData();
21
-
22
- _.each(this.getPayloadKeys(), (key) => {
23
- formData.append(`${this.getParameterName()}[${key}]`, StringUtils.toString(record[key]));
24
- });
25
-
26
- return formData;
27
- }
28
- }
29
-
30
- export default FormDataTransform;