Nasaq

ProviderSwitcher

Lists an app's swappable capabilities (data, queue, cache, storage…) with the backend each runs on, and switches backends at runtime.

PreviewOpen ↗

Code

import { ProviderSwitcher } from "@fadymondy/nasaq/web";<ProviderSwitcher  capabilities={[    { capability: "data", label: "Data", active: "postgres", options: ["postgres", "sqlite"], isDefault: true },    { capability: "queue", label: "Queue", active: "redis", options: ["redis", "nats", "database"], isDefault: false },  ]}  onSelect={(capability, backend) => api.post(`/providers/${capability}`, { backend })}/>;

Developer Tools · beta

Live examples and controls: ProviderSwitcher in the lab.

Install

npx shadcn@latest add https://docs.nasaqui.com/r/provider-switcher.json

An operator panel for apps built on swappable capabilities. Each row is one capability (data, queue, cache, storage, realtime…) with the backend it runs on, and a select to switch it. Rows on the app's configured default say Default; switched rows say Overridden. Rows pinned by config are locked.

When to use

  • In an admin or developer settings page of a framework app whose drivers can change at runtime (the ToGO provider panel).

When not to use

  • Plain environment variables: use EnvList.
  • On/off switches for product features: use FeatureFlags.

Import

import { ProviderSwitcher } from "@fadymondy/nasaq/web";
// inside this monorepo: "@nasaq/web"

Quick start

import { ProviderSwitcher } from "@fadymondy/nasaq/web";

<ProviderSwitcher
  capabilities={[
    { capability: "data", label: "Data", active: "postgres", options: ["postgres", "sqlite"], isDefault: true },
    { capability: "queue", label: "Queue", active: "redis", options: ["redis", "nats", "database"], isDefault: false },
  ]}
  onSelect={(capability, backend) => api.post(`/providers/${capability}`, { backend })}
/>;

Anatomy

div [data-slot=provider-switcher]
├─ header row (Capability · Backend), from sm up
└─ ul
   └─ li [data-slot=provider-switcher-row][data-capability][aria-busy]
      ├─ label + Status (Default / Overridden) + description
      └─ Select [data-slot=provider-switcher-select]

API

ProviderSwitcher

PropTypeDefaultNotes
capabilitiesProviderCapability[]—Required. One row each. An empty list shows a short message.
onSelect(capability, backend) => void | Promise<void>—Leave out for a read-only view. A returned promise keeps the row busy until it settles.
labelsPartial<ProviderSwitcherLabels>—Override the built-in strings.

Plus any <div> prop.

ProviderCapability

FieldTypeNotes
capabilitystringThe key sent to onSelect: "data", "queue".
label / descriptionReactNodeName and one line of what it does. Default name is the key.
activestringThe backend in use.
options(string | ProviderOption)[]Backends to choose from.
isDefaultbooleantrue shows Default, false shows Overridden, unset shows nothing.
lockedbooleanDisables the select (pinned by config).

ProviderOption

FieldTypeNotes
idstringThe backend id.
label / descriptionReactNodeMenu text.
disabledbooleanListed but not selectable.

Examples

Rich options

{
  capability: "data",
  active: "postgres",
  options: [
    { id: "postgres", label: "PostgreSQL" },
    { id: "sqlite", label: "SQLite", description: "Local file, for development" },
  ],
}

Read-only overview

<ProviderSwitcher capabilities={capabilities} />

Accessibility

  • Each select is named "Backend for Data" / "مزوّد البيانات" after its row.
  • A row that is applying a change has aria-busy and its select is disabled.
  • Default and Overridden use Status, which pairs a shape with the colour.

RTL & i18n

Strings ship in English and Arabic. Capability and backend names come from the host; backend ids such as postgres stay Latin.

Styling & tokens

  • rounded-card border-border bg-card surface with divide-border rows; text-label names, text-caption descriptions.
  • Target a row with [data-slot=provider-switcher-row][data-capability=queue].

Do / Don't

  • Do confirm a switch server-side and return the promise, so the row shows the change only once it applied.
  • Do lock capabilities that can't change without a restart.
  • Don't list backends the app has no driver for.

env-list, feature-flags, select, status.

Lab

https://docs.nasaqui.com/?path=/docs/components-developer-tools-provider-switcher--docs

On this page