Skip to content

Commit

Permalink
Merge 7b3f2b9 into cf0f6b6
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Jul 21, 2018
2 parents cf0f6b6 + 7b3f2b9 commit 083d4c0
Show file tree
Hide file tree
Showing 53 changed files with 621 additions and 595 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,8 @@
### Changes
* Pastanaga Editor look and feel improvements and polishment @sneridagh @albertcasado

* Refactor actions @robgietema

## 0.6.0 (2018-07-14)

### Added
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -150,6 +150,7 @@
"debug-logger": "0.4.1",
"decorate-component-with-props": "1.1.0",
"diff": "3.5.0",
"diff-match-patch": "1.0.1",
"draft-js": "0.10.5",
"draft-js-anchor-plugin": "2.0.1",
"draft-js-block-breakout-plugin": "2.0.1",
Expand Down
5 changes: 4 additions & 1 deletion src/actions/actions/actions.js
Expand Up @@ -14,6 +14,9 @@ import { LIST_ACTIONS } from '../../constants/ActionTypes';
export function listActions(url) {
return {
type: LIST_ACTIONS,
promise: api => api.get(`${url}/@actions`),
request: {
op: 'get',
path: `${url}/@actions`,
},
};
}
9 changes: 2 additions & 7 deletions src/actions/actions/actions.test.js
Expand Up @@ -8,13 +8,8 @@ describe('Actions action', () => {
const action = listActions(url);

expect(action.type).toEqual(LIST_ACTIONS);

const apiMock = {
get: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.get).toBeCalledWith(`${url}/@actions`);
expect(action.request.op).toEqual('get');
expect(action.request.path).toEqual(`${url}/@actions`);
});
});
});
5 changes: 4 additions & 1 deletion src/actions/breadcrumbs/breadcrumbs.js
Expand Up @@ -14,6 +14,9 @@ import { GET_BREADCRUMBS } from '../../constants/ActionTypes';
export function getBreadcrumbs(url) {
return {
type: GET_BREADCRUMBS,
promise: api => api.get(`${url}/@breadcrumbs`),
request: {
op: 'get',
path: `${url}/@breadcrumbs`,
},
};
}
9 changes: 2 additions & 7 deletions src/actions/breadcrumbs/breadcrumbs.test.js
Expand Up @@ -8,13 +8,8 @@ describe('Breadcrumbs action', () => {
const action = getBreadcrumbs(url);

expect(action.type).toEqual(GET_BREADCRUMBS);

const apiMock = {
get: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.get).toBeCalledWith(`${url}/@breadcrumbs`);
expect(action.request.op).toEqual('get');
expect(action.request.path).toEqual(`${url}/@breadcrumbs`);
});
});
});
12 changes: 10 additions & 2 deletions src/actions/clipboard/clipboard.js
Expand Up @@ -20,7 +20,11 @@ import {
export function copyContent(source, target) {
return {
type: COPY_CONTENT,
promise: api => api.post(`${target}/@copy`, { data: { source } }),
request: {
op: 'post',
path: `${target}/@copy`,
data: { source },
},
};
}

Expand All @@ -34,7 +38,11 @@ export function copyContent(source, target) {
export function moveContent(source, target) {
return {
type: MOVE_CONTENT,
promise: api => api.post(`${target}/@move`, { data: { source } }),
request: {
op: 'post',
path: `${target}/@move`,
data: { source },
},
};
}

Expand Down
24 changes: 6 additions & 18 deletions src/actions/clipboard/clipboard.test.js
Expand Up @@ -14,15 +14,9 @@ describe('Clipboard action', () => {
const action = copyContent(source, target);

expect(action.type).toEqual(COPY_CONTENT);

const apiMock = {
post: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.post).toBeCalledWith(`${target}/@copy`, {
data: { source },
});
expect(action.request.op).toEqual('post');
expect(action.request.path).toEqual(`${target}/@copy`);
expect(action.request.data).toEqual({ source });
});
});

Expand All @@ -33,15 +27,9 @@ describe('Clipboard action', () => {
const action = moveContent(source, target);

expect(action.type).toEqual(MOVE_CONTENT);

const apiMock = {
post: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.post).toBeCalledWith(`${target}/@move`, {
data: { source },
});
expect(action.request.op).toEqual('post');
expect(action.request.path).toEqual(`${target}/@move`);
expect(action.request.data).toEqual({ source });
});
});

