All files / ee/app/assets/javascripts/analytics/cycle_analytics/store getters.js

100% Statements 33/33
70% Branches 14/20
100% Functions 16/16
100% Lines 26/26

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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87                            9x 92x   129x   94x   95x   9x 98x   9x 88x   9x 2x   9x                   128x   128x             128x               9x   9x 88x   9x 7x   9x 151x               9x 236x             9x 19x  
import { dateFormats } from '~/analytics/shared/constants';
import { OVERVIEW_STAGE_ID } from '~/analytics/cycle_analytics/constants';
import { filterStagesByHiddenStatus } from '~/analytics/cycle_analytics/utils';
import {
  pathNavigationData as basePathNavigationData,
  paginationParams as basePaginationParams,
} from '~/analytics/cycle_analytics/store/getters';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import dateFormat from '~/lib/dateformat';
import { HTTP_STATUS_FORBIDDEN } from '~/lib/utils/http_status';
import { filterToQueryObject } from '~/vue_shared/components/filtered_search_bar/filtered_search_utils';
import { DEFAULT_VALUE_STREAM_ID, OVERVIEW_STAGE_CONFIG } from '../constants';
import { NAMESPACE_TYPES } from '../../../vue_shared/components/runner_tags_dropdown/constants';
 
export const isProjectNamespace = ({ namespace }) =>
  Boolean(namespace.type?.toLowerCase() === NAMESPACE_TYPES.PROJECT);
 
export const namespacePath = ({ namespace }) => namespace?.fullPath || null;
 
export const hasNoAccessError = (state) => state.errorCode === HTTP_STATUS_FORBIDDEN;
 
export const hasValueStreams = ({ valueStreams }) => Boolean(valueStreams?.length);
 
export const currentValueStreamId = ({ selectedValueStream }) =>
  selectedValueStream?.id || DEFAULT_VALUE_STREAM_ID;
 
export const selectedProjectIds = ({ selectedProjects }) =>
  selectedProjects?.map(({ id }) => getIdFromGraphQLId(id)) || [];
 
export const selectedProjectFullPaths = ({ selectedProjects }) =>
  selectedProjects?.map(({ fullPath }) => fullPath) || [];
 
export const cycleAnalyticsRequestParams = (state, getters) => {
  const {
    createdAfter = null,
    createdBefore = null,
    filters: {
      authors: { selected: selectedAuthor },
      milestones: { selected: selectedMilestone },
      assignees: { selectedList: selectedAssigneeList },
      labels: { selectedList: selectedLabelList },
    },
  } = state;
 
  const filterBarQuery = filterToQueryObject({
    milestone_title: selectedMilestone,
    author_username: selectedAuthor,
    label_name: selectedLabelList,
    assignee_username: selectedAssigneeList,
  });
 
  return {
    project_ids: getters.selectedProjectIds?.length ? getters.selectedProjectIds : null,
    created_after: createdAfter ? dateFormat(createdAfter, dateFormats.isoDate) : null,
    created_before: createdBefore ? dateFormat(createdBefore, dateFormats.isoDate) : null,
    ...filterBarQuery,
  };
};
 
export const paginationParams = basePaginationParams;
 
export const hiddenStages = ({ stages }) => filterStagesByHiddenStatus(stages);
export const activeStages = ({ stages }) => filterStagesByHiddenStatus(stages, false);
 
export const customStageFormActive = ({ isCreatingCustomStage, isEditingCustomStage }) =>
  Boolean(isCreatingCustomStage || isEditingCustomStage);
 
export const isOverviewStageSelected = ({ selectedStage }) =>
  selectedStage?.id === OVERVIEW_STAGE_ID;
 
/**
 * Until there are controls in place to edit stages outside of the stage table,
 * the path navigation component will only display active stages.
 *
 * https://gitlab.com/gitlab-org/gitlab/-/issues/216227
 */
export const pathNavigationData = ({ stages, medians, stageCounts, selectedStage }) =>
  basePathNavigationData({
    stages: [OVERVIEW_STAGE_CONFIG, ...stages],
    medians,
    stageCounts,
    selectedStage,
  });
 
export const selectedStageCount = ({ selectedStage, stageCounts }) =>
  stageCounts[selectedStage.id] || null;