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

fix: Check for circular references #13783

Merged
merged 6 commits into from
Oct 30, 2024
Merged

Conversation

TomasEng
Copy link
Contributor

@TomasEng TomasEng commented Oct 14, 2024

Description

Added an alert that pops up when an operation (either moving a node or adding a reference) would lead to a state with circular references, which we currently don't support.

This is done using a new method on the SchemaModel class, which I named willResultInCircularReferences. It takes the potential child node pointer and the target pointer as parameters and returns true when the target pointer is within a definition that is already referred by the potential child or one of its subnodes.

Demos

Adding references

In the following examples, type1 can't be dragged into type2 since type1 contains a reference to type2.
https://github.com/user-attachments/assets/91cd845d-8aee-45d3-af7e-372cac02d76b
https://github.com/user-attachments/assets/c3ca19f1-b805-4ab1-ae8d-e17a310b22f8

Moving references

In this example, a reference to type2 is being dragged into another reference to type2.
https://github.com/user-attachments/assets/2d1c4246-a043-4dbe-b6df-4e610640f2fa

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

@github-actions github-actions bot added area/data-modeling Area: Related to data models - e.g. create, edit, use data models. solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Oct 14, 2024
@TomasEng TomasEng linked an issue Oct 14, 2024 that may be closed by this pull request
@TomasEng TomasEng changed the title Check for circular references fix: Check for circular references Oct 14, 2024
@TomasEng TomasEng force-pushed the check-for-circular-references branch from 15c547a to 4666c82 Compare October 14, 2024 13:00
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.18%. Comparing base (951d041) to head (172817e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13783      +/-   ##
==========================================
+ Coverage   95.16%   95.18%   +0.01%     
==========================================
  Files        1690     1691       +1     
  Lines       22354    22438      +84     
  Branches     2622     2630       +8     
==========================================
+ Hits        21273    21357      +84     
  Misses        835      835              
  Partials      246      246              

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

@TomasEng TomasEng force-pushed the check-for-circular-references branch from 4666c82 to 45aefdf Compare October 15, 2024 06:04
@TomasEng TomasEng marked this pull request as ready for review October 15, 2024 06:27
Copy link
Contributor

@standeren standeren left a comment

Choose a reason for hiding this comment

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

Looks good! Impressive work 💎

# Conflicts:
#	frontend/packages/schema-model/src/lib/SchemaModel/SchemaModel.ts
@TomasEng TomasEng requested a review from standeren October 22, 2024 07:41
Copy link
Contributor

@standeren standeren left a comment

Choose a reason for hiding this comment

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

Nice 🥳

Copy link
Contributor

@Konrad-Simso Konrad-Simso left a comment

Choose a reason for hiding this comment

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

Good work 🚀 it works as expected 😄

@TomasEng TomasEng merged commit 3f0ff04 into main Oct 30, 2024
10 checks passed
@TomasEng TomasEng deleted the check-for-circular-references branch October 30, 2024 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/data-modeling Area: Related to data models - e.g. create, edit, use data models. frontend solution/studio/designer Issues related to the Altinn Studio Designer solution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Studio crashes when adding type to the same type
3 participants