Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
fix(board): use array instead of set, update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil143 committed Jul 24, 2018
1 parent 650d7e8 commit f15782e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="f8-board-column">
<div class="f8-board-column__header">
<span class="badge">{{ itemCount }} </span>
<span class="badge">{{ itemCount ? itemCount : 0 }} </span>
<span class="f8-board-column__header-title">{{ columnName }}</span>
</div>
<div class="f8-board-column__wrapper">
Expand Down
4 changes: 2 additions & 2 deletions src/app/effects/work-item.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ export class WorkItemEffects {
.switchMap((w: WorkItemUI) => {
console.log('#### - 5', w);
return [
new WorkItemActions.UpdateSuccess(w),
new ColumnWorkItemActions.UpdateSuccess({
workItemId: w.id,
prevColumnId: wp.payload.prevColumnId,
newColumnIds: w.columnIds
})
}),
new WorkItemActions.UpdateSuccess(w)
];
})
.catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/models/board.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class ColumnWorkItemQuery {

getWorkItemsByColumnId(id: string): Observable<WorkItemUI[]> {
return this.columnWorkitemSource.select(state => state[id])
.map(items => items || new Set<string>([]))
.flatMap(ids => this.workItemQuery.getWorkItemsByIds(Array.from(ids)));
.map(items => items || [])
.switchMap(ids => this.workItemQuery.getWorkItemsByIds(ids));
}
}
4 changes: 2 additions & 2 deletions src/app/models/work-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,11 @@ export class WorkItemQuery {
const selector = createSelector(
workItemEntities,
state => {
return ids.map(i => state[i])
return ids.length > 0 ? ids.map(i => state[i])
// Sometime
.filter(item => !!item)
.map(item => this.resolveWorkItem(item))
.sort((a, b) => a.order - b.order);
.sort((a, b) => b.order - a.order) : [];
}
);
return this.store.select(selector);
Expand Down
6 changes: 3 additions & 3 deletions src/app/reducers/column-workitem.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe('ColumnWorkitemReducer: ', () => {
] as WorkItemUI[];

const columWorkItemState: ColumnWorkItemState = {
'0000-000-05': new Set(['1', '2']),
'0000-000-06': new Set(['1']),
'0000-000-07': new Set(['2'])
'0000-000-05': ['1', '2'],
'0000-000-06': ['1'],
'0000-000-07': ['2']
};

const action = new GetSuccess(workitems);
Expand Down
16 changes: 9 additions & 7 deletions src/app/reducers/column-workitem.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export type Action = WorkItemActions.All | ColumnWorkItemActions.All;
export const ColumnWorkItemReducer: ActionReducer<ColumnWorkItemState> = (state = InitialColumnWorkItemState, action: Action) => {
switch (action.type) {
case WorkItemActions.GET_SUCCESS: {
const cwState = {...state};
let cwState = {};
action.payload.forEach(item => {
if (item.columnIds !== null) {
item.columnIds.forEach(col => {
if (cwState.hasOwnProperty(col)) {
cwState[col].add(item.id);
cwState[col] = [...cwState[col], item.id];
} else {
cwState[col] = new Set([item.id]);
cwState[col] = [item.id];
}
});
}
Expand All @@ -26,16 +26,18 @@ export const ColumnWorkItemReducer: ActionReducer<ColumnWorkItemState> = (state
case ColumnWorkItemActions.UPDATE_SUCCESS: {
const cwState = {...state};
console.log('#### -- 1', cwState);
cwState[action.payload.prevColumnId].delete(action.payload.workItemId);
cwState[action.payload.prevColumnId] =
cwState[action.payload.prevColumnId]
.filter(id => id !== action.payload.workItemId) ;
action.payload.newColumnIds.forEach(col => {
if (cwState.hasOwnProperty(col)) {
cwState[col].add(action.payload.workItemId);
cwState[col] = [...cwState[col], action.payload.workItemId];
} else {
cwState[col] = new Set([action.payload.workItemId]);
cwState[col] = [action.payload.workItemId];
}
});
console.log('#### -- 2', cwState);
return cwState;
return {...cwState};
}
default: {
return {...state};
Expand Down
2 changes: 1 addition & 1 deletion src/app/states/column-workItem.state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type ColumnWorkItemState = {
[id: string]: Set<string>
[id: string]: string[]
};

export const initialState: ColumnWorkItemState = {} as ColumnWorkItemState;

0 comments on commit f15782e

Please sign in to comment.