← 返回列表
全部 Skill›工具 Tools›migrate-frontend-forms

migrate-frontend-forms

作者 @getsentry · 语言 en
Guide for migrating forms from the legacy JsonForm/FormModel system to the new TanStack-based form system.
工具 Tools自动化工具通用待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
45,876
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Form Migration Guide

This skill helps migrate forms from Sentry's legacy form system (JsonForm, FormModel) to the new TanStack-based system.

Feature Mapping

| Old System | New System | Notes |

| -------------------- | ----------------------------------------- | ---------------------------------------------------- |

| saveOnBlur: true | AutoSaveForm | Default behavior |

| confirm | confirm prop | string \| ((value) => string \| undefined) |

| showHelpInTooltip | variant="compact" | On layout components |

| disabledReason | disabled="reason" | String shows tooltip |

| extraHelp | JSX in layout | Render <Text> below field |

| getData | mutationFn | Transform data in mutation function |

| mapFormErrors | Request error adapter | Explicit for regular forms; provided for auto-save |

| saveMessage | onSuccess | Show toast in mutation onSuccess callback |

| formatMessageValue | onSuccess | Control toast content in onSuccess callback |

| resetOnError | onError | Call form.reset() in mutation onError |

| saveOnBlur: false | useScrapsForm | Use regular form with explicit Save button |

| (automatic) | form.reset() | Call after successful mutation if form stays on page |

| help | hintText | On layout components |

| label | label | On layout components |

| required | required | On layout + Zod schema |

| Display-only content | DisplayField.Row / DisplayField.Stack | No registered input or form state |

Feature Details

confirm → confirm prop

Old:

{
  name: 'require2FA',
  type: 'boolean',
  confirm: {
    true: 'Enable 2FA for all members?',
    false: 'Allow members without 2FA?',
  },
  isDangerous: true,
}

New:

<AutoSaveForm
  name="require2FA"
  confirm={value =>
    value
      ? 'Enable 2FA for all members?'
      : 'Allow members without 2FA?'
  }
  {...}
>

showHelpInTooltip → variant="compact"

Old:

{
  name: 'field',
  help: 'This is help text',
  showHelpInTooltip: true,
}

New:

<field.Layout.Row
  label="Field"
  hintText="This is help text"
  variant="compact"
>

disabledReason → disabled="reason"

Old:

{
  name: 'field',
  disabled: true,
  disabledReason: 'Requires Business plan',
}

New:

<field.Input
  disabled="Requires Business plan"
  {...}
/>

extraHelp → JSX

Old:

{
  name: 'sensitiveFields',
  help: 'Main help text',
  extraHelp: 'Note: These fields apply org-wide',
}

New:

<field.Layout.Stack label="Sensitive Fields" hintText="Main help text">
  <field.TextArea {...} />
  <Text size="sm" variant="muted">
    Note: These fields apply org-wide
  </Text>
</field.Layout.Stack>

getData → mutationFn

The getData function transformed field data before sending to the API. In the new system, handle this in the mutationFn.

Old:

// Wrap field value in 'options' key
{
  name: 'sentry:csp_ignored_sources_defaults',
  type: 'boolean',
  getData: data => ({options: data}),
}

// Or extract/transform specific fields
{
  name: 'slug',
  getData: (data: {slug?: string}) => ({slug: data.slug}),
}

New:

<AutoSaveForm
  name="sentry:csp_ignored_sources_defaults"
  schema={schema}
  initialValue={project.options['sentry:csp_ignored_sources_defaults']}
  mutationOptions={{
    mutationFn: data => {
      // Transform data before API call (equivalent to getData)
      const transformed = {options: data};
      return fetchMutation({
        url: `/projects/${organization.slug}/${project.slug}/`,
        method: 'PUT',
        data: transformed,
      });
    },
  }}
>
  {field => (
    <field.Layout.Row label="Use default ignored sources">
      <field.Switch checked={field.state.value} onChange={field.handleChange} />
    </field.Layout.Row>
  )}
</AutoSaveForm>

Simpler pattern - If you just need to wrap the value:

mutationOptions={{
  mutationFn: fieldData => {
    return fetchMutation({
      url: `/projects/${org}/${project}/`,
      method: 'PUT',
      data: {options: fieldData}, // getData equivalent
    });
  },
}}

Important: Typing mutations correctly

The mutationFn should be typed with the API's data type (e.g., Partial<Organization>, Partial<Project>), not the schema-inferred type. The schema is for client-side field validation only — the mutation receives whatever the API endpoint accepts. Tying the mutation to the schema couples two unrelated concerns and can cause type errors when the schema types don't exactly match the API types.

// ❌ Don't use generic types - breaks field type narrowing
mutationOptions={{
  mutationFn: (data: Record<string, unknown>) => {
    return fetchMutation({url: '/user/', method: 'PUT', data: {options: data}});
  },
}}

// ❌ Don't tie mutation type to the zod schema
mutationOptions={{
  mutationFn: (data:
评论
Ggetsentry
getsentry
getsentry/sentry
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@getsentry
所属大类工具 Tools / 自动化工具
国内可用性通用
最近源活动—
风险提示无
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。