All files / applications/go-by-transit/src/view/bookmarks/component/bookmarkSections/sectionSelector BookmarksInSectionSelectionHandler.tsx

71.42% Statements 10/14
50% Branches 2/4
100% Functions 2/2
71.42% Lines 10/14

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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                      4x 4x 4x 4x           8x 8x   8x                   1x           1x 1x              
import React, { Component } from "react";
import { StopLocation } from "../../../../../api/trimet/interfaces/types";
import BookmarksInSectionSelector from "./BookmarksInSectionSelector";
 
interface Props {
  bookmarksInSection: StopLocation[];
  allBookmarks: StopLocation[];
  removeBookmarkFromSection: (
    bookmarkSectionId: number,
    stopId: number
  ) => void;
  addBookmarkToBookmarkSection: (
    bookmarkSectionId: number,
    stopId: number
  ) => void;
  removeAllBookmarksFromSection: (bookmarkSectionId: number) => void;
  bookmarkSectionId: number;
}
 
export const REMOVE_VALUE = "remove-value";
export const SELECT_OPTION = "select-option";
export const POP_VALUE = "pop-value";
export const CLEAR = "clear";
 
export default class BookmarksInSectionSelectionHandler extends Component<
  Props
> {
  public render() {
    const { allBookmarks, bookmarksInSection, bookmarkSectionId } = this.props;
    const onChange = this.onChange.bind(this, bookmarkSectionId);
 
    return (
      <BookmarksInSectionSelector
        bookmarksInSection={bookmarksInSection}
        allBookmarks={allBookmarks}
        onChange={onChange}
      />
    );
  }
 
  private onChange(id, val, event) {
    switch (event.action) {
      case CLEAR:
        this.props.removeAllBookmarksFromSection(id);
        break;
      case REMOVE_VALUE:
      case POP_VALUE:
        this.props.removeBookmarkFromSection(id, event.removedValue.value);
        break;
      case SELECT_OPTION:
        this.props.addBookmarkToBookmarkSection(id, event.option.value);
        break;
    }
  }
}