All files / src/components running-jobs-indicator.tsx

0% Statements 0/16
0% Branches 0/3
0% Functions 0/3
0% Lines 0/16

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                                                                                                                                                           
import React from 'react';
 
import { UseSignal } from '@jupyterlab/apputils';
import { GroupItem, interactiveItem, TextItem } from '@jupyterlab/statusbar';
 
import { calendarMonthIcon } from './icons';
 
import { useTranslator } from '../hooks';
import { NotebookJobsListingModel } from '../model';
 
import { LabIcon } from '@jupyterlab/ui-components';
 
export type RunningJobsIndicatorComponentProps = {
  /**
   * A click handler for the component. By default this is used
   * to activate the scheduled jobs side panel.
   */
  handleClick: () => void;
 
  runningJobs: number | undefined;
};
 
export function RunningJobsIndicatorComponent(
  props: RunningJobsIndicatorComponentProps
) {
  const runningJobs = props.runningJobs;
 
  // Don't display a status bar indicator if there are no running jobs (0 or undefined).
  Iif (!runningJobs) {
    return null;
  }
 
  const trans = useTranslator('jupyterlab');
 
  const itemTitle =
    runningJobs > 1
      ? trans.__('%1 jobs running', runningJobs)
      : trans.__('%1 job running', runningJobs);
 
  return (
    <div
      className={interactiveItem}
      style={{ paddingLeft: '4px', paddingRight: '4px' }}
    >
      <GroupItem spacing={4} title={itemTitle} onClick={props.handleClick}>
        <TextItem source={`${runningJobs}`} />
        <LabIcon.resolveReact icon={calendarMonthIcon} tag="span" />
      </GroupItem>
    </div>
  );
}
 
export type RunningJobsIndicatorProps = {
  /**
   * A click handler for the item. By default this is used
   * to activate the scheduled jobs side panel.
   */
  onClick: () => void;
 
  /**
   * The model representing a listing of scheduled jobs.
   */
  model: NotebookJobsListingModel;
};
 
export function RunningJobsIndicator(props: RunningJobsIndicatorProps) {
  return (
    <UseSignal signal={props.model.inProgressJobCountChanged}>
      {(_, newCount) => (
        <RunningJobsIndicatorComponent
          handleClick={props.onClick}
          runningJobs={newCount}
        />
      )}
    </UseSignal>
  );
}