Type the widget registry per key, like UtilityTypeMap
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 12/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Active
- Tech stack
- typescript
- Domain
- developer-experience, frontend
Research direction
This is a design discussion, not an implementation task. Read the WidgetPropsMap augmentation in @plone/types, the UtilityTypeMap and UtilityMethodFor pattern it mirrors, and the registerWidget and getWidget signatures in @plone/cmsui. Done means the open questions on what the map buys, where it lives, variance and API value types have a maintainer decision, before any code is written.
Written by the indexing model from the issue text.
Description
Follow-up of #262 and #263. A debate first, before anyone implements it.
Today
WidgetPropsMap in @plone/types is augmented per app, like UtilityTypeMap. It holds one props type for every widget slot. @plone/cmsui declares props: FormWidgetProps<any>, so every registered widget is checked against the widget contract, whatever value it reads and writes.
That catches widgets that don't follow the contract (#262). It can't catch a widget registered for the wrong kind of field. For example, NumberWidget (FormWidgetProps<number | null>) registered for type: 'boolean' type-checks.
Idea
Type each slot by its key, the way UtilityTypeMap types each utility by its type. Keys the map doesn't list fall back to the app-wide props, the way UtilityMethodFor falls back.
declare module '@plone/types' {
interface WidgetKeyPropsMap {
type: {
boolean: FormWidgetProps<boolean>;
number: FormWidgetProps<number | null>;
integer: FormWidgetProps<number | null>;
array: FormWidgetProps<TermValue[] | null>;
};
widget: {
date: FormWidgetProps<string | null>;
datetime: FormWidgetProps<string | null>;
};
factory: {
File: FormWidgetProps<FileValue | null>;
Image: FormWidgetProps<FileValue | null>;
};
}
}
registerWidget({ key: 'type', definition: { boolean: NumberWidget } }) would then fail the type check. getWidget('boolean', 'type') could return a typed component.
Open questions
- What does it buy? It only checks registration. The form picks the widget from the schema at runtime, so
SchemaFieldstill only seesFormWidgetProps<unknown>. Is checking registrations worth a map to maintain? - Where does the map live? In
@plone/cmsui, next to the widgets, augmenting@plone/typeslikeWidgetPropsMapdoes? Volto must stay unaffected, with no augmentation and any props. - Variance.
onChange: (value: T) => voidmakesFormWidgetProps<T>invariant inT, so an add-on that overrides a slot must match the declared value type exactly. Is that what we want, or should a slot declare the value it reads and accept wider widgets? - Field values from the API. Some values come as terms (
{ token, title }) or as another type than their token (allow_discussion). The declared value type has to say what the widget reads, not only what it writes.
Related: #243, #244, #262, #263.
- Dominant language
- JavaScript
- Stars
- 10
- Forks
- 9
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 54
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from plone/aurora
-
01 type: bug 41 lvl: easy
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
Edit content TabList: selected tab's icon/label are hidden by its own selection indicator - a11yOpen01 type: bug 99 tag: UX Accessibility
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days
-
01 type: bug 30 needs: triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 2 days
-
01 type: bug 99 tag: UX Accessibility
Difficulty 1/5 Under an hour Newbie friendliness 76/100
Maintainers usually reply within 2 days
-
01 type: bug 30 needs: triage
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 2 days
Similar issues
-
accessibility bug dark-mode dashboards
Difficulty 1/5 Under an hour Newbie friendliness 84/100
quarto-dev/quarto-cli#15447 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
521xueweihan/HelloGitHub#4655 ·
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount duePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
bug CRIT-3
Difficulty 1/5 Under an hour Newbie friendliness 70/100
NASA-AMMOS/anms#426 ·