Skip to main content

Enums

Reference

A set of platform-wide string constants. Always use Enums instead of hardcoding strings to ensure your widget stays compatible with future Protrak updates.

const { protrakUtils } = React.useContext(customWidgetContext);
const { Enums } = protrakUtils;

Enums.AttributeTypes

Maps attribute type names. Used when reading attribute values to determine which value field to access.

Enums.AttributeTypes = {
Text: 'Text',
Numeric: 'Numeric',
Date: 'Date',
Currency: 'Currency',
Picklist: 'Picklist',
DateTime: 'DateTime',
RichText: 'RichText',
Expression: 'Expression',
Boolean: 'Boolean',
Attachment: 'Attachment',
User: 'User',
Reference: 'Reference',
};

Value field per type:

Enums.AttributeTypes valueValue field on the attribute object
Text, RichText, Date, DateTime, PicklisttextValue
Numeric, Currency, ExpressionnumericValue
BooleanbooleanValue
Reference, UserreferenceValue
AttachmentattachmentValue
const attr = pageContext.attributeValues['Priority'];
let displayValue;

switch (attr?.type) {
case Enums.AttributeTypes.Text:
case Enums.AttributeTypes.Picklist:
displayValue = attr.textValue;
break;
case Enums.AttributeTypes.Numeric:
case Enums.AttributeTypes.Currency:
displayValue = attr.numericValue;
break;
case Enums.AttributeTypes.Boolean:
displayValue = attr.booleanValue ? 'Yes' : 'No';
break;
default:
displayValue = '—';
}

Enums.AllowedOperations

Operations a user may have permission to perform on an instance. Check against pageContext.allowedOperations before showing action buttons.

Enums.AllowedOperations = {
Edit: 'Edit',
Delete: 'Delete',
Promote: 'Promote',
Link: 'Link',
Unlink: 'Unlink',
FileUpload: 'File Upload',
FileDownload: 'File Download',
Export: 'Export',
EditRelation: 'Edit Relation',
CreateACopy: 'Create a Copy',
ViewEditGeolocation: 'View Edit Geolocation',
};
const canEdit = pageContext.allowedOperations.includes(
Enums.AllowedOperations.Edit
);

if (canEdit) {
// show edit button
}

Enums.BasicAttributes

System attribute names that exist on every Protrak instance, regardless of type.

Enums.BasicAttributes = {
Name: 'Name',
TrackingId: 'TrackingId',
TrackingInfo: 'TrackingInfo',
State: 'State',
Creator: 'Creator',
Modifier: 'Modifier',
CreatedDate: 'CreatedDate',
ModifiedDate: 'ModifiedDate',
Description: 'Description',
Lifecycle: 'Lifecycle',
Geolocation: 'Geolocation',
QRCode: 'QRCode',
VersionNumber: 'VersionNumber',
};
const name = pageContext.attributeValues[Enums.BasicAttributes.Name]?.textValue;
const state =
pageContext.attributeValues[Enums.BasicAttributes.State]?.textValue;

Enums.EditMode

Possible values for pageContext.editMode in View / Edit layouts.

Enums.EditMode = {
None: 'None', // read-only; no editing allowed
Inline: 'Inline', // individual field-level inline editing
Full: 'Full', // full edit form
};
const isEditable = pageContext.editMode !== Enums.EditMode.None;

Enums.Conditions

Filter condition operators used when building API query filters.

Enums.Conditions = {
Contains,
NotContains,
Equals,
NotEquals,
In,
NotIn,
IsEmpty,
IsNotEmpty,
LessThan,
GreaterThan,
LessThanOrEqual,
GreaterThanOrEqual,
StartsWith,
EndsWith,
Between,
Today,
LastOneWeek,
LastOneMonth,
LastOneYear,
NextWeek,
NextOneMonth,
NextOneYear,
ContextUser,
};
// Each value is: { name: 'ConditionName', displayName: 'Human label' }

Enums.BulkActionTypes

Types of bulk actions available on grids.

Enums.BulkActionTypes = {
Promote: { name: 'Promote', displayName: 'Promote' },
Delete: { name: 'Delete', displayName: 'Delete' },
PrintSticker: { name: 'Print Sticker', displayName: 'Print Sticker' },
Custom: { name: 'Custom', displayName: 'Custom' },
Unlink: { name: 'Unlink', displayName: 'Unlink' },
};

Usage Example

function PermissionAwareWidget(pageContext) {
const { protrakUtils, protrakComponents } =
React.useContext(customWidgetContext);
const { Enums } = protrakUtils;
const { Box, Button, ButtonEnums, Text } = protrakComponents;

const { allowedOperations, onAttributeEdit, saveInstance } = pageContext;

const canEdit = allowedOperations.includes(Enums.AllowedOperations.Edit);
const canDelete = allowedOperations.includes(Enums.AllowedOperations.Delete);

const titleAttr = pageContext.attributeValues[Enums.BasicAttributes.Name];
const title = titleAttr?.textValue ?? '—';

return (
<Box style={{ padding: '1rem' }}>
<Text>Name: {title}</Text>
{canEdit && (
<Button
text="Mark Reviewed"
appearance={ButtonEnums.Appearance.Primary}
onClick={() => {
onAttributeEdit(
'ReviewStatus',
{
name: 'ReviewStatus',
type: Enums.AttributeTypes.Picklist,
canUpdate: true,
textValue: 'Reviewed',
},
''
);
saveInstance();
}}
/>
)}
{!canEdit && <Text>Read-only view</Text>}
</Box>
);
}