Permalink
Browse files

allow creating new CardLists

  • Loading branch information...
1 parent 8774669 commit 554b04da6b408e78aeeab0a1237878f714ee5fbc @philschatz committed Jun 20, 2015
Showing with 53 additions and 6 deletions.
  1. +1 −0 .eslintrc
  2. +7 −4 src/components/loadable.jsx
  3. +45 −2 src/components/repo-kanban.jsx
View
@@ -14,6 +14,7 @@
"jsx": true
},
"rules": {
+ "no-alert": 1,
"no-unused-vars": 1,
"react/jsx-uses-vars": 1,
"no-var": 2,
@@ -20,10 +20,13 @@ export default React.createClass({
const {promise} = this.props;
promise.then(this.onResolve, this.onError);
},
- // componentDidUpdate() {
- // this.setState({status: STATUS.INITIAL});
- // this.componentDidMount();
- // },
+ componentDidUpdate(prevProps) {
+ if (this.props.promise !== prevProps.promise) {
+ this.setState({status: STATUS.INITIAL});
+ const {promise} = this.props;
+ promise.then(this.onResolve, this.onError);
+ }
+ },
onResolve(value) {
// TODO: Find out why this is being called multiple times
if (this.state.status !== STATUS.RESOLVED) {
@@ -1,5 +1,6 @@
import React from 'react';
import _ from 'underscore';
+import BS from 'react-bootstrap';
import {fetchAll, contains} from '../helpers';
import Client from '../github-client';
@@ -56,17 +57,55 @@ const KanbanRepo = React.createClass({
return this.renderColumn(label, allIssues);
});
},
+ onAddCardList() {
+ const {onLabelsChanged} = this.props;
+ const {labels} = this.props;
+ const {repoOwner, repoName} = this.props;
+
+ const kanbanLabels = filterKanbanLabels(labels);
+
+ let lastId = '-1';
+
+ const lastLabel = kanbanLabels[kanbanLabels.length - 1];
+ if (lastLabel.name === ICEBOX_NAME) {
+ lastId = '-1';
+ } else {
+ lastId = lastLabel.name.match(/^\d+/)[0];
+ }
+ const newId = parseInt(lastId) + 1;
+
+ const labelName = prompt('Name of new CardList');
+ if (labelName) {
+ const name = newId + ' - ' + labelName;
+ const color = 'cccccc';
+
+ // Add the label and re-render
+ Client.getOcto().repos(repoOwner, repoName).labels.create({name, color}).then(() => {
+ // Shortcut: Add the label to the list locally w/o refetching
+ onLabelsChanged();
+ });
+ }
+ },
renderBoard(allIssues) {
const {labels} = this.props;
const kanbanLabels = filterKanbanLabels(labels);
const workflowStateIssues = this.renderColumns(kanbanLabels, allIssues);
+ const addCardList = (
+ <td>
+ <BS.Button
+ alt='Add a new Cardlist to Board'
+ onClick={this.onAddCardList}>+</BS.Button>
+ </td>
+ );
+
return (
<table className='kanban-board'>
<tbody>
<tr>
{workflowStateIssues}
+ {addCardList}
</tr>
</tbody>
</table>
@@ -87,15 +126,18 @@ const KanbanRepo = React.createClass({
const Repo = React.createClass({
displayName: 'Repo',
+ onLabelsChanged() {
+ this.setState({});
+ },
render() {
const {repoOwner, repoName, data} = this.props;
// Get all the issue labels first
const renderLoaded = (labels) => {
- // If there are at least 2 'special' kanban labels then consider it valid
- const kanbanLabels = filterKanbanLabels(labels);
const icebox = [{name: ICEBOX_NAME}];
+ // If there are at least 2 'special' kanban labels then consider it valid
+ // const kanbanLabels = filterKanbanLabels(labels);
// const isValidKanbanRepo = kanbanLabels.length > 1;
return (
@@ -104,6 +146,7 @@ const Repo = React.createClass({
repoName={repoName}
labels={icebox.concat(labels)}
data={data}
+ onLabelsChanged={this.onLabelsChanged}
/>
);
};

0 comments on commit 554b04d

Please sign in to comment.