# Inherited Settings

> Settings that a workspace sets and a team or project can override.

Page: https://uicontext.com/docs/components/inherited-settings

Group: Settings.

## When to use

Settings that a workspace sets and a team or project can override. Use [Settings](https://uicontext.com/docs/components/settings.md) instead when the settings apply at one level only.

## Usage

```ts
import { ScopeSetting } from "./ui/uicontext/components/Scope.ts"

const Message = UiSchema.TaggedEnum({ SetRetention: { value: Schema.NullOr(Schema.String) } })

export const Retention = (h: Html.H<typeof Message.Type>, teamValue: string | null) =>
	ScopeSetting(h, {
		props: {
			label: "Keep run history for",
			options: [{ value: "30", label: "30 days" }, { value: "90", label: "90 days" }],
			levels: [
				{ id: "org", label: "Northwind", value: "30" },
				{ id: "ops", label: "Operations team", ...(teamValue === null ? {} : { value: teamValue }) },
			],
			can: ["edit"],
		},
		onEmit: {
			RequestedInherit: () => Message.SetRetention({ value: null }),
			RequestedValue: ({ value }) => Message.SetRetention({ value }),
		},
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Override, inherit, or enforced from above

Each setting says where its value comes from; set it here, or go back to what the level above sets. An enforced one says who set it.

```ts title="src/demo.ts" source="www/src/examples/inherited-settings/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { ScopeSetting } from "./ui/uicontext/components/Scope.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({ frame: { inlineSize: "min(100%, 40rem)", display: "flex", flexDirection: "column", gap: space.xl } })

const Message = UiSchema.TaggedEnum({
	SetRetention: { value: Schema.NullOr(Schema.String) },
	SetReview: { value: Schema.NullOr(Schema.String) },
})

const org = { id: "org", label: "Northwind", href: "#org" }
const team = { id: "ops", label: "Operations team", href: "#ops" }

export const TeamOverrides = Html.component({
	name: "TeamOverrides",
	model: Schema.Struct({ retention: Schema.NullOr(Schema.String), review: Schema.NullOr(Schema.String) }),
	message: Message,
}).make({
	init: () => ({ retention: "90", review: null }),
	update: {
		SetRetention: ($, { value }) => $.evolve({ retention: value }),
		SetReview: ($, { value }) => $.evolve({ review: value }),
	},
	view: (h, model) => {
		const here = (value: string | null) => ({ id: "billing", label: "#billing-automations", ...(value === null ? {} : { value }) })
		return h.div.attrs(sx(styles.frame)).children(
			ScopeSetting(h, {
				key: "retention",
				props: {
					agentId: "scope-retention",
					label: "Keep run history for",
					description: "Older runs and their data are deleted.",
					options: [
						{ value: "30", label: "30 days" },
						{ value: "90", label: "90 days" },
						{ value: "365", label: "1 year", lockedReason: "Needs the Business plan" },
					],
					levels: [{ ...org, value: "30" }, team, here(model.retention)],
					control: "select",
					can: ["edit"],
				},
				onEmit: {
					RequestedInherit: () => Message.SetRetention({ value: null }),
					RequestedValue: ({ value }) => Message.SetRetention({ value }),
				},
			}),
			ScopeSetting(h, {
				key: "review",
				props: {
					agentId: "scope-review",
					label: "Review before publishing",
					description: "A second person approves a workflow before it goes live.",
					options: [
						{ value: "required", label: "Required", description: "Publishing waits for an approver." },
						{ value: "off", label: "Not required" },
					],
					levels: [{ ...org, value: "required", enforced: true }, team, here(model.review)],
					can: ["edit"],
				},
				onEmit: {
					RequestedInherit: () => Message.SetReview({ value: null }),
					RequestedValue: ({ value }) => Message.SetReview({ value }),
				},
			}),
		)
	},
})
```

## API reference

### ScopeSetting (component)

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `agentId` | `string` | This setting's id for agents, unique on the page: "scope-design-participation" |
| `label` (required) | `string` | "Respond automatically" |
| `description` | `string` | A sentence under the label about what the setting does |
| `options` (required) | `ScopeOption[]` | The values to choose from, each with an example and why it may be locked |
| `levels` (required) | `NonEmptyArray` | Top level first; the last is the level being edited |
| `control` | `"radio" \| "select"` | Radios for a few options, a select for many |
| `can` (required) | `Can(["edit"])` | What the viewer may do here: "edit" changes the value at this level |
| `readOnlyReason` | `string` | Why it's read-only: "Only owners change this" |
| `consequential` | `boolean` | What an agent's change is: consequential (the default) for settings that change what others get |
| `outcome` | `Outcome` | The app's answer to the last request: "inherit" for `RequestedInherit`, "value" for `RequestedValue`. Pending shows "Saving…"; a refusal shows its reason. |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedInherit` | `{}` | Stop setting a value here |
| `RequestedValue` | `{ value: string }` | Set this value at the level being edited |

**Agent actions**

| Action | Description |
| --- | --- |
| `ChoseValue` | Set a value at this level (value from page_query). Target: { value, setHere } as in the snapshot. |
| `ChoseInherit` | Stop setting it here and take the inherited value. Target: { value, setHere }. |

### ScopeTree (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `label` (required) | `string` | What the tree is of, for screen readers: "Workspace and teams" |
| `nodes` (required) | `ScopeNode[]` | The scopes, top level first, each with its children |
| `current` | `string` | The id of the scope being edited, marked as the current page |

## Keyboard and accessibility

- The setting is a fieldset with radios for a few options or a select for many; where its value comes from is tied to it with `aria-describedby`.
- Locked options stay in the list and say why they can't be chosen.
- The tree is a `nav` of links, the scope being edited marked `aria-current="page"`.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/inherited-settings
```

With npm: `npx shadcn@latest add checkfu/uicontext/inherited-settings`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/inherited-settings`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/inherited-settings`.

It writes these files:

- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/Scope.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/domain/Permission.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Scope.ts](https://github.com/checkfu/uicontext/blob/main/src/Scope.ts)

## Related

- [Sign-in Form](https://uicontext.com/docs/components/sign-in-form.md) (`sign-in-form`): Sign in, accept an invitation and manage sessions.
- [Settings](https://uicontext.com/docs/components/settings.md) (`settings`): A settings page with sections, fields and a save bar.
- [Env Editor](https://uicontext.com/docs/components/env-editor.md) (`env-editor`): Names and values such as API keys and URLs, one row each: secrets hidden, a pasted .env file split into rows, mistakes marked.
- [Setting List](https://uicontext.com/docs/components/setting-list.md) (`setting-list`): Settings as rows, each with its control.
- [Members](https://uicontext.com/docs/components/members.md) (`members`): Workspace members, their roles and pending invitations.
- [Connections](https://uicontext.com/docs/components/connections.md) (`connections`): Connect outside services, and see each connection's status.
