Skip to content

Commit

Permalink
Handle multiple doing columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Minishlink committed Aug 26, 2018
1 parent 9df9cdd commit 50b0dad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
32 changes: 22 additions & 10 deletions src/modules/cards/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,30 @@ export function* fetchNotDoneCards(): Generator<*, *, *> {
if (!currentProject || !currentProject.columnMapping) yield cancel();

// fetch in parallel
const cardsCalls = yield all(
Object.values(currentProject.columnMapping).map(
id =>
// if it's not the active sprint, there's no cards that are not done
!isCurrentSprintActive ? all([]) : call(Trello.getCardsFromList, token.trello, id)
)
);
const columnsNames = [];
const columnsCalls = [];
const createCall = (columnId: string) =>
!isCurrentSprintActive ? all([]) : call(Trello.getCardsFromList, token.trello, columnId);
Object.entries(currentProject.columnMapping).forEach(([columnName, columnId]) => {
if (typeof columnId === 'string') {
columnsNames.push(columnName);
columnsCalls.push(createCall(columnId));
} else {
// $FlowFixMe: this is an array
columnId.forEach(subColumnId => {
columnsNames.push(columnName);
columnsCalls.push(createCall(subColumnId));
});
}
});

const columnsCallsResults = yield all(columnsCalls);

let cards = {};
let i = 0;
for (let key of Object.keys(currentProject.columnMapping)) {
cards[key] = adaptCardsFromTrello(cardsCalls[i++]);
for (let i = 0; i < columnsNames.length; i++) {
const columnName = columnsNames[i];
const newCards = columnsCallsResults[i];
cards[columnName] = (cards[columnName] || []).concat(adaptCardsFromTrello(newCards));
}

yield put(putCards(cards));
Expand Down
11 changes: 8 additions & 3 deletions src/services/adapter/ProjectScrumbleToAppAdapter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// @flow
import type { ProjectType } from '../../types';
import type { ScrumbleProjectType } from '../../types/Scrumble';
import type { ProjectType, ColumnMappingType } from '../../types';
import type { ScrumbleProjectType, ScrumbleColumnMappingType } from '../../types/Scrumble';

const retroCompatibleScrumbleColumnMapping = (scrumbleColumnMapping: ScrumbleColumnMappingType): ColumnMappingType => ({
...scrumbleColumnMapping,
doing: typeof scrumbleColumnMapping.doing === 'string' ? [scrumbleColumnMapping.doing] : scrumbleColumnMapping.doing,
});

export default (project: ScrumbleProjectType): ProjectType => ({
id: project.id,
boardId: project.boardId,
name: project.name,
columnMapping: project.columnMapping,
columnMapping: retroCompatibleScrumbleColumnMapping(project.columnMapping),
});
10 changes: 7 additions & 3 deletions src/types/Project.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { ScrumbleColumnMappingType } from './Scrumble';

// @flow
export type ProjectType = {|
id: number,
boardId: string,
name: string,
columnMapping: ColumnMappingType,
|};

type ColumnMappingType = ScrumbleColumnMappingType;
type ColumnMappingType = {|
blocked: string,
doing: string[],
sprint: string,
toValidate: string,
|};
2 changes: 1 addition & 1 deletion src/types/Scrumble/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type ScrumbleColumnMappingType = {
blocked: string,
doing: string,
doing: string | string[],
sprint: string,
toValidate: string,
};
Expand Down

0 comments on commit 50b0dad

Please sign in to comment.