Skip to content

refactor(web): decompose NewInspectionDialogComponent into smart and dumb components - #1052

Merged
kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-osollnyuvulx
Sep 28, 2026
Merged

kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-osollnyuvulx

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 28, 2026

Copy link
Copy Markdown
Member

Background & Problem

NewInspectionDialogComponent previously combined all three wizard steps (inspection type selection, feature selection, and parameter input/metadata preview), backend API orchestration, reactive dryrun streams, and pure domain calculations into a single ~800-line component with a 240-line template and 286-line stylesheet. This monolithic structure violated KHI's Smart-Dumb component architecture and made it impossible to inspect or test the visual states of individual wizard steps in Storybook without mocking the backend API and dialog services.

Solution Approach

This PR decomposes the New Inspection dialog into a Smart container, a Layout component, three step-specific Dumb components, and extracted pure utility functions while preserving all existing runtime behavior:

  • Smart Container (NewInspectionDialogSmartComponent): Retains service dependencies (BACKEND_API, PARAMETER_STORE, FILE_UPLOADER, MatDialogRef, MAT_DIALOG_DATA), manages wizard state via Angular Signals, and coordinates reactive dryrun streams. Its template only renders <khi-new-inspection-layout> with :host { display: contents; }.
  • Layout & Step Dumb Components:
    • NewInspectionLayoutComponent: Manages the dialog title and <mat-stepper> layout, delegating each step's content and events via input() and output().
    • InspectionTypeSelectorComponent: Renders Step 1 (inspection target cards and loading progress indicator).
    • FeatureSelectorComponent: Renders Step 2 (feature toggle cards, empty selection validation message, and Next button).
    • ParameterInputStepComponent: Renders Step 3 (parameter form tree, estimated log volume callout, query cards, job command preview, task graph plan, and Run footer). Also speeds up GroupParameterComponent expand/collapse transitions from 500ms to 150ms and adds Storybook coverage for GroupParameterComponent.
  • Pure Domain Utilities & Types: Extracts view models and dialog types into types/new-inspection.types.ts and pure helper functions (computeTotalEstimatedLogs, hasFormErrors, hasDryRunErrors, flattenDefaultValues, countErrorFields, countPendingFields, countAllFields, buildParameterStepViewModel) into utils/new-inspection.utils.ts with dedicated unit tests.

Alternatives Considered

  • Splitting only NewInspectionLayoutComponent without per-step Dumb components: Rejected because keeping all three steps inside a single layout template would still leave a ~240-line template and prevent isolated Storybook stories and unit tests per wizard step.

Remaining Issues & Future Work

None.

@kyasbal kyasbal added the area:frontend Web frontend application and UI components label Sep 28, 2026
@kyasbal
kyasbal requested a review from RyuSA as a code owner September 28, 2026 06:27
@kyasbal kyasbal added the type:refactor Code refactoring without behavioral change label Sep 28, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the new inspection wizard by decomposing the monolithic NewInspectionDialogComponent into a clean, modular architecture consisting of a smart component (NewInspectionDialogComponent), a layout component (NewInspectionLayoutComponent), and dedicated sub-components for each step (InspectionTypeSelectorComponent, FeatureSelectorComponent, and ParameterInputStepComponent). It also extracts core logic into a utility file with comprehensive unit tests and adds Storybook stories. The review feedback highlights several key improvement opportunities: wrapping the asynchronous client fetch in a try-catch block to handle failures and aborts gracefully, cleaning up the 'abort' event listener in the delay helper to prevent memory leaks, securing flattenDefaultValues against prototype pollution by using Object.create(null) and filtering dangerous keys, and tracking queries by id instead of name in the template's @for loop to ensure stable rendering.

@kyasbal
kyasbal added this pull request to the merge queue Sep 28, 2026
Merged via the queue into GoogleCloudPlatform:main with commit aef8256 Sep 28, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-osollnyuvulx branch September 28, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Web frontend application and UI components type:refactor Code refactoring without behavioral change

1 participant