Skip to content

feat(ui): edit per-commodity flex-contexts through a commodity tab bar#2284

Open
Flix6x wants to merge 5 commits into
mainfrom
feat/2230-ui-commodities
Open

feat(ui): edit per-commodity flex-contexts through a commodity tab bar#2284
Flix6x wants to merge 5 commits into
mainfrom
feat/2230-ui-commodities

Conversation

@Flix6x

@Flix6x Flix6x commented Jul 10, 2026

Copy link
Copy Markdown
Member

Description

Closes #2230. Stacked on #2281.

The flex-context modal gains a commodity pill bar: electricity (the top-level context) plus one pill per entry of the commodities list, an + commodity affordance (with duplicate-name rejection), and a remove icon per commodity. The existing card editor is reused per scope, so all field types (fixed value, sensor picker, sensor lists) work within each commodity context.

  • The add-field dropdown per commodity tab only offers fields that CommodityFlexContextSchema shares, driven by a new per-commodity flag computed onto UI_FLEX_CONTEXT_SCHEMA (guarded by a new test).
  • Saving PATCHes the whole flex-context, including the nested (cleaned) commodities list.
  • commodities documented: new COMMODITIES metadata constant + a row in the scheduling.rst flex-context table; removed from the UI-schema exclusion list so the parity test now enforces coverage.

Look & Feel

Pill bar above the field cards; switching pills swaps the card list and the add-field dropdown to that commodity's scope.

How to test

pytest flexmeasures/ui/tests flexmeasures/data/schemas tests/documentation

Manually (verified end-to-end against a live server with a seeded multi-commodity asset): open an asset's context page → Edit flex-context → switch pills, add a field on the gas tab, add/remove a commodity, Save → PATCH returns 200 and the persisted flex_context round-trips on reload.

Related Items

Stacked on #2281; #1572 (commitments editor) builds on this scope mechanism.

🤖 Generated with Claude Code

https://claude.ai/code/session_016MLCUiSdXDqDBmg8GbYp1B

Flix6x and others added 5 commits July 10, 2026 21:27
Add a 'types' key to every UI_FLEX_CONTEXT_SCHEMA entry (same convention
as UI_FLEX_MODEL_SCHEMA: typeTwo = single sensor reference, typeThree =
fixed value or sensor, typeFour = list of sensors), resolving the todo
about the field type living hardcoded in asset_context.html in 3 places.
The template now derives its sensor-only check from the schema, so new
context fields (e.g. the upcoming commodities and commitments editors)
only need a schema entry. No behaviour change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MLCUiSdXDqDBmg8GbYp1B
#2230)

The flex-context modal gains a pill bar: 'electricity' (the top-level
context) plus one pill per entry of the commodities list, with add/remove
affordances. The existing card editor is reused per scope; the add-field
dropdown only offers fields that CommodityFlexContextSchema shares (driven
by a new per-commodity flag on UI_FLEX_CONTEXT_SCHEMA entries). Saving
PATCHes the whole flex-context including the nested commodities list.

Also documents the commodities field (new COMMODITIES metadata + docs row)
and removes it from the UI-schema exclusion list.

Verified end-to-end against a live server with a seeded multi-commodity
asset: per-scope editing, adding/removing commodities, duplicate-name
rejection, and round-tripping through PATCH + reload.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MLCUiSdXDqDBmg8GbYp1B
Per review on #2281: define each type token's UI description once
(UI_TYPE_DESCRIPTIONS) instead of repeating it per field, and derive the
backend type of each UI_FLEX_CONTEXT_SCHEMA entry from the corresponding
DBFlexContextSchema field. Commitments are now correctly typed as a list
of structured entries (new typeSix token) rather than fixed-or-sensor.
Sensor-only exceptions that live in validators rather than field types
(fixed prices forbidden in the DB, aggregate-power requiring a sensor)
are listed explicitly with pointers to those validators.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MLCUiSdXDqDBmg8GbYp1B
…rives to typeSix

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MLCUiSdXDqDBmg8GbYp1B
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #33536676 | 📁 Comparing 402bc32 against latest (922ecf6)

  🔍 Preview build  

3 files changed
+ _autodoc/COMMODITIES.html
± api/v3_0.html
± features/scheduling.html

@Ahmad-Wahid

Copy link
Copy Markdown
Contributor

Is not a good option to restrict the commodities to the ones we support? User can add any commodity.

image

@Flix6x

Flix6x commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

In theory, anything is fine. The custom commodity only comes into play if the same commodity is referenced in a flex-model. We might want to seed the list with some standard ones, but besides "electricity" none have a special meaning in FlexMeasures right now.

Base automatically changed from feat/ui-flex-context-field-types to main July 17, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants