From 3324f715448956661ae4b59d501edf6fbc57f98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Gaud=C3=A9?= Date: Sat, 20 Mar 2021 00:58:20 +0100 Subject: [PATCH] Manage milestones on multi-projects --- client/src/components/BoardPage/BoardPage.tsx | 17 ++++++++++++----- client/src/store/actions/projects.ts | 4 ++-- client/src/store/reducers/projects.ts | 3 ++- client/src/store/sagas/kanboards.ts | 2 +- client/src/store/sagas/projects.ts | 15 +++++++++++---- client/src/store/sagas/root.ts | 4 ++-- client/src/util/gitea.ts | 2 +- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/client/src/components/BoardPage/BoardPage.tsx b/client/src/components/BoardPage/BoardPage.tsx index f3828ed..8a66cad 100644 --- a/client/src/components/BoardPage/BoardPage.tsx +++ b/client/src/components/BoardPage/BoardPage.tsx @@ -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 { } 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 { renderBoard() { const { kanboard, board, milestones } = this.props; + const { selectedMilestone } = this.state; if (!kanboard) { return @@ -91,7 +91,15 @@ export class BoardPage extends React.Component { { milestones.length > 0 ? milestones.map((k: any) => { return ( - + + { + k.milestones.map((m: any) => { + return ( + + ) + }) + } + ) }) : "" } @@ -326,9 +334,8 @@ export class BoardPage extends React.Component { 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)); } diff --git a/client/src/store/actions/projects.ts b/client/src/store/actions/projects.ts index 23387f2..9d5f372 100644 --- a/client/src/store/actions/projects.ts +++ b/client/src/store/actions/projects.ts @@ -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 }; }; \ No newline at end of file diff --git a/client/src/store/reducers/projects.ts b/client/src/store/reducers/projects.ts index 7919588..7bfbf3d 100644 --- a/client/src/store/reducers/projects.ts +++ b/client/src/store/reducers/projects.ts @@ -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, diff --git a/client/src/store/sagas/kanboards.ts b/client/src/store/sagas/kanboards.ts index f72b7db..663f275 100644 --- a/client/src/store/sagas/kanboards.ts +++ b/client/src/store/sagas/kanboards.ts @@ -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 }); } diff --git a/client/src/store/sagas/projects.ts b/client/src/store/sagas/projects.ts index 299703c..bc294d3 100644 --- a/client/src/store/sagas/projects.ts +++ b/client/src/store/sagas/projects.ts @@ -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; diff --git a/client/src/store/sagas/root.ts b/client/src/store/sagas/root.ts index cf11d77..45dc0f4 100644 --- a/client/src/store/sagas/root.ts +++ b/client/src/store/sagas/root.ts @@ -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), diff --git a/client/src/util/gitea.ts b/client/src/util/gitea.ts index cefe44e..f4eafd9 100644 --- a/client/src/util/gitea.ts +++ b/client/src/util/gitea.ts @@ -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)