github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/dashboard/frontend/src/utils/job.ts (about)

     1  import {
     2    Job,
     3    JobShardState,
     4  } from '../types'
     5  
     6  export const getShortId = (id: string, length = 8) => {
     7    return id.slice(0, length)
     8  }
     9  
    10  export const getJobShardState = (job: Job): JobShardState | undefined => {
    11    const nodeStates = job.Status.JobState.Nodes || {}
    12    const nonEmptyStates = Object.keys(nodeStates)
    13      .filter(nodeID => {
    14        const state = nodeStates[nodeID]
    15        if(!state) return false
    16        const shardState = (state.Shards || {})['0']
    17        if(!shardState) return false
    18        return shardState.State === 'Cancelled' ? false : true
    19      })
    20      .map(nodeID => nodeStates[nodeID].Shards['0'])
    21    return nonEmptyStates[0]
    22  }
    23  
    24  export const getShardStateTitle = (shardState: JobShardState | undefined): string => {
    25    return shardState ?
    26      shardState.State :
    27      'Unknown'
    28  }
    29  
    30  export const getJobStateTitle = (job: Job) => getShardStateTitle(getJobShardState(job))