[PR #7040] [MERGED] Improve APISelect query parameter handling #13202

Closed
opened 2025-12-29 22:25:58 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/7040
Author: @thatmattlove
Created: 8/26/2021
Status: Merged
Merged: 8/30/2021
Merged by: @jeremystretch

Base: featureHead: feature-apiselect-queryparams


📝 Commits (8)

  • 89b7f3f Fixes #7035: Refactor APISelect query_param logic
  • e8b3d19 Merge branch 'feature' into feature-apiselect-queryparams
  • 52a1f9d Add filter_fields to extras.ObjectVar & fix default value handling
  • d0208d4 Update ObjectVar docs to reflect new filter_fields attribute
  • 809de86 Revert changes from 89b7f3f
  • 658ac89 Maintain current query_params API for form fields, transform data structure in widget
  • ba0ab6b Merge branch 'feature' into feature-apiselect-queryparams
  • 0687140 Revert changes from d0208d4

📊 Changes

17 files changed (+532 additions, -214 deletions)

View changed files

📝 netbox/project-static/dist/config.js (+1 -1)
📝 netbox/project-static/dist/config.js.map (+2 -2)
📝 netbox/project-static/dist/jobs.js (+1 -1)
📝 netbox/project-static/dist/jobs.js.map (+2 -2)
📝 netbox/project-static/dist/lldp.js (+1 -1)
📝 netbox/project-static/dist/lldp.js.map (+2 -2)
📝 netbox/project-static/dist/netbox.js (+7 -7)
📝 netbox/project-static/dist/netbox.js.map (+3 -3)
📝 netbox/project-static/dist/status.js (+2 -2)
📝 netbox/project-static/dist/status.js.map (+2 -2)
📝 netbox/project-static/src/select/api/apiSelect.ts (+107 -175)
netbox/project-static/src/select/api/dynamicParams.ts (+76 -0)
netbox/project-static/src/select/api/index.ts (+10 -0)
netbox/project-static/src/select/api/types.ts (+189 -0)
📝 netbox/project-static/src/util.ts (+2 -0)
📝 netbox/utilities/forms/fields.py (+4 -4)
📝 netbox/utilities/forms/widgets.py (+121 -12)

📄 Description

Fixes: #7034, #7035

  • Replaced query_params on DynamicModelChoiceMixin with filter_fields, which carries a more strict data model to define how the field's related fields should be handled. The resulting data is serialized to JSON and added as a single data-filter-fields attribute on the <select/> element, and then appropriately handled in the UI.
  • Refactor APISelect TypeScript class to handle new logic — parsing of the data-filter-fields into an expected structure seems to be much simpler than the previous method. Or at least, it's easier for me follow :)
  • query_params is still available on the widget to add static values only.
  • Restructured former netbox/project-static/src/select/api.ts to a directory to break up the 1000+ LOC into multiple files for better readability.
  • Fixed #7034 which was primarily broken due to how we've restructured the form layout (we needed to hide the field's parent's parent, not the immediate parent). Secondarily, the filter_fields changes also fix the filtering itself.
  • Updated extras.ObjectVar docs to reflect addition of filter_fields.

All the testing I can think to do passes perfectly, from what I can tell.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/7040 **Author:** [@thatmattlove](https://github.com/thatmattlove) **Created:** 8/26/2021 **Status:** ✅ Merged **Merged:** 8/30/2021 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `feature-apiselect-queryparams` --- ### 📝 Commits (8) - [`89b7f3f`](https://github.com/netbox-community/netbox/commit/89b7f3f19d46349b1118cee682d51225fe16cadf) Fixes #7035: Refactor APISelect query_param logic - [`e8b3d19`](https://github.com/netbox-community/netbox/commit/e8b3d191e6abd33510ee0d7fd887f35a03aeac72) Merge branch 'feature' into feature-apiselect-queryparams - [`52a1f9d`](https://github.com/netbox-community/netbox/commit/52a1f9ddf0bca2a8148eaf51d299b1959f5e9a42) Add filter_fields to extras.ObjectVar & fix default value handling - [`d0208d4`](https://github.com/netbox-community/netbox/commit/d0208d473dab0af11e0e644e2b1fc875b764b2b2) Update ObjectVar docs to reflect new filter_fields attribute - [`809de86`](https://github.com/netbox-community/netbox/commit/809de8683b1d65003e421e6b424e5854a7b06b90) Revert changes from 89b7f3f - [`658ac89`](https://github.com/netbox-community/netbox/commit/658ac89af0b897befb7f91d85ef5219f48178506) Maintain current `query_params` API for form fields, transform data structure in widget - [`ba0ab6b`](https://github.com/netbox-community/netbox/commit/ba0ab6be46ac008f8b03e700c92ad15d832132f3) Merge branch 'feature' into feature-apiselect-queryparams - [`0687140`](https://github.com/netbox-community/netbox/commit/06871405b1f604fa723d68156f36a51f1f39f93d) Revert changes from d0208d4 ### 📊 Changes **17 files changed** (+532 additions, -214 deletions) <details> <summary>View changed files</summary> 📝 `netbox/project-static/dist/config.js` (+1 -1) 📝 `netbox/project-static/dist/config.js.map` (+2 -2) 📝 `netbox/project-static/dist/jobs.js` (+1 -1) 📝 `netbox/project-static/dist/jobs.js.map` (+2 -2) 📝 `netbox/project-static/dist/lldp.js` (+1 -1) 📝 `netbox/project-static/dist/lldp.js.map` (+2 -2) 📝 `netbox/project-static/dist/netbox.js` (+7 -7) 📝 `netbox/project-static/dist/netbox.js.map` (+3 -3) 📝 `netbox/project-static/dist/status.js` (+2 -2) 📝 `netbox/project-static/dist/status.js.map` (+2 -2) 📝 `netbox/project-static/src/select/api/apiSelect.ts` (+107 -175) ➕ `netbox/project-static/src/select/api/dynamicParams.ts` (+76 -0) ➕ `netbox/project-static/src/select/api/index.ts` (+10 -0) ➕ `netbox/project-static/src/select/api/types.ts` (+189 -0) 📝 `netbox/project-static/src/util.ts` (+2 -0) 📝 `netbox/utilities/forms/fields.py` (+4 -4) 📝 `netbox/utilities/forms/widgets.py` (+121 -12) </details> ### 📄 Description ### Fixes: #7034, #7035 - Replaced `query_params` on `DynamicModelChoiceMixin` with `filter_fields`, which carries a more strict data model to define how the field's related fields should be handled. The resulting data is serialized to JSON and added as a single `data-filter-fields` attribute on the `<select/>` element, and then appropriately handled in the UI. - Refactor APISelect TypeScript class to handle new logic — parsing of the `data-filter-fields` into an expected structure seems to be much simpler than the previous method. Or at least, it's easier for me follow :) - `query_params` is still available on the widget to add **static** values only. - Restructured former `netbox/project-static/src/select/api.ts` to a directory to break up the 1000+ LOC into multiple files for better readability. - Fixed #7034 which was primarily broken due to how we've restructured the form layout (we needed to hide the field's parent's parent, not the immediate parent). Secondarily, the `filter_fields` changes also fix the filtering itself. - Updated `extras.ObjectVar` docs to reflect addition of `filter_fields`. All the testing I can think to do passes perfectly, from what I can tell. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:25:58 +01:00
adam closed this issue 2025-12-29 22:25:58 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13202