Conditional Widgets
Some widgets only need to appear in certain conditions. You may want to display a widget only when specific requirements are met and hide them otherwise. Widget guard conditions help you with such scenarios.
To define a condition for showing a widget, add a guard function to the widget description in the app manifest.
A widget guard is a JavaScript function that takes a YouTrack entity as its argument and lets you check its properties. For the widget to be shown to the user, such a function must return a value that evaluates to true.
The argument of a widget guard function is the YouTrack entity corresponding to the extension point of the widget. To view the mapping between extension points and YouTrack entities, see Guard Entity Reference.
Guard functions are synchronous. They cannot return promises or use the async/await syntax. Guard functions are executed in an isolated sandbox and can't refer to any resources except function arguments.
Sample Conditional Widget
Here is an example of a conditional widget with a guard function. In the manifest, add a guard property to the widget description.
In this example, the guard condition checks whether the value of the State field in an issue equals to Open. If it's the case, the widget appears in the issue.
Guard Entity Reference
Here is the list of YouTrack entities that guard functions take as arguments, along with the mapping between them and widget extension points. You can use these entities and their properties to form a JavaScript guard function and define the condition.
Issue
Property | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| String | The ID of the issue. | ||||||||||||
| String | The summary of the issue. | ||||||||||||
| Fields | The set of custom fields that are used in the issue. For each custom field, you can use the following field properties:
| ||||||||||||
| Boolean |
| ||||||||||||
| Boolean |
|
The following extension points take issue entity as their guard function argument:
ISSUE_ABOVE_ACTIVITY_STREAMISSUE_BELOW_SUMMARYISSUE_FIELD_PANEL_LASTISSUE_FIELD_PANEL_FIRSTISSUE_OPTIONS_MENU_ITEM
Article
Property | Type | Description |
|---|---|---|
| String | The ID of the article. |
| String | The title of the article. |
| Boolean |
|
| Boolean |
|
The following extension points take article entity as their guard function argument:
ARTICLE_OPTIONS_MENU_ITEMARTICLE_BELOW_SUMMARYARTICLE_ABOVE_ACTIVITY_STREAM
Ticket
Property | Type | Description |
|---|---|---|
| String | The ID of the ticket. |
| String | The summary of the ticket. |
| Fields | The set of custom fields that are used in the ticket. |
| Boolean |
|
The following extension points take ticket entity as their guard function argument:
ISSUE_ABOVE_ACTIVITY_STREAMISSUE_BELOW_SUMMARYISSUE_FIELD_PANEL_LASTISSUE_FIELD_PANEL_FIRSTISSUE_OPTIONS_MENU_ITEM
Project
Property | Type | Description |
|---|---|---|
| String | The ID of the project. |
| String | The key of the project. |
The following extension points take project entity as their guard function argument:
HELPDESK_CHANNELPROJECT_SETTINGS
User
Property | Type | Description |
|---|---|---|
| String | The ID of the user. |
| String | The user login. |
The following extension points take user entity as their guard function argument:
USER_CARDUSER_PROFILE_SETTINGS