mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-03 00:52:32 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
3.3 KiB
3.3 KiB
Forms
Use kea-forms for any form. It manages values, validation, submission state, and
success/failure actions in one builder. Hand-rolling a form means rebuilding all of
that for no good reason.
Why a forms builder and not reducers + listeners
A forms builder named foo generates:
fooValues— current valuesfooValidationErrors— keyed by field, computed fromerrorsfooHasErrors— booleansetFooValues({ a: 1 })/setFooValue('a', 1)— partial updatessubmitFoo()/submitFooSuccess/submitFooFailureisFooSubmitting— booleanresetFoo(defaults?)— back to defaults<Form logic={fooLogic} formKey="foo">and<Field name="...">on the component side
You can't beat that with hand-written reducers without rewriting all of it.
Basic shape
import { forms } from 'kea-forms'
export interface SignupForm {
email: string
organization_name: string
}
forms(() => ({
signup: {
defaults: { email: '', organization_name: '' } as SignupForm,
errors: ({ email, organization_name }) => ({
email: !email ? 'Please enter your email' : undefined,
organization_name: !organization_name ? 'Please enter your org' : undefined,
}),
submit: async (formValues) => {
await api.create('api/social_signup/', formValues)
},
},
})),
defaults— initial values (typed).errors— function from values to a per-field error object. Returnundefinedfor "no error" — never an empty string.submit— async function; throws are caught by the plugin and surface assubmitFooFailure.
Field-dependent and conditional errors
errors: ({ source_type, s3_bucket, access_key }) => ({
source_type: !source_type ? 'Pick a source' : undefined,
s3_bucket: source_type === 's3' && !s3_bucket ? 'Bucket required' : undefined,
access_key: source_type === 's3' && !access_key ? 'Access key required' : undefined,
}),
The errors function re-runs on every value change, so it naturally supports cross-field
validation. Keep it pure — no I/O, no Math.random().
Reacting to submit success or failure
listeners(({ actions }) => ({
submitSignupSuccess: () => {
router.actions.push(urls.home())
},
submitSignupFailure: ({ error }) => {
toast.error(error.message ?? 'Something went wrong')
},
})),
Don't put navigation or toasts inside submit — let the success/failure listeners
handle them. Submit is for the actual work; reacting to outcomes is a listener concern.
Resetting
listeners(({ actions }) => ({
submitSignupSuccess: () => {
actions.resetSignup() // back to defaults
// or: actions.resetSignup({ email: values.signup.email }) // partial reset
},
})),
On the component side
import { Form, Field } from 'kea-forms'
;<Form logic={signupLogic} formKey="signup" enableFormOnSubmit>
<Field name="email" label="Email">
<Input type="email" />
</Field>
<Field name="organization_name" label="Org">
<Input />
</Field>
<Button type="primary" htmlType="submit" loading={isSignupSubmitting}>
Sign up
</Button>
</Form>
enableFormOnSubmit makes Enter submit the form. Use it unless you have a reason
not to.
Anti-patterns
See anti-patterns.md for the consolidated catalogue.