Skip to content

Commit

Permalink
Batch state in folder contents
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Apr 27, 2017
1 parent 0dee3b1 commit 784b4c1
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]
### Added
- Batch state in folder contents @robgietema
- Batch properties in folder contents @robgietema
- Batch tags in folder contents @robgietema
- Batch rename in folder contents @robgietema
Expand Down
24 changes: 16 additions & 8 deletions src/actions/workflow/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@
* @module actions/workflow/workflow
*/

import { GET_WORKFLOW, TRANSITION_WORKFLOW } from '../../constants/ActionTypes';
import {
GET_WORKFLOW,
GET_WORKFLOW_MULTIPLE,
TRANSITION_WORKFLOW,
} from '../../constants/ActionTypes';

/**
* Get workflow function.
* @function getWorkflow
* @param {string} url Workflow url.
* @param {string|Array} urls Workflow url(s).
* @returns {Object} Get workflow action.
*/
export function getWorkflow(url) {
export function getWorkflow(urls) {
return {
type: GET_WORKFLOW,
promise: api => api.get(`${url}/@workflow`),
type: typeof urls === 'string' ? GET_WORKFLOW : GET_WORKFLOW_MULTIPLE,
promise: typeof urls === 'string'
? api => api.get(`${urls}/@workflow`)
: api => Promise.all(urls.map(url => api.get(`${url}/@workflow`))),
};
}

/**
* Transition workflow.
* @function transitionWorkflow
* @param {string} url Content url.
* @param {string} urls Content url(s).
* @returns {Object} Transition workflow action.
*/
export function transitionWorkflow(url) {
export function transitionWorkflow(urls) {
return {
type: TRANSITION_WORKFLOW,
promise: api => api.post(url),
promise: typeof urls === 'string'
? api => api.post(urls)
: api => Promise.all(urls.map(url => api.post(url))),
};
}
36 changes: 35 additions & 1 deletion src/actions/workflow/workflow.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { getWorkflow, transitionWorkflow } from './workflow';
import { GET_WORKFLOW, TRANSITION_WORKFLOW } from '../../constants/ActionTypes';
import {
GET_WORKFLOW,
GET_WORKFLOW_MULTIPLE,
TRANSITION_WORKFLOW,
} from '../../constants/ActionTypes';

describe('Workflow action', () => {
describe('getWorkflow', () => {
Expand All @@ -16,6 +20,21 @@ describe('Workflow action', () => {

expect(apiMock.get).toBeCalledWith(`${url}/@workflow`);
});

it('should create an action to get multiple workflows', () => {
const urls = ['/blog', '/users'];
const action = getWorkflow(urls);

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

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

expect(apiMock.get).toBeCalledWith(`${urls[0]}/@workflow`);
expect(apiMock.get).toBeCalledWith(`${urls[1]}/@workflow`);
});
});

describe('transitionWorkflow', () => {
Expand All @@ -32,5 +51,20 @@ describe('Workflow action', () => {

expect(apiMock.post).toBeCalledWith(url);
});

it('should create an action to transition multiple workflow', () => {
const urls = ['/blog', '/users'];
const action = transitionWorkflow(urls);

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

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

expect(apiMock.post).toBeCalledWith(urls[0]);
expect(apiMock.post).toBeCalledWith(urls[1]);
});
});
});
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export ContentsItem from './manage/Contents/ContentsItem';
export ContentsUploadModal from './manage/Contents/ContentsUploadModal';
export ContentsPropertiesModal from './manage/Contents/ContentsPropertiesModal';
export ContentsRenameModal from './manage/Contents/ContentsRenameModal';
export ContentsWorkflowModal from './manage/Contents/ContentsWorkflowModal';
export ContentsTagsModal from './manage/Contents/ContentsTagsModal';
export Delete from './manage/Delete/Delete';
export Diff from './manage/Diff/Diff';
Expand Down
52 changes: 48 additions & 4 deletions src/components/manage/Contents/Contents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
ContentsItem,
ContentsRenameModal,
ContentsUploadModal,
ContentsWorkflowModal,
ContentsTagsModal,
ContentsPropertiesModal,
Pagination,
Expand Down Expand Up @@ -162,6 +163,8 @@ export default class ContentsComponent extends Component {
this.onTagsCancel = this.onTagsCancel.bind(this);
this.onPropertiesOk = this.onPropertiesOk.bind(this);
this.onPropertiesCancel = this.onPropertiesCancel.bind(this);
this.onWorkflowOk = this.onWorkflowOk.bind(this);
this.onWorkflowCancel = this.onWorkflowCancel.bind(this);
this.onChangeFilter = this.onChangeFilter.bind(this);
this.onChangePage = this.onChangePage.bind(this);
this.onChangePageSize = this.onChangePageSize.bind(this);
Expand All @@ -177,6 +180,7 @@ export default class ContentsComponent extends Component {
this.rename = this.rename.bind(this);
this.tags = this.tags.bind(this);
this.properties = this.properties.bind(this);
this.workflow = this.workflow.bind(this);
this.paste = this.paste.bind(this);
this.fetchContents = this.fetchContents.bind(this);
this.state = {
Expand All @@ -186,6 +190,7 @@ export default class ContentsComponent extends Component {
showRename: false,
showTags: false,
showProperties: false,
showWorkflow: false,
itemsToDelete: [],
items: this.props.items,
filter: '',
Expand Down Expand Up @@ -488,7 +493,6 @@ export default class ContentsComponent extends Component {
* @returns {undefined}
*/
onRenameOk() {
this.fetchContents();
this.setState({
showRename: false,
selected: [],
Expand All @@ -512,7 +516,6 @@ export default class ContentsComponent extends Component {
* @returns {undefined}
*/
onTagsOk() {
this.fetchContents();
this.setState({
showTags: false,
selected: [],
Expand All @@ -536,7 +539,6 @@ export default class ContentsComponent extends Component {
* @returns {undefined}
*/
onPropertiesOk() {
this.fetchContents();
this.setState({
showProperties: false,
selected: [],
Expand All @@ -554,6 +556,30 @@ export default class ContentsComponent extends Component {
});
}

/**
* On workflow ok
* @method onWorkflowOk
* @returns {undefined}
*/
onWorkflowOk() {
this.fetchContents();
this.setState({
showWorkflow: false,
selected: [],
});
}

/**
* On workflow cancel
* @method onWorkflowCancel
* @returns {undefined}
*/
onWorkflowCancel() {
this.setState({
showWorkflow: false,
});
}

/**
* Get field by id
* @method getFieldById
Expand Down Expand Up @@ -665,6 +691,17 @@ export default class ContentsComponent extends Component {
});
}

/**
* Workflow handler
* @method workflow
* @returns {undefined}
*/
workflow() {
this.setState({
showWorkflow: true,
});
}

/**
* Paste handler
* @method paste
Expand Down Expand Up @@ -743,6 +780,13 @@ export default class ContentsComponent extends Component {
onOk={this.onPropertiesOk}
items={this.state.selected}
/>
{this.state.showWorkflow &&
<ContentsWorkflowModal
open={this.state.showWorkflow}
onCancel={this.onWorkflowCancel}
onOk={this.onWorkflowOk}
items={this.state.selected}
/>}
<h1>Contents</h1>
<section id="content-core">
<Menu stackable>
Expand Down Expand Up @@ -776,7 +820,7 @@ export default class ContentsComponent extends Component {
<Dropdown.Item onClick={this.tags}>
<Icon name="tags" /> Tags
</Dropdown.Item>
<Dropdown.Item>
<Dropdown.Item onClick={this.workflow}>
<Icon name="random" /> State
</Dropdown.Item>
<Dropdown.Item onClick={this.properties}>
Expand Down
Loading

0 comments on commit 784b4c1

Please sign in to comment.