-
Notifications
You must be signed in to change notification settings - Fork 46
Add pickers for rule creation with control API and CLI examples #3285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import React, { useState, createContext, useContext, isValidElement, ReactNode } from 'react'; | ||
| import cn from '@ably/ui/core/utils/cn'; | ||
|
|
||
| type MethodContextType = { | ||
| activeMethod: string; | ||
| }; | ||
|
|
||
| const MethodContext = createContext<MethodContextType | undefined>(undefined); | ||
|
|
||
| const METHOD_LABELS: Record<string, string> = { | ||
| dashboard: 'Dashboard', | ||
| 'control-api': 'Control API', | ||
| cli: 'Ably CLI', | ||
| }; | ||
|
|
||
| interface MethodProps { | ||
| value: string; | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| export const Method: React.FC<MethodProps> = ({ value, children }) => { | ||
| const context = useContext(MethodContext); | ||
| if (!context) { | ||
| return null; | ||
| } | ||
| return context.activeMethod === value ? <>{children}</> : null; | ||
| }; | ||
|
|
||
| interface MethodPickerProps { | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| export const MethodPicker: React.FC<MethodPickerProps> = ({ children }) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Could probably benefit from unit tests for this |
||
| // Extract method values from Method children | ||
| const methods: string[] = []; | ||
| React.Children.forEach(children, (child) => { | ||
| if (isValidElement<MethodProps>(child) && child.props.value) { | ||
| methods.push(child.props.value); | ||
| } | ||
| }); | ||
|
|
||
| const [activeMethod, setActiveMethod] = useState(methods[0] ?? 'dashboard'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Did you consider saving the user choice of method? Like we do for languages? |
||
|
|
||
| return ( | ||
| <MethodContext.Provider value={{ activeMethod }}> | ||
| <div className="my-5"> | ||
| <div className="flex gap-1 border-b border-neutral-300 dark:border-neutral-800 mb-5"> | ||
| {methods.map((method) => ( | ||
| <button | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Could add aria attributes |
||
| key={method} | ||
| onClick={() => setActiveMethod(method)} | ||
| className={cn( | ||
| 'px-4 py-2 text-sm font-medium rounded-t-md transition-colors cursor-pointer', | ||
| activeMethod === method | ||
| ? 'bg-neutral-100 dark:bg-neutral-1100 text-neutral-1300 dark:text-neutral-000 border border-neutral-300 dark:border-neutral-800 border-b-transparent -mb-px' | ||
| : 'text-neutral-700 dark:text-neutral-500 hover:text-neutral-1000 dark:hover:text-neutral-300', | ||
| )} | ||
| > | ||
| {METHOD_LABELS[method] ?? method} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| <div>{children}</div> | ||
| </div> | ||
| </MethodContext.Provider> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,7 +202,10 @@ The rules related to enabling features are: | |
| | Message conflation | If enabled, messages are aggregated over a set period of time and evaluated against a conflation key. All but the latest message for each conflation key value will be discarded, and the resulting message, or messages, will be delivered to subscribers as a single batch once the period of time elapses. [Message conflation](/docs/messages#conflation) reduces costs in high-throughput scenarios by removing redundant and outdated messages. | | ||
| | Message annotations, updates, deletes, and appends | If enabled, allows message "annotations":/docs/messages/annotations to be used, as well as updates, deletes, and appends to be published to messages. Note that these features are currently in public preview. When this feature is enabled, messages will be "persisted":/docs/storage-history/storage#all-message-persistence (necessary in order from them later be annotated or updated), and "continuous history":/docs/storage-history/history#continuous-history features will not work. | ||
|
|
||
| To set a rule in the Ably dashboard: | ||
| To set a rule: | ||
|
|
||
| <MethodPicker> | ||
| <Method value="dashboard"> | ||
|
|
||
| 1. Sign in to your Ably account. | ||
| 2. Select an app. | ||
|
|
@@ -211,6 +214,47 @@ To set a rule in the Ably dashboard: | |
| 5. Select channel name or namespace to apply rules to. | ||
| 6. Check required rules. | ||
|
|
||
| </Method> | ||
| <Method value="control-api"> | ||
|
|
||
| Use the [Control API](/docs/platform/account/control-api) to create a channel rule by sending a `POST` request to `/apps/{app_id}/namespaces`: | ||
|
|
||
| <Code> | ||
| ```shell | ||
| curl -X POST https://control.ably.net/v1/apps/{APP_ID}/namespaces \ | ||
| -H "Authorization: Bearer {ACCESS_TOKEN}" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "id": "my-namespace", | ||
| "persisted": true, | ||
| "persistLast": false, | ||
| "pushEnabled": false, | ||
| "tlsOnly": false, | ||
| "authenticated": false | ||
| }' | ||
| ``` | ||
| </Code> | ||
|
|
||
| Refer to the [Control API reference](/docs/api/control-api) for a full list of available parameters. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to link to this for every command considering we already link out to the docs on the Control API. If it's important enough to include then we should make the path a link to the reference for itself. |
||
|
|
||
| </Method> | ||
| <Method value="cli"> | ||
|
|
||
| Use the [Ably CLI](/docs/platform/tools/cli) to create a channel rule: | ||
|
|
||
| <Code> | ||
| ```shell | ||
| ably apps rules create \ | ||
| --name "my-namespace" \ | ||
| --persisted | ||
| ``` | ||
| </Code> | ||
|
|
||
| Run `ably apps rules create --help` for a full list of available options. | ||
|
|
||
| </Method> | ||
| </MethodPicker> | ||
|
|
||
| ## Channel history <a id="history"/> | ||
|
|
||
| Channel [history](/docs/storage-history/history) enables clients to retrieve messages that have been previously published on the channel. Messages can be retrieved from history for up to 72 hours in the past, depending on the [persistence](/docs/storage-history/storage) configured for the channel. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,17 +24,46 @@ When a change event is received over the Change Streams API it is published to a | |
|
|
||
| You first need to create an integration rule in order to sync your MongoDB instance with Ably. | ||
|
|
||
| There are two ways to create a MongoDB database connector rule: | ||
|
|
||
| 1. Using the [Ably Dashboard](https://ably.com/dashboard). | ||
| 2. Using the [Control API](/docs/platform/account/control-api). | ||
| <MethodPicker> | ||
| <Method value="dashboard"> | ||
|
|
||
| To create a rule in your [dashboard](https://ably.com/dashboard): | ||
|
|
||
| 1. Log in and select the application you wish to use. | ||
| 2. Click the *Integrations* tab. | ||
| 3. Click the *New Integration Rule* button. | ||
| 4. Choose *MongoDB* from the list. | ||
| 2. Click the **Integrations** tab. | ||
| 3. Click the **New Integration Rule** button. | ||
| 4. Choose **MongoDB** from the list. | ||
| 5. Configure the [rule settings](#config). | ||
|
|
||
| </Method> | ||
| <Method value="control-api"> | ||
|
|
||
| Use the [Control API](/docs/platform/account/control-api) to create a MongoDB rule by sending a `POST` request to `/apps/{app_id}/rules`: | ||
|
|
||
| <Code> | ||
| ```shell | ||
| curl -X POST https://control.ably.net/v1/apps/{APP_ID}/rules \ | ||
| -H "Authorization: Bearer {ACCESS_TOKEN}" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "ruleType": "ingress/mongodb", | ||
| "target": { | ||
| "url": "mongodb://user:pass@myhost.com", | ||
| "database": "my-database", | ||
| "collection": "my-collection", | ||
| "pipeline": "[{\"$set\": {\"_ablyChannel\": \"myDocuments\"}}]", | ||
| "fullDocument": "off", | ||
| "fullDocumentBeforeChange": "off", | ||
| "primarySite": "us-east-1-A" | ||
| } | ||
| }' | ||
| ``` | ||
| </Code> | ||
|
|
||
| Refer to the [Control API reference](/docs/api/control-api) for a full list of available parameters. | ||
|
|
||
| </Method> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Noticed in a few that we don't always have a CLI method. Due to lack of CLI support or something else? |
||
| </MethodPicker> | ||
|
|
||
| ### Rule configuration <a id="config"/> | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah missed this - I also don't think we should be hardcoding this. At the end of the day it's a label on a tab, so this should just take whatever value is defined by the author to make this a flexible component.