@prefecthq/prefect-ui-library
Version:
This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.
23 lines (18 loc) • 728 B
text/typescript
import { RunHistory } from '@/models/RunHistory'
import { StateHistory } from '@/models/StateHistory'
import { mapper } from '@/services/Mapper'
import { DateString } from '@/types/dates'
import { dateFunctions } from '@/utilities/timezone'
export class FlowRunHistoryMap {
private readonly map: Map<DateString, StateHistory[]>
public constructor(runHistory: RunHistory[]) {
this.map = new Map(runHistory.map(history => [this.getKey(history.intervalStart), history.states]))
}
public get(date: Date): StateHistory[] {
const key = this.getKey(date)
return this.map.get(key) ?? []
}
private getKey(date: Date): DateString {
return mapper.map('Date', dateFunctions.startOfDay(date), 'string')
}
}