Skip to content

Commit

Permalink
docs: use gomplate style for notification template functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 3, 2024
1 parent 0346938 commit c3fe92f
Showing 1 changed file with 202 additions and 84 deletions.
286 changes: 202 additions & 84 deletions mission-control/docs/reference/notifications/template_functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,100 +2,218 @@
title: Template Functions
---

Special Slack template functions are made available on notifications to complex block formation easier.
Special template functions are made available on notifications to complex block formation easier.

Check warning on line 5 in mission-control/docs/reference/notifications/template_functions.mdx

View workflow job for this annotation

GitHub Actions / vale

[vale] mission-control/docs/reference/notifications/template_functions.mdx#L5

[alex.Ablist] When referring to a person, consider using 'has a disability', 'person with a disability', or 'people with disabilities' instead of 'Special'.
Raw output
{"message": "[alex.Ablist] When referring to a person, consider using 'has a disability', 'person with a disability', or 'people with disabilities' instead of 'Special'.", "location": {"path": "mission-control/docs/reference/notifications/template_functions.mdx", "range": {"start": {"line": 5, "column": 1}}}, "severity": "WARNING"}

**slackHealthEmoji:**
<SlackHealthEmoji />
## labelsFormat

Check failure on line 7 in mission-control/docs/reference/notifications/template_functions.mdx

View workflow job for this annotation

GitHub Actions / vale

[vale] mission-control/docs/reference/notifications/template_functions.mdx#L7

[Flanksource.Spelling] Is 'labelsFormat' spelled correctly? Is it missing code formatting?
Raw output
{"message": "[Flanksource.Spelling] Is 'labelsFormat' spelled correctly? Is it missing code formatting?", "location": {"path": "mission-control/docs/reference/notifications/template_functions.mdx", "range": {"start": {"line": 7, "column": 4}}}, "severity": "ERROR"}
Formats the given set of labels into a markdown string

**labelsFormat:**
<LabelsFormat />
Syntax:

**slackSectionLabels:**
<SlackSectionLabels />
```js
labelsFormat(map[string]any): string
```

**slackSectionTextFieldPlain:**
<SlackSectionTextFieldPlain />
Example:

**slackSectionTextFieldMD:**
<SlackSectionTextFieldMD />
```js
labelsFormat(map[string]any{
"namespace": "default",
"cluster": "staging",
})
```

**slackSectionTextMD:**
<SlackSectionTextMD />
```md
### Labels

**slackSectionTextPlain:**
<SlackSectionTextPlain />
**namespace**: default
**cluster**: staging
```

**SlackURLAction:**
<SlackURLAction />
## Slack

export function SlackHealthEmoji() {
return <>
<pre>
slackHealthEmoji(health): string
</pre>
<p>Returns a slack emoji based on the supplied health</p>
</>
These slack helper functions will return a json string suitable for use in slack blocks/messages.

Check warning on line 34 in mission-control/docs/reference/notifications/template_functions.mdx

View workflow job for this annotation

GitHub Actions / vale

[vale] mission-control/docs/reference/notifications/template_functions.mdx#L34

[Flanksource.FutureTense] Use present tense verbs, not future tense verbs like 'will'. Say '(event) happens' instead of '(event) will happen'.
Raw output
{"message": "[Flanksource.FutureTense] Use present tense verbs, not future tense verbs like 'will'. Say '(event) happens' instead of '(event) will happen'.", "location": {"path": "mission-control/docs/reference/notifications/template_functions.mdx", "range": {"start": {"line": 34, "column": 30}}}, "severity": "WARNING"}

### slackHealthEmoji
Returns a slack emoji based on the supplied health

Syntax:

```js
slackHealthEmoji(health): string
```

**Returns:**

- `:large_green_circle:` for `healthy` health status
- `:red_circle:` for `unhealthy` health status
- `:large_orange_circle:` for `warning` health status
- `:white_circle:` for any other health status

### slackSectionLabels

Formats the given set of labels into fields of a <a href="https://api.slack.com/reference/block-kit/blocks#section">slack section block</a>

Syntax:

```js
slackSectionLabels(map[string]any): SlackSection
```

Example:

```js
slackSectionLabels(map[string]any{
"namespace": "default",
"cluster": "staging",
})
```

```json
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Labels*"
},
"fields": [
{
"type": "mrkdwn",
"text": "*namespace*: default",
"verbatim": true
},
{
"type": "mrkdwn",
"text": "*cluster*: staging",
"verbatim": true
}
]
}
```

### slackSectionTextFieldPlain

Creates a plain text field for a Slack section block

Syntax:

export function LabelsFormat() {
return <>
<pre>
labelsFormat(map[string]any): string
</pre>
<p>Formats the given set of labels</p>
</>
```js
slackSectionTextFieldPlain(text: string): string
```

Example:

```js
slackSectionTextFieldPlain("alert-manager")
```

```json
{
"type": "plain_text",
"text": "alert-manager"
}
```

### slackSectionTextFieldMD
Creates a markdown text field for a Slack section block

Syntax:

export const SlackSectionLabels = () => (
<>
<pre>
slackSectionLabels(map[string]any): SlackSection
</pre>
<p>Formats the given set of labels into fields of a <a href="https://api.slack.com/reference/block-kit/blocks#section">slack section block</a></p>
</>
)

export const SlackSectionTextFieldPlain = () => (
<>
<pre>
slackSectionTextFieldPlain(text: string): string
</pre>
<p>Creates a plain text field for a Slack section block</p>
</>
)

export const SlackSectionTextFieldMD = () => (
<>
<pre>
slackSectionTextFieldMD(text: string): string
</pre>
<p>Creates a markdown text field for a Slack section block</p>
</>
)

export const SlackSectionTextMD = () => (
<>
<pre>
slackSectionTextMD(text: string): string
</pre>
<p>Creates a Slack section block with markdown text</p>
</>
)

export const SlackSectionTextPlain = () => (
<>
<pre>
slackSectionTextPlain(text: string): string
</pre>
<p>Creates a Slack section block with plain text</p>
</>
)

export const SlackURLAction = () => (
<>
<pre>
slackURLAction(name: string, url: string): string
</pre>
<p>Creates a Slack action block with a URL button</p>
</>
)
```js
slackSectionTextFieldMD(text: string): string
```

Example:

```js
slackSectionTextFieldPlain("alert-manager")
```

```json
{
"type": "mrkdwn",
"text": "alert-manager"
}
```

### slackSectionTextMD
Creates a Slack section block with markdown text

Syntax:

```js
slackSectionTextMD(text: string): string
```

Example:

```js
slackSectionTextMD("alert-manager")
```

```json
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "alert-manager"
}
}
```

### slackSectionTextPlain
Creates a Slack section block with plain text

Syntax:

```js
slackSectionTextPlain(text: string): string
```

Example:

```js
slackSectionTextMD("alert-manager")
```

```json
{
"type": "section",
"text": {
"type": "plain_text",
"text": "alert-manager"
}
}
```

### SlackURLAction
Creates a Slack action block with a URL button

Syntax:

```js
slackURLAction(name: string, url: string): string
```

Example:

```js
slackURLAction("Grafana", "https://grafana.com")
```

```json
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Grafana",
"emoji": true
},
"url": "https://grafana.com",
"action_id": "Grafana"
}
]
}
```

0 comments on commit c3fe92f

Please sign in to comment.