Skip to content

Commit 0d19cff

Browse files
committed
update docs
1 parent 25f3d11 commit 0d19cff

File tree

1 file changed

+127
-4
lines changed

1 file changed

+127
-4
lines changed
Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
# Snap Components
2+
13
Snap components enable adding custom UI components defined by snap-kit to the DevRev UI.
24
These components can be used to display data or interact with the user.
35
Snap components are defined in the snap-in manifest file. DevRev UI renders these components based on the defined configuration.
46

57
Each snap-component has the following properties:
8+
69
- `surface` : the surfaces where the snap component can be displayed. Currently, only `issue` is supported. // TODO: Confirm this.
710
- `snap_kit_action_name` : the name of the snap kit action that will be triggered when the action defined in the snap-kit of the snap component is interacted with.
811
- `snap_kit_body` : the initial body of the snap kit action that will be rendered when the snap component is loaded.
9-
- `initializer` : references a function that can be called to initialize the snap component. This is useful when the snap component needs to be initialized with data from the server based on the context where it is being initialized.
1012

13+
<!-- - `initializer` : references a function that can be called to initialize the snap component. This is useful when the snap component needs to be initialized with data from the server based on the context where it is being initialized. -->
14+
15+
```yaml
16+
functions:
17+
- name: upgrade_test_function_1
18+
description: first function
1119

12-
```
1320
snap_kit_actions:
1421
- name: show_test_cases
1522
function: show_test_cases_or_runs
@@ -20,20 +27,136 @@ snap_components:
2027
description: Test Case Details
2128
surface: issue
2229
snap_kit_action_name: show_test_cases
30+
<!-- initializer: upgrade_test_function_1 -->
2331
snap_kit_body:
2432
{
2533
"snaps":[]
2634
}
2735

2836
```
2937

30-
## Format of context passed to initializer
38+
## Format of context passed to snap-kit action
39+
40+
```typescript
41+
// The payload contains details and values of the snap-kit from which the action was invoked.
42+
interface Payload {
43+
action: {
44+
block_id: string;
45+
id: string;
46+
timestamp: number;
47+
type: string;
48+
value: string;
49+
};
50+
action_id: string;
51+
actor_id: string;
52+
body: {
53+
snaps: any[];
54+
};
55+
context: {
56+
// id of the object where the snap component is invoked.
57+
object_id: string;
58+
};
59+
dev_org: string;
60+
parent_id: string;
61+
request_id: string;
62+
}
63+
64+
interface Secrets {
65+
actor_session_token: string;
66+
service_account_token: string;
67+
}
68+
69+
interface Context {
70+
dev_oid: string;
71+
// Snap-kit action ID in DONv2 format.
72+
source_id: string;
73+
snap_in_id: string;
74+
snap_in_version_id: string;
75+
service_account_id: string;
76+
secrets: Secrets;
77+
}
78+
79+
interface ExecutionMetadata {
80+
request_id: string;
81+
// function that is being invoked.
82+
function_name: string;
83+
// endpoint for DevRev that can be used to make API calls.
84+
devrev_endpoint: string;
85+
}
86+
87+
interface InputData {
88+
global_values: {
89+
// contains the inputs that are defined in the snap-in.
90+
};
91+
event_sources: any;
92+
resources: {
93+
keyrings: any;
94+
tags: any;
95+
};
96+
}
97+
98+
// Event object passed to the snap-kit action.
99+
interface Event {
100+
// The payload of the event
101+
payload: Payload;
102+
context: Context;
103+
execution_metadata: ExecutionMetadata;
104+
input_data: InputData;
105+
}
106+
```
31107

32108
## Screenshots
33109

34-
## Example for initializer
110+
<!-- ## Example for initializer -->
35111

36112
## List of surfaces
37113

114+
| Surface | Description |
115+
|-------------------------|-----------------------------------------------------------------------------------------------|
116+
| issue | Issue surface is used to display snap components in the issue view. |
117+
| support | Support surface is used to display snap components in the Customer Portal. |
118+
| comments_rte | Comments RTE surface is used to display snap components in the comments section of the timeline. |
119+
| snap_in__configuration | Snap-in configuration surface is used to display snap components in the snap-in configuration view. |
120+
| plug | Plug surface is used to display snap components in the plug widget. |
121+
38122
## Referencing global inputs in snap components' snap-kit
39123

124+
The snap component can reference organization inputs defined in the snap-in manifest file.
125+
An example of such a snap component is below:
126+
127+
```yaml
128+
inputs:
129+
organization:
130+
- name: sample_value
131+
description: Sample input value.
132+
field_type: text
133+
default_value: "primary"
134+
ui:
135+
display_name: Sample Value
136+
137+
snap_components:
138+
- name: show_test_cases
139+
display_name: Test Case Details
140+
description: Test Case Details
141+
surface: issue
142+
snap_kit_action_name: snap_component_submit_action
143+
initializer: snap_component_initializer
144+
snap_kit_body: >
145+
{ "snaps": [
146+
{
147+
"elements":[
148+
{
149+
"elements":[
150+
{
151+
"text":"$variable.sample_value",
152+
"type":"plain_text"
153+
}
154+
],
155+
"type":"content"
156+
}
157+
],
158+
"type":"card"
159+
}
160+
]
161+
}
162+
```

0 commit comments

Comments
 (0)