Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Custom states #8438

Merged
merged 54 commits into from
Dec 28, 2024

Conversation

SchrodingersGat
Copy link
Member

@SchrodingersGat SchrodingersGat commented Nov 6, 2024

This PR is an update to the "custom states" functionality, to improve usability and extend user interface integration

Tasks

  • Improved back-end validation
  • Improved form management for creating / editing a custom state
  • Display proper custom state in PUI for individual detail views
  • Display proper custom state in PUI for tables
  • Ensure matching logical state is set when transitioning to a custom state
  • Check that "custom" state can only be set to appropriate values
  • Add custom states to the demo dataset - Add some custom states demo-dataset#86
  • Extend existing unit testing to ensure that all new validations checks are tested
  • Add playwright tests for custom states (after demo dataset is updated)
  • Ensure table filtering works with custom state values - Custom Stock Status filter does not work #8612

Future Work / Extensions

  • Revisit removing "model" field from CustomState table (or at least making it optional)
  • Update documentation on custom states

@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature user interface refactor Platform UI Related to the React based User Interface labels Nov 6, 2024
@SchrodingersGat SchrodingersGat added this to the 1.0.0 milestone Nov 6, 2024
Copy link

netlify bot commented Nov 6, 2024

Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit 702209d
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/6770667dfbfbfd0008e39dcf
😎 Deploy Preview https://deploy-preview-8438--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 86 (no change from production)
Best Practices: 100 (no change from production)
SEO: 78 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@SchrodingersGat
Copy link
Member Author

@matmair I have been looking at the implementation of custom states and there are a few areas which I think can be cleaned up a bit.

One question I have is: what is the value of the model (ContentType) field on the InvenTreeCustomUserStateModel model? We already map to a status group, which implies a given model type. I don't see the value of having a separate field (which the user has to know how to fill in) - which can conflict with the specified statuscode.

I would suggest that we remove the model field and rely on the reference_status field to perform this functionality

@matmair
Copy link
Member

matmair commented Nov 6, 2024

@SchrodingersGat there is only an implicit link between status groups and models. When you start shipping custom models in plugins and using custom states there you need some way to prefilter possible selections.

@SchrodingersGat
Copy link
Member Author

I don't understand the use case here - in what circumstance would you want to make a custom state which overrides a BuildStatus code, but links to a SalesOrderShipment model? (for example)

@matmair
Copy link
Member

matmair commented Nov 6, 2024

The use case is enabling order when you have 40+ state groups and need to filter to manage them. If you see no value you can remove this and I will patch my custom fork for support, it seems anyway like I will never be able to use upstream.

There is no reliable link between a state named "SomeModelStatus" and the model "SomeModel" - especially with possible model name collisions between (3rd party) apps.

@wolflu05
Copy link
Contributor

wolflu05 commented Nov 6, 2024

(Just a question, no opinion here, I just want to understand your design choice)

Do you have any example scenario where custom states and models are in a relationship other than n:1? (E.g. the same custom state is assigned to multiple models. If not, doesn't that say that each custom state has only one model, which implicitly means there is a reliable link between a state and the model.

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 80.29197% with 54 lines in your changes missing coverage. Please review.

Project coverage is 85.09%. Comparing base (c582ca0) to head (702209d).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/backend/InvenTree/generic/states/states.py 81.01% 15 Missing ⚠️
src/frontend/src/forms/CommonForms.tsx 0.00% 13 Missing ⚠️
src/backend/InvenTree/generic/states/api.py 75.00% 6 Missing ⚠️
src/backend/InvenTree/stock/models.py 76.92% 6 Missing ⚠️
src/backend/InvenTree/common/validators.py 28.57% 5 Missing ⚠️
src/frontend/src/hooks/UseStatusCodes.tsx 40.00% 2 Missing and 1 partial ⚠️
.../frontend/src/components/render/StatusRenderer.tsx 60.00% 1 Missing and 1 partial ⚠️
src/backend/InvenTree/common/models.py 95.23% 1 Missing ⚠️
src/backend/InvenTree/generic/states/validators.py 91.66% 1 Missing ⚠️
src/frontend/src/forms/StockForms.tsx 0.00% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8438      +/-   ##
==========================================
- Coverage   85.30%   85.09%   -0.22%     
==========================================
  Files        1175     1178       +3     
  Lines       51560    51739     +179     
  Branches     2076     2085       +9     
==========================================
+ Hits        43984    44027      +43     
- Misses       7045     7187     +142     
+ Partials      531      525       -6     
Flag Coverage Δ
backend 86.91% <85.71%> (-0.03%) ⬇️
pui 68.67% <44.44%> (-0.96%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matmair
Copy link
Member

matmair commented Nov 9, 2024

Implicit is the key here; there is no reliable way to map a custom state to a model, thus automation that needs to make this link will not be able to function anymore if it is removed. I do not rely on implicit mapping in my business-critical LoB
apps.

Copy link

codecov bot commented Dec 27, 2024

Bundle Report

Changes will increase total bundle size by 4.22kB (0.06%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
pui_v1-esm 6.74MB 4.22kB (0.06%) ⬆️

@SchrodingersGat SchrodingersGat merged commit 964984c into inventree:master Dec 28, 2024
27 checks passed
@SchrodingersGat SchrodingersGat deleted the custom-states branch December 28, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an suggested enhancement or new feature Platform UI Related to the React based User Interface refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Stock Status filter does not work Custom Stock Status cannot be set from Stock Actions
3 participants