Module: lib/util

    Namespaces

    Interfaces

    Type aliases

    DateFormatOptions

    Ƭ DateFormatOptions: "brief" | "mini"

    Defined in

    lib/util.ts:33


    DateParam

    Ƭ DateParam: string | number | Date

    Defined in

    lib/util.ts:31

    Variables

    CLUSTER_ACTION_GRACE_PERIOD

    CLUSTER_ACTION_GRACE_PERIOD: 5000

    Defined in

    lib/util.ts:29

    Functions

    compareUnits

    compareUnits(quantity1, quantity2): boolean

    Parameters

    Name Type
    quantity1 string
    quantity2 string

    Returns

    boolean

    Defined in

    lib/util.ts:301


    filterGeneric

    filterGeneric<T>(item, filter, matchCriteria?): boolean

    Filters a generic item based on the filter state.

    The item is considered to match if any of the matchCriteria (described as JSONPath) matches the filter.search contents. Case matching is insensitive.

    Type parameters

    Name Type
    T extends Object = { [key: string]: any; }

    Parameters

    Name Type Description
    item T The item to filter.
    filter FilterState The filter state.
    matchCriteria? string[] The JSONPath criteria to match.

    Returns

    boolean

    Defined in

    redux/filterSlice.ts:73


    filterResource

    filterResource(item, filter, matchCriteria?): boolean

    Filters a resource based on the filter state.

    Parameters

    Name Type Description
    item KubeObjectInterface | KubeEvent The item to filter.
    filter FilterState The filter state.
    matchCriteria? string[] The JSONPath criteria to match.

    Returns

    boolean

    True if the item matches the filter, false otherwise.

    Defined in

    redux/filterSlice.ts:27


    formatDuration

    formatDuration(duration, options?): string

    Format a duration in milliseconds to a human-readable string.

    Parameters

    Name Type Description
    duration number The duration in milliseconds.
    options TimeAgoOptions format takes “brief” or “mini”. “brief” rounds the date and uses the largest suitable unit (e.g. “4 weeks”). “mini” uses something like “4w” (for 4 weeks).

    Returns

    string

    The formatted duration.

    Defined in

    lib/util.ts:65


    getCluster

    getCluster(): string | null

    Returns

    string | null

    The current cluster name, or null if not in a cluster context.

    Defined in

    lib/cluster.ts:20


    getClusterPrefixedPath

    getClusterPrefixedPath(path?): string

    Parameters

    Name Type
    path? null | string

    Returns

    string

    A path prefixed with cluster path, and the given path.

    The given path does not start with a /, it will be added.

    Defined in

    lib/cluster.ts:9


    getPercentStr

    getPercentStr(value, total): null | string

    Parameters

    Name Type
    value number
    total number

    Returns

    null | string

    Defined in

    lib/util.ts:102


    getReadyReplicas

    getReadyReplicas(item): any

    Parameters

    Name Type
    item Workload

    Returns

    any

    Defined in

    lib/util.ts:111


    getResourceMetrics

    getResourceMetrics(item, metrics, resourceType): any[]

    Parameters

    Name Type
    item Node
    metrics KubeMetrics []
    resourceType "cpu" | "memory"

    Returns

    any[]

    Defined in

    lib/util.ts:129


    getResourceStr

    getResourceStr(value, resourceType): string

    Parameters

    Name Type
    value number
    resourceType "cpu" | "memory"

    Returns

    string

    Defined in

    lib/util.ts:119


    getTotalReplicas

    getTotalReplicas(item): any

    Parameters

    Name Type
    item Workload

    Returns

    any

    Defined in

    lib/util.ts:115


    localeDate

    localeDate(date): string

    Parameters

    Name Type
    date DateParam

    Returns

    string

    Defined in

    lib/util.ts:85


    normalizeUnit

    normalizeUnit(resourceType, quantity): string

    Parameters

    Name Type
    resourceType string
    quantity string

    Returns

    string

    Defined in

    lib/util.ts:310


    timeAgo

    timeAgo(date, options?): string

    Show the time passed since the given date, in the desired format.

    Parameters

    Name Type Description
    date DateParam The date since which to calculate the duration.
    options TimeAgoOptions format takes “brief” or “mini”. “brief” rounds the date and uses the largest suitable unit (e.g. “4 weeks”). “mini” uses something like “4w” (for 4 weeks).

    Returns

    string

    The formatted date.

    Defined in

    lib/util.ts:46


    useErrorState

    useErrorState(dependentSetter?): any[]

    Parameters

    Name Type
    dependentSetter? (…args: any) => void

    Returns

    any[]

    Defined in

    lib/util.ts:168


    useFilterFunc

    useFilterFunc<T>(matchCriteria?): (item: T) => boolean

    Type parameters

    Name Type
    T extends KubeObjectInterface | KubeEvent | { [key: string]: any; } = KubeObjectInterface | KubeEvent

    Parameters

    Name Type Description
    matchCriteria? string[] The JSONPath criteria to match.

    Returns

    fn

    A filter function that can be used to filter a list of items.

    ▸ (item): boolean

    Parameters
    Name Type
    item T
    Returns

    boolean

    Defined in

    lib/util.ts:153


    useId

    useId(prefix?): undefined | string

    Creates a unique ID, with the given prefix. If UNDER_TEST is set to true, it will return the same ID every time, so snapshots do not get invalidated.

    Parameters

    Name Type Default value
    prefix string ''

    Returns

    undefined | string

    Defined in

    lib/util.ts:389


    useURLState

    useURLState(key, defaultValue): [number, React.Dispatch<React.SetStateAction<number>>]

    A hook to manage a state variable that is also stored in the URL.

    Parameters

    Name Type Description
    key string The name of the key in the URL. If empty, then the hook behaves like useState.
    defaultValue number -

    Returns

    [number, React.Dispatch<React.SetStateAction<number>>]

    Defined in

    lib/util.ts:193

    useURLState(key, valueOrParams): [number, React.Dispatch<React.SetStateAction<number>>]

    A hook to manage a state variable that is also stored in the URL.

    Parameters

    Name Type Description
    key string The name of the key in the URL. If empty, then the hook behaves like useState.
    valueOrParams number | URLStateParams<number> -

    Returns

    [number, React.Dispatch<React.SetStateAction<number>>]

    Defined in

    lib/util.ts:197