All files / publisher/pages/Releases/reducers pendingCloses.ts

100% Statements 11/11
100% Branches 9/9
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                          31x   3x 1x   2x   3x 2x   1x   1x 1x   2x   23x      
import { ReleasesReduxState } from "../../../types/releaseTypes";
import { CLOSE_CHANNEL, PendingClosesAction } from "../actions/pendingCloses";
import {
  CANCEL_PENDING_RELEASES,
  RELEASE_REVISION
} from "../actions/pendingReleases";
 
// channels to be closed:
// [ "track/risk", ... ]
export default function pendingCloses(
  state: ReleasesReduxState["pendingCloses"] = [],
  action: PendingClosesAction
) {
  switch (action.type) {
    case CLOSE_CHANNEL:
      if (state.includes(action.payload.channel)) {
        return state;
      }
      return [...state, action.payload.channel];
    case RELEASE_REVISION:
      if (!state.includes(action.payload.channel)) {
        return state;
      }
      state = [...state];
      // remove channel released to from closing channels
      state.splice(state.indexOf(action.payload.channel), 1);
      return state;
    case CANCEL_PENDING_RELEASES:
      return [];
    default:
      return state;
  }
}