Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/embed-default-override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@monad-inc/embed': minor
---

Add a `default` key to `configMetaOverrides` fields so hosts can prefill a value on new connectors.
26 changes: 19 additions & 7 deletions packages/embed/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ controls the surrounding chrome.
| `isDescriptionEditable` | `boolean` | ⛔ | `false` | Show an editable description input in the iframe (prefilled with `description` if provided). |
| `appearance` | `Appearance` | ⛔ | Monad defaults | Theming tokens (see below). |
| `stylesheets` | `string[]` | ⛔ | Monad's built-in stylesheet | Your own stylesheet URLs. All-or-nothing: if set, Monad's defaults are not loaded (see below). |
| `configMetaOverrides` | `ConfigMetaOverrides` | ⛔ | the connector's own copy | Per-field label / description / placeholder overrides (see below). |
| `configMetaOverrides` | `ConfigMetaOverrides` | ⛔ | the connector's own copy | Per-field label / description / placeholder / default overrides (see below). |
| `synthetic` | `boolean` | ⛔ | `false` | Exposes Monad's internal synthetic-data toggle. Keep off in production. |
| `frameOrigin` | `string` | ⛔ | `https://app.monad.com/embed` | Override only for non-prod testing. |
| `apiBase` | `string` | ⛔ | `https://app.monad.com/api` | Override only for non-prod testing. |
Expand Down Expand Up @@ -190,13 +190,25 @@ original copy.

**`placeholder` is a hint, not a default.** It shows as grey text and
disappears as soon as the user types. A field the user never touches
still submits an empty value. There is no option to pre-fill a real
value, because that would change the data your connector is configured
with.
still submits an empty value. To pre-fill a real value, use `default`.

### What you can override

Per field: `name`, `description`, `placeholder`.
Per field: `name`, `description`, `placeholder`, `default`.

`default` pre-fills the field when a user creates a connector. The value
is editable and is submitted like any other. It is ignored when editing an
existing connector, so the saved value always wins. It works on string
(including dropdowns — the value must be one of the options), number, and
boolean fields; anything else, or a value of the wrong type, is ignored.

```ts
configMetaOverrides: {
settings: {
summary_config: { children: { alert_source: { default: 'northstar' } } },
},
}
```

Nested fields are reached with `children`, and the variants of a
multiple-choice field with `discriminator.one_of`:
Expand All @@ -217,8 +229,8 @@ configMetaOverrides: {
}
```

A field's type, whether it is required, its allowed values, and its
default are fixed by the connector and cannot be overridden. Some
A field's type, whether it is required, and its allowed values are fixed
by the connector and cannot be overridden. Some
controls have nowhere to show a placeholder — dropdowns, checkboxes, and
code editors ignore it. If you need a field to _behave_ differently,
that's a change to the connector itself; file an issue.
Expand Down
15 changes: 10 additions & 5 deletions packages/embed/src/connect/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ export interface Appearance {
/**
* Copy overrides for a single field of a connector's config form.
*
* Only copy can be overridden. A field's type, requiredness, allowed
* values, and default are fixed by the connector and cannot be changed
* here.
* Only copy and a scalar `default` can be overridden. A field's type,
* requiredness, and allowed values are fixed by the connector.
*
* `placeholder` is a hint, not a default: a field the user never touches
* still submits an empty value.
* `placeholder` is a hint: a field the user never touches still submits
* an empty value. Use `default` to prefill a real value.
*
* Keys mirror the config shape returned for the connector type, so they
* are snake_case — unlike the camelCase options on
Expand All @@ -64,6 +63,12 @@ export interface FieldMetaOverride {
description?: string;
/** Ephemeral hint text inside the control. Empty string blanks it. */
placeholder?: string;
/**
* Prefilled value for a new connector. Stays editable and is submitted.
* Ignored when editing, so the saved value wins. Applies to string
* (within its allowed values), number and boolean fields only.
*/
default?: string | number | boolean;
/** Overrides for a nested object's child fields, keyed by child wire key. */
children?: Record<string, FieldMetaOverride>;
/** Overrides for a discriminated-union (one_of) field. */
Expand Down
Loading