Expand Down
22 changes: 18 additions & 4 deletions src/actions/comments/comments.js
Expand Up @@ -20,7 +20,11 @@ import {
export function addComment(url, text) {
return {
type: ADD_COMMENT,
promise: api => api.post(`${url}/@comments`, { data: { text } }),
request: {
op: 'post',
path: `${url}/@comments`,
data: { text },
},
};
}

Expand All @@ -33,7 +37,10 @@ export function addComment(url, text) {
export function listComments(url) {
return {
type: LIST_COMMENTS,
promise: api => api.get(`${url}/@comments`),
request: {
op: 'get',
path: `${url}/@comments`,
},
};
}

Expand All @@ -46,7 +53,10 @@ export function listComments(url) {
export function deleteComment(url) {
return {
type: DELETE_COMMENT,
promise: api => api.del(url),
request: {
op: 'del',
path: url,
},
};
}

Expand All @@ -60,6 +70,10 @@ export function deleteComment(url) {
export function updateComment(url, text) {
return {
type: UPDATE_COMMENT,
promise: api => api.patch(url, { data: { text } }),
request: {
op: 'patch',
path: url,
data: { text },
},
};
}
42 changes: 10 additions & 32 deletions src/actions/comments/comments.test.js
Expand Up @@ -19,15 +19,9 @@ describe('Comments action', () => {
const action = addComment(url, text);

expect(action.type).toEqual(ADD_COMMENT);

const apiMock = {
post: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.post).toBeCalledWith(`${url}/@comments`, {
data: { text },
});
expect(action.request.op).toEqual('post');
expect(action.request.path).toEqual(`${url}/@comments`);
expect(action.request.data).toEqual({ text });
});
});

Expand All @@ -37,13 +31,8 @@ describe('Comments action', () => {
const action = deleteComment(url);

expect(action.type).toEqual(DELETE_COMMENT);

const apiMock = {
del: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.del).toBeCalledWith(url);
expect(action.request.op).toEqual('del');
expect(action.request.path).toEqual(url);
});
});

Expand All @@ -54,15 +43,9 @@ describe('Comments action', () => {
const action = updateComment(url, text);

expect(action.type).toEqual(UPDATE_COMMENT);

const apiMock = {
patch: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.patch).toBeCalledWith(url, {
data: { text },
});
expect(action.request.op).toEqual('patch');
expect(action.request.path).toEqual(url);
expect(action.request.data).toEqual({ text });
});
});

Expand All @@ -72,13 +55,8 @@ describe('Comments action', () => {
const action = listComments(url);

expect(action.type).toEqual(LIST_COMMENTS);

const apiMock = {
get: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.get).toBeCalledWith(`${url}/@comments`);
expect(action.request.op).toEqual('get');
expect(action.request.path).toEqual(`${url}/@comments`);
});
});
});
51 changes: 27 additions & 24 deletions src/actions/content/content.js
Expand Up @@ -21,9 +21,9 @@ import {
export function createContent(url, content) {
return {
type: CREATE_CONTENT,
promise: Array.isArray(content)
? api => Promise.all(content.map(item => api.post(url, { data: item })))
: api => api.post(url, { data: content }),
request: Array.isArray(content)
? content.map(item => ({ op: 'post', path: url, data: item }))
: { op: 'post', path: url, data: content },
};
}

Expand All @@ -36,10 +36,10 @@ export function createContent(url, content) {
export function deleteContent(urls) {
return {
type: DELETE_CONTENT,
promise:
request:
typeof urls === 'string'
? api => api.del(urls)
: api => Promise.all(urls.map(url => api.del(url))),
? { op: 'del', path: urls }
: urls.map(url => ({ op: 'del', path: url })),
};
}

Expand All @@ -53,15 +53,14 @@ export function deleteContent(urls) {
export function updateContent(urls, content) {
return {
type: UPDATE_CONTENT,
promise:
request:
typeof urls === 'string'
? api => api.patch(urls, { data: content })
: api =>
Promise.all(
urls.map((url, index) =>
api.patch(url, { data: content[index] }),
),
),
? { op: 'patch', path: urls, data: content }
: urls.map((url, index) => ({
op: 'patch',
path: url,
data: content[index],
})),
};
}

Expand All @@ -77,10 +76,11 @@ export function updateContent(urls, content) {
export function orderContent(parent, url, delta, subset) {
return {
type: ORDER_CONTENT,
promise: api =>
api.patch(parent, {
data: { ordering: { obj_id: url, delta, subset_ids: subset } },
}),
request: {
op: 'patch',
path: parent,
data: { ordering: { obj_id: url, delta, subset_ids: subset } },
},
};
}

Expand All @@ -95,10 +95,11 @@ export function orderContent(parent, url, delta, subset) {
export function sortContent(url, on, order) {
return {
type: UPDATE_CONTENT,
promise: api =>
api.patch(url, {
data: { sort: { on, order } },
}),
request: {
op: 'patch',
path: url,
data: { sort: { on, order } },
},
};
}

Expand All @@ -112,7 +113,9 @@ export function sortContent(url, on, order) {
export function getContent(url, version) {
return {
type: GET_CONTENT,
promise: api =>
api.get(`${url}${version ? `/@history/${version}` : ''}?fullobjects`),
request: {
op: 'get',
path: `${url}${version ? `/@history/${version}` : ''}?fullobjects`,
},
};
}

0 comments on commit 083d4c0

Please sign in to comment.