Skip to content

[OSDEV-1814] Add toggle switch for Additional data section#546

Merged
VadimKovalenkoSNF merged 7 commits intomainfrom
OSDEV-1814-additional-info-toggle-switch
Mar 5, 2025
Merged

[OSDEV-1814] Add toggle switch for Additional data section#546
VadimKovalenkoSNF merged 7 commits intomainfrom
OSDEV-1814-additional-info-toggle-switch

Conversation

@VadimKovalenkoSNF
Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF commented Mar 4, 2025

Fix OSDEV-1814

  1. Replaced arrow dropdown icon by toggle switch button in production location info page.
  2. When go to update flow (contribute/single-location/{os_id}/info/), Update button is active by default.
  3. Additional data section hidden by default for update and create new production location flows.
  4. When _Additional dat_a section expanded, update button can be disabled due to invalid incoming fields (such as number of workers range that starts from zero).
  5. When Additional data section expanded, pre-filled values will be send to the server along with name, country and address values. This applies event if user just expand Additional data section and don't input any data from their side.

@barecheck
Copy link

barecheck bot commented Mar 4, 2025

Dedupe Hub App | Unittest test suite - Code coverage report

Total: 56.14%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@barecheck
Copy link

barecheck bot commented Mar 4, 2025

Contricleaner App | Unittest test suite - Code coverage report

Total: 98.91%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@barecheck
Copy link

barecheck bot commented Mar 4, 2025

Countries App | Unittest test suite - Code coverage report

Total: 100%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@barecheck
Copy link

barecheck bot commented Mar 4, 2025

Django App | Unittest test suite - Code coverage report

Total: 80.55%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@VadimKovalenkoSNF VadimKovalenkoSNF self-assigned this Mar 4, 2025
@barecheck
Copy link

barecheck bot commented Mar 5, 2025

React App | Jest test suite - Code coverage report

Total: 32.27%

Your code coverage diff: 0.67% ▴

✅ All code changes are covered

@VadimKovalenkoSNF VadimKovalenkoSNF force-pushed the OSDEV-1814-additional-info-toggle-switch branch from 7f43174 to 2d20a33 Compare March 5, 2025 06:20
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new section titled "What's new" in the release notes for version 1.32.0, highlighting the addition of a toggle switch button for the production location info page. This switch allows users to render additional data when activated. The ProductionLocationInfo component has been updated to replace the previous icon button toggle with a switch, which modifies the visibility of additional data fields using new methods. Corresponding tests and styles have also been adjusted to support this new functionality.

Changes

File(s) Change Summary
doc/release/RELEASE-NOTES.md Added a new section "What's new" for v1.32.0, detailing the toggle switch feature for the production location info page.
src/react/src/components/Contribute/ProductionLocationInfo.jsx,
src/react/src/__tests__/components/ProductionLocationInfo.test.js,
src/react/src/util/styles.js
Updated ProductionLocationInfo to replace the icon button toggle with a switch, introducing methods fillAdditionalDataFields and resetAdditionalDataFields; tests revised for switch behavior and input validation; styles modified to remove marginRight and add switchButton style.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as ProductionLocationInfo Component
    U->>C: Toggle switch (on/off)
    alt Switch turned ON
        C->>C: Call fillAdditionalDataFields()
        C-->>U: Render additional data fields
    else Switch turned OFF
        C->>C: Call resetAdditionalDataFields()
        C-->>U: Hide additional data fields
    end
Loading

Possibly related PRs

Suggested reviewers

  • Innavin369
  • roman-stolar
  • mazursasha1990
  • vladsha-dev

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aff075c and 1e69e89.

📒 Files selected for processing (1)
  • doc/release/RELEASE-NOTES.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • doc/release/RELEASE-NOTES.md
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: run-django-code-quality

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
doc/release/RELEASE-NOTES.md (1)

15-18: Minor inconsistency in header formatting.

There's a trailing colon in the "Release instructions:" header that's inconsistent with other headers like "What's new" that don't use punctuation.

-### Release instructions:
+### Release instructions
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


17-17: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


18-18: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99c80ae and 2d20a33.

