Skip to main content

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

NameType
quantity1string
quantity2string

Returns

boolean

Defined in

lib/util.ts:302


filterGeneric

filterGeneric<T>(item, search?, 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

NameType
Textends Object = { [key: string]: any; }

Parameters

NameTypeDescription
itemTThe item to filter.
search?string-
matchCriteria?string[]The JSONPath criteria to match.

Returns

boolean

Defined in

redux/filterSlice.ts:71


filterResource

filterResource(item, filter, search?, matchCriteria?): boolean

Filters a resource based on the filter state.

Parameters

NameTypeDescription
itemKubeObjectInterface | KubeEventThe item to filter.
filterFilterStateThe filter state.
search?string-
matchCriteria?string[]The JSONPath criteria to match.

Returns

boolean

True if the item matches the filter, false otherwise.

Defined in

redux/filterSlice.ts:24


formatDuration

formatDuration(duration, options?): string

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

Parameters

NameTypeDescription
durationnumberThe duration in milliseconds.
optionsTimeAgoOptionsformat 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

NameType
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

NameType
valuenumber
totalnumber

Returns

null | string

Defined in

lib/util.ts:102


getReadyReplicas

getReadyReplicas(item): any

Parameters

NameType
itemWorkload

Returns

any

Defined in

lib/util.ts:111


getResourceMetrics

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

Parameters

NameType
itemNode
metricsKubeMetrics[]
resourceType"cpu" | "memory"

Returns

any[]

Defined in

lib/util.ts:129


getResourceStr

getResourceStr(value, resourceType): string

Parameters

NameType
valuenumber
resourceType"cpu" | "memory"

Returns

string

Defined in

lib/util.ts:119


getTotalReplicas

getTotalReplicas(item): any

Parameters

NameType
itemWorkload

Returns

any

Defined in

lib/util.ts:115


localeDate

localeDate(date): string

Parameters

NameType
dateDateParam

Returns

string

Defined in

lib/util.ts:85


normalizeUnit

normalizeUnit(resourceType, quantity): string

Parameters

NameType
resourceTypestring
quantitystring

Returns

string

Defined in

lib/util.ts:311


timeAgo

timeAgo(date, options?): string

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

Parameters

NameTypeDescription
dateDateParamThe date since which to calculate the duration.
optionsTimeAgoOptionsformat 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

NameType
dependentSetter?(...args: any) => void

Returns

any[]

Defined in

lib/util.ts:169


useFilterFunc

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

Get a function to filter kube resources based on the current global filter state.

Type parameters

NameType
Textends KubeObjectInterface | KubeEvent | { [key: string]: any; } = KubeObjectInterface | KubeEvent

Parameters

NameTypeDescription
matchCriteria?string[]The JSONPath criteria to match.

Returns

fn

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

▸ (item, search?): boolean

Parameters
NameType
itemT
search?string
Returns

boolean

Defined in

lib/util.ts:154


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

NameTypeDefault value
prefixstring''

Returns

undefined | string

Defined in

lib/util.ts:390


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

NameTypeDescription
keystringThe name of the key in the URL. If empty, then the hook behaves like useState.
defaultValuenumber-

Returns

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

Defined in

lib/util.ts:194

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

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

Parameters

NameTypeDescription
keystringThe name of the key in the URL. If empty, then the hook behaves like useState.
valueOrParamsnumber | URLStateParams<number>-

Returns

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

Defined in

lib/util.ts:198