Skip to content

Commit

Permalink
fix problem where local files couldn't be edited and would not trigge…
Browse files Browse the repository at this point in the history
…r remove action on upload
  • Loading branch information
rikschennink committed Jun 9, 2021
1 parent 4a7ba37 commit 35dfc7b
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 4.28.2

- Fix issue where local server files could not be re-uploaded after editing and did not trigger remove of source file.

## 4.28.1

- Fix CSS error.
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.28.1
* FilePond 4.28.2
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down
26 changes: 23 additions & 3 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.28.1
* FilePond 4.28.2
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -3857,7 +3857,7 @@ const createItem = (origin = null, serverFileReference = null, file = null) => {

const api = {
id: { get: () => id },
origin: { get: () => origin },
origin: { get: () => origin, set: value => (origin = value) },
serverId: { get: () => state.serverFileReference },
transferId: { get: () => state.transferId },
status: { get: () => state.status },
Expand Down Expand Up @@ -4127,6 +4127,15 @@ const actions = (dispatch, query, state) => ({
return;
}

// if is local item we need to enable upload button so change can be propagated to server
if (item.origin === FileOrigin.LOCAL) {
dispatch('DID_LOAD_ITEM', {
id: item.id,
error: null,
serverFileReference: item.source,
});
}

// for async scenarios
const upload = () => {
// we push this forward a bit so the interface is updated correctly
Expand Down Expand Up @@ -4756,6 +4765,16 @@ const actions = (dispatch, query, state) => ({
success(createItemAPI(item));
processNext();

// if origin is local, and we're instant uploading, trigger remove of original
// as revert will remove file from list
const server = state.options.server;
const instantUpload = state.options.instantUpload;
if (instantUpload && item.origin === FileOrigin.LOCAL && isFunction(server.remove)) {
const noop = () => {};
item.origin = FileOrigin.LIMBO;
state.options.server.remove(item.source, noop, noop);
}

// All items processed? No errors?
const allItemsProcessed =
query('GET_ITEMS_BY_STATUS', ItemStatus.PROCESSING_COMPLETE).length ===
Expand Down Expand Up @@ -4836,7 +4855,8 @@ const actions = (dispatch, query, state) => ({
success(createItemAPI(item));
};

// if this is a local file and the server.remove function has been configured, send source there so dev can remove file from server
// if this is a local file and the `server.remove` function has been configured,
// send source there so dev can remove file from server
const server = state.options.server;
if (
item.origin === FileOrigin.LOCAL &&
Expand Down
4 changes: 2 additions & 2 deletions dist/filepond.esm.min.js

Large diffs are not rendered by default.

31 changes: 29 additions & 2 deletions dist/filepond.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.28.1
* FilePond 4.28.2
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -6065,6 +6065,9 @@
get: function get() {
return origin;
},
set: function set(value) {
return (origin = value);
},
},
serverId: {
get: function get() {
Expand Down Expand Up @@ -6428,6 +6431,15 @@
return;
}

// if is local item we need to enable upload button so change can be propagated to server
if (item.origin === FileOrigin.LOCAL) {
dispatch('DID_LOAD_ITEM', {
id: item.id,
error: null,
serverFileReference: item.source,
});
}

// for async scenarios
var upload = function upload() {
// we push this forward a bit so the interface is updated correctly
Expand Down Expand Up @@ -7131,6 +7143,20 @@
success(createItemAPI(item));
processNext();

// if origin is local, and we're instant uploading, trigger remove of original
// as revert will remove file from list
var server = state.options.server;
var instantUpload = state.options.instantUpload;
if (
instantUpload &&
item.origin === FileOrigin.LOCAL &&
isFunction(server.remove)
) {
var noop = function noop() {};
item.origin = FileOrigin.LIMBO;
state.options.server.remove(item.source, noop, noop);
}

// All items processed? No errors?
var allItemsProcessed =
query('GET_ITEMS_BY_STATUS', ItemStatus.PROCESSING_COMPLETE).length ===
Expand Down Expand Up @@ -7220,7 +7246,8 @@
success(createItemAPI(item));
};

// if this is a local file and the server.remove function has been configured, send source there so dev can remove file from server
// if this is a local file and the `server.remove` function has been configured,
// send source there so dev can remove file from server
var server = state.options.server;
if (
item.origin === FileOrigin.LOCAL &&
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/filepond.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filepond",
"version": "4.28.1",
"version": "4.28.2",
"description": "FilePond, Where files go to stretch their bits.",
"license": "MIT",
"author": {
Expand Down
22 changes: 21 additions & 1 deletion src/js/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ export const actions = (dispatch, query, state) => ({
return;
}

// if is local item we need to enable upload button so change can be propagated to server
if (item.origin === FileOrigin.LOCAL) {
dispatch('DID_LOAD_ITEM', {
id: item.id,
error: null,
serverFileReference: item.source,
});
}

// for async scenarios
const upload = () => {
// we push this forward a bit so the interface is updated correctly
Expand Down Expand Up @@ -797,6 +806,16 @@ export const actions = (dispatch, query, state) => ({
success(createItemAPI(item));
processNext();

// if origin is local, and we're instant uploading, trigger remove of original
// as revert will remove file from list
const server = state.options.server;
const instantUpload = state.options.instantUpload;
if (instantUpload && item.origin === FileOrigin.LOCAL && isFunction(server.remove)) {
const noop = () => {};
item.origin = FileOrigin.LIMBO;
state.options.server.remove(item.source, noop, noop);
}

// All items processed? No errors?
const allItemsProcessed =
query('GET_ITEMS_BY_STATUS', ItemStatus.PROCESSING_COMPLETE).length ===
Expand Down Expand Up @@ -877,7 +896,8 @@ export const actions = (dispatch, query, state) => ({
success(createItemAPI(item));
};

// if this is a local file and the server.remove function has been configured, send source there so dev can remove file from server
// if this is a local file and the `server.remove` function has been configured,
// send source there so dev can remove file from server
const server = state.options.server;
if (
item.origin === FileOrigin.LOCAL &&
Expand Down
2 changes: 1 addition & 1 deletion src/js/app/utils/createItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export const createItem = (origin = null, serverFileReference = null, file = nul

const api = {
id: { get: () => id },
origin: { get: () => origin },
origin: { get: () => origin, set: value => (origin = value) },
serverId: { get: () => state.serverFileReference },
transferId: { get: () => state.transferId },
status: { get: () => state.status },
Expand Down

0 comments on commit 35dfc7b

Please sign in to comment.