Allow issue creation via UI
This commit is contained in:
@ -2,8 +2,6 @@ import { put, call } from 'redux-saga/effects';
|
||||
import { FETCH_BOARDS_SUCCESS, SAVE_BOARD_SUCCESS, SAVE_BOARD_FAILURE, FETCH_BOARDS_FAILURE } from '../actions/boards';
|
||||
import { api } from '../../util/api';
|
||||
|
||||
const boardsLocalStorageKey = 'giteakan.boards';
|
||||
|
||||
export function* fetchBoardsSaga() {
|
||||
let boards;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { put, call, retry } from 'redux-saga/effects';
|
||||
import { FETCH_ISSUES_SUCCESS, FETCH_ISSUES_FAILURE, ADD_LABEL_FAILURE, ADD_LABEL_SUCCESS, REMOVE_LABEL_FAILURE, REMOVE_LABEL_SUCCESS } from '../actions/issues';
|
||||
import { FETCH_ISSUES_SUCCESS, FETCH_ISSUES_FAILURE, ADD_LABEL_FAILURE, ADD_LABEL_SUCCESS, REMOVE_LABEL_FAILURE, REMOVE_LABEL_SUCCESS, CREATE_ISSUE_FAILURE, CREATE_ISSUE_SUCCESS } from '../actions/issues';
|
||||
import { gitea } from '../../util/gitea';
|
||||
|
||||
export function* fetchIssuesSaga(action) {
|
||||
@ -64,5 +64,26 @@ export function* removeLabelSaga(action) {
|
||||
|
||||
|
||||
yield put({ type: REMOVE_LABEL_SUCCESS, project, issueNumber, label });
|
||||
|
||||
}
|
||||
|
||||
export function* createIssueSaga(action) {
|
||||
const { project, title, label, body } = action;
|
||||
const labels = yield call(gitea.fetchProjectLabels.bind(gitea), project);
|
||||
const giteaLabel = labels.find(l => l.name === label)
|
||||
|
||||
if (!giteaLabel) {
|
||||
yield put({ type: CREATE_ISSUE_FAILURE, error: new Error(`Label "${label}" not found !`) });
|
||||
return;
|
||||
}
|
||||
|
||||
let issue;
|
||||
try {
|
||||
issue = yield call(gitea.createIssue.bind(gitea), project, title, body, giteaLabel.id);
|
||||
} catch(error) {
|
||||
yield put({ type: CREATE_ISSUE_FAILURE, error });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
yield put({ type: CREATE_ISSUE_SUCCESS, project, title, label, body, issue });
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { select, put } from 'redux-saga/effects';
|
||||
import { fetchIssues, addLabel, removeLabel } from '../actions/issues';
|
||||
import { fetchIssuesSaga } from './issues';
|
||||
import { BUILD_KANBOARD_SUCCESS } from '../actions/kanboards';
|
||||
import { BUILD_KANBOARD_SUCCESS, buildKanboard } from '../actions/kanboards';
|
||||
|
||||
export function* moveCardSaga(action) {
|
||||
const {
|
||||
@ -30,7 +30,6 @@ export function* moveCardSaga(action) {
|
||||
}
|
||||
|
||||
export function* buildKanboardSaga(action) {
|
||||
|
||||
const { board } = action;
|
||||
|
||||
let kanboard;
|
||||
@ -50,7 +49,18 @@ export function* buildKanboardSaga(action) {
|
||||
}
|
||||
|
||||
yield put({ type: BUILD_KANBOARD_SUCCESS, kanboard });
|
||||
}
|
||||
|
||||
export function* refreshKanboardSaga(action) {
|
||||
const { project } = action;
|
||||
const boards = yield select(state => state.boards);
|
||||
const boardValues = Object.values(boards.byID);
|
||||
|
||||
for (let b, i = 0; (b = boardValues[i]); i++) {
|
||||
const hasProject = b.projects.indexOf(project) !== -1;
|
||||
if (!hasProject) continue;
|
||||
yield put(buildKanboard(b));
|
||||
}
|
||||
}
|
||||
|
||||
function createCards(projects, issues, lane) {
|
||||
|
@ -2,14 +2,14 @@ import { all, takeEvery, takeLatest } from 'redux-saga/effects';
|
||||
import { failuresSaga } from './failure';
|
||||
import { FETCH_BOARDS_REQUEST, SAVE_BOARD_REQUEST } from '../actions/boards';
|
||||
import { fetchBoardsSaga, saveBoardSaga } from './boards';
|
||||
import { FETCH_ISSUES_REQUEST, ADD_LABEL_REQUEST, REMOVE_LABEL_REQUEST } from '../actions/issues';
|
||||
import { fetchIssuesSaga, addLabelSaga, removeLabelSaga } from './issues';
|
||||
import { FETCH_ISSUES_REQUEST, ADD_LABEL_REQUEST, REMOVE_LABEL_REQUEST, CREATE_ISSUE_REQUEST, CREATE_ISSUE_SUCCESS } from '../actions/issues';
|
||||
import { fetchIssuesSaga, addLabelSaga, removeLabelSaga, createIssueSaga } from './issues';
|
||||
import { FETCH_PROJECTS_REQUEST } from '../actions/projects';
|
||||
import { fetchProjectsSaga } from './projects';
|
||||
import { LOGOUT } from '../actions/logout';
|
||||
import { logoutSaga } from './logout';
|
||||
import { BUILD_KANBOARD_REQUEST, MOVE_CARD } from '../actions/kanboards';
|
||||
import { buildKanboardSaga, moveCardSaga } from './kanboards';
|
||||
import { buildKanboardSaga, moveCardSaga, refreshKanboardSaga } from './kanboards';
|
||||
|
||||
export function* rootSaga() {
|
||||
yield all([
|
||||
@ -22,6 +22,8 @@ export function* rootSaga() {
|
||||
takeEvery(MOVE_CARD, moveCardSaga),
|
||||
takeEvery(ADD_LABEL_REQUEST, addLabelSaga),
|
||||
takeEvery(REMOVE_LABEL_REQUEST, removeLabelSaga),
|
||||
takeLatest(CREATE_ISSUE_REQUEST, createIssueSaga),
|
||||
takeLatest(CREATE_ISSUE_SUCCESS, refreshKanboardSaga),
|
||||
takeLatest(LOGOUT, logoutSaga)
|
||||
]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user