Skip to content

Let custom item types behave as starting materials or equipment - #2205

Draft
jbouquiaux wants to merge 3 commits into
datalab-org:mainfrom
Matgenix:jbouquiaux/custom-types-behave-as
Draft

jbouquiaux wants to merge 3 commits into
datalab-org:mainfrom
Matgenix:jbouquiaux/custom-types-behave-as

Conversation

@jbouquiaux

Copy link
Copy Markdown
Member

Follow up on #2204

Plugins can already define custom item types that subclass StartingMaterial or Equipment, but in practice those types still behave like samples: they show up on the Samples page and are private to whoever created them. That's because the core decides listings and permissions from type strings ("starting_materials", "equipment"), so a subclass with its own type never matches.

This PR lets a plugin opt in to the behaviour of the built-in type it extends:

class Precursor(StartingMaterial):
    model_config = ConfigDict(json_schema_extra={"datalab_behave_as": "starting_materials"})
    type: Literal["precursors"] = "precursors"

With the hint, Precursor items are listed and created from the Starting Materials page, are shared like inventory (no owner, visible to everyone or restricted to groups, following UNGROUPED_INVENTORY), and show up in item pickers that search for starting materials. Equipment works the same way.

Custom item types inheriting from StartingMaterial or Equipment can declare
datalab_behave_as to be listed with, and share the inventory permissions of,
that built-in type. INVENTORY_TYPES becomes a set that registration extends,
and /info/types exposes the hint. Without the hint, behaviour is unchanged.
Custom types with the hint are registered as inventory/equipment types,
offered in the matching create dialog, added to the right list on creation,
and included in item searches for the built-in type they behave as.
@jbouquiaux
jbouquiaux marked this pull request as draft October 9, 2026 13:20
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.53%. Comparing base (ddb057c) to head (29dede4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2205      +/-   ##
==========================================
+ Coverage   82.48%   82.53%   +0.05%     
==========================================
  Files          91       91              
  Lines        8782     8797      +15     
==========================================
+ Hits         7244     7261      +17     
+ Misses       1538     1536       -2     
Files with missing lines Coverage Δ
pydatalab/src/pydatalab/models/__init__.py 96.29% <100.00%> (+0.42%) ⬆️
pydatalab/src/pydatalab/models/schema_hints.py 90.72% <100.00%> (+2.42%) ⬆️
pydatalab/src/pydatalab/permissions.py 92.89% <100.00%> (ø)
pydatalab/src/pydatalab/routes/v0_1/info.py 84.96% <ø> (ø)
pydatalab/src/pydatalab/routes/v0_1/items.py 86.84% <100.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

1 participant