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

Metadata Templates Selection UI #914

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open

Conversation

joshsadam
Copy link
Contributor

@joshsadam joshsadam commented Jan 24, 2025

What does this PR do and why?

Describe in detail what your merge request does and why.

  1. Updated the ability to display none or all metadata fields via a new select input
  2. Added the ability to select existing metadata templates via the same select dropdown

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other pull requests.

image

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. In the user interface, login as [email protected] and create a new project
  2. Create a couple new samples in the project and add some metadata fields (e.g. a, b, c)
  3. Go into the rails console;
  4. Get the user: user = User.find_by(email: "[email protected]")
  5. Get the namespace for the project you created: namespace = Project.last.namespace
  6. Create a new metadata template inside the project namespace: template = MetadataTemplates::CreateService.new(user, namespace, {name: "template1", fields: ['b', 'c']}).execute
  7. Back inside the user interface, you should be able to go to the samples page for the project you created, and from the select above the table select either: all fields, no fields, or a template.

PR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

@joshsadam joshsadam self-assigned this Jan 24, 2025
@joshsadam joshsadam added the enhancement New feature or request label Jan 28, 2025
@joshsadam joshsadam force-pushed the metadata-templates/dropdown branch 2 times, most recently from bb04467 to 7cc8fc8 Compare January 30, 2025 14:12
…thorization checks

- Added `create_metadata_template?` method to `GroupPolicy` and `ProjectNamespacePolicy` for authorization.
- Removed the obsolete `MetadataTemplatePolicy` class.
- Enhanced `CreateService` to include authorization logic for creating metadata templates.
- Updated locale files to include new activity messages for metadata template creation.
…ndling

- Introduced parameter validation in CreateService to ensure required fields are present before creating a metadata template.
- Added custom error handling for missing name and fields, improving user feedback during template creation.
- Updated tests to cover new validation scenarios, ensuring robust functionality for metadata template creation.
- Standardized quotation marks in locale files for consistency across English and French translations.
…ror handling and validation

- Initialized @metadata_template to streamline template creation process.
- Simplified error handling by directly adding errors to the namespace instead of the template.
- Refined parameter validation to ensure required fields are checked before template creation.
- Updated tests to reflect changes in error handling and validation logic, ensuring robust functionality.
- Added support for displaying metadata template creation activities in both group and project activity components.
- Introduced a new method `metadata_template_link` in the activity components to check for metadata template creation actions.
- Updated HTML templates to render appropriate translations for metadata template activities, ensuring user clarity.
- Refactored locale files to standardize the use of `template_name` in activity messages for consistency across English and French translations.
- Improved parameter handling in the `track_activity` concern to include metadata template details during activity tracking.
… error handling

- Updated CreateService to enforce validation rules ensuring fields are either present as an array or raise appropriate errors.
- Enhanced error messages in locale files for better user feedback during template creation.
- Added tests to cover scenarios for missing fields, unauthorized access, and duplicate template names, ensuring robust functionality.
- Standardized quotation marks in locale files for consistency across English and French translations.
…ncements

- Added a new `DestroyService` for handling the destruction of metadata templates, including authorization checks.
- Updated `ProjectNamespacePolicy` to include `destroy_metadata_template?` method for permission validation.
- Enhanced tests for both the `DestroyService` and `ProjectNamespacePolicy` to ensure correct permission handling and functionality.
- Improved clarity in policy and service interactions for better maintainability and user feedback.
- Refactored `create_metadata_template?` and `destroy_metadata_template?` methods to use effective access level checks for authorization.
- Updated tests to include assertions for the new permission methods, ensuring proper functionality and coverage.
- Improved clarity in permission handling for metadata template operations.
…ermissions

- Introduced `UpdateService` for handling updates to metadata templates, including authorization checks.
- Added `update_metadata_template?` method to `GroupPolicy` and `ProjectNamespacePolicy` for permission validation.
- Updated activity components to recognize metadata template update actions.
- Enhanced locale files to include new activity messages for metadata template updates.
- Added tests for `UpdateService` to ensure correct functionality and permission handling.
…a templates

- Eliminated the `validate_params` method from the `UpdateService`, simplifying the update process.
- Streamlined the execution flow by directly handling updates without pre-validation of parameters.
- Maintained authorization checks to ensure proper permissions during metadata template updates.
- Changed the update method to use `update!` for better error management during metadata template updates.
- Updated error handling to capture `ActiveRecord::RecordInvalid` exceptions and add relevant error messages to the template.
- Modified tests to reflect the new error handling behavior, ensuring accurate assertions for invalid update scenarios.
…mplate updates

- Fixed a typo in the test description for invalid parameter updates.
- Updated the test for numerical fields to assert specific error messages returned by the metadata template, ensuring accurate validation feedback.
- Improved clarity and accuracy in test cases related to metadata template updates.
- Changed the save method in CreateService to use `save!` for better error management.
- Added new validation error messages for the `name` attribute in both English and French locale files.
- Updated tests to assert the presence of specific error messages for invalid metadata template creation scenarios, ensuring accurate feedback for users.
- Refactored methods to modularize the addition of sample activity and metadata template parameters.
- Replaced conditional merges with dedicated methods for clarity and maintainability.
- Introduced a new method to handle bulk sample parameters for 'sample_destroy_multiple' action.
- Improved overall readability and structure of the parameter handling logic.
- Eliminated redundant blank lines in the `create_service.rb` file to improve code readability.
- Ensured that the file maintains a clean and consistent formatting style.
…services

