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

Custom fields on user v7 rebased #15146

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

uberbrady
Copy link
Collaborator

This is another stab at Custom Fields as a Trait, with that trait being used on Assets (which we already had) and Users (which we did not have). This should put us in a good position going forward to start adding custom fields to other things. This is rebased and squashed against latest Develop, so it should be easier to merge develop back into it, or to rebase it against develop, or whatever else we need to do to it.

There are definitely some elements here that need buttoning-up. One that bothers me a lot is that I renamed the "default values for custom fields" table - and that makes it brutally hard to switch back and forth between branches. Not fun. Maybe I should've just stuck with the old name, and just added the columns, maybe renaming it later, if ever? Or maybe we rip this band-aid off now.

There are FIXME's scattered throughout that we should address, deprioritize into TODO's, or remove (if they've already been handled, of course).

The UI probably is going to need some pretty close attention to get it looking and working well enough.

I think once we have everything looking kinda how we like, it's probably worth it to do another squash to make this one clean set of changes.

I definitely ran into some weird problems with the squash/merge where stuff got duplicated and messed up in a few spots. I tried to clean those up, but those spurious changes are probably worth squashing out because they're unnecessarily weird.

Copy link

what-the-diff bot commented Jul 23, 2024

PR Summary

  • Introduction of helper methods for custom fields
    A new helper file, CustomFieldHelper.php has been added to facilitate the handling of custom fields, enhancing modularity and reusability.

  • Enhancement and Refactor of Existing Files
    Several files, including controllers like AssetModelsController.php, AssetsController.php, CustomFieldsetsController.php, and UsersController.php, have been optimized by removing default values for custom fields during update processes and eliminating redundant counts from various queries. This simplifies the codebase and makes the application more efficient.

  • Code Clean-up in Controllers
    There was some code cleanup to remove commented-out code and redundant methods from the AssetsController.php, AssetModelsController.php, CustomFieldsController.php, and UsersController.php files, creating a cleaner and more maintainable codebase.

  • Addition of Conditions in Custom Fields & Fieldsets
    New conditions have been incorporated into the CustomFieldsetsController.php and CustomFieldsController.php files to optimize how custom fields and fieldsets are created and managed, improving usability and functionality.

  • Improvements in Data Transformation
    Several transformation files such as AssetsTransformer.php, CustomFieldsetsTransformer.php, and UsersTransformer.php have been upgraded to use the new CustomFieldHelper for better transformation of custom field data, enhancing consistency and modularity of the code.

  • Modifications in Importers and Models
    The Importer.php and AssetImporter.php files, along with various models (Asset.php, AssetModel.php, CustomField.php, and CustomFieldset.php), now accommodate changes in handling custom fields, allowing for more robust and versatile usage.

  • New Model for Custom Fields Defaults
    The addition of a new model, DefaultValuesForCustomFields, provides a dedicated framework for managing default values of custom fields, enhancing readability and maintainability.

  • Trait for Custom Fields Handling
    With the new trait HasCustomFields, models like the User model can now handle custom fields more efficiently, promoting code reuse and adherence to the DRY principle.

  • Updates to Presenter Files and Factories
    The AssetPresenter, UserPresenter, along with several factory classes have been updated to adapt to the custom fields changes, ensuring that the data models and factories comply with the new structure.

  • Important Database Migrations
    Database migrations were performed to effectively adapt the custom_fields and custom_fieldsets tables to the new changes.

  • Updates to View Files
    Several view files were updated to accommodate changes related to custom fields. Improvements in UI for ‘tab’ query parameter and display of custom fields enhances interaction with the application.

  • New Tests and Logs
    Addition of new logs and unit tests (HasCustomFieldsTraitTest.php) ensures that the changes made are effective and correctly validated.

Please note, updates to several PHP and blade files, and new additions have been done to ensure smoother and more sophisticated handling and representation of custom fields across the application. These changes cater to improving the functionality, readability and maintainability of the codebase.

…the new HasCustomFields trait.

This should allow us to add custom fields to just about anything we want to within Snipe-IT.

Below are the commits that have been squashed together:

Initial decoupling of custom field behavior from Assets for re-use

Add new DB columns to Custom Fields and fieldsets for 'type'

WIP: trying to figure out UI for custom fields for things other than Assets, find problematic places

Real progress towards getting to where this stuff might actually work...

Fix the table-name determining code for Custom Fields

Getting it closer to where Assets at least work

Rename the trait to it's new, even better name

Solid progress on the new Trait!

WIP: HasCustomFields, still working some stuff out

Got some basics working; creating custom fields and stuff

HasCustomFields now validates and saves

Starting to yank the other boilerplate code as things start to work (!)

Got the start of defaultValuesForCustomField() working

More progress (squash me!)

Add migrations for default_values_for_custom_fields table

WIP: more towards hasCustomFields trait

Progress cleaning up the PR, fixing FIXME's

New, passing HasCustomFieldsTrait test!

Fix date formatter helper for custom fields

Fixed more FIXME's

Got a chunk of Custom Fields for Users worked out, still needs cleanup

Wiring up custom fields for users - still some big UI challenges tho

Remove some code duplication

Refactor out common code for 'custom fields view' partial

Clean up this migration so it runs forwards and backwards OK

Clean up the fieldset experience for custom fields for users

Make tests pass, at least to start with. Still needs cleanup
@uberbrady uberbrady force-pushed the custom_fields_on_user_v7_rebased branch from d3ee857 to 5c77c9b Compare November 14, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant