Skip to content

Commit e98d40b

Browse files
[Rules] Snippets UI updates (#20273)
--------- Co-authored-by: Kate Tungusova <[email protected]>
1 parent 28ed9ad commit e98d40b

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/content/docs/rules/snippets/create-dashboard.mdx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,24 @@ import { Render } from "~/components";
1313

1414
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/), and select your account and website.
1515

16-
2. Go to **Rules** > **Snippets**, and select **Create a Snippet**.
16+
2. Go to **Rules** > **Snippets**.
1717

18-
3. In **Snippet name**, enter a descriptive name for the snippet. You cannot change the name after creating the snippet.
18+
3. (Optional) If you have not created any snippets yet, select one of the snippet templates that addresses a common use case. Then, review and adjust the proposed snippet code.
1919

20-
4. Enter the snippet's JavaScript code in the code editor. You can test how your snippet will handle incoming requests using the **HTTP** and **Preview** tabs.
20+
To start from scratch, select **Create Snippet**.
2121

22-
5. Select **Snippet rule** to configure when the snippet will run.
22+
4. In **Snippet name**, enter a descriptive name for the snippet. You cannot change the name after creating the snippet.
2323

24-
6. Under **Run this Snippet if incoming requests match**, select if you wish to run the snippet only for requests that match a custom filter expression or for all incoming requests.
24+
5. Enter the snippet's JavaScript code in the code editor. You can test how your snippet will handle incoming requests using the **HTTP** and **Preview** tabs.
2525

26-
7. (Optional) To define a custom expression, use the Expression Builder (specifying one or more values for **Field**, **Operator**, and **Value**) or manually enter an expression using the Expression Editor. For more information, refer to [Edit expressions in the dashboard](/ruleset-engine/rules-language/expressions/edit-expressions/).
26+
6. Select **Snippet rule** to configure when the snippet will run.
2727

28-
8. Select **Done**.
28+
7. Under **Run this Snippet if incoming requests match**, select if you wish to run the snippet only for requests that match a custom filter expression or for all incoming requests.
2929

30-
9. To deploy your snippet, select **Deploy**. If you are not ready to deploy your snippet, open the dropdown next to **Deploy** and select **Save as Draft**.
30+
8. (Optional) To define a custom expression, use the Expression Builder (specifying one or more values for **Field**, **Operator**, and **Value**) or manually enter an expression using the Expression Editor. For more information, refer to [Edit expressions in the dashboard](/ruleset-engine/rules-language/expressions/edit-expressions/).
3131

32-
<Render file="rules-creation-dash-dns-popup" />
32+
9. Select **Done**.
33+
34+
10. To deploy your snippet, select **Deploy**. If you are not ready to deploy your snippet, open the dropdown next to **Deploy** and select **Save as Draft**.
35+
36+
<Render file="rules-creation-dash-dns-popup" />

src/content/docs/rules/snippets/index.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ For code samples addressing common use cases, please refer to the [Examples](/ru
2424

2525
## Snippets elements
2626

27-
To create and deploy a Snippet, you need to define the following elements:
27+
To create and deploy a snippet, you need to define the following elements:
2828

2929
- **Code snippet**: JavaScript code to be executed during the request-handling process.
30-
- **Snippet rule**: A [filter expression](/ruleset-engine/rules-language/expressions/) that determines which requests the Snippet will be applied to. Each Snippet can only be associated with one Snippet Rule.
30+
- **Snippet rule**: A [filter expression](/ruleset-engine/rules-language/expressions/) that determines which requests the Snippet will be applied to. Each snippet can only be associated with one snippet rule.
3131

32-
For more information, refer to the [How it works](/rules/snippets/how-it-works/) and [Create a snippet in the dashboard](/rules/snippets/create-dashboard/) sections.
32+
For more information, refer to [How it works](/rules/snippets/how-it-works/) and [Create a snippet in the dashboard](/rules/snippets/create-dashboard/).
33+
34+
:::note
35+
If you have used the Cloudflare API to create a code snippet that is not associated with a snippet rule, the Cloudflare dashboard will show that code snippet in a separate tab called **Unused Snippets**. You can either edit the snippet code and associate it with a snippet rule, or delete the unused code snippet.
36+
:::
3337

3438
## Templates
3539

@@ -41,9 +45,7 @@ For more information, refer to the [How it works](/rules/snippets/how-it-works/)
4145

4246
<FeatureTable id="rules.snippets" />
4347

44-
:::caution[Redirects will count as subrequests]
4548
Each <GlossaryTooltip term="Snippets subrequest" prepend="A subrequest is ">subrequest</GlossaryTooltip> in a redirect chain counts against the subrequest limit. This means that if a subrequest was redirected it would count as two subrequests. To avoid issues, ensure that you make a subrequest to the end location of the redirect chain.
46-
:::
4749

4850
## Limits
4951

0 commit comments

Comments
 (0)