Dummy Data Generator
Multi-step modal wizard that generates Docyrus-compatible sample records — per-field strategies (text/number/date/enum/relation), value-renderer preview, and an opt-in batch save to the data source.
Installation
pnpm dlx @docyrus/cli add @docyrus/ui-dummy-data-generatorpnpm add @docyrus/api-client @tanstack/react-queryWhen to Use
Reach for <DummyDataGenerator> (and the matching useDocyrusDummyDataGeneratorWizard hook) whenever you want to seed a Docyrus data source with realistic records — internal staging environments, onboarding tutorials, performance testing, or design reviews where empty grids look bad.
The component is presentational — every prop is a state slice plus a callback — so the smart hook does the heavy lifting (field-aware strategies, deterministic generation, batch insert). The wizard renders inline by default; wrap it in your own dialog / drawer / sheet if you want modal behavior. Pass previewOnly if you only want to download / inspect the generated rows without persisting them.
Usage
'use client';
import { useDocyrusAuth } from '@docyrus/signin';
import { useDocyrusDummyDataGeneratorWizard } from '@docyrus/ui/hooks/use-docyrus-dummy-data-generator-wizard';
export function ContactsSeeder({ onGenerated }: { onGenerated: () => void }) {
const { client } = useDocyrusAuth();
if (!client) return null;
const { wizard } = useDocyrusDummyDataGeneratorWizard({
client,
appSlug: 'crm',
dataSourceSlug: 'contact',
defaultCount: 25,
onGenerated: () => onGenerated()
});
return wizard;
}Wrapping in a dialog
The wizard always renders inline. Drop the returned wizard into any container — including your own modal:
import { Dialog, DialogContent } from '@docyrus/ui/primitives/ui/dialog';
const [open, setOpen] = useState(false);
const { wizard } = useDocyrusDummyDataGeneratorWizard({
client,
appSlug: 'crm',
dataSourceSlug: 'contact'
});
return (
<>
<Button onClick={() => setOpen(true)}>Seed sample contacts…</Button>
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent>{wizard}</DialogContent>
</Dialog>
</>
);Wizard Steps
| Step | Purpose |
|---|---|
| Configure | Pick how many records to generate, then tune each field individually. Strategies are pre-filled per field type (text shape, number range, date window, enum subset, etc.). Read-only or unsupported fields are auto-skipped. |
| Preview | Renders the first N rows using useDocyrusFieldComponent(field.type, 'value-renderer') so every cell looks the same as it does in <DataGrid>. "Regenerate sample" reseeds the PRNG. |
| Progress | One spinner while the hook walks each row through collection.create (or client.post('…/items', row)). |
| Result | Tiles for created / failed / total rows. Per-row error list when inserts fail. |
Field-Type Strategies
| Field type | Default strategy | Configurable |
|---|---|---|
field-text, field-textarea, field-code | Slug-aware sentence/full-name/company/job-title detection. | Text shape (word, sentence, paragraph, full name, company, job title, static). |
field-email, field-url, field-color, field-icon, field-currency | Random pick from a bundled pool. | — |
field-phone | Random number with default country code. | Country code (e.g. +90). |
field-number, field-money, field-percent, field-duration, field-rating | Random integer in a sensible range. | Mode (random / sequence / fixed), min / max, integer toggle. |
field-money | Adds the companion __<slug>_currency value automatically. | Plus currency code (e.g. USD). |
field-checkbox, field-switch | 50/50 boolean. | Truth ratio slider. |
field-date, field-dateTime | Random date within last 30 days. | Mode (recent / past / future / random / now), days window. |
field-dateRange | Pair of dates with a random span. | Same plus max span in days. |
field-time | Random HH:mm. | — |
field-select, field-radioGroup, field-status, field-enum, field-systemEnum | Random pick from field.enums / field.options. | Subset of allowed option ids. |
field-multiSelect, field-tagSelect | 1–3 random picks. | Subset of option ids, items-per-row range. |
field-userSelect, field-userMultiSelect | Random pick from the users array passed to the hook. | Subset of user ids. |
field-relation | Random pick from the relationOptionsByFieldSlug[slug] pool. Skipped if the pool isn't supplied. | Subset of relation ids. |
field-json | Generates { sample, generated, index }. | — |
field-formula, field-relatedField, field-identity, field-autonumber, files, images, html / doc editors, location select, query builder, schema repeater, … | Skipped automatically. | — |
The deterministic seed (Mulberry32) means the preview matches the rows that get inserted — pressing Regenerate sample reseeds and re-renders.
API Reference
<DummyDataGenerator>
The component renders as an inline panel (header + stepper + step body + footer). Wrap it in your own dialog / drawer / sheet if you want modal behavior.
| Prop | Type | Description |
|---|---|---|
step / onStepChange | DummyDataGeneratorStep / (step) => void | Current step + setter. Steps: configure, preview, progress, result. |
targetFields | ReadonlyArray<DocyrusFieldLike> | Fields the user can populate. Supplied by the hook from useDocyrusDataViewSelect. |
requiredFieldSlugs | ReadonlyArray<string> | Slugs locked to enabled: true. |
count / onCountChange | number / (next) => void | Number of records to generate. |
maxCount | number | UI hard cap. Default 1000. |
strategies / onStrategiesChange | DummyStrategyMap / (next) => void | Per-field generation knobs keyed by slug. |
generatedRows / onRegenerate | Array<Record<string, unknown>> / () => void | Generated rows (preview + insert) and a "reseed" callback. |
isGenerating / isCreating | boolean | Internal pending flags surfaced in the spinner / footer. |
generationError / result | Error | null / DummyGenerationResult | null | Final-step state. |
previewOnly | boolean | When true the preview-step CTA is "Finish" — the hook never POSTs. |
users | ReadonlyArray<DummyUserOption> | Tenant users used by user-select strategies (and shown in the configure step). |
onConfirmConfigure / onStartGeneration / onReset | callbacks | Hook into each step's primary action. |
previewRowCount | number | Default 10. |
exportFileName | string | File name (without extension) for CSV / XLSX downloads. Default 'dummy-data'. |
title / description / icon | ReactNode / ReactNode / string | Header customization (defaults are translated). |
className | string | Extra class for the panel root. |
Components
| Component | Description |
|---|---|
DummyDataGenerator | Top-level shell — composes AwesomeDialog + Stepper + step bodies + footer. |
ConfigureStep | Step 1 — count slider + per-field strategy controls. |
PreviewStep | Step 2 — value-renderer-driven preview table + reseed button. |
ProgressStep | Steps 3/4 — progress spinner + result tiles + per-row error list. |
Helpers
| Helper | Description |
|---|---|
buildInitialStrategyMap(fields, existing?) | Per-slug strategy map seeded from inferStrategyForField. Reuses any existing user overrides. |
inferStrategyForField(field) | Default strategy for a single field. |
isSupportedFieldType(type) | false for read-only, file, html-editor, location, formula, etc. |
generateDummyRows(ctx) | Pure deterministic generator. Returns count rows of slug → value pairs. |
createRng(seed) | Mulberry32 PRNG used internally — exported for tests. |
Type Exports
| Type | Description |
|---|---|
DummyDataGeneratorProps | Props for the top-level component. |
DummyDataGeneratorStep | 'configure' | 'preview' | 'progress' | 'result'. |
DummyStrategyMap | Record<fieldSlug, DummyFieldStrategy>. |
DummyFieldStrategy | Per-field generation knobs (enabled, textMode, min, max, dateMode, selectedOptionIds, …). |
DummyGenerationContext | Pure-generator input (fields, strategies, count, seed, users?, relationOptionsByFieldSlug?). |
DummyGenerationResult | { totalGenerated, totalCreated, totalFailed, errors }. |
DummyUserOption | User pool entry shape (id, name?, display_name?, email?, avatar_url?). |
DummyRelationOption | Relation pool entry shape (id, name). |
See Also
useDocyrusDummyDataGeneratorWizard— smart hook that wires the wizard to a Docyrus data source in one call.useDocyrusDataImportWizard— companion wizard for ingesting real spreadsheets.useDocyrusFieldComponent— the registry that powers the preview-step value renderers.