Manage milestones on multi-projects

This commit is contained in:
Benjamin Gaudé 2021-03-20 00:58:20 +01:00
parent 7ca6e63680
commit 3324f71544
7 changed files with 31 additions and 16 deletions

View File

@ -8,7 +8,7 @@ import { buildKanboard, moveCard } from '../../store/actions/kanboards';
import { Loader } from '../Loader';
import { IssueCard } from './IssueCard';
import { Modal } from '../Modal';
import { fetchProjectMilestones } from '../../store/actions/projects';
import { fetchProjectsMilestones } from '../../store/actions/projects';
export interface BoardPageProps extends DispatchProp {
board: any
@ -52,7 +52,6 @@ export class BoardPage extends React.Component<BoardPageProps> {
}
handleMilestonesChange(e: any) {
console.log("EVT VALUE", e.target.value);
let m = (e.target as HTMLInputElement).value;
this.setState(state => ({ ...state, selectedMilestone: m }), this.requestBuildKanboard);
//this.requestBuildKanboard();
@ -69,6 +68,7 @@ export class BoardPage extends React.Component<BoardPageProps> {
renderBoard() {
const { kanboard, board, milestones } = this.props;
const { selectedMilestone } = this.state;
if (!kanboard) {
return <Loader></Loader>
@ -91,7 +91,15 @@ export class BoardPage extends React.Component<BoardPageProps> {
{
milestones.length > 0 ? milestones.map((k: any) => {
return (
<option value={k.title} key={k.id}>{k.title}</option>
<optgroup label={k.project}>
{
k.milestones.map((m: any) => {
return (
<option value={m.title} key={m.id}>{m.title}</option>
)
})
}
</optgroup>
)
}) : ""
}
@ -326,9 +334,8 @@ export class BoardPage extends React.Component<BoardPageProps> {
requestBuildKanboard() {
const { board } = this.props;
const { selectedMilestone } = this.state;
console.log("SELECTED MILESTONE", selectedMilestone)
if (!board) return;
this.props.dispatch(fetchProjectMilestones(board.projects[0]));
this.props.dispatch(fetchProjectsMilestones(board.projects));
this.props.dispatch(buildKanboard(board, selectedMilestone));
}

View File

@ -10,6 +10,6 @@ export function fetchProjects() {
return { type: FETCH_PROJECTS_REQUEST };
};
export function fetchProjectMilestones(project: any) {
return { type: FETCH_PROJECT_MILESTONES_REQUEST, project };
export function fetchProjectsMilestones(projects: any) {
return { type: FETCH_PROJECT_MILESTONES_REQUEST, projects };
};

View File

@ -2,7 +2,7 @@ import { FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_MILESTONES_SUCCESS } from "../act
export const defaultState = {
byName: {},
milestones: ""
milestones: {}
};
export function projectsReducer(state = defaultState, action: any) {
@ -32,6 +32,7 @@ function handleFetchProjectsSuccess(state: any, action: any) {
}
function handleFetchProjectMilestonesSuccess(state: any, action: any) {
console.log(action.milestones);
return {
...state,
milestones: action.milestones,

View File

@ -39,7 +39,7 @@ export function* buildKanboardSaga(action: any) {
try {
for (let p, i = 0; (p = board.projects[i]); i++) {
const { project } = yield fetchIssues(p, "test");
const { project } = yield fetchIssues(p, milestones);
yield fetchIssuesSaga({ project: project, milestones: milestones });
}

View File

@ -15,11 +15,18 @@ export function* fetchProjectsSaga() {
yield put({ type: FETCH_PROJECTS_SUCCESS, projects });
}
export function* fetchProjectMilestonesSaga(action: any) {
const { project } = action;
let milestones;
export function* fetchProjectsMilestonesSaga(action: any) {
const { projects } = action;
let milestones = [];
try {
milestones = yield call(gitea.fetchMilestones.bind(gitea), project)
for (var i = 0; i < projects.length; i++) {
console.log("PROJECT ", projects[i])
milestones.push({
project: projects[i],
milestones: yield call(gitea.fetchMilestones.bind(gitea), projects[i])
})
}
console.log("MILESTONES", milestones)
} catch (error) {
yield put({ type: FETCH_PROJECT_MILESTONES_FAILURE, error });
return;

View File

@ -5,7 +5,7 @@ import { fetchBoardsSaga, saveBoardSaga, deleteBoardSaga } from './boards';
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, FETCH_PROJECT_MILESTONES_REQUEST } from '../actions/projects';
import { fetchProjectMilestonesSaga, fetchProjectsSaga } from './projects';
import { fetchProjectsMilestonesSaga, fetchProjectsSaga } from './projects';
import { LOGOUT_REQUEST, LOGOUT_SUCCESS } from '../actions/logout';
import { logoutSaga, logoutSuccessSaga } from './logout';
import { BUILD_KANBOARD_REQUEST, MOVE_CARD } from '../actions/kanboards';
@ -22,7 +22,7 @@ export function* rootSaga() {
takeLatest(DELETE_BOARD_REQUEST, deleteBoardSaga),
takeLatest(FETCH_ISSUES_REQUEST, fetchIssuesSaga),
takeLatest(FETCH_PROJECTS_REQUEST, fetchProjectsSaga),
takeLatest(FETCH_PROJECT_MILESTONES_REQUEST, fetchProjectMilestonesSaga),
takeLatest(FETCH_PROJECT_MILESTONES_REQUEST, fetchProjectsMilestonesSaga),
takeEvery(MOVE_CARD, moveCardSaga),
takeEvery(ADD_LABEL_REQUEST, addLabelSaga),
takeEvery(REMOVE_LABEL_REQUEST, removeLabelSaga),

View File

@ -8,7 +8,7 @@ export class GiteaUnauthorizedError extends Error {
export class GiteaClient {
fetchIssues(project: any, page = 1, milestones = "") {
fetchIssues(project: any, page = "", milestones = "") {
return fetch(`/gitea/api/v1/repos/${project}/issues?page=${page}&milestones=${milestones}`)
.then(this.assertAuthorization)
.then(this.assertOk)