📒 Files selected for processing (4)
  • doc/release/RELEASE-NOTES.md (1 hunks)
  • src/react/src/__tests__/components/ProductionLocationInfo.test.js (6 hunks)
  • src/react/src/components/Contribute/ProductionLocationInfo.jsx (5 hunks)
  • src/react/src/util/styles.js (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
doc/release/RELEASE-NOTES.md

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


17-17: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


18-18: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-contricleaner-cov
🔇 Additional comments (15)
src/react/src/util/styles.js (1)

1295-1297: The new switchButton style looks good for the toggle switch implementation.

This style with a 10px top margin provides proper spacing for the new toggle switch component that replaces the previous icon button in the ProductionLocationInfo component.

doc/release/RELEASE-NOTES.md (1)

6-14: The new release section is well-structured and informative.

The information about the new toggle switch button for conditional rendering of additional data is clearly documented along with the product name and release date.

src/react/src/__tests__/components/ProductionLocationInfo.test.js (7)

3-3: Import statement updated to include router components.

The import statement now correctly includes MemoryRouter and Route from 'react-router-dom' for testing router-dependent functionality in the new test cases.


32-32: Test description clarified.

The test description has been improved to clearly specify that this test suite is for testing input fields for POST requests to v1/production-locations.


92-94: Updated test to use switch button instead of icon button.

The test now correctly looks for the new switch component with data-testid "switch-additional-info-fields" instead of the previous icon button.


138-140: Tests updated to use switch button interaction.

The test now properly targets the switch button for interaction testing, maintaining test coverage for the toggle functionality with the new UI component.


154-155: Click event maintained for toggling state.

The test correctly maintains the same logic for testing the toggle functionality, with just the target element changed from icon button to switch.


180-185: Added switch state verification.

Good addition of tests to verify the checked/unchecked state of the switch button, which ensures the switch visual state is correctly synchronized with the component's internal state.


209-290: Added new test suite for UPDATE requests with invalid data.

This is a good addition that tests an important edge case: when a form contains invalid data in the additional fields, but those fields are hidden, the submit button should still be enabled. This test ensures the validation logic works correctly with the new toggle switch implementation.

src/react/src/components/Contribute/ProductionLocationInfo.jsx (6)

11-11: Added Switch component import.

The Material-UI Switch component is correctly imported to replace the previous IconButton for toggling additional information.


108-130: New method to fill additional data fields.

This method properly initializes the form's additional fields with data from the existing record when the switch is toggled on. Good implementation of the convertRangeField utility for number of workers and consistent use of updateStateFromData for other fields.


132-139: New method to reset additional data fields.

This method correctly resets all additional data fields to their default values when the switch is toggled off, ensuring no stale data remains in the form state.


224-235: New switch state handling implementation.

The implementation for managing the switch state and toggling additional information fields is well-structured:

  1. Uses a boolean state variable for tracking visibility
  2. Updates the state with a functional state update (recommended pattern)
  3. Calls appropriate methods to fill or reset data fields based on the toggle state

This is a clean implementation that properly separates concerns.


589-599: Replaced icon button with Switch component.

The Switch component implementation is well-configured:

  1. Color set to "primary" for consistent theming
  2. Proper event handler for toggle action
  3. State controlled via the checked prop
  4. Test ID added for testing
  5. z-index style to prevent any potential layout issues

This is a more intuitive UI element for toggling visibility compared to the previous icon button.


609-609: Updated conditional rendering to use switch state.

The conditional rendering now correctly uses the showAdditionalInfo state variable to determine whether to display the additional information fields.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/react/src/__tests__/components/ProductionLocationInfo.test.js (1)

273-289: Consider adding an edge case test.

While the current test verifies the basic toggle behavior, consider adding a test for the edge case where the user first expands the additional info section (disabling the update button due to invalid data), then collapses it again. The expected behavior would be that the update button becomes enabled again since the invalid fields are hidden.

 test("update button should be enabled when number of workers invalid but additional info is hidden", () => {
     const { getByRole, getByText, getByTestId, getByPlaceholderText, queryByText } = renderComponent();

     expect(queryByText("Enter the number of workers as a number or range")).not.toBeInTheDocument();

     const updateButton = getByRole("button", { name: /Update/i });
     expect(updateButton).toBeEnabled();

     const switchButton = getByTestId("switch-additional-info-fields");
     fireEvent.click(switchButton);

     const numberOfWorkersInput = getByPlaceholderText("Enter the number of workers as a number or range");
     expect(numberOfWorkersInput).toHaveAttribute("aria-invalid", "true");
     expect(getByText("Enter the number of workers as a number or range")).toBeInTheDocument();

     expect(updateButton).toBeDisabled();
+
+    // Test that hiding the section re-enables the update button
+    fireEvent.click(switchButton);
+    expect(queryByText("Enter the number of workers as a number or range")).not.toBeInTheDocument();
+    expect(updateButton).toBeEnabled();
 });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d20a33 and f64bd10.

📒 Files selected for processing (1)
  • src/react/src/__tests__/components/ProductionLocationInfo.test.js (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-django-cov
🔇 Additional comments (6)
src/react/src/__tests__/components/ProductionLocationInfo.test.js (6)

3-3: Good update to the import statement.

The addition of MemoryRouter and Route from react-router-dom is appropriate for the new test suite that simulates URL-based routing with the osID parameter.


32-32: Clear test suite description.

The updated description clearly specifies that this test suite focuses on POST requests to the production locations endpoint, which helps differentiate it from the new UPDATE request test suite added later.


92-94: Switch element correctly implemented in tests.

The test correctly looks for the new switch component using the appropriate test ID, aligning with the PR objective of replacing the arrow dropdown icon with a toggle switch.


138-140: UI interaction correctly updated.

The reference to the switch button and the click interaction properly match the updated component implementation.


180-185: Complete test coverage for switch functionality.

The test now correctly verifies both the initial unchecked state of the switch button and the checked state after clicking, ensuring the toggle functionality works as expected.


209-290: Well-structured test for invalid update scenarios.

This test suite effectively addresses a key PR objective: verifying that the Update button is disabled when the Additional data section is expanded and contains invalid fields (number of workers starting from zero). The test demonstrates that:

  1. The Update button is initially enabled with the additional info section hidden
  2. After expanding the section, invalid data causes the button to be disabled

The comprehensive test data setup with realistic production location data makes this test highly valuable.

roman-stolar
roman-stolar previously approved these changes Mar 5, 2025
Copy link
Contributor

@roman-stolar roman-stolar left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/react/src/__tests__/components/ProductionLocationInfo.test.js (1)

209-294: Good test coverage for invalid input handling with the toggle.

This new test suite effectively demonstrates the behavior specified in the PR objectives where:

  1. The Update button is enabled by default
  2. The Update button is disabled when additional fields are shown with invalid data
  3. The Update button becomes enabled again when additional fields are hidden

Consider adding more test cases for other validation scenarios mentioned in the PR objectives, such as testing that pre-filled values are sent to the server when the additional data section is expanded.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac1061e and aff075c.

📒 Files selected for processing (1)
  • src/react/src/__tests__/components/ProductionLocationInfo.test.js (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-fe-cov
🔇 Additional comments (7)
src/react/src/__tests__/components/ProductionLocationInfo.test.js (7)

3-3: Good addition of router components for testing.

The addition of MemoryRouter and Route is appropriate for the new test suite that tests route-dependent behavior.


32-32: Improved test description clarity.

The updated description clarifies the purpose of the test suite, making it more maintainable.


92-94: UI component change properly tested.

The test has been correctly updated to check for the new switch button instead of the previous icon button implementation.


138-140: Testing click interaction with switch is appropriate.

Good test for interaction with the switch button to toggle the additional information fields.


180-185: Good switch state verification.

The test now properly verifies the state of the switch button (checked/unchecked), which is essential for confirming the toggle behavior functions correctly.


273-293: Comprehensive test for toggle behavior with invalid data.

This test effectively verifies that:

  1. The Update button is initially enabled (when additional fields are hidden)
  2. When the additional fields are shown with invalid data, the Update button is disabled
  3. When the additional fields are hidden again, the Update button is re-enabled

This matches the PR objective of hiding the Additional data section by default and controlling the Update button state based on field validity.


235-240:

Details

✅ Verification successful

Verify min value of zero is correctly identified as invalid.

The test data correctly includes an invalid number_of_workers range (starting from zero), which aligns with the PR objective stating "When the Additional data section is expanded, the Update button may be disabled if there are invalid incoming fields, such as a number of workers range starting from zero."


🌐 Web query:

Is zero an invalid value for minimum number of workers in manufacturing facilities?

💡 Result:

The concept of a manufacturing facility operating with zero workers is not explicitly addressed in regulatory or industry standards as an "invalid" value, but practical and operational realities make it infeasible. Here’s the breakdown:

Workforce Requirements in Manufacturing

  1. Human Oversight and Maintenance: Even highly automated facilities require human intervention for maintenance, quality control, and system management. For example, collaborative robotics (mentioned in [9]) still necessitate human oversight for programming, troubleshooting, and safety checks.
  2. Regulatory and Safety Compliance: OSHA standards (referenced in [8]) mandate safety protocols, training, and emergency response measures, which inherently require human presence to implement and monitor.
  3. Employment Data: The Bureau of Labor Statistics ([10]) lists employment estimates for production roles across industries, indicating that even in highly automated sectors like motor vehicle manufacturing, workers are still present for operational roles.

Automation and Workforce Trends

  • Zero-Based Factory Design: While BCG’s zero-based approach ([9]) emphasizes reimagining operations through digitization and automation, it does not advocate for eliminating all workers. Instead, it focuses on optimizing human roles alongside technology (e.g., using temporary workers or upskilling employees).
  • Labor Gaps: Studies ([1][7]) highlight shortages in technical roles like maintenance technicians and engineers, underscoring the ongoing need for skilled human labor despite automation.

Conclusion

A manufacturing facility cannot realistically operate with zero workers due to the need for oversight, compliance, and roles that automation cannot fully replace. While automation reduces labor dependency, a minimal workforce remains essential for operational integrity.

Citations:


Invalid Minimum Worker Count Is Correctly Tested

The test data in src/react/src/__tests__/components/ProductionLocationInfo.test.js (lines 235–240) appropriately sets number_of_workers.min to 0. Given that a manufacturing facility realistically requires at least one worker for oversight and operational integrity, using a zero minimum is an effective way to trigger the invalid state (and consequently disable the Update button) as intended by the PR objectives.

roman-stolar
roman-stolar previously approved these changes Mar 5, 2025
Copy link
Contributor

@roman-stolar roman-stolar left a comment

Choose a reason for hiding this comment

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

Re-Approve

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2025

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants