Skip to content

Added keep open boolean field to Stock Location modal form#11074

Merged
SchrodingersGat merged 24 commits intoinventree:masterfrom
spamik:form-keep-open-feature
Mar 29, 2026
Merged

Added keep open boolean field to Stock Location modal form#11074
SchrodingersGat merged 24 commits intoinventree:masterfrom
spamik:form-keep-open-feature

Conversation

@spamik
Copy link
Copy Markdown
Contributor

@spamik spamik commented Jan 1, 2026

Added new boolean form field to Stock Location modal form which allows to keep form open after submitting instead closing it and redirecting browser to new stock location. This was discussed in this FR: #10412

@netlify
Copy link
Copy Markdown

netlify bot commented Jan 1, 2026

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

Name Link
🔨 Latest commit 0a791e5
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/69c89c2b5a0efd00087bc530
😎 Deploy Preview https://deploy-preview-11074--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: 94 (no change from production)
Accessibility: 81 (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 project configuration.

},
location_type: {}
location_type: {},
keep_form_open: keepFormOpenField(create)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not really like this method here, I would prefer a generic approach here. What do you mean @SchrodingersGat ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem out of step with how are pass other parameters. It could be a simple keep_form_open attribute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we have this parameter for all forms on InvenTree (if it's not disabled for that form) and then don't mix the form fields with the keep open toggle we render independently at the bottom of keep open is available for that form?

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Jan 8, 2026

Ok, I've rewrited it a little. What about now? Calling method is gone. I had to still leave there some parameter passing because I didn't figured out how to hide this field in edit forms in some other way.

@SchrodingersGat SchrodingersGat added this to the 1.3.0 milestone Feb 12, 2026
@SchrodingersGat
Copy link
Copy Markdown
Member

The button should not be within the form itself - place it down in the bottom bar:

image

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 8, 2026

Ok, I now rewritted it as a form property, enabled on create forms.

Copy link
Copy Markdown
Member

@matmair matmair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks for the contribution

@SchrodingersGat
Copy link
Copy Markdown
Member

@spamik it looks like your current implementation does not actually use the "keep open" feature in any forms yet - is this intentional?

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 9, 2026

@SchrodingersGat It shouldn't be; I added keepFormOpenOption=true to CreateApiModalForm so this option should be visible on all create forms (and at least it looks like that when I was testing it). But it's for sure possible to change this option on create form and enable it only on specific forms.

@SchrodingersGat
Copy link
Copy Markdown
Member

Please address this issue:

8:16:46 PM: $ tsc && vite build --emptyOutDir --outDir dist
8:16:56 PM: src/components/forms/ApiForm.tsx(136,9): error TS2353: Object literal may only specify known properties, and 'field_name' does not exist in type '{ field: ApiFormFieldType; definition?: ApiFormFieldType | undefined; }'.
8:16:56 PM: error Command failed with exit code 2. (https://ntl.fyi/exit-code-2)

@SchrodingersGat
Copy link
Copy Markdown
Member

@spamik I have pulled this code branch down to test, and I notice a real performance hit when toggling the "keep form open" switch.

When compared to a normal boolean input within the form (which toggles very quickly) there is a significant slow-down / lag which is introduced into the browser - especially when quickly toggling the "keep form open" input multiple times.

I have not had a chance to try to profile this yet, but this will need to be addressed before we can merge.

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 11, 2026

I'll try to look on both of the issues.

Regarding the performance hit - any idea from experienced react developers what can cause it? Because I've just used mantis switch component and on onchange event it's changing boolean property so I'm really wondering what can be wrong with this part :-)

@SchrodingersGat
Copy link
Copy Markdown
Member

Another consideration here - I do not think that adding this button should be the default option. I have found a number of dialogs where it certainly does not make sense:

image

So, we should make it opt-in and decide where it is actually useful!

@SchrodingersGat
Copy link
Copy Markdown
Member

SchrodingersGat commented Mar 15, 2026

@spamik very nice, happy with this now! Just some very small changes to request:

Changelog

  • Can you please add a brief entry into ./CHANGELOG.md into the Added section for the upcoming release?

Docs

  • Please add a brief description (and a screenshot) to the "forms" section in ./docs/docs/concepts/user_interface.md

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 15, 2026

Done :-)

@SchrodingersGat
Copy link
Copy Markdown
Member

@spamik thanks!

One last thing (sorry!) - I note that there are no test added for this new feature - can you please add a playwright test to ensure that it is functioning as expected:

https://docs.inventree.org/en/stable/develop/react-frontend/#testing

@SchrodingersGat
Copy link
Copy Markdown
Member

Please add a test, fix conflicts, and I'm happy to merge this in!

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 19, 2026

Yep, I'll try that. Maybe it will take a little time - playwright is another technology I didn't used so far :-)

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 22, 2026

I've added new test case to pui_forms_spec.ts. Seem it's working as I was testing it by playing with test code. But look if it make sense; I was little fithing with it :-)

@SchrodingersGat
Copy link
Copy Markdown
Member

@spamik thanks, the test looks good! Please merge in master / fix conflicts here

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 22, 2026

Conflict should be resolved now

@SchrodingersGat
Copy link
Copy Markdown
Member

@spamik thanks - just looks like the added test is broken!

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 24, 2026

@SchrodingersGat It's weird, I was running playwright test locally in devcontainer and it was running fine (I even played with commenting parts of test to be sure it will fail if miss some step). I lookend in logs in QC / Tests and it's failing on start when clicking on switch. It seems that for some reason this switch is missing when it's running in CI/CD pipeline.

Is there some way how can I build the same image like what is used in CI/CD pipeline so I can look how app is really looking in it?

@SchrodingersGat
Copy link
Copy Markdown
Member

It may be the text selector you are using - and the use of {exact: true} - from reviewing the test run it appears that this text is not exactly what you are testing for?

image

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 26, 2026

Without exact: true it was failing even on my setup... I thought that it was because of duplicity with the description. If I look on your screenshot - I guess that if I use getByRole('switch', ...) selector as it is described here it should be working and it's better than generic getByText, right?

@SchrodingersGat
Copy link
Copy Markdown
Member

Worth a try at least!

@spamik
Copy link
Copy Markdown
Contributor Author

spamik commented Mar 27, 2026

Ok, I've made patch, please try if it now works in CI/CD pipeline. With this change it's failing on my setup but according to your screenshot it can work.

Still I'm wondering what is doing this difference. I've installed playwright extension in browser and try to use it on inventree running in dev container on my WS. I can see this (which is explaining why previous test on my WS was working OK).

Snímek obrazovky z 2026-03-27 00-56-56

@SchrodingersGat SchrodingersGat merged commit 9cd0b52 into inventree:master Mar 29, 2026
27 checks passed
@SchrodingersGat
Copy link
Copy Markdown
Member

@spamik thanks for this contribution!

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (e3c9a35) to head (0a791e5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11074   +/-   ##
=======================================
  Coverage   91.43%   91.43%           
=======================================
  Files         962      962           
  Lines       49762    49762           
=======================================
  Hits        45500    45500           
  Misses       4262     4262           
Components Coverage Δ
Backend Apps 91.71% <ø> (ø)
Backend General 93.40% <ø> (ø)
Frontend ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

SchrodingersGat added a commit to SchrodingersGat/InvenTree that referenced this pull request Mar 29, 2026
- Following inventree#11074
- Option to keep allocation forms open
SchrodingersGat added a commit that referenced this pull request Mar 29, 2026
- Following #11074
- Option to keep allocation forms open
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.

4 participants