Migration du client sur Typescript

This commit is contained in:
2020-04-30 13:02:56 +02:00
parent 676df834f7
commit 647c5c0806
41 changed files with 428 additions and 234 deletions

View File

@ -10,7 +10,7 @@ export const SAVE_BOARD_REQUEST = "SAVE_BOARD_REQUEST";
export const SAVE_BOARD_SUCCESS = "SAVE_BOARD_SUCCESS";
export const SAVE_BOARD_FAILURE = "SAVE_BOARD_FAILURE";
export function saveBoard(board) {
export function saveBoard(board: any) {
return { type: SAVE_BOARD_REQUEST, board };
};
@ -18,6 +18,6 @@ export const DELETE_BOARD_REQUEST = "DELETE_BOARD_REQUEST";
export const DELETE_BOARD_SUCCESS = "DELETE_BOARD_SUCCESS";
export const DELETE_BOARD_FAILURE = "DELETE_BOARD_FAILURE";
export function deleteBoard(id) {
export function deleteBoard(id: any) {
return { type: DELETE_BOARD_REQUEST, id };
};

View File

@ -2,7 +2,7 @@ export const FETCH_ISSUES_REQUEST = "FETCH_ISSUES_REQUEST";
export const FETCH_ISSUES_SUCCESS = "FETCH_ISSUES_SUCCESS";
export const FETCH_ISSUES_FAILURE = "FETCH_ISSUES_FAILURE";
export function fetchIssues(project) {
export function fetchIssues(project: any) {
return { type: FETCH_ISSUES_REQUEST, project };
};
@ -10,7 +10,7 @@ export const ADD_LABEL_REQUEST = "ADD_LABEL_REQUEST";
export const ADD_LABEL_SUCCESS = "ADD_LABEL_SUCCESS";
export const ADD_LABEL_FAILURE = "ADD_LABEL_FAILURE";
export function addLabel(project, issueNumber, label) {
export function addLabel(project: any, issueNumber: any, label: string) {
return { type: ADD_LABEL_REQUEST, project, issueNumber, label };
}
@ -18,7 +18,7 @@ export const REMOVE_LABEL_REQUEST = "REMOVE_LABEL_REQUEST";
export const REMOVE_LABEL_SUCCESS = "REMOVE_LABEL_SUCCESS";
export const REMOVE_LABEL_FAILURE = "REMOVE_LABEL_FAILURE";
export function removeLabel(project, issueNumber, label) {
export function removeLabel(project: any, issueNumber: any, label: string) {
return { type: REMOVE_LABEL_REQUEST, project, issueNumber, label };
}
@ -26,6 +26,6 @@ export const CREATE_ISSUE_REQUEST = "CREATE_ISSUE_REQUEST";
export const CREATE_ISSUE_SUCCESS = "CREATE_ISSUE_SUCCESS";
export const CREATE_ISSUE_FAILURE = "CREATE_ISSUE_FAILURE";
export function createIssue(project, title, body, label) {
export function createIssue(project: any, title: string, body: any, label: string) {
return { type: CREATE_ISSUE_REQUEST, project, title, body, label };
};

View File

@ -2,12 +2,12 @@ export const BUILD_KANBOARD_REQUEST = "BUILD_KANBOARD_REQUEST";
export const BUILD_KANBOARD_SUCCESS = "BUILD_KANBOARD_SUCCESS";
export const BUILD_KANBOARD_FAILURE = "BUILD_KANBOARD_FAILURE";
export function buildKanboard(board) {
export function buildKanboard(board: string) {
return { type: BUILD_KANBOARD_REQUEST, board };
};
export const MOVE_CARD = "MOVE_CARD";
export function moveCard(boardID, fromLaneID, fromPosition, toLaneID, toPosition) {
export function moveCard(boardID: string, fromLaneID: string, fromPosition: any, toLaneID: any, toPosition: any) {
return { type: MOVE_CARD, boardID, fromLaneID, fromPosition, toLaneID, toPosition };
};

View File

@ -4,7 +4,7 @@ export const defaultState = {
byID: {},
};
export function boardsReducer(state = defaultState, action) {
export function boardsReducer(state = defaultState, action: any) {
switch(action.type) {
case SAVE_BOARD_SUCCESS:
return handleSaveBoardSuccess(state, action);
@ -15,7 +15,7 @@ export function boardsReducer(state = defaultState, action) {
}
}
function handleSaveBoardSuccess(state, action) {
function handleSaveBoardSuccess(state: any, action: any) {
const { board } = action;
return {
...state,
@ -28,8 +28,8 @@ function handleSaveBoardSuccess(state, action) {
};
}
function handleFetchBoardsSuccess(state, action) {
const boardsByID = action.boards.reduce((byID, board) => {
function handleFetchBoardsSuccess(state: any, action: any) {
const boardsByID = action.boards.reduce((byID: any, board: any) => {
byID[board.id] = board;
return byID;
}, {});

View File

@ -2,7 +2,7 @@ const defaultState = {
actions: {}
};
export function flagsReducer(state = defaultState, action) {
export function flagsReducer(state = defaultState, action: any) {
const matches = (/^(.*)_((SUCCESS)|(FAILURE)|(REQUEST))$/).exec(action.type);
if(!matches) return state;

View File

@ -4,7 +4,7 @@ const defaultState = {
byProject: {}
};
export function issuesReducer(state = defaultState, action) {
export function issuesReducer(state = defaultState, action: any) {
switch(action.type) {
case FETCH_ISSUES_SUCCESS:
return handleFetchIssuesSuccess(state, action);
@ -16,7 +16,7 @@ export function issuesReducer(state = defaultState, action) {
}
function handleFetchIssuesSuccess(state, action) {
function handleFetchIssuesSuccess(state: any, action: any) {
return {
...state,
byProject: {
@ -28,7 +28,7 @@ function handleFetchIssuesSuccess(state, action) {
}
}
function handleCreateIssueSuccess(state, action) {
function handleCreateIssueSuccess(state: any, action: any) {
return {
...state,
byProject: {

View File

@ -5,7 +5,7 @@ export const defaultState = {
byID: {},
};
export function kanboardsReducer(state = defaultState, action) {
export function kanboardsReducer(state = defaultState, action: any) {
switch(action.type) {
case BUILD_KANBOARD_SUCCESS:
return handleBuildKanboardSuccess(state, action);
@ -16,7 +16,7 @@ export function kanboardsReducer(state = defaultState, action) {
}
}
function handleBuildKanboardSuccess(state, action) {
function handleBuildKanboardSuccess(state: any, action: any) {
return {
...state,
byID: {
@ -28,7 +28,7 @@ function handleBuildKanboardSuccess(state, action) {
};
}
function handleMoveCard(state, action) {
function handleMoveCard(state: any, action: any) {
const {
boardID, fromLaneID,
fromPosition, toLaneID,

View File

@ -4,7 +4,7 @@ export const defaultState = {
byName: {},
};
export function projectsReducer(state = defaultState, action) {
export function projectsReducer(state = defaultState, action: any) {
switch(action.type) {
case FETCH_PROJECTS_SUCCESS:
return handleFetchProjectsSuccess(state, action);
@ -13,8 +13,8 @@ export function projectsReducer(state = defaultState, action) {
}
}
function handleFetchProjectsSuccess(state, action) {
const projectsByName = action.projects.reduce((byName, project) => {
function handleFetchProjectsSuccess(state: any, action: any) {
const projectsByName = action.projects.reduce((byName: any, project: any) => {
byName[project.full_name] = project;
return byName;
}, {});

View File

@ -1,5 +1,9 @@
import { put, call } from 'redux-saga/effects';
import { FETCH_BOARDS_SUCCESS, SAVE_BOARD_SUCCESS, SAVE_BOARD_FAILURE, FETCH_BOARDS_FAILURE, DELETE_BOARD_FAILURE, DELETE_BOARD_SUCCESS } from '../actions/boards';
import {
FETCH_BOARDS_SUCCESS, SAVE_BOARD_SUCCESS,
SAVE_BOARD_FAILURE, FETCH_BOARDS_FAILURE,
DELETE_BOARD_FAILURE, DELETE_BOARD_SUCCESS
} from '../actions/boards';
import { api } from '../../util/api';
export function* fetchBoardsSaga() {
@ -15,7 +19,7 @@ export function* fetchBoardsSaga() {
yield put({ type: FETCH_BOARDS_SUCCESS, boards });
}
export function* saveBoardSaga(action) {
export function* saveBoardSaga(action: any) {
let { board } = action;
try {
@ -29,11 +33,11 @@ export function* saveBoardSaga(action) {
}
export function* deleteBoardSaga(action) {
export function* deleteBoardSaga(action: any) {
let { id } = action;
try {
board = yield call(api.deleteBoard, id)
yield call(api.deleteBoard, id)
} catch(error) {
yield put({ type: DELETE_BOARD_FAILURE, error });
return

View File

@ -1,8 +1,13 @@
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, CREATE_ISSUE_FAILURE, CREATE_ISSUE_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) {
export function* fetchIssuesSaga(action: any) {
const { project } = action;
let issues = [];
@ -25,10 +30,10 @@ export function* fetchIssuesSaga(action) {
yield put({ type: FETCH_ISSUES_SUCCESS, project, issues });
}
export function* addLabelSaga(action) {
export function* addLabelSaga(action: any) {
const { project, issueNumber, label } = action;
const labels = yield call(gitea.fetchProjectLabels.bind(gitea), project);
const giteaLabel = labels.find(l => l.name === label)
const giteaLabel = labels.find((l: any) => l.name === label)
if (!giteaLabel) {
yield put({ type: ADD_LABEL_FAILURE, error: new Error(`Label "${label}" not found !`) });
@ -45,10 +50,10 @@ export function* addLabelSaga(action) {
yield put({ type: ADD_LABEL_SUCCESS, project, issueNumber, label });
}
export function* removeLabelSaga(action) {
export function* removeLabelSaga(action: any) {
const { project, issueNumber, label } = action;
const labels = yield call(gitea.fetchProjectLabels.bind(gitea), project);
const giteaLabel = labels.find(l => l.name === label)
const giteaLabel = labels.find((l: any) => l.name === label)
if (!giteaLabel) {
yield put({ type: REMOVE_LABEL_FAILURE, error: new Error(`Label "${label}" not found !`) });
@ -66,10 +71,10 @@ export function* removeLabelSaga(action) {
yield put({ type: REMOVE_LABEL_SUCCESS, project, issueNumber, label });
}
export function* createIssueSaga(action) {
export function* createIssueSaga(action: any) {
const { project, title, label, body } = action;
const labels = yield call(gitea.fetchProjectLabels.bind(gitea), project);
const giteaLabel = labels.find(l => l.name === label)
const giteaLabel = labels.find((l: any) => l.name === label)
if (!giteaLabel) {
yield put({ type: CREATE_ISSUE_FAILURE, error: new Error(`Label "${label}" not found !`) });

View File

@ -1,9 +1,9 @@
import { select, put } from 'redux-saga/effects';
import { fetchIssues, addLabel, removeLabel } from '../actions/issues';
import { fetchIssuesSaga } from './issues';
import { BUILD_KANBOARD_SUCCESS, buildKanboard } from '../actions/kanboards';
import { BUILD_KANBOARD_SUCCESS, buildKanboard, BUILD_KANBOARD_FAILURE } from '../actions/kanboards';
export function* moveCardSaga(action) {
export function* moveCardSaga(action: any) {
const {
boardID, fromLaneID,
fromPosition, toLaneID,
@ -29,14 +29,15 @@ export function* moveCardSaga(action) {
}
export function* buildKanboardSaga(action) {
export function* buildKanboardSaga(action: any) {
const { board } = action;
let kanboard;
try {
for (let p, i = 0; (p = board.projects[i]); i++) {
yield* fetchIssuesSaga(fetchIssues(p));
const { project } = yield fetchIssues(p);
yield fetchIssuesSaga({ project });
}
const issues = yield select(state => state.issues);
@ -51,25 +52,25 @@ export function* buildKanboardSaga(action) {
yield put({ type: BUILD_KANBOARD_SUCCESS, kanboard });
}
export function* refreshKanboardSaga(action) {
export function* refreshKanboardSaga(action: any) {
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++) {
for (let b: any, 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) {
function createCards(projects: any[], issues: any, lane: any) {
return projects.reduce((laneCards, p) => {
const projectIssues = p in issues.byProject ? issues.byProject[p] : [];
return projectIssues.reduce((projectCards, issue) => {
const hasLabel = issue.labels.some(l => l.name === lane.issueLabel);
return projectIssues.reduce((projectCards: any, issue: any) => {
const hasLabel = issue.labels.some((l: any) => l.name === lane.issueLabel);
if (hasLabel) {
projectCards.push({
@ -87,7 +88,7 @@ function createCards(projects, issues, lane) {
}, []);
}
function createLane(projects, issues, lane, index) {
function createLane(projects: any, issues: any, lane: any, index: any) {
return {
id: index,
title: lane.title,
@ -95,7 +96,7 @@ function createLane(projects, issues, lane, index) {
}
}
function createKanboard(board, issues) {
function createKanboard(board: any, issues: any) {
if (!board) return null;
const kanboard = {

View File

@ -30,8 +30,8 @@ export function* rootSaga() {
]);
}
export function patternFromRegExp(re) {
return (action) => {
export function patternFromRegExp(re: any) {
return (action: any) => {
return re.test(action.type);
};
}

View File

@ -1,8 +1,8 @@
export function selectBoardByUserProjects(boardsByID, projectsByName) {
export function selectBoardByUserProjects(boardsByID: any, projectsByName: any) {
const userProjects = Object.keys(projectsByName);
return Object.keys(boardsByID).reduce((filteredBoardsByID, boardID) => {
return Object.keys(boardsByID).reduce((filteredBoardsByID: any, boardID: string) => {
const board = boardsByID[boardID];
const hasProject = board.projects.length === 0 || board.projects.some(p => userProjects.indexOf(p) !== -1);
const hasProject = board.projects.length === 0 || board.projects.some((p: any) => userProjects.indexOf(p) !== -1);
if (hasProject) {
filteredBoardsByID[boardID] = board;
}

View File

@ -1,4 +1,4 @@
export function selectFlagsIsLoading(state, ...actionPrefixes) {
export function selectFlagsIsLoading(state: any, ...actionPrefixes: any[]) {
const { actions } = state.flags;
return actionPrefixes.reduce((isLoading, prefix) => {
if (!(prefix in actions)) return isLoading;