Skip to content

refactor(frontend): avoid redundant validateOperator call in applyOperatorBorder#5702

Open
PG1204 wants to merge 2 commits into
apache:mainfrom
PG1204:refactor/apply-operator-border-reuse-validation
Open

refactor(frontend): avoid redundant validateOperator call in applyOperatorBorder#5702
PG1204 wants to merge 2 commits into
apache:mainfrom
PG1204:refactor/apply-operator-border-reuse-validation

Conversation

@PG1204

@PG1204 PG1204 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

WorkflowEditorComponent.applyOperatorBorder(operatorID)` always recomputes validation as its first step:

const validation = this.validationWorkflowService.validateOperator(operatorID);

This is redundant when the helper is called from the validation-stream subscriber in handleOperatorValidation, the stream's emitted event already carries the Validation result that was just computed by updateValidationState.

This PR:

  • Adds an optional validation?: Validation parameter to applyOperatorBorder. The helper uses it when provided, and falls back to validateOperator(operatorID) otherwise.
  • Updates handleOperatorValidation to pass value.validation from the stream into the helper.
  • Leaves the operator-add stream subscriber unchanged and hence it doesn't have a Validation in hand at that point, so it correctly falls through to the lazy-fetch path.
  • Functionally identical (the stream emits the same Validation that would have been recomputed), purely avoids the duplicate call.

Originally flagged as an optional nit during the PR #5146 review. Attempted in PR #5626 but split out as per the reviewer's request so that PR could stay scoped to test restructuring; this PR completes the follow-up.

Any related issues, documentation, discussions?

Closes #5683
Related: PR #5146 (where the nit was raised), PR #5626 (where this was attempted and split out).

How was this PR tested?

Added one focused unit test in workflow-editor.component.spec.ts inside the existing operator border restoration after navigation describe block: it("uses the Validation passed in instead of recomputing it", ...). The test clears the validateOperator spy after the operator-add validation chain settles, then calls applyOperatorBorder directly with a Validation argument and asserts validateOperator is not called.

Verified locally:

  • tsc --noEmit: clean
  • eslint: clean
  • ng test (jsdom): 26/26 pass in the editor spec (was 25, new test adds one)
  • ng run gui:test-browser: 13/13 pass

Was this PR authored or co-authored using generative AI tooling?

This PR was co-authored using Claude Code (Anthropic Claude Opus 4.7)

@github-actions github-actions Bot added refactor Refactor the code frontend Changes related to the frontend GUI labels Jun 14, 2026
@codecov-commenter

codecov-commenter commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.71%. Comparing base (891d2ad) to head (27a2cf0).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5702      +/-   ##
============================================
- Coverage     52.95%   52.71%   -0.25%     
+ Complexity     2627     2501     -126     
============================================
  Files          1090     1090              
  Lines         42210    42053     -157     
  Branches       4534     4520      -14     
============================================
- Hits          22353    22167     -186     
- Misses        18546    18569      +23     
- Partials       1311     1317       +6     
Flag Coverage Δ *Carryforward flag
access-control-service 71.42% <ø> (+0.51%) ⬆️ Carriedforward from 58e5b43
agent-service 34.36% <ø> (ø) Carriedforward from 58e5b43
amber 52.56% <ø> (-0.56%) ⬇️ Carriedforward from 58e5b43
computing-unit-managing-service 1.65% <ø> (ø) Carriedforward from 58e5b43
config-service 56.71% <ø> (ø) Carriedforward from 58e5b43
file-service 57.06% <ø> (ø) Carriedforward from 58e5b43
frontend 47.89% <100.00%> (-0.04%) ⬇️
pyamber 90.71% <ø> (+0.93%) ⬆️ Carriedforward from 58e5b43
python 90.73% <ø> (ø) Carriedforward from 58e5b43
workflow-compiling-service 58.69% <ø> (ø) Carriedforward from 58e5b43

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PG1204

PG1204 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

/request-review @Xiao-zhen-Liu

Follow-up for the split-out applyOperatorBorder change: #5626. Includes the test for the "validation passed in" path.

@github-actions github-actions Bot requested a review from Xiao-zhen-Liu June 14, 2026 00:17
Comment on lines +406 to 410
const resolved = validation ?? this.validationWorkflowService.validateOperator(operatorID);
if (!resolved.isValid) {
this.jointUIService.changeOperatorColor(this.paper, operatorID, false);
return;
}

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.

if all validations are done already, we could even remove this if fallback?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question, but I think keeping the fallback would be good to have. It's there for the operator-add case, which fires before validation has been computed (separate event streams), so there's genuinely no validation result to pass in at that point. That path was added for the navigation-reset fix (#3614) and needs to color the border right away. The optimization just removes the duplicate computation on the validation-handler path, where we already have the result. Happy to revisit if you're seeing a case where validation always runs first.

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.

ok. can we combine the logic of operator-add case? I think logically it should also have a validation result right away. maybe a follow up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i agree with this, this would be a good follow up. The two paths currently run off separate event streams (operator-add restore vs. the validation stream), so unifying them so a new operator is validated/painted exactly once is worth doing, should be done carefully though, especially to preserve the #3614 navigation-reset behavior. I can file a follow-up issue to track it so we can keep this PR scoped.
Thanks!

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.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Changes related to the frontend GUI refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reuse validation result from the validation stream in applyOperatorBorder

3 participants