- Changed the save method in CreateService to use `save` instead of `save!`, raising a custom error with detailed messages on failure.
- Updated the update method in UpdateService to use `update` instead of `update!`, removing the rescue block for `ActiveRecord::RecordInvalid`.
- Adjusted tests to reflect the new error handling logic, ensuring accurate assertions for invalid metadata template creation scenarios.
…mplate action types

- Introduced `template_name` to both group and project activity components for enhanced context.
- Refined `metadata_template_link` method in both components to exclude the `metadata_template_destroy` action, simplifying the action types handled.
- Removed the `template_id` parameter from the destroy service to streamline the metadata template destruction process.
- Changed the access level requirement for creating, updating, and destroying metadata templates from ANALYST to MAINTAINER in both GroupPolicy and ProjectNamespacePolicy.
- This change enhances security by ensuring that only users with higher privileges can perform these actions.
- Replaced direct comparisons with `Member::AccessLevel.manageable.include?` for determining access levels in `create_metadata_template?`, `update_metadata_template?`, and `destroy_metadata_template?` methods in both GroupPolicy and ProjectNamespacePolicy.
- This change improves code readability and maintainability by utilizing a more flexible access level management approach.
- Changed the test description to clarify that the update operation fails when incorrect permissions are provided.
- This enhances the readability and understanding of the test's purpose, ensuring it accurately reflects the expected behavior of the system.
- Changed the test description to clarify that the operation fails when incorrect permissions are provided, enhancing the readability and understanding of the test's purpose.
- Extracted `current_metadata_template` method from SamplesController to the Metadata concern
- Centralized metadata template parameter handling in the shared concern
- Simplified code by removing duplicate method definition
- Created `MetadataTemplatesDropdownComponent` to render a reusable dropdown for metadata templates
- Updated `Namespace` model to return metadata templates with their IDs
- Modified `Metadata` concern to return metadata templates as `[name, id]` pairs
- Refactored samples table filter to use the new dropdown component
- Improved metadata template selection with grouped options for all, none, and custom templates
- Deleted the `_metadata_toggle.html.erb` partial from shared samples views
- Removes an unused view component related to metadata display
- Updated dropdown component to use default 'none' selection
- Replaced hardcoded options with internationalized translations
- Added conditional rendering for metadata templates
- Removed unnecessary `w-full` class from dropdown styling
Modify `fields_for_namespace_or_template` method to correctly handle blank metadata templates by adding an additional condition to the existing template checks
- Introduced `metadata_templates` before action to load available metadata templates
- Updated `query` method to use `metadata_fields` with selected metadata template
- Refactored metadata field selection logic to support template-based filtering
- Added `metadata_templates` method to retrieve templates for the current group
- Replaced metadata toggle partial with MetadataTemplatesDropdownComponent in groups and projects samples table filters
- Refactored table filter views to use new dropdown component with metadata templates
- Updated locales to include translations for metadata templates dropdown
Clean up unnecessary `puts` debugging output in the MetadataTemplatesDropdownComponent, improving code cleanliness
Improve accessibility by adding a hidden label for the metadata templates dropdown, ensuring better screen reader support for form inputs
- Wrapped dropdown in a relative container for better layout control
- Added an explicit ID to the select element for improved accessibility
- Refactored class names to use an array for better readability and maintainability
- Simplified and consolidated Tailwind CSS classes for light and dark mode styling
…wn component

Remove unnecessary `puts` debugging output in the component initialization method, improving code cleanliness and removing potential performance overhead
Update en.yml and fr.yml to use consistent single quotes for string values, improving code readability and maintaining a uniform style across localization files
Remove unnecessary metadata toggle label translations from both English and French locale files, cleaning up unused localization entries
Remove unused `fields_for_namespace` method and update `WorkflowExecutions::SubmissionsController` to use `fields_for_namespace_or_template`
Modify system test to assert the presence of the metadata template select dropdown instead of the import metadata button
Replace metadata toggle label click with select dropdown interaction in system tests, ensuring consistent test coverage for the new metadata template selection method
Replace metadata toggle label click with select dropdown interaction across multiple test scenarios, ensuring consistent test coverage for the new metadata template selection method
Modify system test to replace metadata toggle label click with select dropdown interaction, ensuring consistent test coverage for the new metadata template selection method
@joshsadam joshsadam force-pushed the metadata-templates/dropdown branch from 7cc8fc8 to 3c4f208 Compare January 31, 2025 01:42
…e selection

Implement a system test to verify that selecting different metadata templates dynamically updates the table columns, ensuring proper rendering and responsiveness of the samples table
@joshsadam joshsadam marked this pull request as ready for review January 31, 2025 01:56
Clean up unnecessary assertion for metadata toggle label after recent dropdown interaction updates
Enhance system test for samples table by adding explicit scrolling to last column and refactoring sorting assertions within table header context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant