All files / ee/app/assets/javascripts/boards/components boards_selector.vue

76.47% Statements 13/17
57.14% Branches 8/14
90% Functions 9/10
76.47% Lines 13/17

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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                    5x             6x     6x               1x     1x           6x 2x     6x       6x   6x           12x                   6x 4x            
<script>
import BoardsSelectorFoss from '~/boards/components/boards_selector.vue';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import Tracking from '~/tracking';
import { setError } from '~/boards/graphql/cache_updates';
import epicBoardsQuery from '../graphql/epic_boards.query.graphql';
import { fullBoardId, fullEpicBoardId } from '../boards_util';
 
// This is a false violation of @gitlab/no-runtime-template-compiler, since it
// extends a valid Vue single file component.
// eslint-disable-next-line @gitlab/no-runtime-template-compiler
export default {
  extends: BoardsSelectorFoss,
  mixins: [Tracking.mixin()],
  inject: ['isEpicBoard'],
  computed: {
    showCreate() {
      return this.isEpicBoard || this.multipleIssueBoardsAvailable;
    },
    boardsQuery() {
      return this.isEpicBoard ? epicBoardsQuery : this.issueBoardsQuery;
    },
  },
  methods: {
    fullBoardId(boardId) {
      return this.isEpicBoard ? fullEpicBoardId(boardId) : fullBoardId(boardId);
    },
    epicBoardUpdate(data) {
      Iif (!data?.group) {
        return [];
      }
      return data.group.boards.nodes.map((node) => ({
        id: getIdFromGraphQLId(node.id),
        name: node.name,
      }));
    },
    loadBoards(toggleDropdown = true) {
      if (this.isEpicBoard) {
        this.track('click_dropdown', { label: 'board_switcher' });
      }
 
      Iif (toggleDropdown && this.boards.length > 0) {
        return;
      }
 
      this.$apollo.addSmartQuery('boards', {
        variables() {
          return { fullPath: this.fullPath };
        },
        query: this.boardsQuery,
        update: (data) =>
          this.isEpicBoard ? this.epicBoardUpdate(data) : this.boardUpdate(data, 'boards'),
        watchLoading: (isLoading) => {
          this.loadingBoards = isLoading;
        },
        error(error) {
          setError({
            error,
            message: this.$options.i18n.fetchBoardsError,
          });
        },
      });
 
      if (!this.isEpicBoard) {
        this.loadRecentBoards();
      }
    },
  },
};
</script>