• /
  • Log in

nerdlet

A set of methods to interact with the platform.

Usage

import { nerdlet } from 'nr1'

API methods

nerdlet.getSetUrlStateLocation

Returns a location object. Location objects can be passed into <Link to={location} /> component to navigate inside the platform. When navigated to that location, properties from urlState argument will be able to be read from NerdletStateContext.Consumer.

This method behaves like React’s setState(), meaning that it performs a shallow merge between the current URL state and the provided value in the urlState parameter.

function (
urlState: Object //

New nerdlet URL state.

) => Location

nerdlet.setConfig

Updates the current nerdlet's configuration.

This method behaves like React’s setState(), meaning that it performs a shallow merge between the current config state and the provided config.

function (
config: NerdletConfig //

New nerdlet config

) => undefined

nerdlet.setUrlState

Updates the current nerdlet's URL state that can be read from NerdletStateContext.Consumer.

If you wish to update nerdlet's state without persisting its value in the url, use React's built-in setState().

This method behaves like React’s setState(), meaning that it performs a shallow merge between the current URL state and the provided state in the urlState parameter.

If you wish to navigate without adding an entry to the browser history, set urlStateOptions.replaceHistory to true.

function (
urlState: Object, //

New nerdlet URL state.

urlStateOptions: UrlStateOptions //

Options for the URL state.

) => void

Type definitions

Location

{
pathname: string, //

String representing the path to link to.

search: string, //

String representing query parameters.

hash: string, //

String to put in the URL as hash, e.g. #entities.

}

NerdletConfig

{
accountPicker: boolean, //

Enable or disable the nerdlet's account picker.

accountPickerValues: any[], //

Config the available accounts for the account picker. There are only two options: all authorized accounts (default) or all authorized accounts plus the 'All accounts' option (cross-account support). See examples for more details.

actionControls: boolean, //

Enable or disable the nerdlet's action controls.

actionControlButtons: ActionControlButton[], //

Config of your own custom action controls for the nerldet.

filterBar: boolean, //

Enable or disable the nerdlet's filter bar.

header: boolean, //

Enable or disable the nerdlet's header.

headerTitle: string, //

Set the title of the nerdlet's header.

headerTitleMetadata: string, //

Set the title metadata of the nerdlet's header.

headerType: string, //

Set the header type of the nerdlet's header. Possible values are from nerdlet.HEADER_TYPE.

headerParentTitle: string, //

Set the parent title of the nerdlet's header.

headerParentLocation: Location, //

Set the parent location of the nerdlet's header.

timePicker: boolean, //

Enable or disable the nerdlet's time picker.

timePickerRanges: TimePickerRange[], //

Set of time ranges to display for this nerdlet.

timePickerDefaultOffset: number, //

Time range offset to select by default.

}

ActionControlButton

{
label: string, //

Label of the action control button.

type: Button.TYPE.PRIMARY | Button.TYPE.PLAIN, //

Type of the action control button.

iconType: string, //

Name of the icon to display.

hint: string, //

Text used for the action control button's tooltip.

onClick: () => void, //

Callback fired any time the user clicks on the action control button.

}

TimePickerRange

{
label: string, //

Label for this time range.

offset: number, //

Offset in ms.

}

UrlStateOptions

{
replaceHistory: boolean, //

If true, the current entry in the browser history will be replaced with the new one.

}

Constants

nerdlet.ACCOUNT_PICKER_DEFAULT_VALUES

[
{ id: "authorized-accounts" }
]

nerdlet.ACCOUNT_PICKER_VALUE

{
CROSS_ACCOUNT: { id: "cross-account" }
}

nerdlet.ACTION_CONTROL_BUTTON_TYPES

{
PRIMARY: "primary",
SECONDARY: "secondary",
TERTIARY: "tertiary"
}

nerdlet.HEADER_TYPE

{
CUSTOM: "custom",
ENTITY: "entity"
}

nerdlet.TIME_PICKER_DEFAULT_RANGES

[
{ label: "30 minutes", offset: 1800000 },
{ label: "60 minutes", offset: 3600000 },
{ label: "3 hours", offset: 10800000 },
{ label: "6 hours", offset: 21600000 },
{ label: "12 hours", offset: 43200000 },
{ label: "24 hours", offset: 86400000 },
{ label: "3 days", offset: 259200000 },
{ label: "7 days", offset: 604800000 },
{ label: "Set custom", offset: "Custom" }
]

nerdlet.TIME_PICKER_RANGE

{
CUSTOM: { label: "Set custom", offset: "Custom" },
NONE: { label: "Default", offset: null }
}
Create issueEdit page
Copyright © 2021 New Relic Inc.