Skip to content

Commit c6c621a

Browse files
committed
new field to alias & include data from server #29
1 parent cd06429 commit c6c621a

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ A library that will make things easier within the React framework for galleries
8282
| `rules` | `Object` | `null` | `size`,` limit`, `width`,` height` features can be limited. [Rules](#Rules) |
8383
| `customRequest` | `Function` | `null` | You can customize the http request in your own way. [CustomRequest](#CustomRequest) |
8484
| `source` | `Function` | `null` | Enter the url of the photo from the returned answer. `(response) => response.url` |
85+
| `alias` | `Function` | `null` | Can include the data of the image to be loaded in the object and change its name. `(response) => ({ id: response.imageID, slug: response.slug })` |
8586
| `onSuccess` | `Function` | `empty` | Return for uploaded image. `function(image)` |
8687
| `onWarning` | `Function` | `empty` | Returns elements that do not conform to rules created in `accept` or` rules`. [Rules](#Rules) |
8788
| `onDeleted` | `Function` | `empty` | Returns the information of the deleted image. `function(image)` |

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "react-upload-gallery",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"license": "MIT",
55
"author": "Muhammet INAN",
66
"repository": {
77
"type": "git",
8-
"url": "https://github.com/TPMinan/react-upload-gallery.git"
8+
"url": "https://github.com/m-inan/react-upload-gallery.git"
99
},
1010
"bugs": {
11-
"url": "https://github.com/TPMinan/react-upload-gallery/issues"
11+
"url": "https://github.com/m-inan/react-upload-gallery/issues"
1212
},
1313
"keywords": [
1414
"react",

src/PropTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const defaultProps = {
2828

2929
customRequest: null,
3030
source: null,
31+
alias: null,
3132

3233
onSuccess: func,
3334
onWarning: func,
@@ -84,6 +85,7 @@ export const propTypes = {
8485

8586
customRequest: PropTypes.func,
8687
source: PropTypes.func,
88+
alias: PropTypes.func,
8789

8890
onSuccess: PropTypes.func,
8991
onWarning: PropTypes.func,

src/RUG.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,19 @@ class RUG extends React.Component {
146146
}
147147

148148
onSuccess(uid, response, append = {}) {
149-
let { source } = this.props;
149+
let { source, alias } = this.props;
150150

151-
source = typeof source === "function" ? source(response) : response.source;
151+
let fields = {};
152+
153+
// extra object elements from the server service
154+
if (typeof alias === "function") {
155+
fields = alias(response);
156+
}
157+
158+
if (!fields.source) {
159+
source =
160+
typeof source === "function" ? source(response) : response.source;
161+
}
152162

153163
this.setImage(
154164
uid,
@@ -159,6 +169,7 @@ class RUG extends React.Component {
159169
uploading: false,
160170
progress: 100,
161171
...append,
172+
...fields,
162173
},
163174
() =>
164175
this.props.onSuccess(this.state.images.find((item) => item.uid === uid))

0 commit comments

Comments
 (0)