mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
Fix attachment duplication on add
This commit is contained in:
parent
dc66a93e18
commit
cb2f795ef1
8 changed files with 36 additions and 7 deletions
|
@ -10,8 +10,8 @@ export const transformAttachment = (attachment) => ({
|
||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
|
|
||||||
const createAttachment = (cardId, data, headers) =>
|
const createAttachment = (cardId, data, requestId, headers) =>
|
||||||
http.post(`/cards/${cardId}/attachments`, data, headers).then((body) => ({
|
http.post(`/cards/${cardId}/attachments?requestId=${requestId}`, data, headers).then((body) => ({
|
||||||
...body,
|
...body,
|
||||||
item: transformAttachment(body.item),
|
item: transformAttachment(body.item),
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -23,7 +23,7 @@ export function* createAttachmentRequest(cardId, localId, data) {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { item } = yield call(request, api.createAttachment, cardId, data);
|
const { item } = yield call(request, api.createAttachment, cardId, data, localId);
|
||||||
|
|
||||||
const action = createAttachmentSucceeded(localId, item);
|
const action = createAttachmentSucceeded(localId, item);
|
||||||
yield put(action);
|
yield put(action);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { logoutService } from './login';
|
||||||
import { closeModalService } from './modal';
|
import { closeModalService } from './modal';
|
||||||
import { deleteNotificationsRequest, fetchUsersRequest } from '../requests';
|
import { deleteNotificationsRequest, fetchUsersRequest } from '../requests';
|
||||||
import {
|
import {
|
||||||
|
attachmentWithIdExistsSelector,
|
||||||
currentModalSelector,
|
currentModalSelector,
|
||||||
currentUserIdSelector,
|
currentUserIdSelector,
|
||||||
currentUserSelector,
|
currentUserSelector,
|
||||||
|
@ -208,9 +209,13 @@ export function* deleteTaskReceivedService(task) {
|
||||||
yield put(deleteTaskReceived(task));
|
yield put(deleteTaskReceived(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* createAttachmentReceivedService(attachment) {
|
export function* createAttachmentReceivedService(attachment, requestId) {
|
||||||
|
const exists = yield select(attachmentWithIdExistsSelector, requestId);
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
yield put(createAttachmentReceived(attachment));
|
yield put(createAttachmentReceived(attachment));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function* updateAttachmentReceivedService(attachment) {
|
export function* updateAttachmentReceivedService(attachment) {
|
||||||
yield put(updateAttachmentReceived(attachment));
|
yield put(updateAttachmentReceived(attachment));
|
||||||
|
|
|
@ -156,8 +156,8 @@ const createSocketEventsChannel = () =>
|
||||||
emit([deleteTaskReceivedService, item]);
|
emit([deleteTaskReceivedService, item]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAttachmentCreate = api.makeHandleAttachmentCreate(({ item }) => {
|
const handleAttachmentCreate = api.makeHandleAttachmentCreate(({ item, requestId }) => {
|
||||||
emit([createAttachmentReceivedService, item]);
|
emit([createAttachmentReceivedService, item, requestId]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleAttachmentUpdate = api.makeHandleAttachmentUpdate(({ item }) => {
|
const handleAttachmentUpdate = api.makeHandleAttachmentUpdate(({ item }) => {
|
||||||
|
|
11
client/src/selectors/boolean.js
Normal file
11
client/src/selectors/boolean.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { createSelector } from 'redux-orm';
|
||||||
|
|
||||||
|
import orm from '../orm';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
|
export const attachmentWithIdExistsSelector = () =>
|
||||||
|
createSelector(
|
||||||
|
orm,
|
||||||
|
(_, id) => id,
|
||||||
|
({ Attachment }, id) => Attachment.idExists(id),
|
||||||
|
);
|
|
@ -3,4 +3,5 @@ export * from './all';
|
||||||
export * from './path';
|
export * from './path';
|
||||||
export * from './current';
|
export * from './current';
|
||||||
export * from './by-id';
|
export * from './by-id';
|
||||||
|
export * from './boolean';
|
||||||
export * from './next-position';
|
export * from './next-position';
|
||||||
|
|
|
@ -11,6 +11,10 @@ module.exports = {
|
||||||
regex: /^[0-9]+$/,
|
regex: /^[0-9]+$/,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
requestId: {
|
||||||
|
type: 'string',
|
||||||
|
isNotEmptyString: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
exits: {
|
exits: {
|
||||||
|
@ -58,6 +62,7 @@ module.exports = {
|
||||||
isImage: file.extra.isImage,
|
isImage: file.extra.isImage,
|
||||||
name: file.filename,
|
name: file.filename,
|
||||||
},
|
},
|
||||||
|
inputs.requestId,
|
||||||
this.req,
|
this.req,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,12 @@ module.exports = {
|
||||||
type: 'json',
|
type: 'json',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
requestId: {
|
||||||
|
type: 'string',
|
||||||
|
isNotEmptyString: true,
|
||||||
|
allowNull: true,
|
||||||
|
defaultsTo: null,
|
||||||
|
},
|
||||||
request: {
|
request: {
|
||||||
type: 'ref',
|
type: 'ref',
|
||||||
},
|
},
|
||||||
|
@ -29,6 +35,7 @@ module.exports = {
|
||||||
'attachmentCreate',
|
'attachmentCreate',
|
||||||
{
|
{
|
||||||
item: attachment,
|
item: attachment,
|
||||||
|
requestId: inputs.requestId,
|
||||||
},
|
},
|
||||||
inputs.request,
|
inputs.request,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue