summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/store/getters.js
blob: 4ce395a9106570900fb83ba2b237b4f93b1506d4 (plain)
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
import _ from 'underscore';
import { __ } from '~/locale';
import { isScrolledToBottom } from '~/lib/utils/scroll_utils';

export const headerActions = state => {
  if (state.job.new_issue_path) {
    return [
      {
        label: __('New issue'),
        path: state.job.new_issue_path,
        cssClass:
          'js-new-issue btn btn-success btn-inverted d-none d-md-block d-lg-block d-xl-block',
        type: 'link',
      },
    ];
  }
  return [];
};

export const headerTime = state => (state.job.started ? state.job.started : state.job.created_at);

export const shouldRenderCalloutMessage = state =>
  !_.isEmpty(state.job.status) && !_.isEmpty(state.job.callout_message);

/**
 * When job has not started the key will be null
 * When job started the key will be a string with a date.
 */
export const shouldRenderTriggeredLabel = state => _.isString(state.job.started);

export const hasEnvironment = state => !_.isEmpty(state.job.deployment_status);

/**
 * Checks if it the job has trace.
 * Used to check if it should render the job log or the empty state
 * @returns {Boolean}
 */
export const hasTrace = state => state.job.has_trace || (!_.isEmpty(state.job.status) && state.job.status.group === 'running');

export const emptyStateIllustration = state =>
  (state.job && state.job.status && state.job.status.illustration) || {};

export const emptyStateAction = state =>  (state.job && state.job.status && state.job.status.action) || {};
/**
 * When the job is pending and there are no available runners
 * we need to render the stuck block;
 *
 * @returns {Boolean}
 */
export const isJobStuck = state =>
  (!_.isEmpty(state.job.status) && state.job.status.group === 'pending') &&
  (!_.isEmpty(state.job.runners) && state.job.runners.available === false);

export const isScrollingDown = state => isScrolledToBottom() && !state.isTraceComplete;

// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};