{"size": 1144, "ext": "js", "max_stars_repo_path": "src/components/Jobs/components/PreviewsJobs/PreviewsJobs.js", "max_stars_repo_name": "folio-org/ui-catload", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/Jobs/components/PreviewsJobs/PreviewsJobs.js", "max_issues_repo_name": "folio-org/ui-catload", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/Jobs/components/PreviewsJobs/PreviewsJobs.js", "max_forks_repo_name": "folio-org/ui-catload", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.3333333333, "max_line_length": 93, "alphanum_fraction": 0.652972028}
import React, { PureComponent } from 'react';
import { get } from 'lodash';

import { JobsListAccordion } from '@folio/stripes-data-transfer-components';

import { itemFormatter } from '../../utils';
import { sortPreviewJobs } from './sortPreviewJobs';
import { JOB_STATUSES } from '../../../../utils';
import { DataFetcherContext } from '../../../DataFetcher';

export class PreviewsJobs extends PureComponent {
  static contextType = DataFetcherContext;

  prepareJobsData() {
    const jobStatuses = [JOB_STATUSES.READY_FOR_PREVIEW, JOB_STATUSES.PREPARING_FOR_PREVIEW];
    const jobs = [...get(this.context, ['jobs'], [])]
      .filter(({ uiStatus }) => jobStatuses.includes(uiStatus));

    return sortPreviewJobs(jobs);
  }

  render() {
    const { hasLoaded } = this.context;
    const jobs = this.prepareJobsData();

    return (
      <div data-test-preview-jobs>
        <JobsListAccordion
          jobs={jobs}
          hasLoaded={hasLoaded}
          itemFormatter={itemFormatter}
          titleId="ui-data-import.previewJobs"
          emptyMessageId="ui-data-import.noPreviewsJobsMessage"
        />
      </div>
    );
  }
}
